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.beans.XPropertySet; 35 import com.sun.star.container.XEnumerationAccess; 36 import com.sun.star.lang.XComponent; 37 import com.sun.star.lang.XMultiServiceFactory; 38 import com.sun.star.sheet.XDatabaseRanges; 39 import com.sun.star.sheet.XSpreadsheetDocument; 40 import com.sun.star.table.CellRangeAddress; 41 import com.sun.star.uno.AnyConverter; 42 import com.sun.star.uno.Type; 43 import com.sun.star.uno.UnoRuntime; 44 import com.sun.star.uno.XInterface; 45 46 47 public class ScIndexEnumeration_DatabaseRangesEnumeration extends TestCase { 48 static XSpreadsheetDocument xSheetDoc = null; 49 50 /** 51 * Creates Spreadsheet document. 52 */ 53 protected void initialize( TestParameters tParam, PrintWriter log ) { 54 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() ); 55 56 try { 57 log.println( "creating a Spreadsheet document" ); 58 xSheetDoc = SOF.createCalcDoc(null); 59 } catch ( com.sun.star.uno.Exception e ) { 60 // Some exception occures.FAILED 61 e.printStackTrace( log ); 62 throw new StatusException( "Couldn't create document", e ); 63 } 64 65 } 66 67 /** 68 * Disposes Spreadsheet document. 69 */ 70 protected void cleanup( TestParameters tParam, PrintWriter log ) { 71 log.println( " disposing xSheetDoc " ); 72 XComponent oComp = (XComponent) 73 UnoRuntime.queryInterface (XComponent.class, xSheetDoc) ; 74 util.DesktopTools.closeDoc(oComp); 75 } 76 77 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) { 78 79 XInterface oObj = null; 80 81 // creation of testobject here 82 // first we write what we are intend to do to log file 83 log.println( "Creating a test environment" ); 84 85 log.println("Getting test object ") ; 86 XPropertySet docProps = (XPropertySet) 87 UnoRuntime.queryInterface(XPropertySet.class, xSheetDoc); 88 89 XDatabaseRanges dbRanges = null; 90 try { 91 dbRanges = (XDatabaseRanges) AnyConverter.toObject( 92 new Type(XDatabaseRanges.class), 93 docProps.getPropertyValue("DatabaseRanges")); 94 } catch (com.sun.star.lang.WrappedTargetException e) { 95 e.printStackTrace(log) ; 96 throw new StatusException( 97 "Error getting test object from spreadsheet document",e) ; 98 } catch (com.sun.star.beans.UnknownPropertyException e) { 99 e.printStackTrace(log) ; 100 throw new StatusException( 101 "Error getting test object from spreadsheet document",e) ; 102 } catch (com.sun.star.lang.IllegalArgumentException e) { 103 e.printStackTrace(log) ; 104 throw new StatusException( 105 "Error getting test object from spreadsheet document",e) ; 106 } 107 108 log.println("Adding at least one element for ElementAccess interface"); 109 CellRangeAddress aRange = new CellRangeAddress((short)0, 2, 4, 5, 6); 110 if (!dbRanges.hasByName("dbRange")) { 111 dbRanges.addNewByName("dbRange", aRange); 112 } 113 114 oObj = dbRanges; 115 XEnumerationAccess ea = (XEnumerationAccess) 116 UnoRuntime.queryInterface(XEnumerationAccess.class,oObj); 117 118 oObj = ea.createEnumeration(); 119 120 log.println("ImplementationName: "+util.utils.getImplName(oObj)); 121 // creating test environment 122 TestEnvironment tEnv = new TestEnvironment( oObj ); 123 124 tEnv.addObjRelation("ENUM",ea); 125 return tEnv; 126 } 127 128 } 129 130 131