1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SwXTextTable.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 import java
.io
.PrintWriter
;
34 import lib
.StatusException
;
36 import lib
.TestEnvironment
;
37 import lib
.TestParameters
;
38 import util
.SOfficeFactory
;
39 import util
.ValueComparer
;
41 import com
.sun
.star
.beans
.XPropertySet
;
42 import com
.sun
.star
.lang
.XMultiServiceFactory
;
43 import com
.sun
.star
.table
.XCell
;
44 import com
.sun
.star
.text
.XTextContent
;
45 import com
.sun
.star
.text
.XTextDocument
;
46 import com
.sun
.star
.text
.XTextRange
;
47 import com
.sun
.star
.text
.XTextTable
;
48 import com
.sun
.star
.uno
.UnoRuntime
;
52 * this class tests the implementation of listed interfaces
53 * @see com.sun.star.beans.XPropertySet
54 * @see com.sun.star.container.XNamed
55 * @see com.sun.star.lang.XComponent
56 * @see com.sun.star.text.TextContent
57 * @see com.sun.star.text.XTextContent
58 * @see com.sun.star.text.XTextTable
60 public class SwXTextTable
extends TestCase
{
62 XTextDocument xTextDoc
;
64 protected void initialize(TestParameters tParam
, PrintWriter log
) {
65 SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
) tParam
.getMSF());
68 log
.println("creating a textdocument");
69 xTextDoc
= SOF
.createTextDoc(null);
70 } catch (com
.sun
.star
.uno
.Exception e
) {
71 // Some exception occures.FAILED
72 e
.printStackTrace(log
);
73 throw new StatusException("Couldn't create document", e
);
77 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
78 log
.println(" disposing xTextDoc ");
79 util
.DesktopTools
.closeDoc(xTextDoc
);
83 this method creates the testenvironment
84 @param tParam TestParameters class which contains additional
86 @param log PrintWriter class to log the test state and result
88 @return TestEnvironment class
93 protected synchronized TestEnvironment
createTestEnvironment(TestParameters tParam
,
95 // creation of testobject here
96 XTextTable oObj
= null;
97 TestEnvironment tEnv
= null;
98 Object instance
= null;
101 oObj
= SOF
.createTextTable(xTextDoc
);
102 instance
= SOF
.createTextTable(xTextDoc
);
103 } catch (com
.sun
.star
.uno
.Exception uE
) {
104 uE
.printStackTrace(log
);
105 throw new StatusException("Couldn't create testobj : " +
106 uE
.getMessage(), uE
);
111 oObj
.initialize(nRow
, nCol
);
113 log
.println("Creating instance...");
114 tEnv
= new TestEnvironment(oObj
);
116 if (SOF
.getTableCollection(xTextDoc
).getCount() == 0) {
118 SOF
.insertTextContent(xTextDoc
, oObj
);
119 } catch (com
.sun
.star
.uno
.Exception uE
) {
120 uE
.printStackTrace(log
);
121 throw new StatusException("Couldn't create TextTable : " +
122 uE
.getMessage(), uE
);
126 XPropertySet props
= (XPropertySet
) UnoRuntime
.queryInterface(
127 XPropertySet
.class, oObj
);
130 props
.setPropertyValue("ChartRowAsLabel", new Boolean(true));
131 props
.setPropertyValue("ChartColumnAsLabel", new Boolean(true));
132 } catch (Exception e
) {
133 e
.printStackTrace(log
);
137 //Adding relation for util.XTextTable
138 tEnv
.addObjRelation("NROW", new Integer(nRow
));
139 tEnv
.addObjRelation("NCOL", new Integer(nCol
));
141 //Adding ObjRelation for XCellRangeData
142 Object
[][] newData
= new Object
[6][];
143 Object
[] line
= new Object
[2];
144 line
[0] = new Double(1.5);
145 line
[1] = new Double(2.5);
152 tEnv
.addObjRelation("NewData", newData
);
154 //Adding relation for util.XSortable
155 final PrintWriter finalLog
= log
;
156 final XTextTable oTable
= oObj
;
157 tEnv
.addObjRelation("SORTCHECKER",
158 new ifc
.util
._XSortable
.XSortChecker() {
159 PrintWriter out
= finalLog
;
161 public void setPrintWriter(PrintWriter log
) {
165 public void prepareToSort() {
166 oTable
.getCellByName("A1").setValue(4);
168 XTextRange textRange
= (XTextRange
) UnoRuntime
.queryInterface(
170 oTable
.getCellByName("A2"));
171 textRange
.setString("b");
172 oTable
.getCellByName("A3").setValue(3);
173 textRange
= (XTextRange
) UnoRuntime
.queryInterface(
175 oTable
.getCellByName("A4"));
176 textRange
.setString("a");
177 oTable
.getCellByName("A5").setValue(23);
178 textRange
= (XTextRange
) UnoRuntime
.queryInterface(
180 oTable
.getCellByName("A6"));
181 textRange
.setString("ab");
185 public boolean checkSort(boolean isSortNumbering
,
186 boolean isSortAscending
) {
187 out
.println("Sort checking...");
190 String
[] value
= new String
[6];
192 for (int i
= 0; i
< 6; i
++) {
193 XCell cell
= oTable
.getCellByName("A" + (i
+ 1));
194 XTextRange textRange
= (XTextRange
) UnoRuntime
.queryInterface(
195 XTextRange
.class, cell
);
196 value
[i
] = textRange
.getString();
199 if (isSortNumbering
) {
200 if (isSortAscending
) {
201 String
[] rightVal
= { "3", "4", "23" };
202 String
[] vals
= { value
[3], value
[4], value
[5] };
203 res
= ValueComparer
.equalValue(vals
, rightVal
);
206 out
.println("Expected: 3, 4, 23");
207 out
.println("Getting: " + value
[3] + ", " +
208 value
[4] + ", " + value
[5]);
211 String
[] rightVal
= { "23", "4", "3" };
212 String
[] vals
= { value
[0], value
[1], value
[2] };
213 res
= ValueComparer
.equalValue(vals
, rightVal
);
216 out
.println("Expected: 23, 4, 3");
217 out
.println("Getting: " + value
[1] + ", " +
218 value
[2] + ", " + value
[3]);
222 if (isSortAscending
) {
223 String
[] rightVal
= { "23", "3", "4", "a", "ab", "b" };
224 res
= ValueComparer
.equalValue(value
, rightVal
);
227 out
.println("Expected: 23, 3, 4, a, ab, b");
228 out
.println("Getting: " + value
[0] + ", " +
229 value
[1] + ", " + value
[2] +
230 ", " + value
[3] + ", " +
231 value
[4] + ", " + value
[5]);
234 String
[] rightVal
= { "b", "ab", "a", "4", "3", "23" };
235 res
= ValueComparer
.equalValue(value
, rightVal
);
238 out
.println("Expected: b, ab, a, 4, 3, 23");
239 out
.println("Getting: " + value
[0] + ", " +
240 value
[1] + ", " + value
[2] +
241 ", " + value
[3] + ", " +
242 value
[4] + ", " + value
[5]);
248 out
.println("Sorted correctly");
250 out
.println("Sorted uncorrectly");
257 tEnv
.addObjRelation("CONTENT",
258 (XTextContent
) UnoRuntime
.queryInterface(
259 XTextContent
.class, instance
));
260 tEnv
.addObjRelation("RANGE", xTextDoc
.getText().createTextCursor());
264 } // finish class SwXTextTable