Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScCellObj.java
blobf877d5dd0f4ac1381e52252867f752309608e844
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.sheet.XSpreadsheet;
34 import com.sun.star.sheet.XSpreadsheetDocument;
35 import com.sun.star.sheet.XSpreadsheets;
36 import com.sun.star.table.XCell;
37 import com.sun.star.uno.AnyConverter;
38 import com.sun.star.uno.Type;
39 import com.sun.star.uno.UnoRuntime;
40 import com.sun.star.uno.XInterface;
41 import ifc.sheet._XCellRangesQuery;
43 /**
44 * Test for object which is represented by service
45 * <code>com.sun.star.sheet.SheetCell</code>. <p>
46 * Object implements the following interfaces :
47 * <ul>
48 * <li> <code>com::sun::star::table::CellProperties</code></li>
49 * <li> <code>com::sun::star::text::XSimpleText</code></li>
50 * <li> <code>com::sun::star::table::XCell</code></li>
51 * <li> <code>com::sun::star::text::XTextRange</code></li>
52 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
53 * <li> <code>com::sun::star::style::CharacterProperties</code></li>
54 * <li> <code>com::sun::star::document::XActionLockable</code></li>
55 * <li> <code>com::sun::star::style::ParagraphProperties</code></li>
56 * <li> <code>com::sun::star::text::XText</code></li>
57 * <li> <code>com::sun::star::sheet::XCellAddressable</code></li>
58 * </ul>
59 * @see com.sun.star.sheet.SheetCell
60 * @see com.sun.star.table.CellProperties
61 * @see com.sun.star.text.XSimpleText
62 * @see com.sun.star.table.XCell
63 * @see com.sun.star.text.XTextRange
64 * @see com.sun.star.beans.XPropertySet
65 * @see com.sun.star.style.CharacterProperties
66 * @see com.sun.star.document.XActionLockable
67 * @see com.sun.star.style.ParagraphProperties
68 * @see com.sun.star.text.XText
69 * @see com.sun.star.sheet.XCellAddressable
70 * @see ifc.table._CellProperties
71 * @see ifc.text._XSimpleText
72 * @see ifc.table._XCell
73 * @see ifc.text._XTextRange
74 * @see ifc.beans._XPropertySet
75 * @see ifc.style._CharacterProperties
76 * @see ifc.document._XActionLockable
77 * @see ifc.style._ParagraphProperties
78 * @see ifc.text._XText
79 * @see ifc.sheet._XCellAddressable
81 public class ScCellObj extends TestCase {
82 private XSpreadsheetDocument xSheetDoc = null;
85 /**
86 * Creates Spreadsheet document.
88 @Override
89 protected void initialize( TestParameters tParam, PrintWriter log ) {
90 SOfficeFactory SOF = SOfficeFactory.getFactory( 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 @Override
106 protected void cleanup( TestParameters tParam, PrintWriter log ) {
107 log.println( " disposing xSheetDoc " );
108 XComponent oComp = UnoRuntime.queryInterface (XComponent.class, xSheetDoc);
109 util.DesktopTools.closeDoc(oComp);
113 * Creating a Testenvironment for the interfaces to be tested.
114 * Retrieves a collection of spreadsheets from a document,
115 * and takes one of them. Retrieves some cell from the spreadsheet
116 * that is instance of the service <code>com.sun.star.sheet.SheetCell</code>.
117 * Object relations created :
118 * <ul>
119 * <li> <code>'XTEXTINFO',</code> for
120 * {@link ifc.text._XText} </li>
121 * </ul>
122 * @see com.sun.star.sheet.SheetCell
124 @Override
125 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
127 XInterface oObj = null;
129 // creation of testobject here
130 // first we write what we are intend to do to log file
131 log.println( "Creating a test environment" );
133 XSpreadsheet oSheet = null;
134 XCell cell = null;
135 try {
136 log.println("Getting spreadsheet") ;
137 XSpreadsheets oSheets = xSheetDoc.getSheets() ;
138 XIndexAccess oIndexSheets = UnoRuntime.queryInterface(XIndexAccess.class, oSheets);
139 oSheet = (XSpreadsheet) AnyConverter.toObject(
140 new Type(XSpreadsheet.class),oIndexSheets.getByIndex(0));
142 log.println("Getting a cell from sheet") ;
143 oObj = oSheet.getCellByPosition(2, 3) ;
144 cell = UnoRuntime.queryInterface(XCell.class, oObj);
146 } catch (com.sun.star.lang.WrappedTargetException e) {
147 e.printStackTrace(log);
148 throw new StatusException(
149 "Error getting cell object from spreadsheet document", e);
150 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
151 e.printStackTrace(log);
152 throw new StatusException(
153 "Error getting cell object from spreadsheet document", e);
154 } catch (com.sun.star.lang.IllegalArgumentException e) {
155 e.printStackTrace(log);
156 throw new StatusException(
157 "Error getting cell object from spreadsheet document", e);
160 log.println( "creating a new environment for ScCellObj object" );
161 TestEnvironment tEnv = new TestEnvironment( oObj );
163 // Object relations for interface tests
164 DefaultDsc tDsc = new DefaultDsc(
165 "com.sun.star.text.XTextContent", "com.sun.star.text.TextField.URL");
166 log.println( " adding InstCreator object" );
167 tEnv.addObjRelation( "XTEXTINFO", new InstCreator( xSheetDoc, tDsc ) );
168 // add the sheet
169 tEnv.addObjRelation("SHEET", oSheet);
170 // add expected results for the XCellRangesQuery interface test
171 String[]expectedResults = new String[7];
173 expectedResults[_XCellRangesQuery.QUERYCOLUMNDIFFERENCES] = "Sheet1.C4";
174 expectedResults[_XCellRangesQuery.QUERYCONTENTCELLS] = "";
175 expectedResults[_XCellRangesQuery.QUERYEMPTYCELLS] = "Sheet1.C4";
176 expectedResults[_XCellRangesQuery.QUERYFORMULACELLS] = "";
177 expectedResults[_XCellRangesQuery.QUERYINTERSECTION] = "";
178 expectedResults[_XCellRangesQuery.QUERYROWDIFFERENCES] = "Sheet1.C4";
179 expectedResults[_XCellRangesQuery.QUERYVISIBLECELLS] = "Sheet1.C4";
180 tEnv.addObjRelation("XCellRangesQuery.EXPECTEDRESULTS", expectedResults);
181 tEnv.addObjRelation("XCellRangesQuery.CREATEENTRIES", Boolean.TRUE);
183 // make entries in this cell at the interface test
184 tEnv.addObjRelation("XTextFieldsSupplier.MAKEENTRY", Boolean.TRUE);
185 tEnv.addObjRelation("MAKEENTRYINCELL", cell);
187 // for XSearchable amd XReplaceable interface test
188 tEnv.addObjRelation("XSearchable.MAKEENTRYINCELL", cell);
189 tEnv.addObjRelation("EXCLUDEFINDNEXT", Boolean.TRUE);
191 // for XFormulaQuery interface test
192 tEnv.addObjRelation("EXPECTEDDEPENDENTVALUES", new int[]{2,2,3,3});
193 tEnv.addObjRelation("EXPECTEDPRECEDENTVALUES", new int[]{0,3,0,0});
194 tEnv.addObjRelation("RANGEINDICES", new int[]{0,0});
196 // XTextFieldsSupplier
197 tEnv.addObjRelation("SPREADSHEET", xSheetDoc);
199 XPropertySet PropSet = UnoRuntime.queryInterface(XPropertySet.class, oObj);
200 tEnv.addObjRelation("PropSet",PropSet);
202 return tEnv;
203 } // finish method getTestEnvironment
205 } // finish class ScCellObj