1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package mod._sc; 25 26 import java.io.PrintWriter; 27 28 import lib.StatusException; 29 import lib.TestCase; 30 import lib.TestEnvironment; 31 import lib.TestParameters; 32 import util.SOfficeFactory; 33 34 import com.sun.star.container.XEnumerationAccess; 35 import com.sun.star.container.XIndexAccess; 36 import com.sun.star.lang.XComponent; 37 import com.sun.star.lang.XMultiServiceFactory; 38 import com.sun.star.sheet.XCellRangeAddressable; 39 import com.sun.star.sheet.XScenariosSupplier; 40 import com.sun.star.sheet.XSpreadsheet; 41 import com.sun.star.sheet.XSpreadsheetDocument; 42 import com.sun.star.sheet.XSpreadsheets; 43 import com.sun.star.table.CellRangeAddress; 44 import com.sun.star.table.XCellRange; 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 50 public class ScIndexEnumeration_ScenariosEnumeration extends TestCase { 51 public static XSpreadsheetDocument xSpreadsheetDoc; 52 53 /** 54 * Creates Spreadsheet document. 55 */ initialize( TestParameters Param, PrintWriter log )56 public void initialize( TestParameters Param, PrintWriter log ) { 57 // get a soffice factory object 58 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF()); 59 60 try { 61 log.println("creating a spreadsheetdocument"); 62 xSpreadsheetDoc = SOF.createCalcDoc(null); 63 } catch (com.sun.star.uno.Exception e) { 64 e.printStackTrace( log ); 65 throw new StatusException( "Couldn't create document ", e ); 66 } 67 } 68 69 /** 70 * Disposes Spreadsheet document. 71 */ cleanup( TestParameters tParam, PrintWriter log )72 protected void cleanup( TestParameters tParam, PrintWriter log ) { 73 log.println( " disposing xSheetDoc " ); 74 XComponent oComp = (XComponent) 75 UnoRuntime.queryInterface (XComponent.class, xSpreadsheetDoc) ; 76 util.DesktopTools.closeDoc(oComp); 77 } 78 createTestEnvironment(TestParameters Param, PrintWriter log)79 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) { 80 81 log.println("getting sheets"); 82 XSpreadsheets xSpreadsheets = (XSpreadsheets)xSpreadsheetDoc.getSheets(); 83 log.println("getting a sheet"); 84 XSpreadsheet oSheet = null; 85 XIndexAccess oIndexAccess = (XIndexAccess) 86 UnoRuntime.queryInterface(XIndexAccess.class, xSpreadsheets); 87 try { 88 oSheet = (XSpreadsheet) AnyConverter.toObject( 89 new Type(XSpreadsheet.class),oIndexAccess.getByIndex(0)); 90 } catch (com.sun.star.lang.WrappedTargetException e) { 91 e.printStackTrace(log); 92 throw new StatusException( "Couldn't get a spreadsheet", e); 93 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 94 e.printStackTrace(log); 95 throw new StatusException( "Couldn't get a spreadsheet", e); 96 } catch (com.sun.star.lang.IllegalArgumentException e) { 97 e.printStackTrace(log); 98 throw new StatusException( "Couldn't get a spreadsheet", e); 99 } 100 101 log.println("filling some cells"); 102 try { 103 oSheet.getCellByPosition(5, 5).setValue(15); 104 oSheet.getCellByPosition(1, 4).setValue(10); 105 oSheet.getCellByPosition(2, 0).setValue(-5.15); 106 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 107 e.printStackTrace(log); 108 throw new StatusException("Couldn't fill some cell", e); 109 } 110 111 XScenariosSupplier xSupp = (XScenariosSupplier) 112 UnoRuntime.queryInterface(XScenariosSupplier.class, oSheet); 113 XCellRange oRange = (XCellRange) 114 UnoRuntime.queryInterface(XCellRange.class, oSheet); 115 XCellRange myRange = oRange.getCellRangeByName("A1:N4"); 116 XCellRangeAddressable oRangeAddr = (XCellRangeAddressable) 117 UnoRuntime.queryInterface(XCellRangeAddressable.class, myRange); 118 CellRangeAddress myAddr = oRangeAddr.getRangeAddress(); 119 120 CellRangeAddress[] oAddr = new CellRangeAddress[1]; 121 oAddr[0] = myAddr; 122 123 xSupp.getScenarios().addNewByName("ScScenarios", oAddr, "Range"); 124 125 XInterface oObj = xSupp.getScenarios(); 126 127 XEnumerationAccess ea = (XEnumerationAccess) 128 UnoRuntime.queryInterface(XEnumerationAccess.class,oObj); 129 130 oObj = ea.createEnumeration(); 131 132 log.println("ImplementationName: "+util.utils.getImplName(oObj)); 133 // creating test environment 134 TestEnvironment tEnv = new TestEnvironment( oObj ); 135 136 tEnv.addObjRelation("ENUM",ea); 137 138 return tEnv; 139 } 140 } 141 142