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 .
20 import com
.sun
.star
.container
.XIndexAccess
;
21 import com
.sun
.star
.frame
.XController
;
22 import com
.sun
.star
.frame
.XModel
;
23 import com
.sun
.star
.lang
.XComponent
;
24 import com
.sun
.star
.lang
.XMultiServiceFactory
;
25 import com
.sun
.star
.sheet
.XSpreadsheet
;
26 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
27 import com
.sun
.star
.sheet
.XSpreadsheets
;
28 import com
.sun
.star
.table
.XCell
;
29 import com
.sun
.star
.uno
.AnyConverter
;
30 import com
.sun
.star
.uno
.Type
;
31 import com
.sun
.star
.uno
.UnoRuntime
;
32 import com
.sun
.star
.uno
.XInterface
;
33 import com
.sun
.star
.view
.XSelectionSupplier
;
34 import ifc
.view
._XPrintJobBroadcaster
;
37 import java
.io
.PrintWriter
;
39 import lib
.StatusException
;
41 import lib
.TestEnvironment
;
42 import lib
.TestParameters
;
44 import util
.SOfficeFactory
;
49 * Test for object which is represented by service
50 * <code>com.sun.star.sheet.SpreadsheetDocument</code>. <p>
51 * Object implements the following interfaces :
53 * <li> <code>com::sun::star::sheet::XSpreadsheetDocument</code></li>
54 * <li> <code>com::sun::star::sheet::SpreadsheetDocumentSettings</code></li>
55 * <li> <code>com::sun::star::lang::XComponent</code></li>
56 * <li> <code>com::sun::star::frame::XModel</code></li>
57 * <li> <code>com::sun::star::sheet::SpreadsheetDocument</code></li>
58 * <li> <code>com::sun::star::util::XNumberFormatsSupplier</code></li>
59 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
61 * @see com.sun.star.sheet.SpreadsheetDocument
62 * @see com.sun.star.sheet.XSpreadsheetDocument
63 * @see com.sun.star.sheet.SpreadsheetDocumentSettings
64 * @see com.sun.star.lang.XComponent
65 * @see com.sun.star.frame.XModel
66 * @see com.sun.star.sheet.SpreadsheetDocument
67 * @see com.sun.star.util.XNumberFormatsSupplier
68 * @see com.sun.star.beans.XPropertySet
69 * @see ifc.sheet._XSpreadsheetDocument
70 * @see ifc.sheet._SpreadsheetDocumentSettings
71 * @see ifc.lang._XComponent
72 * @see ifc.frame._XModel
73 * @see ifc.sheet._SpreadsheetDocument
74 * @see ifc.util._XNumberFormatsSupplier
75 * @see ifc.beans._XPropertySet
77 public class ScModelObj
extends TestCase
{
78 private XSpreadsheetDocument xSpreadsheetDoc
;
79 private XSpreadsheetDocument xSecondsheetDoc
;
82 * Disposes Spreadsheet documents.
84 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
85 log
.println(" disposing xSheetDoc ");
87 XComponent oComp
= UnoRuntime
.queryInterface(
88 XComponent
.class, xSpreadsheetDoc
);
89 util
.DesktopTools
.closeDoc(oComp
);
91 oComp
= UnoRuntime
.queryInterface(XComponent
.class,
93 util
.DesktopTools
.closeDoc(oComp
);
97 * Creating a Testenvironment for the interfaces to be tested.
98 * Disposes the spreadsheet documents if they was created already.
99 * Creates two spreadsheet documents. Rertieves the current controller for
100 * each of them. Obtains the collection of spreadsheets, takes one of them
101 * and takes some cell from the spreadsheet. The created documents are the instances
102 * of the service <code>com.sun.star.sheet.SpreadsheetDocument</code>.
103 * Object relations created :
105 * <li> <code>'SELSUPP'</code> for
106 * {@link ifc.frame._XModel}( the interface
107 * <code>XSelectionSupplier</code> that was queried from the current
108 * controller of the spreadsheet)</li>
109 * <li> <code>'TOSELECT'</code> for
110 * {@link ifc.frame._XModel}( the cell that was retrieved from the
112 * <li> <code>'CONT2'</code> for
113 * {@link ifc.frame._XModel}( the current controller of the second
117 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
,
119 // creation of the testobject here
120 // first we write what we are intend to do to log file
121 log
.println("craeting a test environment");
123 // get a soffice factory object
124 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
125 (XMultiServiceFactory
) Param
.getMSF());
127 if (xSpreadsheetDoc
!= null) {
128 XComponent oComp
= UnoRuntime
.queryInterface(
129 XComponent
.class, xSpreadsheetDoc
);
130 util
.DesktopTools
.closeDoc(oComp
);
133 if (xSecondsheetDoc
!= null) {
134 XComponent oComp
= UnoRuntime
.queryInterface(
135 XComponent
.class, xSecondsheetDoc
);
136 util
.DesktopTools
.closeDoc(oComp
);
140 log
.println("creating two spreadsheet documents");
141 xSpreadsheetDoc
= SOF
.createCalcDoc(null);
142 xSecondsheetDoc
= SOF
.createCalcDoc(null);
143 } catch (com
.sun
.star
.uno
.Exception e
) {
144 e
.printStackTrace(log
);
145 throw new StatusException("Couldn't create document ", e
);
148 XModel model1
= UnoRuntime
.queryInterface(XModel
.class,
150 XModel model2
= UnoRuntime
.queryInterface(XModel
.class,
152 XInterface oObj
= model1
;
154 TestEnvironment tEnv
= new TestEnvironment(oObj
);
156 XController cont1
= model1
.getCurrentController();
157 XController cont2
= model2
.getCurrentController();
158 cont1
.getFrame().setName("cont1");
159 cont2
.getFrame().setName("cont2");
161 XSelectionSupplier sel
= UnoRuntime
.queryInterface(
162 XSelectionSupplier
.class, cont1
);
165 XCell
[] xCalculatableCells
= null;
167 log
.println("Getting spreadsheet");
169 XSpreadsheets oSheets
= xSpreadsheetDoc
.getSheets();
170 XIndexAccess oIndexSheets
= UnoRuntime
.queryInterface(
171 XIndexAccess
.class, oSheets
);
172 XSpreadsheet oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
173 new Type(XSpreadsheet
.class),
174 oIndexSheets
.getByIndex(0));
176 log
.println("Getting a cell from sheet");
177 toSel
= oSheet
.getCellByPosition(2, 3);
178 // create a simple formula for XCalculatable
179 oSheet
.getCellByPosition(4, 5).setValue(15);
180 oSheet
.getCellByPosition(5, 5).setValue(10);
181 oSheet
.getCellByPosition(6, 5).setFormula("= E6 * F6");
182 xCalculatableCells
= new XCell
[]{
183 oSheet
.getCellByPosition(4, 5),
184 oSheet
.getCellByPosition(5, 5),
185 oSheet
.getCellByPosition(6, 5)
188 // Make sure there are at least two sheets:
189 oSheets
.insertNewByName("Some Sheet", (short) 1);
190 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
191 e
.printStackTrace(log
);
192 throw new StatusException(
193 "Error getting cell object from spreadsheet document", e
);
194 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
195 e
.printStackTrace(log
);
196 throw new StatusException(
197 "Error getting cell object from spreadsheet document", e
);
198 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
199 e
.printStackTrace(log
);
200 throw new StatusException(
201 "Error getting cell object from spreadsheet document", e
);
204 log
.println("Adding SelectionSupplier and Shape to select for XModel");
205 tEnv
.addObjRelation("SELSUPP", sel
);
206 tEnv
.addObjRelation("TOSELECT", toSel
);
208 log
.println("Adding cells for XCalculatable");
209 tEnv
.addObjRelation("XCalculatable.Cells", xCalculatableCells
);
210 log
.println("adding Controller as ObjRelation for XModel");
211 tEnv
.addObjRelation("CONT2", cont2
);
213 // create object relation for XPrintJobBroadcaster
214 String fileName
= utils
.getOfficeTempDirSys((XMultiServiceFactory
) Param
.getMSF())+"printfile.prt" ;
215 File f
= new File(fileName
);
219 _XPrintJobBroadcaster
.MyPrintJobListener listener
= new _XPrintJobBroadcaster
.MyPrintJobListener(oObj
, fileName
);
220 tEnv
.addObjRelation("XPrintJobBroadcaster.XPrintJobListener", listener
);
225 } // finish class ScModelObj