Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScIndexEnumeration_ScenariosEnumeration.java
blob14703a65b8f7ce9b9f73fca0fcdee9811ac10a1b
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 java.io.PrintWriter;
23 import lib.StatusException;
24 import lib.TestCase;
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.sheet.XCellRangeAddressable;
33 import com.sun.star.sheet.XScenariosSupplier;
34 import com.sun.star.sheet.XSpreadsheet;
35 import com.sun.star.sheet.XSpreadsheetDocument;
36 import com.sun.star.sheet.XSpreadsheets;
37 import com.sun.star.table.CellRangeAddress;
38 import com.sun.star.table.XCellRange;
39 import com.sun.star.uno.AnyConverter;
40 import com.sun.star.uno.Type;
41 import com.sun.star.uno.UnoRuntime;
42 import com.sun.star.uno.XInterface;
44 public class ScIndexEnumeration_ScenariosEnumeration extends TestCase {
45 private XSpreadsheetDocument xSpreadsheetDoc;
47 /**
48 * Creates Spreadsheet document.
50 @Override
51 public void initialize( TestParameters Param, PrintWriter log ) {
52 // get a soffice factory object
53 SOfficeFactory SOF = SOfficeFactory.getFactory( Param.getMSF());
55 try {
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 );
64 /**
65 * Disposes Spreadsheet document.
67 @Override
68 protected void cleanup( TestParameters tParam, PrintWriter log ) {
69 log.println( " disposing xSheetDoc " );
70 XComponent oComp = UnoRuntime.queryInterface (XComponent.class, xSpreadsheetDoc) ;
71 util.DesktopTools.closeDoc(oComp);
74 @Override
75 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
77 log.println("getting sheets");
78 XSpreadsheets xSpreadsheets = xSpreadsheetDoc.getSheets();
79 log.println("getting a sheet");
80 XSpreadsheet oSheet = null;
81 XIndexAccess oIndexAccess = UnoRuntime.queryInterface(XIndexAccess.class, xSpreadsheets);
82 try {
83 oSheet = (XSpreadsheet) AnyConverter.toObject(
84 new Type(XSpreadsheet.class),oIndexAccess.getByIndex(0));
85 } catch (com.sun.star.lang.WrappedTargetException e) {
86 e.printStackTrace(log);
87 throw new StatusException( "Couldn't get a spreadsheet", e);
88 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
89 e.printStackTrace(log);
90 throw new StatusException( "Couldn't get a spreadsheet", e);
91 } catch (com.sun.star.lang.IllegalArgumentException e) {
92 e.printStackTrace(log);
93 throw new StatusException( "Couldn't get a spreadsheet", e);
96 log.println("filling some cells");
97 try {
98 oSheet.getCellByPosition(5, 5).setValue(15);
99 oSheet.getCellByPosition(1, 4).setValue(10);
100 oSheet.getCellByPosition(2, 0).setValue(-5.15);
101 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
102 e.printStackTrace(log);
103 throw new StatusException("Couldn't fill some cell", e);
106 XScenariosSupplier xSupp = UnoRuntime.queryInterface(XScenariosSupplier.class, oSheet);
107 XCellRange oRange = UnoRuntime.queryInterface(XCellRange.class, oSheet);
108 XCellRange myRange = oRange.getCellRangeByName("A1:N4");
109 XCellRangeAddressable oRangeAddr = UnoRuntime.queryInterface(XCellRangeAddressable.class, myRange);
110 CellRangeAddress myAddr = oRangeAddr.getRangeAddress();
112 CellRangeAddress[] oAddr = new CellRangeAddress[1];
113 oAddr[0] = myAddr;
115 xSupp.getScenarios().addNewByName("ScScenarios", oAddr, "Range");
117 XInterface oObj = xSupp.getScenarios();
119 XEnumerationAccess ea = UnoRuntime.queryInterface(XEnumerationAccess.class,oObj);
121 oObj = ea.createEnumeration();
123 log.println("ImplementationName: "+util.utils.getImplName(oObj));
124 // creating test environment
125 TestEnvironment tEnv = new TestEnvironment( oObj );
127 tEnv.addObjRelation("ENUM",ea);
129 return tEnv;