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.XIndexAccess; 40 import com.sun.star.frame.XController; 41 import com.sun.star.frame.XModel; 42 import com.sun.star.lang.XComponent; 43 import com.sun.star.lang.XMultiServiceFactory; 44 import com.sun.star.sheet.XSpreadsheetDocument; 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_SpreadsheetViewPanesEnumeration extends TestCase { 51 private static XSpreadsheetDocument xSpreadsheetDoc; 52 private static SOfficeFactory SOF; 53 private static XInterface oObj; 54 55 /** 56 * Creates Spreadsheet document. 57 */ 58 public void initialize( TestParameters Param, PrintWriter log ) { 59 // get a soffice factory object 60 SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF()); 61 62 try { 63 log.println("creating a spreadsheetdocument"); 64 xSpreadsheetDoc = SOF.createCalcDoc(null); 65 } catch (com.sun.star.uno.Exception e) { 66 e.printStackTrace( log ); 67 throw new StatusException( "Couldn't create document ", e ); 68 } 69 } 70 71 /** 72 * Disposes Spreadsheet document. 73 */ 74 protected void cleanup( TestParameters tParam, PrintWriter log ) { 75 log.println("disposing xSpreadsheetDocument"); 76 XComponent oComp = (XComponent) 77 UnoRuntime.queryInterface(XComponent.class, xSpreadsheetDoc); 78 util.DesktopTools.closeDoc(oComp); 79 } 80 81 protected TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) { 82 83 XModel xm = (XModel) 84 UnoRuntime.queryInterface(XModel.class, xSpreadsheetDoc); 85 XController xc = xm.getCurrentController(); 86 XIndexAccess xIA = (XIndexAccess) 87 UnoRuntime.queryInterface(XIndexAccess.class, xc); 88 try { 89 oObj = (XInterface) AnyConverter.toObject( 90 new Type(XInterface.class),xIA.getByIndex(0)); 91 } catch (com.sun.star.lang.WrappedTargetException e) { 92 e.printStackTrace(log); 93 throw new StatusException("Couldn't get by index", e); 94 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 95 e.printStackTrace(log); 96 throw new StatusException("Couldn't get by index", e); 97 } catch (com.sun.star.lang.IllegalArgumentException e) { 98 e.printStackTrace(log); 99 throw new StatusException("Couldn't get by index", e); 100 } 101 102 XEnumerationAccess ea = (XEnumerationAccess) 103 UnoRuntime.queryInterface(XEnumerationAccess.class,xIA); 104 105 oObj = ea.createEnumeration(); 106 107 log.println("ImplementationName: "+util.utils.getImplName(oObj)); 108 // creating test environment 109 TestEnvironment tEnv = new TestEnvironment( oObj ); 110 111 tEnv.addObjRelation("ENUM",ea); 112 113 return tEnv; 114 } 115 } 116 117