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.lang.XComponent; 39 import com.sun.star.lang.XMultiServiceFactory; 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.uno.UnoRuntime; 44 import com.sun.star.uno.XInterface; 45 46 /** 47 * Test for object which is represented by service 48 * <code>com.sun.star.sheet.Spreadsheets</code>. <p> 49 * Object implements the following interfaces : 50 * <ul> 51 * <li> <code>com::sun::star::sheet::XSpreadsheets</code></li> 52 * <li> <code>com::sun::star::container::XNameAccess</code></li> 53 * <li> <code>com::sun::star::container::XIndexAccess</code></li> 54 * <li> <code>com::sun::star::container::XElementAccess</code></li> 55 * <li> <code>com::sun::star::container::XNameReplace</code></li> 56 * <li> <code>com::sun::star::container::XNameContainer</code></li> 57 * </ul> 58 * @see com.sun.star.sheet.Spreadsheets 59 * @see com.sun.star.sheet.XSpreadsheets 60 * @see com.sun.star.container.XNameAccess 61 * @see com.sun.star.container.XIndexAccess 62 * @see com.sun.star.container.XElementAccess 63 * @see com.sun.star.container.XNameReplace 64 * @see com.sun.star.container.XNameContainer 65 * @see ifc.sheet._XSpreadsheets 66 * @see ifc.container._XNameAccess 67 * @see ifc.container._XIndexAccess 68 * @see ifc.container._XElementAccess 69 * @see ifc.container._XNameReplace 70 * @see ifc.container._XNameContainer 71 */ 72 public class ScTableSheetsObj extends TestCase { 73 private static XSpreadsheetDocument xSpreadsheetDoc = null; 74 75 /** 76 * Creates Spreadsheet document. 77 */ 78 public void initialize( TestParameters Param, PrintWriter log ) { 79 // get a soffice factory object 80 81 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF()); 82 try { 83 log.println("creating a spreadsheetdocument"); 84 xSpreadsheetDoc = SOF.createCalcDoc(null); 85 } catch (com.sun.star.uno.Exception e) { 86 e.printStackTrace( log ); 87 throw new StatusException( "Couldn't create document ", e ); 88 } 89 } 90 91 /** 92 * Disposes Spreadsheet document. 93 */ 94 protected void cleanup( TestParameters tParam, PrintWriter log ) { 95 log.println("disposing xSpreadsheetDocument"); 96 XComponent oComp = (XComponent) 97 UnoRuntime.queryInterface(XComponent.class, xSpreadsheetDoc); 98 util.DesktopTools.closeDoc(oComp); 99 } 100 101 /** 102 * Creating a Testenvironment for the interfaces to be tested. 103 * Retrieves the collection of the spreadsheets using the interface 104 * <code>XSpreadsheetDocument</code>. The retrieved collection is the 105 * instance of the service <code>com.sun.star.sheet.Spreadsheets</code>. 106 * Creates instances of the service <code>com.sun.star.sheet.Spreadsheet</code>. 107 * Object relations created : 108 * <ul> 109 * <li> <code>'SecondInstance'</code> for 110 * {@link ifc.container._XNameContainer} (the created instance of the 111 * service <code>com.sun.star.sheet.Spreadsheet</code>) </li> 112 * <li> <code>'INSTANCE1', ..., 'INSTANCEN'</code> for 113 * {@link ifc.container._XNameContainer} (the created instances of the 114 * service <code>com.sun.star.sheet.Spreadsheet</code>) </li> 115 * </ul> 116 * @see com.sun.star.sheet.Spreadsheets 117 * @see com.sun.star.sheet.XSpreadsheetDocument 118 * @see com.sun.star.sheet.Spreadsheet 119 */ 120 protected TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) { 121 122 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF()); 123 124 log.println("getting sheets"); 125 XSpreadsheets xSpreadsheets = (XSpreadsheets)xSpreadsheetDoc.getSheets(); 126 127 XInterface oObj = (XInterface) 128 UnoRuntime.queryInterface(XInterface.class, xSpreadsheets); 129 130 log.println("creating a new environment for object"); 131 TestEnvironment tEnv = new TestEnvironment(oObj); 132 133 log.println("creating instance of the sheet object to use it in tests"); 134 XSpreadsheet oSecondSheet = null; 135 136 try { 137 oSecondSheet = SOF.createSpreadsheet(xSpreadsheetDoc); 138 } catch (com.sun.star.uno.Exception e) { 139 e.printStackTrace(log); 140 throw new StatusException("Couldn't create instances", e); 141 } 142 143 //adding Instance for XNameContainer 144 tEnv.addObjRelation("SecondInstance",oSecondSheet); 145 146 // INSTANCEn : _XNameContainer; _XNameReplace 147 log.println( "adding INSTANCEn as mod relation to environment" ); 148 149 int THRCNT = 1; 150 if ((String)Param.get("THRCNT") != null) { 151 THRCNT = Integer.parseInt((String)Param.get("THRCNT")); 152 } 153 try { 154 for (int n = 1; n < (THRCNT+1) ;n++ ) { 155 log.println( 156 "adding INSTANCE" + n +" as mod relation to environment" ); 157 tEnv.addObjRelation( 158 "INSTANCE" + n, 159 SOF.createSpreadsheet(xSpreadsheetDoc) ); 160 } 161 } catch (com.sun.star.uno.Exception e) { 162 e.printStackTrace(log); 163 throw new StatusException( 164 "Couldn't create instances for object relations", e); 165 } 166 167 return tEnv; 168 } 169 } 170 171 172