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
.XEnumerationAccess
;
30 import com
.sun
.star
.container
.XIndexAccess
;
31 import com
.sun
.star
.lang
.XComponent
;
32 import com
.sun
.star
.lang
.XMultiServiceFactory
;
33 import com
.sun
.star
.sheet
.XCellRangeAddressable
;
34 import com
.sun
.star
.sheet
.XScenariosSupplier
;
35 import com
.sun
.star
.sheet
.XSpreadsheet
;
36 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
37 import com
.sun
.star
.sheet
.XSpreadsheets
;
38 import com
.sun
.star
.table
.CellRangeAddress
;
39 import com
.sun
.star
.table
.XCellRange
;
40 import com
.sun
.star
.uno
.AnyConverter
;
41 import com
.sun
.star
.uno
.Type
;
42 import com
.sun
.star
.uno
.UnoRuntime
;
43 import com
.sun
.star
.uno
.XInterface
;
45 public class ScIndexEnumeration_ScenariosEnumeration
extends TestCase
{
46 private XSpreadsheetDocument xSpreadsheetDoc
;
49 * Creates Spreadsheet document.
51 public void initialize( TestParameters Param
, PrintWriter log
) {
52 // get a soffice factory object
53 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)Param
.getMSF());
56 log
.println("creating a spreadsheetdocument");
57 xSpreadsheetDoc
= SOF
.createCalcDoc(null);
58 } catch (com
.sun
.star
.uno
.Exception e
) {
59 e
.printStackTrace( log
);
60 throw new StatusException( "Couldn't create document ", e
);
65 * Disposes Spreadsheet document.
67 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
68 log
.println( " disposing xSheetDoc " );
69 XComponent oComp
= UnoRuntime
.queryInterface (XComponent
.class, xSpreadsheetDoc
) ;
70 util
.DesktopTools
.closeDoc(oComp
);
73 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
75 log
.println("getting sheets");
76 XSpreadsheets xSpreadsheets
= xSpreadsheetDoc
.getSheets();
77 log
.println("getting a sheet");
78 XSpreadsheet oSheet
= null;
79 XIndexAccess oIndexAccess
= UnoRuntime
.queryInterface(XIndexAccess
.class, xSpreadsheets
);
81 oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
82 new Type(XSpreadsheet
.class),oIndexAccess
.getByIndex(0));
83 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
84 e
.printStackTrace(log
);
85 throw new StatusException( "Couldn't get a spreadsheet", e
);
86 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
87 e
.printStackTrace(log
);
88 throw new StatusException( "Couldn't get a spreadsheet", e
);
89 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
90 e
.printStackTrace(log
);
91 throw new StatusException( "Couldn't get a spreadsheet", e
);
94 log
.println("filling some cells");
96 oSheet
.getCellByPosition(5, 5).setValue(15);
97 oSheet
.getCellByPosition(1, 4).setValue(10);
98 oSheet
.getCellByPosition(2, 0).setValue(-5.15);
99 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
100 e
.printStackTrace(log
);
101 throw new StatusException("Couldn't fill some cell", e
);
104 XScenariosSupplier xSupp
= UnoRuntime
.queryInterface(XScenariosSupplier
.class, oSheet
);
105 XCellRange oRange
= UnoRuntime
.queryInterface(XCellRange
.class, oSheet
);
106 XCellRange myRange
= oRange
.getCellRangeByName("A1:N4");
107 XCellRangeAddressable oRangeAddr
= UnoRuntime
.queryInterface(XCellRangeAddressable
.class, myRange
);
108 CellRangeAddress myAddr
= oRangeAddr
.getRangeAddress();
110 CellRangeAddress
[] oAddr
= new CellRangeAddress
[1];
113 xSupp
.getScenarios().addNewByName("ScScenarios", oAddr
, "Range");
115 XInterface oObj
= xSupp
.getScenarios();
117 XEnumerationAccess ea
= UnoRuntime
.queryInterface(XEnumerationAccess
.class,oObj
);
119 oObj
= ea
.createEnumeration();
121 log
.println("ImplementationName: "+util
.utils
.getImplName(oObj
));
122 // creating test environment
123 TestEnvironment tEnv
= new TestEnvironment( oObj
);
125 tEnv
.addObjRelation("ENUM",ea
);