1ef39d40dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3ef39d40dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4ef39d40dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5ef39d40dSAndrew Rist  * distributed with this work for additional information
6ef39d40dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7ef39d40dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8ef39d40dSAndrew Rist  * "License"); you may not use this file except in compliance
9ef39d40dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10ef39d40dSAndrew Rist  *
11ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12ef39d40dSAndrew Rist  *
13ef39d40dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14ef39d40dSAndrew Rist  * software distributed under the License is distributed on an
15ef39d40dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16ef39d40dSAndrew Rist  * KIND, either express or implied.  See the License for the
17ef39d40dSAndrew Rist  * specific language governing permissions and limitations
18ef39d40dSAndrew Rist  * under the License.
19ef39d40dSAndrew Rist  *
20ef39d40dSAndrew Rist  *************************************************************/
21ef39d40dSAndrew Rist 
22ef39d40dSAndrew Rist 
23cdf0e10cSrcweir package mod._sc;
24cdf0e10cSrcweir 
25cdf0e10cSrcweir import java.io.PrintWriter;
26cdf0e10cSrcweir 
27cdf0e10cSrcweir import lib.StatusException;
28cdf0e10cSrcweir import lib.TestCase;
29cdf0e10cSrcweir import lib.TestEnvironment;
30cdf0e10cSrcweir import lib.TestParameters;
31cdf0e10cSrcweir import util.DefaultDsc;
32cdf0e10cSrcweir import util.InstCreator;
33cdf0e10cSrcweir import util.SOfficeFactory;
34cdf0e10cSrcweir 
35cdf0e10cSrcweir import com.sun.star.beans.XPropertySet;
36cdf0e10cSrcweir import com.sun.star.container.XIndexAccess;
37cdf0e10cSrcweir import com.sun.star.lang.XComponent;
38cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
39cdf0e10cSrcweir import com.sun.star.sheet.XSpreadsheet;
40cdf0e10cSrcweir import com.sun.star.sheet.XSpreadsheetDocument;
41cdf0e10cSrcweir import com.sun.star.sheet.XSpreadsheets;
42cdf0e10cSrcweir import com.sun.star.table.XCell;
43cdf0e10cSrcweir import com.sun.star.uno.AnyConverter;
44cdf0e10cSrcweir import com.sun.star.uno.Type;
45cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
46cdf0e10cSrcweir import com.sun.star.uno.XInterface;
47cdf0e10cSrcweir import ifc.sheet._XCellRangesQuery;
48cdf0e10cSrcweir 
49cdf0e10cSrcweir /**
50cdf0e10cSrcweir * Test for object which is represented by service
51cdf0e10cSrcweir * <code>com.sun.star.sheet.SheetCell</code>. <p>
52cdf0e10cSrcweir * Object implements the following interfaces :
53cdf0e10cSrcweir * <ul>
54cdf0e10cSrcweir *  <li> <code>com::sun::star::table::CellProperties</code></li>
55cdf0e10cSrcweir *  <li> <code>com::sun::star::text::XSimpleText</code></li>
56cdf0e10cSrcweir *  <li> <code>com::sun::star::table::XCell</code></li>
57cdf0e10cSrcweir *  <li> <code>com::sun::star::text::XTextRange</code></li>
58cdf0e10cSrcweir *  <li> <code>com::sun::star::beans::XPropertySet</code></li>
59cdf0e10cSrcweir *  <li> <code>com::sun::star::style::CharacterProperties</code></li>
60cdf0e10cSrcweir *  <li> <code>com::sun::star::document::XActionLockable</code></li>
61cdf0e10cSrcweir *  <li> <code>com::sun::star::style::ParagraphProperties</code></li>
62cdf0e10cSrcweir *  <li> <code>com::sun::star::text::XText</code></li>
63cdf0e10cSrcweir *  <li> <code>com::sun::star::sheet::XCellAddressable</code></li>
64cdf0e10cSrcweir * </ul>
65cdf0e10cSrcweir * @see com.sun.star.sheet.SheetCell
66cdf0e10cSrcweir * @see com.sun.star.table.CellProperties
67cdf0e10cSrcweir * @see com.sun.star.text.XSimpleText
68cdf0e10cSrcweir * @see com.sun.star.table.XCell
69cdf0e10cSrcweir * @see com.sun.star.text.XTextRange
70cdf0e10cSrcweir * @see com.sun.star.beans.XPropertySet
71cdf0e10cSrcweir * @see com.sun.star.style.CharacterProperties
72cdf0e10cSrcweir * @see com.sun.star.document.XActionLockable
73cdf0e10cSrcweir * @see com.sun.star.style.ParagraphProperties
74cdf0e10cSrcweir * @see com.sun.star.text.XText
75cdf0e10cSrcweir * @see com.sun.star.sheet.XCellAddressable
76cdf0e10cSrcweir * @see ifc.table._CellProperties
77cdf0e10cSrcweir * @see ifc.text._XSimpleText
78cdf0e10cSrcweir * @see ifc.table._XCell
79cdf0e10cSrcweir * @see ifc.text._XTextRange
80cdf0e10cSrcweir * @see ifc.beans._XPropertySet
81cdf0e10cSrcweir * @see ifc.style._CharacterProperties
82cdf0e10cSrcweir * @see ifc.document._XActionLockable
83cdf0e10cSrcweir * @see ifc.style._ParagraphProperties
84cdf0e10cSrcweir * @see ifc.text._XText
85cdf0e10cSrcweir * @see ifc.sheet._XCellAddressable
86cdf0e10cSrcweir */
87cdf0e10cSrcweir public class ScCellObj extends TestCase {
88cdf0e10cSrcweir     static XSpreadsheetDocument xSheetDoc = null;
89cdf0e10cSrcweir 
90cdf0e10cSrcweir 
91cdf0e10cSrcweir     /**
92cdf0e10cSrcweir     * Creates Spreadsheet document.
93cdf0e10cSrcweir     */
initialize( TestParameters tParam, PrintWriter log )94cdf0e10cSrcweir     protected void initialize( TestParameters tParam, PrintWriter log ) {
95cdf0e10cSrcweir         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
96cdf0e10cSrcweir 
97cdf0e10cSrcweir         try {
98cdf0e10cSrcweir             log.println( "Creating a Spreadsheet document" );
99cdf0e10cSrcweir             xSheetDoc = SOF.createCalcDoc(null);
100cdf0e10cSrcweir         } catch ( com.sun.star.uno.Exception e ) {
101*30acf5e8Spfg             // Some exception occured.FAILED
102cdf0e10cSrcweir             e.printStackTrace( log );
103cdf0e10cSrcweir             throw new StatusException( "Couldn't create document", e );
104cdf0e10cSrcweir         }
105cdf0e10cSrcweir     }
106cdf0e10cSrcweir 
107cdf0e10cSrcweir     /**
108cdf0e10cSrcweir     * Disposes Spreadsheet document.
109cdf0e10cSrcweir     */
cleanup( TestParameters tParam, PrintWriter log )110cdf0e10cSrcweir     protected void cleanup( TestParameters tParam, PrintWriter log ) {
111cdf0e10cSrcweir         log.println( "    disposing xSheetDoc " );
112cdf0e10cSrcweir         XComponent oComp = (XComponent)
113cdf0e10cSrcweir             UnoRuntime.queryInterface (XComponent.class, xSheetDoc);
114cdf0e10cSrcweir         util.DesktopTools.closeDoc(oComp);
115cdf0e10cSrcweir     }
116cdf0e10cSrcweir 
117cdf0e10cSrcweir     /**
118cdf0e10cSrcweir     * Creating a Testenvironment for the interfaces to be tested.
119cdf0e10cSrcweir     * Retrieves a collection of spreadsheets from a document,
120cdf0e10cSrcweir     * and takes one of them. Retrieves some cell from the spreadsheet
121cdf0e10cSrcweir     * that is instance of the service <code>com.sun.star.sheet.SheetCell</code>.
122cdf0e10cSrcweir     * Object relations created :
123cdf0e10cSrcweir     * <ul>
124cdf0e10cSrcweir     *  <li> <code>'XTEXTINFO',</code> for
125cdf0e10cSrcweir     *      {@link ifc.text._XText} </li>
126cdf0e10cSrcweir     * </ul>
127cdf0e10cSrcweir     * @see com.sun.star.sheet.SheetCell
128cdf0e10cSrcweir     */
createTestEnvironment(TestParameters Param, PrintWriter log)129cdf0e10cSrcweir     protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
130cdf0e10cSrcweir 
131cdf0e10cSrcweir         XInterface oObj = null;
132cdf0e10cSrcweir 
133cdf0e10cSrcweir         // creation of testobject here
134cdf0e10cSrcweir         // first we write what we are intend to do to log file
135cdf0e10cSrcweir         log.println( "Creating a test environment" );
136cdf0e10cSrcweir 
137cdf0e10cSrcweir         XSpreadsheet oSheet = null;
138cdf0e10cSrcweir         XCell cell = null;
139cdf0e10cSrcweir         try {
140cdf0e10cSrcweir             log.println("Getting spreadsheet") ;
141cdf0e10cSrcweir             XSpreadsheets oSheets = xSheetDoc.getSheets() ;
142cdf0e10cSrcweir             XIndexAccess oIndexSheets = (XIndexAccess)
143cdf0e10cSrcweir             UnoRuntime.queryInterface(XIndexAccess.class, oSheets);
144cdf0e10cSrcweir             oSheet = (XSpreadsheet) AnyConverter.toObject(
145cdf0e10cSrcweir                     new Type(XSpreadsheet.class),oIndexSheets.getByIndex(0));
146cdf0e10cSrcweir 
147cdf0e10cSrcweir             log.println("Getting a cell from sheet") ;
148cdf0e10cSrcweir             oObj = oSheet.getCellByPosition(2, 3) ;
149cdf0e10cSrcweir             cell = (XCell)UnoRuntime.queryInterface(XCell.class, oObj);
150cdf0e10cSrcweir 
151cdf0e10cSrcweir         } catch (com.sun.star.lang.WrappedTargetException e) {
152cdf0e10cSrcweir             e.printStackTrace(log);
153cdf0e10cSrcweir             throw new StatusException(
154cdf0e10cSrcweir                 "Error getting cell object from spreadsheet document", e);
155cdf0e10cSrcweir         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
156cdf0e10cSrcweir             e.printStackTrace(log);
157cdf0e10cSrcweir             throw new StatusException(
158cdf0e10cSrcweir                 "Error getting cell object from spreadsheet document", e);
159cdf0e10cSrcweir         } catch (com.sun.star.lang.IllegalArgumentException e) {
160cdf0e10cSrcweir             e.printStackTrace(log);
161cdf0e10cSrcweir             throw new StatusException(
162cdf0e10cSrcweir                 "Error getting cell object from spreadsheet document", e);
163cdf0e10cSrcweir         }
164cdf0e10cSrcweir 
165cdf0e10cSrcweir         log.println( "creating a new environment for ScCellObj object" );
166cdf0e10cSrcweir         TestEnvironment tEnv = new TestEnvironment( oObj );
167cdf0e10cSrcweir 
168cdf0e10cSrcweir         // Object relations for interface tests
169cdf0e10cSrcweir         DefaultDsc tDsc = new DefaultDsc(
170cdf0e10cSrcweir             "com.sun.star.text.XTextContent", "com.sun.star.text.TextField.URL");
171cdf0e10cSrcweir         log.println( "    adding InstCreator object" );
172cdf0e10cSrcweir         tEnv.addObjRelation( "XTEXTINFO", new InstCreator( xSheetDoc, tDsc ) );
173cdf0e10cSrcweir         // add the sheet
174cdf0e10cSrcweir         tEnv.addObjRelation("SHEET", oSheet);
175cdf0e10cSrcweir         // add expected results for the XCellRangesQuery interface test
176cdf0e10cSrcweir         String[]expectedResults = new String[7];
177cdf0e10cSrcweir 
178cdf0e10cSrcweir         expectedResults[_XCellRangesQuery.QUERYCOLUMNDIFFERENCES] = "Sheet1.C4";
179cdf0e10cSrcweir         expectedResults[_XCellRangesQuery.QUERYCONTENTCELLS] = "";
180cdf0e10cSrcweir         expectedResults[_XCellRangesQuery.QUERYEMPTYCELLS] = "Sheet1.C4";
181cdf0e10cSrcweir         expectedResults[_XCellRangesQuery.QUERYFORMULACELLS] = "";
182cdf0e10cSrcweir         expectedResults[_XCellRangesQuery.QUERYINTERSECTION] = "";
183cdf0e10cSrcweir         expectedResults[_XCellRangesQuery.QUERYROWDIFFERENCES] = "Sheet1.C4";
184cdf0e10cSrcweir         expectedResults[_XCellRangesQuery.QUERYVISIBLECELLS] = "Sheet1.C4";
185cdf0e10cSrcweir         tEnv.addObjRelation("XCellRangesQuery.EXPECTEDRESULTS", expectedResults);
186cdf0e10cSrcweir         tEnv.addObjRelation("XCellRangesQuery.CREATEENTRIES", Boolean.TRUE);
187cdf0e10cSrcweir 
188cdf0e10cSrcweir         // make entries in this cell at the interface test
189cdf0e10cSrcweir         tEnv.addObjRelation("XTextFieldsSupplier.MAKEENTRY", Boolean.TRUE);
190cdf0e10cSrcweir         tEnv.addObjRelation("MAKEENTRYINCELL", cell);
191cdf0e10cSrcweir 
192cdf0e10cSrcweir         // for XSearchable amd XReplaceable interface test
193cdf0e10cSrcweir         tEnv.addObjRelation("XSearchable.MAKEENTRYINCELL", cell);
194cdf0e10cSrcweir         tEnv.addObjRelation("EXCLUDEFINDNEXT", Boolean.TRUE);
195cdf0e10cSrcweir 
196cdf0e10cSrcweir         // for XFormulaQuery interface test
197cdf0e10cSrcweir         tEnv.addObjRelation("EXPECTEDDEPENDENTVALUES", new int[]{2,2,3,3});
198cdf0e10cSrcweir         tEnv.addObjRelation("EXPECTEDPRECEDENTVALUES", new int[]{0,3,0,0});
199cdf0e10cSrcweir         tEnv.addObjRelation("RANGEINDICES", new int[]{0,0});
200cdf0e10cSrcweir 
201cdf0e10cSrcweir         // XTextFieldsSupplier
202cdf0e10cSrcweir         tEnv.addObjRelation("SPREADSHEET", xSheetDoc);
203cdf0e10cSrcweir 
204cdf0e10cSrcweir         XPropertySet PropSet = (XPropertySet)
205cdf0e10cSrcweir                     UnoRuntime.queryInterface(XPropertySet.class, oObj);
206cdf0e10cSrcweir         tEnv.addObjRelation("PropSet",PropSet);
207cdf0e10cSrcweir 
208cdf0e10cSrcweir         return tEnv;
209cdf0e10cSrcweir     } // finish method getTestEnvironment
210cdf0e10cSrcweir 
211cdf0e10cSrcweir }    // finish class ScCellObj
212cdf0e10cSrcweir 
213