1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ScCellObj.java,v $
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 ************************************************************************/
32 import java
.io
.PrintWriter
;
34 import lib
.StatusException
;
36 import lib
.TestEnvironment
;
37 import lib
.TestParameters
;
38 import util
.DefaultDsc
;
39 import util
.InstCreator
;
40 import util
.SOfficeFactory
;
42 import com
.sun
.star
.beans
.XPropertySet
;
43 import com
.sun
.star
.container
.XIndexAccess
;
44 import com
.sun
.star
.lang
.XComponent
;
45 import com
.sun
.star
.lang
.XMultiServiceFactory
;
46 import com
.sun
.star
.sheet
.XSpreadsheet
;
47 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
48 import com
.sun
.star
.sheet
.XSpreadsheets
;
49 import com
.sun
.star
.table
.XCell
;
50 import com
.sun
.star
.uno
.AnyConverter
;
51 import com
.sun
.star
.uno
.Type
;
52 import com
.sun
.star
.uno
.UnoRuntime
;
53 import com
.sun
.star
.uno
.XInterface
;
54 import ifc
.sheet
._XCellRangesQuery
;
57 * Test for object which is represented by service
58 * <code>com.sun.star.sheet.SheetCell</code>. <p>
59 * Object implements the following interfaces :
61 * <li> <code>com::sun::star::table::CellProperties</code></li>
62 * <li> <code>com::sun::star::text::XSimpleText</code></li>
63 * <li> <code>com::sun::star::table::XCell</code></li>
64 * <li> <code>com::sun::star::text::XTextRange</code></li>
65 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
66 * <li> <code>com::sun::star::style::CharacterProperties</code></li>
67 * <li> <code>com::sun::star::document::XActionLockable</code></li>
68 * <li> <code>com::sun::star::style::ParagraphProperties</code></li>
69 * <li> <code>com::sun::star::text::XText</code></li>
70 * <li> <code>com::sun::star::sheet::XCellAddressable</code></li>
72 * @see com.sun.star.sheet.SheetCell
73 * @see com.sun.star.table.CellProperties
74 * @see com.sun.star.text.XSimpleText
75 * @see com.sun.star.table.XCell
76 * @see com.sun.star.text.XTextRange
77 * @see com.sun.star.beans.XPropertySet
78 * @see com.sun.star.style.CharacterProperties
79 * @see com.sun.star.document.XActionLockable
80 * @see com.sun.star.style.ParagraphProperties
81 * @see com.sun.star.text.XText
82 * @see com.sun.star.sheet.XCellAddressable
83 * @see ifc.table._CellProperties
84 * @see ifc.text._XSimpleText
85 * @see ifc.table._XCell
86 * @see ifc.text._XTextRange
87 * @see ifc.beans._XPropertySet
88 * @see ifc.style._CharacterProperties
89 * @see ifc.document._XActionLockable
90 * @see ifc.style._ParagraphProperties
91 * @see ifc.text._XText
92 * @see ifc.sheet._XCellAddressable
94 public class ScCellObj
extends TestCase
{
95 static XSpreadsheetDocument xSheetDoc
= null;
99 * Creates Spreadsheet document.
101 protected void initialize( TestParameters tParam
, PrintWriter log
) {
102 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
105 log
.println( "Creating a Spreadsheet document" );
106 xSheetDoc
= SOF
.createCalcDoc(null);
107 } catch ( com
.sun
.star
.uno
.Exception e
) {
108 // Some exception occures.FAILED
109 e
.printStackTrace( log
);
110 throw new StatusException( "Couldn't create document", e
);
115 * Disposes Spreadsheet document.
117 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
118 log
.println( " disposing xSheetDoc " );
119 XComponent oComp
= (XComponent
)
120 UnoRuntime
.queryInterface (XComponent
.class, xSheetDoc
);
121 util
.DesktopTools
.closeDoc(oComp
);
125 * Creating a Testenvironment for the interfaces to be tested.
126 * Retrieves a collection of spreadsheets from a document,
127 * and takes one of them. Retrieves some cell from the spreadsheet
128 * that is instance of the service <code>com.sun.star.sheet.SheetCell</code>.
129 * Object relations created :
131 * <li> <code>'XTEXTINFO',</code> for
132 * {@link ifc.text._XText} </li>
134 * @see com.sun.star.sheet.SheetCell
136 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
138 XInterface oObj
= null;
140 // creation of testobject here
141 // first we write what we are intend to do to log file
142 log
.println( "Creating a test environment" );
144 XSpreadsheet oSheet
= null;
147 log
.println("Getting spreadsheet") ;
148 XSpreadsheets oSheets
= xSheetDoc
.getSheets() ;
149 XIndexAccess oIndexSheets
= (XIndexAccess
)
150 UnoRuntime
.queryInterface(XIndexAccess
.class, oSheets
);
151 oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
152 new Type(XSpreadsheet
.class),oIndexSheets
.getByIndex(0));
154 log
.println("Getting a cell from sheet") ;
155 oObj
= oSheet
.getCellByPosition(2, 3) ;
156 cell
= (XCell
)UnoRuntime
.queryInterface(XCell
.class, oObj
);
158 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
159 e
.printStackTrace(log
);
160 throw new StatusException(
161 "Error getting cell object from spreadsheet document", e
);
162 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
163 e
.printStackTrace(log
);
164 throw new StatusException(
165 "Error getting cell object from spreadsheet document", e
);
166 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
167 e
.printStackTrace(log
);
168 throw new StatusException(
169 "Error getting cell object from spreadsheet document", e
);
172 log
.println( "creating a new environment for ScCellObj object" );
173 TestEnvironment tEnv
= new TestEnvironment( oObj
);
175 // Object relations for interface tests
176 DefaultDsc tDsc
= new DefaultDsc(
177 "com.sun.star.text.XTextContent", "com.sun.star.text.TextField.URL");
178 log
.println( " adding InstCreator object" );
179 tEnv
.addObjRelation( "XTEXTINFO", new InstCreator( xSheetDoc
, tDsc
) );
181 tEnv
.addObjRelation("SHEET", oSheet
);
182 // add expected results for the XCellRangesQuery interface test
183 String
[]expectedResults
= new String
[7];
185 expectedResults
[_XCellRangesQuery
.QUERYCOLUMNDIFFERENCES
] = "Sheet1.C4";
186 expectedResults
[_XCellRangesQuery
.QUERYCONTENTCELLS
] = "";
187 expectedResults
[_XCellRangesQuery
.QUERYEMPTYCELLS
] = "Sheet1.C4";
188 expectedResults
[_XCellRangesQuery
.QUERYFORMULACELLS
] = "";
189 expectedResults
[_XCellRangesQuery
.QUERYINTERSECTION
] = "";
190 expectedResults
[_XCellRangesQuery
.QUERYROWDIFFERENCES
] = "Sheet1.C4";
191 expectedResults
[_XCellRangesQuery
.QUERYVISIBLECELLS
] = "Sheet1.C4";
192 tEnv
.addObjRelation("XCellRangesQuery.EXPECTEDRESULTS", expectedResults
);
193 tEnv
.addObjRelation("XCellRangesQuery.CREATEENTRIES", Boolean
.TRUE
);
195 // make entries in this cell at the interface test
196 tEnv
.addObjRelation("XTextFieldsSupplier.MAKEENTRY", Boolean
.TRUE
);
197 tEnv
.addObjRelation("MAKEENTRYINCELL", cell
);
199 // for XSearchable amd XReplaceable interface test
200 tEnv
.addObjRelation("XSearchable.MAKEENTRYINCELL", cell
);
201 tEnv
.addObjRelation("EXCLUDEFINDNEXT", Boolean
.TRUE
);
203 // for XFormulaQuery interface test
204 tEnv
.addObjRelation("EXPECTEDDEPENDENTVALUES", new int[]{2,2,3,3});
205 tEnv
.addObjRelation("EXPECTEDPRECEDENTVALUES", new int[]{0,3,0,0});
206 tEnv
.addObjRelation("RANGEINDICES", new int[]{0,0});
208 // XTextFieldsSupplier
209 tEnv
.addObjRelation("SPREADSHEET", xSheetDoc
);
211 XPropertySet PropSet
= (XPropertySet
)
212 UnoRuntime
.queryInterface(XPropertySet
.class, oObj
);
213 tEnv
.addObjRelation("PropSet",PropSet
);
216 } // finish method getTestEnvironment
218 } // finish class ScCellObj