bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScViewPaneObj.java
blobb96da0233a79ccb66cc7427a0889a044f6b17070
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 java.io.PrintWriter;
24 import lib.StatusException;
25 import lib.TestCase;
26 import lib.TestEnvironment;
27 import lib.TestParameters;
28 import util.SOfficeFactory;
30 import com.sun.star.container.XIndexAccess;
31 import com.sun.star.container.XNameContainer;
32 import com.sun.star.drawing.XDrawPage;
33 import com.sun.star.drawing.XDrawPages;
34 import com.sun.star.drawing.XDrawPagesSupplier;
35 import com.sun.star.drawing.XShape;
36 import com.sun.star.form.XForm;
37 import com.sun.star.frame.XController;
38 import com.sun.star.frame.XModel;
39 import com.sun.star.lang.WrappedTargetException;
40 import com.sun.star.lang.XComponent;
41 import com.sun.star.lang.XMultiServiceFactory;
42 import com.sun.star.sheet.XSpreadsheetDocument;
43 import com.sun.star.sheet.XViewPane;
44 import com.sun.star.table.CellRangeAddress;
45 import com.sun.star.uno.AnyConverter;
46 import com.sun.star.uno.Type;
47 import com.sun.star.uno.UnoRuntime;
48 import com.sun.star.uno.XInterface;
49 import util.FormTools;
51 /**
52 * Test for object which is represented by service
53 * <code>com.sun.star.sheet.SpreadsheetViewPane</code>. <p>
54 * Object implements the following interfaces :
55 * <ul>
56 * <li> <code>com::sun::star::sheet::XViewPane</code></li>
57 * <li> <code>com::sun::star::sheet::XCellRangeReferrer</code></li>
58 * </ul>
59 * @see com.sun.star.sheet.SpreadsheetViewPane
60 * @see com.sun.star.sheet.XViewPane
61 * @see com.sun.star.sheet.XCellRangeReferrer
62 * @see ifc.sheet._XViewPane
63 * @see ifc.sheet._XCellRangeReferrer
65 public class ScViewPaneObj extends TestCase {
66 static private XSpreadsheetDocument xSpreadsheetDoc;
67 static private SOfficeFactory SOF;
68 static private XInterface oObj;
70 /**
71 * Creates Spreadsheet document.
73 public void initialize( TestParameters Param, PrintWriter log ) {
74 // get a soffice factory object
75 SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF());
77 try {
78 log.println("creating a spreadsheetdocument");
79 xSpreadsheetDoc = SOF.createCalcDoc(null);
80 } catch (com.sun.star.uno.Exception e) {
81 e.printStackTrace( log );
82 throw new StatusException( "Couldn't create document ", e );
86 /**
87 * Disposes Spreadsheet document.
89 protected void cleanup( TestParameters tParam, PrintWriter log ) {
90 log.println("disposing xSpreadsheetDocument");
91 XComponent oComp = UnoRuntime.queryInterface(XComponent.class, xSpreadsheetDoc);
92 util.DesktopTools.closeDoc(oComp);
95 /**
96 * Creating a Testenvironment for the interfaces to be tested.
97 * Retieves the current controller of the spreadsheet document using the
98 * interface <code>XModel</code>. The controller contains the collection
99 * of the view panes so retrieves the view pane with index 0 from
100 * the collection. The retrived view pane is the instance of the service
101 * <code>com.sun.star.sheet.SpreadsheetViewPane</code>. Retrieves the address
102 * of the cell range that consists of the cells which are visible in the pane.
103 * Object relations created :
104 * <ul>
105 * <li> <code>'DATAAREA'</code> for
106 * {@link ifc.sheet._XViewPane}(the retrieved address)</li>
107 * </ul>
108 * @see com.sun.star.frame.XModel
110 protected TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
111 XDrawPage oDrawPage;
113 XModel xm = UnoRuntime.queryInterface(XModel.class, xSpreadsheetDoc);
114 XController xc = xm.getCurrentController();
115 XIndexAccess xIA = UnoRuntime.queryInterface(XIndexAccess.class, xc);
116 try {
117 oObj = (XInterface) AnyConverter.toObject(
118 new Type(XInterface.class),xIA.getByIndex(0));
119 } catch (com.sun.star.lang.WrappedTargetException e) {
120 e.printStackTrace(log);
121 throw new StatusException("Couldn't get by index", e);
122 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
123 e.printStackTrace(log);
124 throw new StatusException("Couldn't get by index", e);
125 } catch (com.sun.star.lang.IllegalArgumentException e) {
126 e.printStackTrace(log);
127 throw new StatusException("Couldn't get by index", e);
130 TestEnvironment tEnv = new TestEnvironment(oObj);
132 //Relation for XControlAccess
133 tEnv.addObjRelation("DOCUMENT", UnoRuntime.queryInterface(XComponent.class,xSpreadsheetDoc));
134 tEnv.addObjRelation("XControlAccess.isSheet", Boolean.TRUE);
136 XViewPane VP = UnoRuntime.queryInterface(XViewPane.class, oObj);
137 CellRangeAddress dataArea = VP.getVisibleRange();
138 tEnv.addObjRelation("DATAAREA", dataArea);
140 // XForm for com.sun.star.view.XFormLayerAccess
141 log.println("adding relation for com.sun.star.view.XFormLayerAccess: XForm");
143 XForm myForm = null;
144 String kindOfControl="CommandButton";
145 XShape aShape = null;
146 try{
147 log.println("adding contol shape '" + kindOfControl + "'");
148 XComponent oComp = UnoRuntime.queryInterface(XComponent.class, xSpreadsheetDoc) ;
150 aShape = FormTools.createControlShape(oComp, 3000, 4500, 15000, 10000, kindOfControl);
152 } catch (Exception e){
153 e.printStackTrace(log);
154 throw new StatusException("Couldn't create following control shape : '" +
155 kindOfControl + "': ", e);
158 try {
159 log.println( "getting Drawpages" );
160 XDrawPagesSupplier oDPS = UnoRuntime.queryInterface(XDrawPagesSupplier.class,xSpreadsheetDoc);
161 XDrawPages oDP = oDPS.getDrawPages();
162 oDP.insertNewByIndex(1);
163 oDP.insertNewByIndex(2);
164 oDrawPage = (XDrawPage) AnyConverter.toObject(
165 new Type(XDrawPage.class),oDP.getByIndex(0));
166 if (oDrawPage == null)
167 log.println("ERROR: could not get DrawPage: null");
169 oDrawPage.add(aShape);
170 log.println("getting XForm");
171 XNameContainer xForm = FormTools.getForms(oDrawPage);
172 try {
173 myForm = (XForm) AnyConverter.toObject(new Type(XForm.class),xForm.getByName("Standard"));
174 } catch (WrappedTargetException ex) {
175 log.println("ERROR: could not XFormm 'Standard': " + ex.toString());
176 } catch (com.sun.star.lang.IllegalArgumentException ex) {
177 log.println("ERROR: could not XFormm 'Standard': " + ex.toString());
178 } catch (NoSuchElementException ex) {
179 log.println("ERROR: could not XFormm 'Standard': " + ex.toString());
181 if (myForm == null)
182 log.println("ERROR: could not get XForm: null");
183 tEnv.addObjRelation("XFormLayerAccess.XForm", myForm);
184 } catch (com.sun.star.lang.IndexOutOfBoundsException ex) {
185 log.println("ERROR: could not add ObjectRelation 'XFormLayerAccess.XForm': " + ex.toString());
186 } catch (WrappedTargetException ex) {
187 log.println("ERROR: could not add ObjectRelation 'XFormLayerAccess.XForm': " + ex.toString());
188 } catch (com.sun.star.lang.IllegalArgumentException ex) {
189 log.println("ERROR: could not add ObjectRelation 'XFormLayerAccess.XForm': " + ex.toString());
192 return tEnv;