merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _sw / SwXTextTable.java
blob739f9d4a1a7ede1ab9fe108ec04ba5fb39bc8010
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SwXTextTable.java,v $
10 * $Revision: 1.7 $
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 ************************************************************************/
30 package mod._sw;
32 import java.io.PrintWriter;
34 import lib.StatusException;
35 import lib.TestCase;
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;
51 /**
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 {
61 SOfficeFactory SOF;
62 XTextDocument xTextDoc;
64 protected void initialize(TestParameters tParam, PrintWriter log) {
65 SOF = SOfficeFactory.getFactory( (XMultiServiceFactory) tParam.getMSF());
67 try {
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);
82 /**
83 this method creates the testenvironment
84 @param tParam TestParameters class which contains additional
85 test parameters
86 @param log PrintWriter class to log the test state and result
88 @return TestEnvironment class
90 @see TestParameters
91 @see PrintWriter
93 protected synchronized TestEnvironment createTestEnvironment(TestParameters tParam,
94 PrintWriter log) {
95 // creation of testobject here
96 XTextTable oObj = null;
97 TestEnvironment tEnv = null;
98 Object instance = null;
100 try {
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);
109 int nRow = 6;
110 int nCol = 2;
111 oObj.initialize(nRow, nCol);
113 log.println("Creating instance...");
114 tEnv = new TestEnvironment(oObj);
116 if (SOF.getTableCollection(xTextDoc).getCount() == 0) {
117 try {
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);
129 try {
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);
146 newData[0] = line;
147 newData[1] = line;
148 newData[2] = line;
149 newData[3] = line;
150 newData[4] = line;
151 newData[5] = line;
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) {
162 out = log;
165 public void prepareToSort() {
166 oTable.getCellByName("A1").setValue(4);
168 XTextRange textRange = (XTextRange) UnoRuntime.queryInterface(
169 XTextRange.class,
170 oTable.getCellByName("A2"));
171 textRange.setString("b");
172 oTable.getCellByName("A3").setValue(3);
173 textRange = (XTextRange) UnoRuntime.queryInterface(
174 XTextRange.class,
175 oTable.getCellByName("A4"));
176 textRange.setString("a");
177 oTable.getCellByName("A5").setValue(23);
178 textRange = (XTextRange) UnoRuntime.queryInterface(
179 XTextRange.class,
180 oTable.getCellByName("A6"));
181 textRange.setString("ab");
185 public boolean checkSort(boolean isSortNumbering,
186 boolean isSortAscending) {
187 out.println("Sort checking...");
189 boolean res = false;
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);
205 if (!res) {
206 out.println("Expected: 3, 4, 23");
207 out.println("Getting: " + value[3] + ", " +
208 value[4] + ", " + value[5]);
210 } else {
211 String[] rightVal = { "23", "4", "3" };
212 String[] vals = { value[0], value[1], value[2] };
213 res = ValueComparer.equalValue(vals, rightVal);
215 if (!res) {
216 out.println("Expected: 23, 4, 3");
217 out.println("Getting: " + value[1] + ", " +
218 value[2] + ", " + value[3]);
221 } else {
222 if (isSortAscending) {
223 String[] rightVal = { "23", "3", "4", "a", "ab", "b" };
224 res = ValueComparer.equalValue(value, rightVal);
226 if (!res) {
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]);
233 } else {
234 String[] rightVal = { "b", "ab", "a", "4", "3", "23" };
235 res = ValueComparer.equalValue(value, rightVal);
237 if (!res) {
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]);
247 if (res) {
248 out.println("Sorted correctly");
249 } else {
250 out.println("Sorted uncorrectly");
253 return res;
257 tEnv.addObjRelation("CONTENT",
258 (XTextContent) UnoRuntime.queryInterface(
259 XTextContent.class, instance));
260 tEnv.addObjRelation("RANGE", xTextDoc.getText().createTextCursor());
262 return tEnv;
264 } // finish class SwXTextTable