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
.table
.XCell
;
31 import com
.sun
.star
.text
.XTextContent
;
32 import com
.sun
.star
.text
.XTextDocument
;
33 import com
.sun
.star
.text
.XTextRange
;
34 import com
.sun
.star
.text
.XTextTable
;
35 import com
.sun
.star
.uno
.UnoRuntime
;
39 * this class tests the implementation of listed interfaces
40 * @see com.sun.star.beans.XPropertySet
41 * @see com.sun.star.container.XNamed
42 * @see com.sun.star.lang.XComponent
43 * @see com.sun.star.text.TextContent
44 * @see com.sun.star.text.XTextContent
45 * @see com.sun.star.text.XTextTable
47 public class SwXTextTable
extends TestCase
{
49 XTextDocument xTextDoc
;
52 protected void initialize(TestParameters tParam
, PrintWriter log
) {
53 SOF
= SOfficeFactory
.getFactory( 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
);
66 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
67 log
.println(" disposing xTextDoc ");
68 util
.DesktopTools
.closeDoc(xTextDoc
);
72 this method creates the testenvironment
73 @param tParam TestParameters class which contains additional
75 @param log PrintWriter class to log the test state and result
77 @return TestEnvironment class
83 protected synchronized TestEnvironment
createTestEnvironment(TestParameters tParam
,
85 // creation of testobject here
86 XTextTable oObj
= null;
87 TestEnvironment tEnv
= null;
88 Object instance
= null;
90 oObj
= SOfficeFactory
.createTextTable(xTextDoc
);
91 instance
= SOfficeFactory
.createTextTable(xTextDoc
);
95 oObj
.initialize(nRow
, nCol
);
97 log
.println("Creating instance...");
98 tEnv
= new TestEnvironment(oObj
);
100 if (SOfficeFactory
.getTableCollection(xTextDoc
).getCount() == 0) {
102 SOfficeFactory
.insertTextContent(xTextDoc
, oObj
);
103 } catch (com
.sun
.star
.lang
.IllegalArgumentException uE
) {
104 uE
.printStackTrace(log
);
105 throw new StatusException("Couldn't create TextTable : " +
106 uE
.getMessage(), uE
);
110 XPropertySet props
= UnoRuntime
.queryInterface(
111 XPropertySet
.class, oObj
);
114 props
.setPropertyValue("ChartRowAsLabel", Boolean
.TRUE
);
115 props
.setPropertyValue("ChartColumnAsLabel", Boolean
.TRUE
);
116 } catch (Exception e
) {
117 e
.printStackTrace(log
);
121 //Adding relation for util.XTextTable
122 tEnv
.addObjRelation("NROW", Integer
.valueOf(nRow
));
123 tEnv
.addObjRelation("NCOL", Integer
.valueOf(nCol
));
125 //Adding ObjRelation for XCellRangeData
126 Object
[][] newData
= new Object
[6][];
127 Object
[] line
= new Object
[2];
128 line
[0] = new Double(1.5);
129 line
[1] = new Double(2.5);
136 tEnv
.addObjRelation("NewData", newData
);
138 //Adding relation for util.XSortable
139 final PrintWriter finalLog
= log
;
140 final XTextTable oTable
= oObj
;
141 tEnv
.addObjRelation("SORTCHECKER",
142 new ifc
.util
._XSortable
.XSortChecker() {
143 PrintWriter out
= finalLog
;
145 public void setPrintWriter(PrintWriter log
) {
149 public void prepareToSort() {
150 oTable
.getCellByName("A1").setValue(4);
152 XTextRange textRange
= UnoRuntime
.queryInterface(
154 oTable
.getCellByName("A2"));
155 textRange
.setString("b");
156 oTable
.getCellByName("A3").setValue(3);
157 textRange
= UnoRuntime
.queryInterface(
159 oTable
.getCellByName("A4"));
160 textRange
.setString("a");
161 oTable
.getCellByName("A5").setValue(23);
162 textRange
= UnoRuntime
.queryInterface(
164 oTable
.getCellByName("A6"));
165 textRange
.setString("ab");
169 public boolean checkSort(boolean isSortNumbering
,
170 boolean isSortAscending
) {
171 out
.println("Sort checking...");
174 String
[] value
= new String
[6];
176 for (int i
= 0; i
< 6; i
++) {
177 XCell cell
= oTable
.getCellByName("A" + (i
+ 1));
178 XTextRange textRange
= UnoRuntime
.queryInterface(
179 XTextRange
.class, cell
);
180 value
[i
] = textRange
.getString();
183 if (isSortNumbering
) {
184 if (isSortAscending
) {
185 String
[] rightVal
= { "3", "4", "23" };
186 String
[] vals
= { value
[3], value
[4], value
[5] };
187 res
= ValueComparer
.equalValue(vals
, rightVal
);
190 out
.println("Expected: 3, 4, 23");
191 out
.println("Getting: " + value
[3] + ", " +
192 value
[4] + ", " + value
[5]);
195 String
[] rightVal
= { "23", "4", "3" };
196 String
[] vals
= { value
[0], value
[1], value
[2] };
197 res
= ValueComparer
.equalValue(vals
, rightVal
);
200 out
.println("Expected: 23, 4, 3");
201 out
.println("Getting: " + value
[1] + ", " +
202 value
[2] + ", " + value
[3]);
206 if (isSortAscending
) {
207 String
[] rightVal
= { "23", "3", "4", "a", "ab", "b" };
208 res
= ValueComparer
.equalValue(value
, rightVal
);
211 out
.println("Expected: 23, 3, 4, a, ab, b");
212 out
.println("Getting: " + value
[0] + ", " +
213 value
[1] + ", " + value
[2] +
214 ", " + value
[3] + ", " +
215 value
[4] + ", " + value
[5]);
218 String
[] rightVal
= { "b", "ab", "a", "4", "3", "23" };
219 res
= ValueComparer
.equalValue(value
, rightVal
);
222 out
.println("Expected: b, ab, a, 4, 3, 23");
223 out
.println("Getting: " + value
[0] + ", " +
224 value
[1] + ", " + value
[2] +
225 ", " + value
[3] + ", " +
226 value
[4] + ", " + value
[5]);
232 out
.println("Sorted correctly");
234 out
.println("Sorted uncorrectly");
241 tEnv
.addObjRelation("CONTENT",
242 UnoRuntime
.queryInterface(
243 XTextContent
.class, instance
));
244 tEnv
.addObjRelation("RANGE", xTextDoc
.getText().createTextCursor());
248 } // finish class SwXTextTable