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.XNameAccess; 36 import com.sun.star.lang.XComponent; 37 import com.sun.star.lang.XMultiServiceFactory; 38 import com.sun.star.sheet.XSpreadsheet; 39 import com.sun.star.sheet.XSpreadsheetDocument; 40 import com.sun.star.sheet.XSpreadsheets; 41 import com.sun.star.table.XColumnRowRange; 42 import com.sun.star.table.XTableColumns; 43 import com.sun.star.uno.AnyConverter; 44 import com.sun.star.uno.Type; 45 import com.sun.star.uno.UnoRuntime; 46 import com.sun.star.uno.XInterface; 47 48 public class ScIndexEnumeration_TableColumnsEnumeration extends TestCase { 49 static XSpreadsheetDocument xSheetDoc = null; 50 51 /** 52 * Creates Spreadsheet document. 53 */ initialize( TestParameters tParam, PrintWriter log )54 protected void initialize( TestParameters tParam, PrintWriter log ) { 55 // get a soffice factory object 56 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF()); 57 58 try { 59 log.println( "creating a sheetdocument" ); 60 xSheetDoc = SOF.createCalcDoc(null); 61 } catch (com.sun.star.uno.Exception e) { 62 // Some exception occured.FAILED 63 e.printStackTrace( log ); 64 throw new StatusException( "Couldn't create document", e ); 65 } 66 } 67 68 /** 69 * Disposes Spreadsheet document. 70 */ cleanup( TestParameters tParam, PrintWriter log )71 protected void cleanup( TestParameters tParam, PrintWriter log ) { 72 log.println( " disposing xSheetDoc " ); 73 XComponent oComp = (XComponent) 74 UnoRuntime.queryInterface (XComponent.class, xSheetDoc) ; 75 util.DesktopTools.closeDoc(oComp); 76 } 77 createTestEnvironment(TestParameters Param, PrintWriter log)78 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) { 79 80 XInterface oObj = null; 81 82 // creation of the testobject here 83 // first we write what we are intend to do to log file 84 log.println("craeting a test environment"); 85 86 log.println("getting column"); 87 XSpreadsheets xSpreadsheets = (XSpreadsheets)xSheetDoc.getSheets(); 88 XNameAccess oNames = (XNameAccess) 89 UnoRuntime.queryInterface( XNameAccess.class, xSpreadsheets ); 90 XSpreadsheet xSpreadsheet = null; 91 try { 92 xSpreadsheet = (XSpreadsheet) AnyConverter.toObject( 93 new Type(XSpreadsheet.class), 94 oNames.getByName(oNames.getElementNames()[0])); 95 } catch (com.sun.star.lang.WrappedTargetException e) { 96 e.printStackTrace(log); 97 throw new StatusException("Couldn't get spreadsheet", e); 98 } catch (com.sun.star.container.NoSuchElementException e) { 99 e.printStackTrace(log); 100 throw new StatusException("Couldn't get spreadsheet", e); 101 } catch (com.sun.star.lang.IllegalArgumentException e) { 102 e.printStackTrace(log); 103 throw new StatusException("Couldn't get spreadsheet", e); 104 } 105 106 XColumnRowRange oColumnRowRange = (XColumnRowRange) 107 UnoRuntime.queryInterface(XColumnRowRange.class, xSpreadsheet); 108 XTableColumns oColumns = (XTableColumns) oColumnRowRange.getColumns(); 109 oObj = oColumns; 110 111 log.println("creating a new environment for object"); 112 XEnumerationAccess ea = (XEnumerationAccess) 113 UnoRuntime.queryInterface(XEnumerationAccess.class,oObj); 114 115 oObj = ea.createEnumeration(); 116 117 log.println("ImplementationName: "+util.utils.getImplName(oObj)); 118 // creating test environment 119 TestEnvironment tEnv = new TestEnvironment( oObj ); 120 121 tEnv.addObjRelation("ENUM",ea); 122 123 return tEnv; 124 } 125 } 126