bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwXTextTable.java
blobdfbec2492c74bfaf2784e7e5b0e3483d73fb20d3
1 /*
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 .
18 package mod._sw;
20 import java.io.PrintWriter;
22 import lib.StatusException;
23 import lib.TestCase;
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;
39 /**
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 {
49 SOfficeFactory SOF;
50 XTextDocument xTextDoc;
52 protected void initialize(TestParameters tParam, PrintWriter log) {
53 SOF = SOfficeFactory.getFactory( (XMultiServiceFactory) tParam.getMSF());
55 try {
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);
70 /**
71 this method creates the testenvironment
72 @param tParam TestParameters class which contains additional
73 test parameters
74 @param log PrintWriter class to log the test state and result
76 @return TestEnvironment class
78 @see TestParameters
79 @see PrintWriter
81 protected synchronized TestEnvironment createTestEnvironment(TestParameters tParam,
82 PrintWriter log) {
83 // creation of testobject here
84 XTextTable oObj = null;
85 TestEnvironment tEnv = null;
86 Object instance = null;
88 try {
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 : " +
94 uE.getMessage(), uE);
97 int nRow = 6;
98 int nCol = 2;
99 oObj.initialize(nRow, nCol);
101 log.println("Creating instance...");
102 tEnv = new TestEnvironment(oObj);
104 if (SOfficeFactory.getTableCollection(xTextDoc).getCount() == 0) {
105 try {
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);
117 try {
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);
134 newData[0] = line;
135 newData[1] = line;
136 newData[2] = line;
137 newData[3] = line;
138 newData[4] = line;
139 newData[5] = line;
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) {
150 out = log;
153 public void prepareToSort() {
154 oTable.getCellByName("A1").setValue(4);
156 XTextRange textRange = UnoRuntime.queryInterface(
157 XTextRange.class,
158 oTable.getCellByName("A2"));
159 textRange.setString("b");
160 oTable.getCellByName("A3").setValue(3);
161 textRange = UnoRuntime.queryInterface(
162 XTextRange.class,
163 oTable.getCellByName("A4"));
164 textRange.setString("a");
165 oTable.getCellByName("A5").setValue(23);
166 textRange = UnoRuntime.queryInterface(
167 XTextRange.class,
168 oTable.getCellByName("A6"));
169 textRange.setString("ab");
173 public boolean checkSort(boolean isSortNumbering,
174 boolean isSortAscending) {
175 out.println("Sort checking...");
177 boolean res = false;
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);
193 if (!res) {
194 out.println("Expected: 3, 4, 23");
195 out.println("Getting: " + value[3] + ", " +
196 value[4] + ", " + value[5]);
198 } else {
199 String[] rightVal = { "23", "4", "3" };
200 String[] vals = { value[0], value[1], value[2] };
201 res = ValueComparer.equalValue(vals, rightVal);
203 if (!res) {
204 out.println("Expected: 23, 4, 3");
205 out.println("Getting: " + value[1] + ", " +
206 value[2] + ", " + value[3]);
209 } else {
210 if (isSortAscending) {
211 String[] rightVal = { "23", "3", "4", "a", "ab", "b" };
212 res = ValueComparer.equalValue(value, rightVal);
214 if (!res) {
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]);
221 } else {
222 String[] rightVal = { "b", "ab", "a", "4", "3", "23" };
223 res = ValueComparer.equalValue(value, rightVal);
225 if (!res) {
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]);
235 if (res) {
236 out.println("Sorted correctly");
237 } else {
238 out.println("Sorted uncorrectly");
241 return res;
245 tEnv.addObjRelation("CONTENT",
246 UnoRuntime.queryInterface(
247 XTextContent.class, instance));
248 tEnv.addObjRelation("RANGE", xTextDoc.getText().createTextCursor());
250 return tEnv;
252 } // finish class SwXTextTable