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.XIndexAccess; 39 import com.sun.star.lang.XComponent; 40 import com.sun.star.lang.XMultiServiceFactory; 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 import com.sun.star.util.XImportable; 46 47 /** 48 * 49 * initial description 50 * @see com.sun.star.sheet.DatabaseImportDescriptor 51 * 52 */ 53 public class ScImportDescriptorBase extends TestCase { 54 55 XSpreadsheetDocument xSpreadsheetDoc; 56 57 /** 58 * in general this method creates a testdocument 59 * 60 * @param tParam class which contains additional test parameters 61 * @param log class to log the test state and result 62 * 63 * 64 * @see TestParameters 65 * @see PrintWriter 66 * 67 */ 68 protected void initialize( TestParameters tParam, PrintWriter log ) { 69 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory) tParam.getMSF() ); 70 71 try { 72 log.println( "creating a Spreadsheet document" ); 73 xSpreadsheetDoc = SOF.createCalcDoc(null); 74 } catch ( com.sun.star.uno.Exception e ) { 75 // Some exception occures.FAILED 76 e.printStackTrace( log ); 77 throw new StatusException( "Couldn't create document", e ); 78 } 79 80 } 81 82 /** 83 * in general this method disposes the testenvironment and document 84 * 85 * @param tParam class which contains additional test parameters 86 * @param log class to log the test state and result 87 * 88 * 89 * @see TestParameters 90 * @see PrintWriter 91 * 92 */ 93 protected void cleanup( TestParameters tParam, PrintWriter log ) { 94 log.println( " disposing xSheetDoc " ); 95 XComponent oComp = (XComponent) UnoRuntime.queryInterface 96 (XComponent.class, xSpreadsheetDoc) ; 97 util.DesktopTools.closeDoc(oComp); 98 } 99 100 101 102 /** 103 * creating a Testenvironment for the interfaces to be tested 104 * 105 * @param tParam class which contains additional test parameters 106 * @param log class to log the test state and result 107 * 108 * @return Status class 109 * 110 * @see TestParameters 111 * @see PrintWriter 112 */ 113 public TestEnvironment createTestEnvironment( TestParameters tParam, 114 PrintWriter log ) 115 throws StatusException { 116 117 XInterface oObj = null; 118 XImportable xIMP = null; 119 120 // creation of testobject here 121 // first we write what we are intend to do to log file 122 log.println( "creating a test environment" ); 123 124 // create testobject here 125 126 log.println("getting sheets"); 127 XSpreadsheets xSpreadsheets = (XSpreadsheets)xSpreadsheetDoc.getSheets(); 128 if (xSpreadsheets == null) log.println("FAILED"); else log.println("OK"); 129 130 log.println("getting a sheet"); 131 XIndexAccess oIndexAccess = (XIndexAccess) 132 UnoRuntime.queryInterface(XIndexAccess.class, xSpreadsheets); 133 134 try { 135 oObj = (XInterface) UnoRuntime.queryInterface(XInterface.class,oIndexAccess.getByIndex(0)); 136 } catch (Exception e) { 137 throw new StatusException( "Couldn't get a spreadsheet", e); 138 } 139 140 xIMP = (XImportable) UnoRuntime.queryInterface(XImportable.class,oObj); 141 142 TestEnvironment tEnv = new TestEnvironment(oObj); 143 tEnv.addObjRelation("xIMP",xIMP); 144 return tEnv; 145 146 } // finish method getTestEnvironment 147 148 } // finish class ScImportDescriptorBase 149 150