1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 package mod._sc; 29 30 import java.io.PrintWriter; 31 32 import lib.StatusException; 33 import lib.TestCase; 34 import lib.TestEnvironment; 35 import lib.TestParameters; 36 import util.SOfficeFactory; 37 38 import com.sun.star.container.XEnumerationAccess; 39 import com.sun.star.container.XNameAccess; 40 import com.sun.star.lang.XComponent; 41 import com.sun.star.lang.XMultiServiceFactory; 42 import com.sun.star.sheet.XSpreadsheet; 43 import com.sun.star.sheet.XSpreadsheetDocument; 44 import com.sun.star.sheet.XSpreadsheets; 45 import com.sun.star.table.XColumnRowRange; 46 import com.sun.star.table.XTableColumns; 47 import com.sun.star.uno.AnyConverter; 48 import com.sun.star.uno.Type; 49 import com.sun.star.uno.UnoRuntime; 50 import com.sun.star.uno.XInterface; 51 52 public class ScIndexEnumeration_TableColumnsEnumeration extends TestCase { 53 static XSpreadsheetDocument xSheetDoc = null; 54 55 /** 56 * Creates Spreadsheet document. 57 */ 58 protected void initialize( TestParameters tParam, PrintWriter log ) { 59 // get a soffice factory object 60 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF()); 61 62 try { 63 log.println( "creating a sheetdocument" ); 64 xSheetDoc = SOF.createCalcDoc(null);; 65 } catch (com.sun.star.uno.Exception e) { 66 // Some exception occures.FAILED 67 e.printStackTrace( log ); 68 throw new StatusException( "Couldn't create document", e ); 69 } 70 } 71 72 /** 73 * Disposes Spreadsheet document. 74 */ 75 protected void cleanup( TestParameters tParam, PrintWriter log ) { 76 log.println( " disposing xSheetDoc " ); 77 XComponent oComp = (XComponent) 78 UnoRuntime.queryInterface (XComponent.class, xSheetDoc) ; 79 util.DesktopTools.closeDoc(oComp); 80 } 81 82 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) { 83 84 XInterface oObj = null; 85 86 // creation of the testobject here 87 // first we write what we are intend to do to log file 88 log.println("craeting a test environment"); 89 90 log.println("getting column"); 91 XSpreadsheets xSpreadsheets = (XSpreadsheets)xSheetDoc.getSheets(); 92 XNameAccess oNames = (XNameAccess) 93 UnoRuntime.queryInterface( XNameAccess.class, xSpreadsheets ); 94 XSpreadsheet xSpreadsheet = null; 95 try { 96 xSpreadsheet = (XSpreadsheet) AnyConverter.toObject( 97 new Type(XSpreadsheet.class), 98 oNames.getByName(oNames.getElementNames()[0])); 99 } catch (com.sun.star.lang.WrappedTargetException e) { 100 e.printStackTrace(log); 101 throw new StatusException("Couldn't get spreadsheet", e); 102 } catch (com.sun.star.container.NoSuchElementException e) { 103 e.printStackTrace(log); 104 throw new StatusException("Couldn't get spreadsheet", e); 105 } catch (com.sun.star.lang.IllegalArgumentException e) { 106 e.printStackTrace(log); 107 throw new StatusException("Couldn't get spreadsheet", e); 108 } 109 110 XColumnRowRange oColumnRowRange = (XColumnRowRange) 111 UnoRuntime.queryInterface(XColumnRowRange.class, xSpreadsheet); 112 XTableColumns oColumns = (XTableColumns) oColumnRowRange.getColumns(); 113 oObj = oColumns; 114 115 log.println("creating a new environment for object"); 116 XEnumerationAccess ea = (XEnumerationAccess) 117 UnoRuntime.queryInterface(XEnumerationAccess.class,oObj); 118 119 oObj = ea.createEnumeration(); 120 121 log.println("ImplementationName: "+util.utils.getImplName(oObj)); 122 // creating test environment 123 TestEnvironment tEnv = new TestEnvironment( oObj ); 124 125 tEnv.addObjRelation("ENUM",ea); 126 127 return tEnv; 128 } 129 }