2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 import java
.io
.PrintWriter
;
22 import lib
.StatusException
;
24 import lib
.TestEnvironment
;
25 import lib
.TestParameters
;
26 import util
.SOfficeFactory
;
27 import util
.ValueComparer
;
29 import com
.sun
.star
.beans
.XPropertySet
;
30 import com
.sun
.star
.lang
.XMultiServiceFactory
;
31 import com
.sun
.star
.table
.XCell
;
32 import com
.sun
.star
.text
.XTextContent
;
33 import com
.sun
.star
.text
.XTextDocument
;
34 import com
.sun
.star
.text
.XTextRange
;
35 import com
.sun
.star
.text
.XTextTable
;
36 import com
.sun
.star
.uno
.UnoRuntime
;
40 * this class tests the implementation of listed interfaces
41 * @see com.sun.star.beans.XPropertySet
42 * @see com.sun.star.container.XNamed
43 * @see com.sun.star.lang.XComponent
44 * @see com.sun.star.text.TextContent
45 * @see com.sun.star.text.XTextContent
46 * @see com.sun.star.text.XTextTable
48 public class SwXTextTable
extends TestCase
{
50 XTextDocument xTextDoc
;
52 protected void initialize(TestParameters tParam
, PrintWriter log
) {
53 SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
) tParam
.getMSF());
56 log
.println("creating a textdocument");
57 xTextDoc
= SOF
.createTextDoc(null);
58 } catch (com
.sun
.star
.uno
.Exception e
) {
59 // Some exception occurs.FAILED
60 e
.printStackTrace(log
);
61 throw new StatusException("Couldn't create document", e
);
65 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
66 log
.println(" disposing xTextDoc ");
67 util
.DesktopTools
.closeDoc(xTextDoc
);
71 this method creates the testenvironment
72 @param tParam TestParameters class which contains additional
74 @param log PrintWriter class to log the test state and result
76 @return TestEnvironment class
81 protected synchronized TestEnvironment
createTestEnvironment(TestParameters tParam
,
83 // creation of testobject here
84 XTextTable oObj
= null;
85 TestEnvironment tEnv
= null;
86 Object instance
= null;
89 oObj
= SOfficeFactory
.createTextTable(xTextDoc
);
90 instance
= SOfficeFactory
.createTextTable(xTextDoc
);
91 } catch (com
.sun
.star
.uno
.Exception uE
) {
92 uE
.printStackTrace(log
);
93 throw new StatusException("Couldn't create testobj : " +
99 oObj
.initialize(nRow
, nCol
);
101 log
.println("Creating instance...");
102 tEnv
= new TestEnvironment(oObj
);
104 if (SOfficeFactory
.getTableCollection(xTextDoc
).getCount() == 0) {
106 SOfficeFactory
.insertTextContent(xTextDoc
, oObj
);
107 } catch (com
.sun
.star
.lang
.IllegalArgumentException uE
) {
108 uE
.printStackTrace(log
);
109 throw new StatusException("Couldn't create TextTable : " +
110 uE
.getMessage(), uE
);
114 XPropertySet props
= UnoRuntime
.queryInterface(
115 XPropertySet
.class, oObj
);
118 props
.setPropertyValue("ChartRowAsLabel", new Boolean(true));
119 props
.setPropertyValue("ChartColumnAsLabel", new Boolean(true));
120 } catch (Exception e
) {
121 e
.printStackTrace(log
);
125 //Adding relation for util.XTextTable
126 tEnv
.addObjRelation("NROW", new Integer(nRow
));
127 tEnv
.addObjRelation("NCOL", new Integer(nCol
));
129 //Adding ObjRelation for XCellRangeData
130 Object
[][] newData
= new Object
[6][];
131 Object
[] line
= new Object
[2];
132 line
[0] = new Double(1.5);
133 line
[1] = new Double(2.5);
140 tEnv
.addObjRelation("NewData", newData
);
142 //Adding relation for util.XSortable
143 final PrintWriter finalLog
= log
;
144 final XTextTable oTable
= oObj
;
145 tEnv
.addObjRelation("SORTCHECKER",
146 new ifc
.util
._XSortable
.XSortChecker() {
147 PrintWriter out
= finalLog
;
149 public void setPrintWriter(PrintWriter log
) {
153 public void prepareToSort() {
154 oTable
.getCellByName("A1").setValue(4);
156 XTextRange textRange
= UnoRuntime
.queryInterface(
158 oTable
.getCellByName("A2"));
159 textRange
.setString("b");
160 oTable
.getCellByName("A3").setValue(3);
161 textRange
= UnoRuntime
.queryInterface(
163 oTable
.getCellByName("A4"));
164 textRange
.setString("a");
165 oTable
.getCellByName("A5").setValue(23);
166 textRange
= UnoRuntime
.queryInterface(
168 oTable
.getCellByName("A6"));
169 textRange
.setString("ab");
173 public boolean checkSort(boolean isSortNumbering
,
174 boolean isSortAscending
) {
175 out
.println("Sort checking...");
178 String
[] value
= new String
[6];
180 for (int i
= 0; i
< 6; i
++) {
181 XCell cell
= oTable
.getCellByName("A" + (i
+ 1));
182 XTextRange textRange
= UnoRuntime
.queryInterface(
183 XTextRange
.class, cell
);
184 value
[i
] = textRange
.getString();
187 if (isSortNumbering
) {
188 if (isSortAscending
) {
189 String
[] rightVal
= { "3", "4", "23" };
190 String
[] vals
= { value
[3], value
[4], value
[5] };
191 res
= ValueComparer
.equalValue(vals
, rightVal
);
194 out
.println("Expected: 3, 4, 23");
195 out
.println("Getting: " + value
[3] + ", " +
196 value
[4] + ", " + value
[5]);
199 String
[] rightVal
= { "23", "4", "3" };
200 String
[] vals
= { value
[0], value
[1], value
[2] };
201 res
= ValueComparer
.equalValue(vals
, rightVal
);
204 out
.println("Expected: 23, 4, 3");
205 out
.println("Getting: " + value
[1] + ", " +
206 value
[2] + ", " + value
[3]);
210 if (isSortAscending
) {
211 String
[] rightVal
= { "23", "3", "4", "a", "ab", "b" };
212 res
= ValueComparer
.equalValue(value
, rightVal
);
215 out
.println("Expected: 23, 3, 4, a, ab, b");
216 out
.println("Getting: " + value
[0] + ", " +
217 value
[1] + ", " + value
[2] +
218 ", " + value
[3] + ", " +
219 value
[4] + ", " + value
[5]);
222 String
[] rightVal
= { "b", "ab", "a", "4", "3", "23" };
223 res
= ValueComparer
.equalValue(value
, rightVal
);
226 out
.println("Expected: b, ab, a, 4, 3, 23");
227 out
.println("Getting: " + value
[0] + ", " +
228 value
[1] + ", " + value
[2] +
229 ", " + value
[3] + ", " +
230 value
[4] + ", " + value
[5]);
236 out
.println("Sorted correctly");
238 out
.println("Sorted uncorrectly");
245 tEnv
.addObjRelation("CONTENT",
246 UnoRuntime
.queryInterface(
247 XTextContent
.class, instance
));
248 tEnv
.addObjRelation("RANGE", xTextDoc
.getText().createTextCursor());
252 } // finish class SwXTextTable