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 java
.io
.PrintWriter
;
23 import lib
.StatusException
;
25 import lib
.TestEnvironment
;
26 import lib
.TestParameters
;
27 import util
.SOfficeFactory
;
29 import com
.sun
.star
.container
.XIndexAccess
;
30 import com
.sun
.star
.lang
.XComponent
;
31 import com
.sun
.star
.sheet
.XCellRangeAddressable
;
32 import com
.sun
.star
.sheet
.XScenariosSupplier
;
33 import com
.sun
.star
.sheet
.XSpreadsheet
;
34 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
35 import com
.sun
.star
.sheet
.XSpreadsheets
;
36 import com
.sun
.star
.table
.CellRangeAddress
;
37 import com
.sun
.star
.table
.XCellRange
;
38 import com
.sun
.star
.uno
.AnyConverter
;
39 import com
.sun
.star
.uno
.Type
;
40 import com
.sun
.star
.uno
.UnoRuntime
;
41 import com
.sun
.star
.uno
.XInterface
;
44 * Test for object which is represented by service
45 * <code>com.sun.star.sheet.Scenarios</code>. <p>
46 * Object implements the following interfaces :
48 * <li> <code>com::sun::star::container::XNameAccess</code></li>
49 * <li> <code>com::sun::star::container::XElementAccess</code></li>
50 * <li> <code>com::sun::star::sheet::XScenarios</code></li>
52 * @see com.sun.star.sheet.Scenarios
53 * @see com.sun.star.container.XNameAccess
54 * @see com.sun.star.container.XElementAccess
55 * @see com.sun.star.sheet.XScenarios
56 * @see ifc.container._XNameAccess
57 * @see ifc.container._XElementAccess
58 * @see ifc.sheet._XScenarios
60 public class ScScenariosObj
extends TestCase
{
61 private XSpreadsheetDocument xSpreadsheetDoc
;
64 * Creates Spreadsheet document.
67 public void initialize( TestParameters Param
, PrintWriter log
) {
68 // get a soffice factory object
69 SOfficeFactory SOF
= SOfficeFactory
.getFactory( Param
.getMSF());
72 log
.println("creating a spreadsheetdocument");
73 xSpreadsheetDoc
= SOF
.createCalcDoc(null);
74 } catch (com
.sun
.star
.uno
.Exception e
) {
75 e
.printStackTrace( log
);
76 throw new StatusException( "Couldn't create document ", e
);
81 * Disposes Spreadsheet document.
84 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
85 log
.println( " disposing xSheetDoc " );
86 XComponent oComp
= UnoRuntime
.queryInterface (XComponent
.class, xSpreadsheetDoc
) ;
87 util
.DesktopTools
.closeDoc(oComp
);
91 * Creating a Testenvironment for the interfaces to be tested.
92 * Retrieves a collection of spreadsheets from a document
93 * and takes one of them. Fills some cells of the spreadsheet.
94 * Retrieves the collection of all scenarios using the interface
95 * <code>XScenariosSupplier</code>. Creates a new scenario and adds it to the
96 * collection. This collection is the instance of the service
97 * <code>com.sun.star.sheet.Scenarios</code>.
98 * Object relations created :
100 * <li> <code>'ADDR'</code> for
101 * {@link ifc.sheet._XScenarios}(the array of cell range addresses
102 * of the created scenario)</li>
104 * @see com.sun.star.sheet.Scenarios
105 * @see com.sun.star.sheet.XScenariosSupplier
108 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
110 log
.println("getting sheets");
111 XSpreadsheets xSpreadsheets
= xSpreadsheetDoc
.getSheets();
112 log
.println("getting a sheet");
113 XSpreadsheet oSheet
= null;
114 XIndexAccess oIndexAccess
= UnoRuntime
.queryInterface(XIndexAccess
.class, xSpreadsheets
);
116 oSheet
= (XSpreadsheet
)AnyConverter
.toObject(
117 new Type(XSpreadsheet
.class),oIndexAccess
.getByIndex(0));
118 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
119 e
.printStackTrace(log
);
120 throw new StatusException( "Couldn't get a spreadsheet", e
);
121 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
122 e
.printStackTrace(log
);
123 throw new StatusException( "Couldn't get a spreadsheet", e
);
124 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
125 e
.printStackTrace(log
);
126 throw new StatusException( "Couldn't get a spreadsheet", e
);
129 log
.println("filling some cells");
131 oSheet
.getCellByPosition(5, 5).setValue(15);
132 oSheet
.getCellByPosition(1, 4).setValue(10);
133 oSheet
.getCellByPosition(2, 0).setValue(-5.15);
134 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
135 e
.printStackTrace(log
);
136 throw new StatusException("Couldn't fill some cell", e
);
139 XScenariosSupplier xSupp
= UnoRuntime
.queryInterface(XScenariosSupplier
.class, oSheet
);
140 XCellRange oRange
= UnoRuntime
.queryInterface(XCellRange
.class, oSheet
);
141 XCellRange myRange
= oRange
.getCellRangeByName("A1:N4");
142 XCellRangeAddressable oRangeAddr
= UnoRuntime
.queryInterface(XCellRangeAddressable
.class, myRange
);
143 CellRangeAddress myAddr
= oRangeAddr
.getRangeAddress();
145 CellRangeAddress
[] oAddr
= new CellRangeAddress
[1];
148 xSupp
.getScenarios().addNewByName("ScScenarios", oAddr
, "Range");
150 XInterface oObj
= xSupp
.getScenarios();
152 TestEnvironment tEnv
= new TestEnvironment(oObj
);
154 log
.println("adding ObjectRelation for XScenarios");
155 tEnv
.addObjRelation("ADDR", oAddr
);
161 } // finish class ScScenariosObj