tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScTabViewObj.java
bloba00b2724d80f4ee3475740748042694af3ae4bc6
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 .
19 package mod._sc;
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;
30 import java.io.PrintWriter;
31 import java.util.Comparator;
33 import lib.TestCase;
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;
54 /**
55 * Test for object which is represented by service
56 * <code>com.sun.star.sheet.SpreadsheetView</code>. <p>
57 * Object implements the following interfaces :
58 * <ul>
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>
67 * </ul>
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;
89 /**
90 * Creates Spreadsheet document.
92 @Override
93 public void initialize( TestParameters Param, PrintWriter log ) throws Exception {
94 // get a soffice factory object
95 SOfficeFactory SOF = SOfficeFactory.getFactory( Param.getMSF());
96 log.println("creating two spreadsheet documents");
97 xSpreadsheetDoc = SOF.createCalcDoc(null);
98 util.utils.waitForEventIdle(Param.getMSF());
99 xSpreadsheetDoc2 = SOF.createCalcDoc(null);
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, xSpreadsheetDoc) ;
109 util.DesktopTools.closeDoc(oComp);
110 XComponent oComp2 = UnoRuntime.queryInterface(XComponent.class, xSpreadsheetDoc2) ;
111 util.DesktopTools.closeDoc(oComp2);
115 * Creating a TestEnvironment for the interfaces to be tested.
116 * Retrieves the current controller of the spreadsheet document using the
117 * interface <code>XModel</code>. The controller is the instance of the
118 * service <code>com.sun.star.sheet.SpreadsheetView</code>. Retrieves
119 * a collection of spreadsheets from the document and takes one of them.
120 * Fills two cells in the spreadsheet.
121 * Object relations created :
122 * <ul>
123 * <li> <code>'Sheet'</code> for
124 * {@link ifc.sheet._XSpreadsheetView}(the retrieved spreadsheet)</li>
125 * </ul>
126 * @see com.sun.star.frame.XModel
127 * @see com.sun.star.sheet.SpreadsheetView
129 @Override
130 protected TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) throws Exception {
131 XDrawPage oDrawPage = null;
133 XModel aModel = UnoRuntime.queryInterface(XModel.class, xSpreadsheetDoc);
135 XModel aSecondModel = UnoRuntime.queryInterface(XModel.class, xSpreadsheetDoc2);
137 XInterface oObj = aModel.getCurrentController();
139 log.println("getting sheets");
140 XSpreadsheets xSpreadsheets = xSpreadsheetDoc.getSheets();
142 log.println("getting a sheet");
143 XSpreadsheet oSheet = null;
144 XIndexAccess oIndexAccess = UnoRuntime.queryInterface(XIndexAccess.class, xSpreadsheets);
145 oSheet = (XSpreadsheet) AnyConverter.toObject(
146 new Type(XSpreadsheet.class), oIndexAccess.getByIndex(1));
148 TestEnvironment tEnv = new TestEnvironment(oObj);
150 tEnv.addObjRelation("XDispatchProvider.URL", ".uno:Copy") ;
152 log.println("adding 'Sheet' as ObjRelation");
153 tEnv.addObjRelation("Sheet", oSheet);
154 tEnv.addObjRelation("Frame",aModel.getCurrentController().getFrame());
155 tEnv.addObjRelation("SecondModel",aSecondModel);
156 tEnv.addObjRelation("FirstModel",aModel);
158 //Relation for XControlAccess
159 tEnv.addObjRelation("DOCUMENT", UnoRuntime.queryInterface(XComponent.class,xSpreadsheetDoc));
160 tEnv.addObjRelation("XControlAccess.isSheet", Boolean.TRUE);
161 //Relations for XSelectionSupplier
162 XCell cell_1 = null;
163 XCell cell_2 = null;
164 Object cellRange = null;
165 cellRange = oSheet.getCellRangeByPosition(0, 0, 3, 3);
166 cell_1 = oSheet.getCellByPosition(5,5);
167 cell_2 = oSheet.getCellByPosition(7,7);
168 cell_2.setValue(17.5);
169 cell_1.setValue(5.5);
171 Object[] selections = {oSheet, cellRange, cell_1, cell_2};
172 tEnv.addObjRelation("Selections", selections);
174 tEnv.addObjRelation("Comparer", new Comparator<Object>() {
175 public int compare(Object o1, Object o2) {
176 XCellRangeAddressable adr1 = UnoRuntime.queryInterface(XCellRangeAddressable.class, o1);
177 XCellRangeAddressable adr2 = UnoRuntime.queryInterface(XCellRangeAddressable.class, o2);
178 if (adr1 == null || adr2 == null) return -1;
179 CellRangeAddress range1 = adr1.getRangeAddress();
180 CellRangeAddress range2 = adr2.getRangeAddress();
181 return ValueComparer.equalValue(range1, range2) ? 0 : 1 ;
182 }});
184 tEnv.addObjRelation("XUserInputInterception.XModel", aModel);
186 // XForm for com.sun.star.view.XFormLayerAccess
188 XForm myForm = null;
189 String kindOfControl="CommandButton";
190 XShape aShape = null;
191 log.println("adding control shape '" + kindOfControl + "'");
192 XComponent oComp = UnoRuntime.queryInterface(XComponent.class, xSpreadsheetDoc) ;
194 aShape = FormTools.createControlShape(oComp, 3000, 4500, 15000, 10000, kindOfControl);
196 log.println("adding relation for com.sun.star.view.XFormLayerAccess: XForm");
197 try {
198 log.println( "getting Drawpages" );
199 XDrawPagesSupplier oDPS = UnoRuntime.queryInterface(XDrawPagesSupplier.class,xSpreadsheetDoc);
200 XDrawPages oDP = oDPS.getDrawPages();
201 oDP.insertNewByIndex(1);
202 oDP.insertNewByIndex(2);
203 oDrawPage = (XDrawPage) AnyConverter.toObject(
204 new Type(XDrawPage.class),oDP.getByIndex(0));
205 if (oDrawPage == null)
206 log.println("ERROR: could not get DrawPage: null");
208 oDrawPage.add(aShape);
209 log.println("getting XForm");
210 XNameContainer xForm = FormTools.getForms(oDrawPage);
211 try {
212 myForm = (XForm) AnyConverter.toObject(new Type(XForm.class),xForm.getByName("Standard"));
213 } catch (WrappedTargetException ex) {
214 log.println("ERROR: could not XForm 'Standard': " + ex.toString());
215 } catch (com.sun.star.lang.IllegalArgumentException ex) {
216 log.println("ERROR: could not XForm 'Standard': " + ex.toString());
217 } catch (NoSuchElementException ex) {
218 log.println("ERROR: could not XForm 'Standard': " + ex.toString());
220 if (myForm == null)
221 log.println("ERROR: could not get XForm: null");
222 tEnv.addObjRelation("XFormLayerAccess.XForm", myForm);
223 } catch (com.sun.star.lang.IndexOutOfBoundsException ex) {
224 log.println("ERROR: could not add ObjectRelation 'XFormLayerAccess.XForm': " + ex.toString());
225 } catch (WrappedTargetException ex) {
226 log.println("ERROR: could not add ObjectRelation 'XFormLayerAccess.XForm': " + ex.toString());
227 } catch (com.sun.star.lang.IllegalArgumentException ex) {
228 log.println("ERROR: could not add ObjectRelation 'XFormLayerAccess.XForm': " + ex.toString());
230 return tEnv;
233 } // finish class ScTabViewObj