bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScCellObj.java
blob928cf2011382a51ae561dfdf03ec84a05a69181a
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._sc;
20 import java.io.PrintWriter;
22 import lib.StatusException;
23 import lib.TestCase;
24 import lib.TestEnvironment;
25 import lib.TestParameters;
26 import util.DefaultDsc;
27 import util.InstCreator;
28 import util.SOfficeFactory;
30 import com.sun.star.beans.XPropertySet;
31 import com.sun.star.container.XIndexAccess;
32 import com.sun.star.lang.XComponent;
33 import com.sun.star.lang.XMultiServiceFactory;
34 import com.sun.star.sheet.XSpreadsheet;
35 import com.sun.star.sheet.XSpreadsheetDocument;
36 import com.sun.star.sheet.XSpreadsheets;
37 import com.sun.star.table.XCell;
38 import com.sun.star.uno.AnyConverter;
39 import com.sun.star.uno.Type;
40 import com.sun.star.uno.UnoRuntime;
41 import com.sun.star.uno.XInterface;
42 import ifc.sheet._XCellRangesQuery;
44 /**
45 * Test for object which is represented by service
46 * <code>com.sun.star.sheet.SheetCell</code>. <p>
47 * Object implements the following interfaces :
48 * <ul>
49 * <li> <code>com::sun::star::table::CellProperties</code></li>
50 * <li> <code>com::sun::star::text::XSimpleText</code></li>
51 * <li> <code>com::sun::star::table::XCell</code></li>
52 * <li> <code>com::sun::star::text::XTextRange</code></li>
53 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
54 * <li> <code>com::sun::star::style::CharacterProperties</code></li>
55 * <li> <code>com::sun::star::document::XActionLockable</code></li>
56 * <li> <code>com::sun::star::style::ParagraphProperties</code></li>
57 * <li> <code>com::sun::star::text::XText</code></li>
58 * <li> <code>com::sun::star::sheet::XCellAddressable</code></li>
59 * </ul>
60 * @see com.sun.star.sheet.SheetCell
61 * @see com.sun.star.table.CellProperties
62 * @see com.sun.star.text.XSimpleText
63 * @see com.sun.star.table.XCell
64 * @see com.sun.star.text.XTextRange
65 * @see com.sun.star.beans.XPropertySet
66 * @see com.sun.star.style.CharacterProperties
67 * @see com.sun.star.document.XActionLockable
68 * @see com.sun.star.style.ParagraphProperties
69 * @see com.sun.star.text.XText
70 * @see com.sun.star.sheet.XCellAddressable
71 * @see ifc.table._CellProperties
72 * @see ifc.text._XSimpleText
73 * @see ifc.table._XCell
74 * @see ifc.text._XTextRange
75 * @see ifc.beans._XPropertySet
76 * @see ifc.style._CharacterProperties
77 * @see ifc.document._XActionLockable
78 * @see ifc.style._ParagraphProperties
79 * @see ifc.text._XText
80 * @see ifc.sheet._XCellAddressable
82 public class ScCellObj extends TestCase {
83 private XSpreadsheetDocument xSheetDoc = null;
86 /**
87 * Creates Spreadsheet document.
89 protected void initialize( TestParameters tParam, PrintWriter log ) {
90 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
92 try {
93 log.println( "Creating a Spreadsheet document" );
94 xSheetDoc = SOF.createCalcDoc(null);
95 } catch ( com.sun.star.uno.Exception e ) {
96 // Some exception occurs.FAILED
97 e.printStackTrace( log );
98 throw new StatusException( "Couldn't create document", e );
103 * Disposes Spreadsheet document.
105 protected void cleanup( TestParameters tParam, PrintWriter log ) {
106 log.println( " disposing xSheetDoc " );
107 XComponent oComp = UnoRuntime.queryInterface (XComponent.class, xSheetDoc);
108 util.DesktopTools.closeDoc(oComp);
112 * Creating a Testenvironment for the interfaces to be tested.
113 * Retrieves a collection of spreadsheets from a document,
114 * and takes one of them. Retrieves some cell from the spreadsheet
115 * that is instance of the service <code>com.sun.star.sheet.SheetCell</code>.
116 * Object relations created :
117 * <ul>
118 * <li> <code>'XTEXTINFO',</code> for
119 * {@link ifc.text._XText} </li>
120 * </ul>
121 * @see com.sun.star.sheet.SheetCell
123 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
125 XInterface oObj = null;
127 // creation of testobject here
128 // first we write what we are intend to do to log file
129 log.println( "Creating a test environment" );
131 XSpreadsheet oSheet = null;
132 XCell cell = null;
133 try {
134 log.println("Getting spreadsheet") ;
135 XSpreadsheets oSheets = xSheetDoc.getSheets() ;
136 XIndexAccess oIndexSheets = UnoRuntime.queryInterface(XIndexAccess.class, oSheets);
137 oSheet = (XSpreadsheet) AnyConverter.toObject(
138 new Type(XSpreadsheet.class),oIndexSheets.getByIndex(0));
140 log.println("Getting a cell from sheet") ;
141 oObj = oSheet.getCellByPosition(2, 3) ;
142 cell = UnoRuntime.queryInterface(XCell.class, oObj);
144 } catch (com.sun.star.lang.WrappedTargetException e) {
145 e.printStackTrace(log);
146 throw new StatusException(
147 "Error getting cell object from spreadsheet document", e);
148 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
149 e.printStackTrace(log);
150 throw new StatusException(
151 "Error getting cell object from spreadsheet document", e);
152 } catch (com.sun.star.lang.IllegalArgumentException e) {
153 e.printStackTrace(log);
154 throw new StatusException(
155 "Error getting cell object from spreadsheet document", e);
158 log.println( "creating a new environment for ScCellObj object" );
159 TestEnvironment tEnv = new TestEnvironment( oObj );
161 // Object relations for interface tests
162 DefaultDsc tDsc = new DefaultDsc(
163 "com.sun.star.text.XTextContent", "com.sun.star.text.TextField.URL");
164 log.println( " adding InstCreator object" );
165 tEnv.addObjRelation( "XTEXTINFO", new InstCreator( xSheetDoc, tDsc ) );
166 // add the sheet
167 tEnv.addObjRelation("SHEET", oSheet);
168 // add expected results for the XCellRangesQuery interface test
169 String[]expectedResults = new String[7];
171 expectedResults[_XCellRangesQuery.QUERYCOLUMNDIFFERENCES] = "Sheet1.C4";
172 expectedResults[_XCellRangesQuery.QUERYCONTENTCELLS] = "";
173 expectedResults[_XCellRangesQuery.QUERYEMPTYCELLS] = "Sheet1.C4";
174 expectedResults[_XCellRangesQuery.QUERYFORMULACELLS] = "";
175 expectedResults[_XCellRangesQuery.QUERYINTERSECTION] = "";
176 expectedResults[_XCellRangesQuery.QUERYROWDIFFERENCES] = "Sheet1.C4";
177 expectedResults[_XCellRangesQuery.QUERYVISIBLECELLS] = "Sheet1.C4";
178 tEnv.addObjRelation("XCellRangesQuery.EXPECTEDRESULTS", expectedResults);
179 tEnv.addObjRelation("XCellRangesQuery.CREATEENTRIES", Boolean.TRUE);
181 // make entries in this cell at the interface test
182 tEnv.addObjRelation("XTextFieldsSupplier.MAKEENTRY", Boolean.TRUE);
183 tEnv.addObjRelation("MAKEENTRYINCELL", cell);
185 // for XSearchable amd XReplaceable interface test
186 tEnv.addObjRelation("XSearchable.MAKEENTRYINCELL", cell);
187 tEnv.addObjRelation("EXCLUDEFINDNEXT", Boolean.TRUE);
189 // for XFormulaQuery interface test
190 tEnv.addObjRelation("EXPECTEDDEPENDENTVALUES", new int[]{2,2,3,3});
191 tEnv.addObjRelation("EXPECTEDPRECEDENTVALUES", new int[]{0,3,0,0});
192 tEnv.addObjRelation("RANGEINDICES", new int[]{0,0});
194 // XTextFieldsSupplier
195 tEnv.addObjRelation("SPREADSHEET", xSheetDoc);
197 XPropertySet PropSet = UnoRuntime.queryInterface(XPropertySet.class, oObj);
198 tEnv.addObjRelation("PropSet",PropSet);
200 return tEnv;
201 } // finish method getTestEnvironment
203 } // finish class ScCellObj