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 .
21 import com
.sun
.star
.container
.NoSuchElementException
;
22 import com
.sun
.star
.container
.XNameContainer
;
23 import com
.sun
.star
.drawing
.XDrawPage
;
24 import com
.sun
.star
.drawing
.XDrawPages
;
25 import com
.sun
.star
.drawing
.XDrawPagesSupplier
;
26 import com
.sun
.star
.drawing
.XShape
;
27 import com
.sun
.star
.form
.XForm
;
28 import com
.sun
.star
.lang
.WrappedTargetException
;
29 import java
.io
.PrintWriter
;
30 import java
.util
.Comparator
;
32 import lib
.StatusException
;
34 import lib
.TestEnvironment
;
35 import lib
.TestParameters
;
36 import util
.FormTools
;
37 import util
.SOfficeFactory
;
38 import util
.ValueComparer
;
40 import com
.sun
.star
.container
.XIndexAccess
;
41 import com
.sun
.star
.frame
.XModel
;
42 import com
.sun
.star
.lang
.XComponent
;
43 import com
.sun
.star
.sheet
.XCellRangeAddressable
;
44 import com
.sun
.star
.sheet
.XSpreadsheet
;
45 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
46 import com
.sun
.star
.sheet
.XSpreadsheets
;
47 import com
.sun
.star
.table
.CellRangeAddress
;
48 import com
.sun
.star
.table
.XCell
;
49 import com
.sun
.star
.uno
.AnyConverter
;
50 import com
.sun
.star
.uno
.Type
;
51 import com
.sun
.star
.uno
.UnoRuntime
;
52 import com
.sun
.star
.uno
.XInterface
;
55 * Test for object which is represented by service
56 * <code>com.sun.star.sheet.SpreadsheetView</code>. <p>
57 * Object implements the following interfaces :
59 * <li> <code>com::sun::star::sheet::XViewSplitable</code></li>
60 * <li> <code>com::sun::star::sheet::XViewFreezable</code></li>
61 * <li> <code>com::sun::star::sheet::SpreadsheetViewSettings</code></li>
62 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
63 * <li> <code>com::sun::star::container::XIndexAccess</code></li>
64 * <li> <code>com::sun::star::container::XElementAccess</code></li>
65 * <li> <code>com::sun::star::sheet::XSpreadsheetView</code></li>
66 * <li> <code>com::sun::star::view::XSelectionSupplier</code></li>
68 * @see com.sun.star.sheet.XViewSplitable
69 * @see com.sun.star.sheet.XViewFreezable
70 * @see com.sun.star.sheet.SpreadsheetViewSettings
71 * @see com.sun.star.beans.XPropertySet
72 * @see com.sun.star.container.XIndexAccess
73 * @see com.sun.star.container.XElementAccess
74 * @see com.sun.star.sheet.XSpreadsheetView
75 * @see com.sun.star.view.XSelectionSupplier
76 * @see ifc.sheet._XViewSplitable
77 * @see ifc.sheet._XViewFreezable
78 * @see ifc.sheet._SpreadsheetViewSettings
79 * @see ifc.beans._XPropertySet
80 * @see ifc.container._XIndexAccess
81 * @see ifc.container._XElementAccess
82 * @see ifc.sheet._XSpreadsheetView
83 * @see ifc.view._XSelectionSupplier
85 public class ScTabViewObj
extends TestCase
{
86 private XSpreadsheetDocument xSpreadsheetDoc
;
87 private XSpreadsheetDocument xSpreadsheetDoc2
;
90 * Creates Spreadsheet document.
93 public void initialize( TestParameters Param
, PrintWriter log
) {
94 // get a soffice factory object
96 SOfficeFactory SOF
= SOfficeFactory
.getFactory( Param
.getMSF());
99 log
.println("creating two spreadsheet documents");
100 xSpreadsheetDoc
= SOF
.createCalcDoc(null);
101 util
.utils
.pause(1000);
102 xSpreadsheetDoc2
= SOF
.createCalcDoc(null);
103 } catch (com
.sun
.star
.uno
.Exception e
) {
104 e
.printStackTrace( log
);
105 throw new StatusException( "Couldn't create document ", e
);
110 * Disposes Spreadsheet document.
113 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
114 log
.println( " disposing xSheetDoc " );
115 XComponent oComp
= UnoRuntime
.queryInterface(XComponent
.class, xSpreadsheetDoc
) ;
116 util
.DesktopTools
.closeDoc(oComp
);
117 XComponent oComp2
= UnoRuntime
.queryInterface(XComponent
.class, xSpreadsheetDoc2
) ;
118 util
.DesktopTools
.closeDoc(oComp2
);
122 * Creating a Testenvironment for the interfaces to be tested.
123 * Retieves the current controller of the spreadsheet document using the
124 * interface <code>XModel</code>. The controller is the instance of the
125 * service <code>com.sun.star.sheet.SpreadsheetView</code>. Retrieves
126 * a collection of spreadsheets from the document and takes one of them.
127 * Fills two cells in the spreadsheet.
128 * Object relations created :
130 * <li> <code>'Sheet'</code> for
131 * {@link ifc.sheet._XSpreadsheetView}(the retrieved spreadsheet)</li>
133 * @see com.sun.star.frame.XModel
134 * @see com.sun.star.sheet.SpreadsheetView
137 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
138 XDrawPage oDrawPage
= null;
140 XModel aModel
= UnoRuntime
.queryInterface(XModel
.class, xSpreadsheetDoc
);
142 XModel aSecondModel
= UnoRuntime
.queryInterface(XModel
.class, xSpreadsheetDoc2
);
144 XInterface oObj
= aModel
.getCurrentController();
146 log
.println("getting sheets");
147 XSpreadsheets xSpreadsheets
= xSpreadsheetDoc
.getSheets();
149 log
.println("getting a sheet");
150 XSpreadsheet oSheet
= null;
151 XIndexAccess oIndexAccess
= UnoRuntime
.queryInterface(XIndexAccess
.class, xSpreadsheets
);
153 oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
154 new Type(XSpreadsheet
.class), oIndexAccess
.getByIndex(1));
155 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
156 e
.printStackTrace(log
);
157 throw new StatusException( "Couldn't get a spreadsheet", e
);
158 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
159 e
.printStackTrace(log
);
160 throw new StatusException( "Couldn't get a spreadsheet", e
);
161 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
162 e
.printStackTrace(log
);
163 throw new StatusException( "Couldn't get a spreadsheet", e
);
166 TestEnvironment tEnv
= new TestEnvironment(oObj
);
168 tEnv
.addObjRelation("XDispatchProvider.URL", ".uno:Copy") ;
170 log
.println("adding 'Sheet' as ObjRelation");
171 tEnv
.addObjRelation("Sheet", oSheet
);
172 tEnv
.addObjRelation("Frame",aModel
.getCurrentController().getFrame());
173 tEnv
.addObjRelation("SecondModel",aSecondModel
);
174 tEnv
.addObjRelation("FirstModel",aModel
);
176 //Relation for XControlAccess
177 tEnv
.addObjRelation("DOCUMENT", UnoRuntime
.queryInterface(XComponent
.class,xSpreadsheetDoc
));
178 tEnv
.addObjRelation("XControlAccess.isSheet", Boolean
.TRUE
);
179 //Relations for XSelectionSupplier
182 Object cellRange
= null;
184 cellRange
= oSheet
.getCellRangeByPosition(0, 0, 3, 3);
185 cell_1
= oSheet
.getCellByPosition(5,5);
186 cell_2
= oSheet
.getCellByPosition(7,7);
187 cell_2
.setValue(17.5);
188 cell_1
.setValue(5.5);
189 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
190 e
.printStackTrace(log
);
191 throw new StatusException("Couldn't get some cell", e
);
194 Object
[] selections
= {oSheet
, cellRange
, cell_1
, cell_2
};
195 tEnv
.addObjRelation("Selections", selections
);
197 tEnv
.addObjRelation("Comparer", new Comparator
<Object
>() {
198 public int compare(Object o1
, Object o2
) {
199 XCellRangeAddressable adr1
= UnoRuntime
.queryInterface(XCellRangeAddressable
.class, o1
);
200 XCellRangeAddressable adr2
= UnoRuntime
.queryInterface(XCellRangeAddressable
.class, o2
);
201 if (adr1
== null || adr2
== null) return -1;
202 CellRangeAddress range1
= adr1
.getRangeAddress();
203 CellRangeAddress range2
= adr2
.getRangeAddress();
204 return ValueComparer
.equalValue(range1
, range2
) ?
0 : 1 ;
207 tEnv
.addObjRelation("XUserInputInterception.XModel", aModel
);
209 // XForm for com.sun.star.view.XFormLayerAccess
212 String kindOfControl
="CommandButton";
213 XShape aShape
= null;
215 log
.println("adding contol shape '" + kindOfControl
+ "'");
216 XComponent oComp
= UnoRuntime
.queryInterface(XComponent
.class, xSpreadsheetDoc
) ;
218 aShape
= FormTools
.createControlShape(oComp
, 3000, 4500, 15000, 10000, kindOfControl
);
220 } catch (Exception e
){
221 e
.printStackTrace(log
);
222 throw new StatusException("Couldn't create following control shape : '" +
223 kindOfControl
+ "': ", e
);
226 log
.println("adding relation for com.sun.star.view.XFormLayerAccess: XForm");
228 log
.println( "getting Drawpages" );
229 XDrawPagesSupplier oDPS
= UnoRuntime
.queryInterface(XDrawPagesSupplier
.class,xSpreadsheetDoc
);
230 XDrawPages oDP
= oDPS
.getDrawPages();
231 oDP
.insertNewByIndex(1);
232 oDP
.insertNewByIndex(2);
233 oDrawPage
= (XDrawPage
) AnyConverter
.toObject(
234 new Type(XDrawPage
.class),oDP
.getByIndex(0));
235 if (oDrawPage
== null)
236 log
.println("ERROR: could not get DrawPage: null");
238 oDrawPage
.add(aShape
);
239 log
.println("getting XForm");
240 XNameContainer xForm
= FormTools
.getForms(oDrawPage
);
242 myForm
= (XForm
) AnyConverter
.toObject(new Type(XForm
.class),xForm
.getByName("Standard"));
243 } catch (WrappedTargetException ex
) {
244 log
.println("ERROR: could not XFormm 'Standard': " + ex
.toString());
245 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
246 log
.println("ERROR: could not XFormm 'Standard': " + ex
.toString());
247 } catch (NoSuchElementException ex
) {
248 log
.println("ERROR: could not XFormm 'Standard': " + ex
.toString());
251 log
.println("ERROR: could not get XForm: null");
252 tEnv
.addObjRelation("XFormLayerAccess.XForm", myForm
);
253 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException ex
) {
254 log
.println("ERROR: could not add ObjectRelation 'XFormLayerAccess.XForm': " + ex
.toString());
255 } catch (WrappedTargetException ex
) {
256 log
.println("ERROR: could not add ObjectRelation 'XFormLayerAccess.XForm': " + ex
.toString());
257 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
258 log
.println("ERROR: could not add ObjectRelation 'XFormLayerAccess.XForm': " + ex
.toString());
263 } // finish class ScTabViewObj