summaryrefslogtreecommitdiff
path: root/sw/qa/complex/writer/CheckTable.java
blob: 50ce8c76c64ee773d16addf1285a4e84292e2518 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

package complex.writer;

import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.RuntimeException;
import com.sun.star.uno.XComponentContext;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.beans.XPropertySet;
import com.sun.star.beans.XPropertySetInfo;
import com.sun.star.beans.Property;
import com.sun.star.text.XText;
import com.sun.star.text.XTextDocument;
import com.sun.star.text.XTextCursor;
import com.sun.star.text.XTextRange;
import com.sun.star.text.XTextTable;
import com.sun.star.table.TableBorder;
import com.sun.star.table.TableBorder2;
import com.sun.star.table.BorderLine;
import com.sun.star.table.BorderLine2;
import static com.sun.star.table.BorderLineStyle.*;

import org.openoffice.test.OfficeConnection;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;


public class CheckTable
{
    private static final OfficeConnection connection = new OfficeConnection();

    @BeforeClass public static void setUpConnection() throws Exception {
        connection.setUp();
//Thread.sleep(5000);
    }

    @AfterClass public static void tearDownConnection()
        throws InterruptedException, com.sun.star.uno.Exception
    {
        connection.tearDown();
    }

    private XMultiServiceFactory m_xMSF = null;
    private XComponentContext m_xContext = null;
    private XTextDocument m_xDoc = null;

    @Before public void before() throws Exception
    {
        m_xMSF = UnoRuntime.queryInterface(
            XMultiServiceFactory.class,
            connection.getComponentContext().getServiceManager());
        m_xContext = connection.getComponentContext();
        assertNotNull("could not get component context.", m_xContext);
        m_xDoc = util.WriterTools.createTextDoc(m_xMSF);
    }

    @After public void after()
    {
        util.DesktopTools.closeDoc(m_xDoc);
    }

    @Test
    public void test_tableborder() throws Exception
    {
        // insert table
        XMultiServiceFactory xDocF =
            UnoRuntime.queryInterface(XMultiServiceFactory.class, m_xDoc);
        XTextTable xTable = UnoRuntime.queryInterface(XTextTable.class,
            xDocF.createInstance("com.sun.star.text.TextTable"));
        xTable.initialize(3, 3);
        XText xText = m_xDoc.getText();
        XTextCursor xCursor = xText.createTextCursor();
        xText.insertTextContent(xCursor, xTable, false);
        // read orig border
        XPropertySet xProps = UnoRuntime.queryInterface(XPropertySet.class,
                xTable);
        TableBorder border = (TableBorder) xProps.getPropertyValue("TableBorder");
        assertTrue(border.IsTopLineValid);
        assertEquals(0, border.TopLine.InnerLineWidth);
        assertEquals(2, border.TopLine.OuterLineWidth);
        assertEquals(0, border.TopLine.LineDistance);
        assertEquals(0, border.TopLine.Color);
        assertTrue(border.IsBottomLineValid);
        assertEquals(0, border.BottomLine.InnerLineWidth);
        assertEquals(2, border.BottomLine.OuterLineWidth);
        assertEquals(0, border.BottomLine.LineDistance);
        assertEquals(0, border.BottomLine.Color);
        assertTrue(border.IsLeftLineValid);
        assertEquals(0, border.LeftLine.InnerLineWidth);
        assertEquals(2, border.LeftLine.OuterLineWidth);
        assertEquals(0, border.LeftLine.LineDistance);
        assertEquals(0, border.LeftLine.Color);
        assertTrue(border.IsRightLineValid);
        assertEquals(0, border.RightLine.InnerLineWidth);
        assertEquals(2, border.RightLine.OuterLineWidth);
        assertEquals(0, border.RightLine.LineDistance);
        assertEquals(0, border.RightLine.Color);
        assertTrue(border.IsHorizontalLineValid);
        assertEquals(0, border.HorizontalLine.InnerLineWidth);
        assertEquals(2, border.HorizontalLine.OuterLineWidth);
        assertEquals(0, border.HorizontalLine.LineDistance);
        assertEquals(0, border.HorizontalLine.Color);
        assertTrue(border.IsVerticalLineValid);
        assertEquals(0, border.VerticalLine.InnerLineWidth);
        assertEquals(2, border.VerticalLine.OuterLineWidth);
        assertEquals(0, border.VerticalLine.LineDistance);
        assertEquals(0, border.VerticalLine.Color);
        assertTrue(border.IsDistanceValid);
        assertEquals(97, border.Distance);
        // set border
        border.TopLine = new BorderLine(0, (short)11, (short)19, (short)19);
        border.BottomLine = new BorderLine(0xFF, (short)0, (short)11, (short)0);
        border.HorizontalLine = new BorderLine(0xFF00, (short)0, (short)90, (short)0);
        xProps.setPropertyValue("TableBorder", border);
        // read set border
        border = (TableBorder) xProps.getPropertyValue("TableBorder");
        assertTrue(border.IsTopLineValid);
        assertEquals(11, border.TopLine.InnerLineWidth);
        assertEquals(19, border.TopLine.OuterLineWidth);
        assertEquals(19, border.TopLine.LineDistance);
        assertEquals(0, border.TopLine.Color);
        assertTrue(border.IsBottomLineValid);
        assertEquals(0, border.BottomLine.InnerLineWidth);
        assertEquals(11, border.BottomLine.OuterLineWidth);
        assertEquals(0, border.BottomLine.LineDistance);
        assertEquals(0xFF, border.BottomLine.Color);
        assertTrue(border.IsLeftLineValid);
        assertEquals(0, border.LeftLine.InnerLineWidth);
        assertEquals(2, border.LeftLine.OuterLineWidth);
        assertEquals(0, border.LeftLine.LineDistance);
        assertEquals(0, border.LeftLine.Color);
        assertTrue(border.IsRightLineValid);
        assertEquals(0, border.RightLine.InnerLineWidth);
        assertEquals(2, border.RightLine.OuterLineWidth);
        assertEquals(0, border.RightLine.LineDistance);
        assertEquals(0, border.RightLine.Color);
        assertTrue(border.IsHorizontalLineValid);
        assertEquals(0, border.HorizontalLine.InnerLineWidth);
        assertEquals(90, border.HorizontalLine.OuterLineWidth);
        assertEquals(0, border.HorizontalLine.LineDistance);
        assertEquals(0xFF00, border.HorizontalLine.Color);
        assertTrue(border.IsVerticalLineValid);
        assertEquals(0, border.VerticalLine.InnerLineWidth);
        assertEquals(2, border.VerticalLine.OuterLineWidth);
        assertEquals(0, border.VerticalLine.LineDistance);
        assertEquals(0, border.VerticalLine.Color);
        assertTrue(border.IsDistanceValid);
        assertEquals(97, border.Distance);
        TableBorder2 border2 = (TableBorder2) xProps.getPropertyValue("TableBorder2");
        assertTrue(border2.IsTopLineValid);
        assertEquals(11, border2.TopLine.InnerLineWidth);
        assertEquals(19, border2.TopLine.OuterLineWidth);
        assertEquals(19, border2.TopLine.LineDistance);
        assertEquals(0, border2.TopLine.Color);
        assertEquals(DOUBLE, border2.TopLine.LineStyle);
        assertEquals(49, border2.TopLine.LineWidth);
        assertTrue(border2.IsBottomLineValid);
        assertEquals(0, border2.BottomLine.InnerLineWidth);
        assertEquals(11, border2.BottomLine.OuterLineWidth);
        assertEquals(0, border2.BottomLine.LineDistance);
        assertEquals(0xFF, border2.BottomLine.Color);
        assertEquals(SOLID, border2.BottomLine.LineStyle);
        assertEquals(11, border2.BottomLine.LineWidth);
        assertTrue(border2.IsLeftLineValid);
        assertEquals(0, border2.LeftLine.InnerLineWidth);
        assertEquals(2, border2.LeftLine.OuterLineWidth);
        assertEquals(0, border2.LeftLine.LineDistance);
        assertEquals(0, border2.LeftLine.Color);
        assertEquals(SOLID, border2.LeftLine.LineStyle);
        assertEquals(2, border2.LeftLine.LineWidth);
        assertTrue(border2.IsRightLineValid);
        assertEquals(0, border2.RightLine.InnerLineWidth);
        assertEquals(2, border2.RightLine.OuterLineWidth);
        assertEquals(0, border2.RightLine.LineDistance);
        assertEquals(0, border2.RightLine.Color);
        assertEquals(SOLID, border2.RightLine.LineStyle);
        assertEquals(2, border2.RightLine.LineWidth);
        assertTrue(border2.IsHorizontalLineValid);
        assertEquals(0, border2.HorizontalLine.InnerLineWidth);
        assertEquals(90, border2.HorizontalLine.OuterLineWidth);
        assertEquals(0, border2.HorizontalLine.LineDistance);
        assertEquals(0xFF00, border2.HorizontalLine.Color);
        assertEquals(SOLID, border2.HorizontalLine.LineStyle);
        assertEquals(90, border2.HorizontalLine.LineWidth);
        assertTrue(border2.IsVerticalLineValid);
        assertEquals(0, border2.VerticalLine.InnerLineWidth);
        assertEquals(2, border2.VerticalLine.OuterLineWidth);
        assertEquals(0, border2.VerticalLine.LineDistance);
        assertEquals(0, border2.VerticalLine.Color);
        assertEquals(SOLID, border2.VerticalLine.LineStyle);
        assertEquals(2, border2.VerticalLine.LineWidth);
        assertTrue(border2.IsDistanceValid);
        assertEquals(97, border2.Distance);

        // set border2
        border2.RightLine =
            new BorderLine2(0, (short)0, (short)0, (short)0, THICKTHIN_LARGEGAP, 120);
        border2.LeftLine =
            new BorderLine2(0, (short)0, (short)0, (short)0, EMBOSSED, 90);
        border2.VerticalLine =
            new BorderLine2(0xFF, (short)0, (short)90, (short)0, DOTTED, 0);
        border2.HorizontalLine =
            new BorderLine2(0xFF00, (short)0, (short)0, (short)0, DASHED, 11);
        xProps.setPropertyValue("TableBorder2", border2);

        // read set border2
        border2 = (TableBorder2) xProps.getPropertyValue("TableBorder2");
        assertTrue(border2.IsTopLineValid);
        assertEquals(11, border2.TopLine.InnerLineWidth);
        assertEquals(19, border2.TopLine.OuterLineWidth);
        assertEquals(19, border2.TopLine.LineDistance);
        assertEquals(0, border2.TopLine.Color);
        assertEquals(DOUBLE, border2.TopLine.LineStyle);
        assertEquals(49, border2.TopLine.LineWidth);
        assertTrue(border2.IsBottomLineValid);
        assertEquals(0, border2.BottomLine.InnerLineWidth);
        assertEquals(11, border2.BottomLine.OuterLineWidth);
        assertEquals(0, border2.BottomLine.LineDistance);
        assertEquals(0xFF, border2.BottomLine.Color);
        assertEquals(SOLID, border2.BottomLine.LineStyle);
        assertEquals(11, border2.BottomLine.LineWidth);
        assertTrue(border2.IsLeftLineValid);
        assertEquals(23, border2.LeftLine.InnerLineWidth);
        assertEquals(23, border2.LeftLine.OuterLineWidth);
        assertEquals(46, border2.LeftLine.LineDistance);
        assertEquals(0, border2.LeftLine.Color);
        assertEquals(EMBOSSED, border2.LeftLine.LineStyle);
        assertEquals(90, border2.LeftLine.LineWidth);
        assertTrue(border2.IsRightLineValid);
        assertEquals(53, border2.RightLine.InnerLineWidth);
        assertEquals(26, border2.RightLine.OuterLineWidth);
        assertEquals(41, border2.RightLine.LineDistance);
        assertEquals(0, border2.RightLine.Color);
        assertEquals(THICKTHIN_LARGEGAP, border2.RightLine.LineStyle);
        assertEquals(120, border2.RightLine.LineWidth);
        assertTrue(border2.IsHorizontalLineValid);
        assertEquals(0, border2.HorizontalLine.InnerLineWidth);
        assertEquals(11, border2.HorizontalLine.OuterLineWidth);
        assertEquals(0, border2.HorizontalLine.LineDistance);
        assertEquals(0xFF00, border2.HorizontalLine.Color);
        assertEquals(DASHED, border2.HorizontalLine.LineStyle);
        assertEquals(11, border2.HorizontalLine.LineWidth);
        assertTrue(border2.IsVerticalLineValid);
        assertEquals(0, border2.VerticalLine.InnerLineWidth);
        assertEquals(90, border2.VerticalLine.OuterLineWidth);
        assertEquals(0, border2.VerticalLine.LineDistance);
        assertEquals(0xFF, border2.VerticalLine.Color);
        assertEquals(DOTTED, border2.VerticalLine.LineStyle);
        assertEquals(90, border2.VerticalLine.LineWidth);
        assertTrue(border2.IsDistanceValid);
        assertEquals(97, border2.Distance);
    }

    @Test
    public void test_fdo58242() throws Exception
    {
        // insert table
        XMultiServiceFactory xDocF =
            UnoRuntime.queryInterface(XMultiServiceFactory.class, m_xDoc);
        XTextTable xTable = UnoRuntime.queryInterface(XTextTable.class,
            xDocF.createInstance("com.sun.star.text.TextTable"));
        xTable.initialize(3, 3);
        XText xText = m_xDoc.getText();
        XTextCursor xCursor = xText.createTextCursor();
        xText.insertTextContent(xCursor, xTable, false);
        // get anchor
        XTextRange xAnchor = xTable.getAnchor();
        // check all properties on the anchor - shouldn't crash despite
        // pointing to a non-SwTxtNode
        XPropertySet xProps = UnoRuntime.queryInterface(XPropertySet.class, xAnchor);
        XPropertySetInfo xPropsInfo = xProps.getPropertySetInfo();
        Property[] props = xPropsInfo.getProperties();
        for (int i = 0; i < props.length; ++i)
        {
            try {
                xProps.getPropertyValue(props[i].Name);
            } catch (RuntimeException e) { }
        }
    }
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */