merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _sc / ScTabViewObj.java
blobb73707573d274072d7b4e096615351f6e26c30b5
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ScTabViewObj.java,v $
10 * $Revision: 1.13 $
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 ************************************************************************/
31 package mod._sc;
33 import com.sun.star.container.NoSuchElementException;
34 import com.sun.star.container.XNameContainer;
35 import com.sun.star.drawing.XDrawPage;
36 import com.sun.star.drawing.XDrawPages;
37 import com.sun.star.drawing.XDrawPagesSupplier;
38 import com.sun.star.drawing.XShape;
39 import com.sun.star.form.XForm;
40 import com.sun.star.lang.WrappedTargetException;
41 import java.io.PrintWriter;
42 import java.util.Comparator;
44 import lib.StatusException;
45 import lib.TestCase;
46 import lib.TestEnvironment;
47 import lib.TestParameters;
48 import util.FormTools;
49 import util.SOfficeFactory;
50 import util.ValueComparer;
52 import com.sun.star.container.XIndexAccess;
53 import com.sun.star.frame.XModel;
54 import com.sun.star.lang.XComponent;
55 import com.sun.star.lang.XMultiServiceFactory;
56 import com.sun.star.sheet.XCellRangeAddressable;
57 import com.sun.star.sheet.XSpreadsheet;
58 import com.sun.star.sheet.XSpreadsheetDocument;
59 import com.sun.star.sheet.XSpreadsheets;
60 import com.sun.star.table.CellRangeAddress;
61 import com.sun.star.table.XCell;
62 import com.sun.star.uno.AnyConverter;
63 import com.sun.star.uno.Type;
64 import com.sun.star.uno.UnoRuntime;
65 import com.sun.star.uno.XInterface;
67 /**
68 * Test for object which is represented by service
69 * <code>com.sun.star.sheet.SpreadsheetView</code>. <p>
70 * Object implements the following interfaces :
71 * <ul>
72 * <li> <code>com::sun::star::sheet::XViewSplitable</code></li>
73 * <li> <code>com::sun::star::sheet::XViewFreezable</code></li>
74 * <li> <code>com::sun::star::sheet::SpreadsheetViewSettings</code></li>
75 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
76 * <li> <code>com::sun::star::container::XIndexAccess</code></li>
77 * <li> <code>com::sun::star::container::XElementAccess</code></li>
78 * <li> <code>com::sun::star::sheet::XSpreadsheetView</code></li>
79 * <li> <code>com::sun::star::view::XSelectionSupplier</code></li>
80 * </ul>
81 * @see com.sun.star.sheet.XViewSplitable
82 * @see com.sun.star.sheet.XViewFreezable
83 * @see com.sun.star.sheet.SpreadsheetViewSettings
84 * @see com.sun.star.beans.XPropertySet
85 * @see com.sun.star.container.XIndexAccess
86 * @see com.sun.star.container.XElementAccess
87 * @see com.sun.star.sheet.XSpreadsheetView
88 * @see com.sun.star.view.XSelectionSupplier
89 * @see ifc.sheet._XViewSplitable
90 * @see ifc.sheet._XViewFreezable
91 * @see ifc.sheet._SpreadsheetViewSettings
92 * @see ifc.beans._XPropertySet
93 * @see ifc.container._XIndexAccess
94 * @see ifc.container._XElementAccess
95 * @see ifc.sheet._XSpreadsheetView
96 * @see ifc.view._XSelectionSupplier
98 public class ScTabViewObj extends TestCase {
99 public static XSpreadsheetDocument xSpreadsheetDoc;
100 public static XSpreadsheetDocument xSpreadsheetDoc2;
103 * Creates Spreadsheet document.
105 public void initialize( TestParameters Param, PrintWriter log ) {
106 // get a soffice factory object
108 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF());
110 try {
111 log.println("creating two spreadsheet documents");
112 xSpreadsheetDoc = SOF.createCalcDoc(null);
113 try {
114 Thread.sleep(1000);
115 } catch (java.lang.InterruptedException e) {}
116 xSpreadsheetDoc2 = SOF.createCalcDoc(null);
117 } catch (com.sun.star.uno.Exception e) {
118 e.printStackTrace( log );
119 throw new StatusException( "Couldn't create document ", e );
124 * Disposes Spreadsheet document.
126 protected void cleanup( TestParameters tParam, PrintWriter log ) {
127 log.println( " disposing xSheetDoc " );
128 XComponent oComp = (XComponent)
129 UnoRuntime.queryInterface(XComponent.class, xSpreadsheetDoc) ;
130 util.DesktopTools.closeDoc(oComp);
131 XComponent oComp2 = (XComponent)
132 UnoRuntime.queryInterface(XComponent.class, xSpreadsheetDoc2) ;
133 util.DesktopTools.closeDoc(oComp2);
137 * Creating a Testenvironment for the interfaces to be tested.
138 * Retieves the current controller of the spreadsheet document using the
139 * interface <code>XModel</code>. The controller is the instance of the
140 * service <code>com.sun.star.sheet.SpreadsheetView</code>. Retrieves
141 * a collection of spreadsheets from the document and takes one of them.
142 * Fills two cells in the spreadsheet.
143 * Object relations created :
144 * <ul>
145 * <li> <code>'Sheet'</code> for
146 * {@link ifc.sheet._XSpreadsheetView}(the retrieved spreadsheet)</li>
147 * </ul>
148 * @see com.sun.star.frame.XModel
149 * @see com.sun.star.sheet.SpreadsheetView
151 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
152 XDrawPage oDrawPage = null;
154 XModel aModel = (XModel)
155 UnoRuntime.queryInterface(XModel.class, xSpreadsheetDoc);
157 XModel aSecondModel = (XModel)
158 UnoRuntime.queryInterface(XModel.class, xSpreadsheetDoc2);
160 XInterface oObj = aModel.getCurrentController();
162 log.println("getting sheets");
163 XSpreadsheets xSpreadsheets = (XSpreadsheets)xSpreadsheetDoc.getSheets();
165 log.println("getting a sheet");
166 XSpreadsheet oSheet = null;
167 XIndexAccess oIndexAccess = (XIndexAccess)
168 UnoRuntime.queryInterface(XIndexAccess.class, xSpreadsheets);
169 try {
170 oSheet = (XSpreadsheet) AnyConverter.toObject(
171 new Type(XSpreadsheet.class), oIndexAccess.getByIndex(1));
172 } catch (com.sun.star.lang.WrappedTargetException e) {
173 e.printStackTrace(log);
174 throw new StatusException( "Couldn't get a spreadsheet", e);
175 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
176 e.printStackTrace(log);
177 throw new StatusException( "Couldn't get a spreadsheet", e);
178 } catch (com.sun.star.lang.IllegalArgumentException e) {
179 e.printStackTrace(log);
180 throw new StatusException( "Couldn't get a spreadsheet", e);
183 TestEnvironment tEnv = new TestEnvironment(oObj);
185 tEnv.addObjRelation("XDispatchProvider.URL", ".uno:Copy") ;
187 log.println("adding 'Sheet' as ObjRelation");
188 tEnv.addObjRelation("Sheet", oSheet);
189 tEnv.addObjRelation("Frame",aModel.getCurrentController().getFrame());
190 tEnv.addObjRelation("SecondModel",aSecondModel);
191 tEnv.addObjRelation("FirstModel",aModel);
193 //Relation for XControlAccess
194 tEnv.addObjRelation("DOCUMENT", UnoRuntime.queryInterface(XComponent.class,xSpreadsheetDoc));
195 tEnv.addObjRelation("XControlAccess.isSheet", Boolean.TRUE);
196 //Relations for XSelectionSupplier
197 XCell cell_1 = null;
198 XCell cell_2 = null;
199 Object cellRange = null;
200 try {
201 cellRange = (Object)oSheet.getCellRangeByPosition(0, 0, 3, 3);
202 cell_1 = oSheet.getCellByPosition(5,5);
203 cell_2 = oSheet.getCellByPosition(7,7);
204 cell_2.setValue(17.5);
205 cell_1.setValue(5.5);
206 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
207 e.printStackTrace(log);
208 throw new StatusException("Couldn't get some cell", e);
211 Object[] selections = {oSheet, cellRange, cell_1, cell_2};
212 tEnv.addObjRelation("Selections", selections);
214 tEnv.addObjRelation("Comparer", new Comparator() {
215 public int compare(Object o1, Object o2) {
216 XCellRangeAddressable adr1 = (XCellRangeAddressable)
217 UnoRuntime.queryInterface(XCellRangeAddressable.class, o1);
218 XCellRangeAddressable adr2 = (XCellRangeAddressable)
219 UnoRuntime.queryInterface(XCellRangeAddressable.class, o2);
220 if (adr1 == null || adr2 == null) return -1;
221 CellRangeAddress range1 = adr1.getRangeAddress();
222 CellRangeAddress range2 = adr2.getRangeAddress();
223 return ValueComparer.equalValue(range1, range2) ? 0 : 1 ;
225 public boolean equals(Object obj) {
226 return compare(this, obj) == 0;
227 } });
229 tEnv.addObjRelation("XUserInputInterception.XModel", aModel);
231 // XForm for com.sun.star.view.XFormLayerAccess
233 XForm myForm = null;
234 String kindOfControl="CommandButton";
235 XShape aShape = null;
236 try{
237 log.println("adding contol shape '" + kindOfControl + "'");
238 XComponent oComp = (XComponent) UnoRuntime.queryInterface(XComponent.class, xSpreadsheetDoc) ;
240 aShape = FormTools.createControlShape(oComp, 3000, 4500, 15000, 10000, kindOfControl);
242 } catch (Exception e){
243 e.printStackTrace(log);
244 throw new StatusException("Couldn't create following control shape : '" +
245 kindOfControl + "': ", e);
248 log.println("adding relation for com.sun.star.view.XFormLayerAccess: XForm");
249 try {
250 log.println( "getting Drawpages" );
251 XDrawPagesSupplier oDPS = (XDrawPagesSupplier)
252 UnoRuntime.queryInterface(XDrawPagesSupplier.class,xSpreadsheetDoc);
253 XDrawPages oDP = (XDrawPages) oDPS.getDrawPages();
254 oDP.insertNewByIndex(1);
255 oDP.insertNewByIndex(2);
256 oDrawPage = (XDrawPage) AnyConverter.toObject(
257 new Type(XDrawPage.class),oDP.getByIndex(0));
258 if (oDrawPage == null)
259 log.println("ERROR: could not get DrawPage: null");
261 oDrawPage.add(aShape);
262 log.println("getting XForm");
263 XNameContainer xForm = FormTools.getForms(oDrawPage);
264 try {
265 myForm = (XForm) AnyConverter.toObject(new Type(XForm.class),xForm.getByName("Standard"));
266 } catch (WrappedTargetException ex) {
267 log.println("ERROR: could not XFormm 'Standard': " + ex.toString());
268 } catch (com.sun.star.lang.IllegalArgumentException ex) {
269 log.println("ERROR: could not XFormm 'Standard': " + ex.toString());
270 } catch (NoSuchElementException ex) {
271 log.println("ERROR: could not XFormm 'Standard': " + ex.toString());
273 if (myForm == null)
274 log.println("ERROR: could not get XForm: null");
275 tEnv.addObjRelation("XFormLayerAccess.XForm", myForm);
276 } catch (com.sun.star.lang.IndexOutOfBoundsException ex) {
277 log.println("ERROR: could not add ObjectRelation 'XFormLayerAccess.XForm': " + ex.toString());
278 } catch (WrappedTargetException ex) {
279 log.println("ERROR: could not add ObjectRelation 'XFormLayerAccess.XForm': " + ex.toString());
280 } catch (com.sun.star.lang.IllegalArgumentException ex) {
281 log.println("ERROR: could not add ObjectRelation 'XFormLayerAccess.XForm': " + ex.toString());
283 return tEnv;
286 } // finish class ScTabViewObj