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.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.XTableRows; 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 /** 53 * Test for object which is represented by service 54 * <code>com.sun.star.table.TableRow</code>. <p> 55 * Object implements the following interfaces : 56 * <ul> 57 * <li> <code>com::sun::star::table::TableRow</code></li> 58 * <li> <code>com::sun::star::table::XCellRange</code></li> 59 * <li> <code>com::sun::star::beans::XPropertySet</code></li> 60 * </ul> 61 * @see com.sun.star.table.TableRow 62 * @see com.sun.star.table.XCellRange 63 * @see com.sun.star.beans.XPropertySet 64 * @see ifc.table._TableRow 65 * @see ifc.table._XCellRange 66 * @see ifc.beans._XPropertySet 67 */ 68 public class ScTableRowObj extends TestCase { 69 static XSpreadsheetDocument xSheetDoc = null; 70 71 /** 72 * Creates Spreadsheet document. 73 */ 74 protected void initialize( TestParameters tParam, PrintWriter log ) { 75 // get a soffice factory object 76 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF()); 77 78 try { 79 log.println( "creating a sheetdocument" ); 80 xSheetDoc = SOF.createCalcDoc(null);; 81 } catch (com.sun.star.uno.Exception e) { 82 // Some exception occures.FAILED 83 e.printStackTrace( log ); 84 throw new StatusException( "Couldn't create document", e ); 85 } 86 } 87 88 /** 89 * Disposes Spreadsheet document. 90 */ 91 protected void cleanup( TestParameters tParam, PrintWriter log ) { 92 log.println( " disposing xSheetDoc " ); 93 XComponent oComp = (XComponent) 94 UnoRuntime.queryInterface (XComponent.class, xSheetDoc) ; 95 util.DesktopTools.closeDoc(oComp); 96 } 97 98 /** 99 * Creating a Testenvironment for the interfaces to be tested. 100 * Retrieves a collection of spreadsheets from the document and takes one of 101 * them. Obtains the collection of rows using the interface 102 * <code>XColumnRowRange</code>. Obtains the row with index 6 from the 103 * collection and this is the instance of the service 104 * <code>com.sun.star.table.TableRow</code>. 105 * Object relations created : 106 * <ul> 107 * <li> <code>'ValidRange'</code> for 108 * {@link ifc.table._XCellRange} </li> 109 * </ul> 110 * @see com.sun.star.table.XColumnRowRange 111 * @see com.sun.star.table.TableRow 112 */ 113 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) { 114 115 XInterface oObj = null; 116 117 // creation of the testobject here 118 // first we write what we are intend to do to log file 119 log.println("creating a test environment"); 120 121 XSpreadsheet xSpreadsheet = null; 122 XSpreadsheets xSpreadsheets = (XSpreadsheets)xSheetDoc.getSheets(); 123 XNameAccess oNames = (XNameAccess) 124 UnoRuntime.queryInterface( XNameAccess.class, xSpreadsheets ); 125 try { 126 xSpreadsheet = (XSpreadsheet) AnyConverter.toObject( 127 new Type(XSpreadsheet.class), 128 oNames.getByName(oNames.getElementNames()[0])); 129 130 XColumnRowRange oColumnRowRange = (XColumnRowRange) 131 UnoRuntime.queryInterface(XColumnRowRange.class, xSpreadsheet); 132 XTableRows oRows = (XTableRows) oColumnRowRange.getRows(); 133 XIndexAccess oIndexAccess = (XIndexAccess) 134 UnoRuntime.queryInterface(XIndexAccess.class, oRows); 135 oObj = (XInterface) AnyConverter.toObject( 136 new Type(XInterface.class),oIndexAccess.getByIndex(6)); 137 } catch(com.sun.star.lang.WrappedTargetException e) { 138 e.printStackTrace(log); 139 throw new StatusException( 140 "Exception during creating Testenvironment", e); 141 } catch(com.sun.star.container.NoSuchElementException e) { 142 e.printStackTrace(log); 143 throw new StatusException( 144 "Exception during creating Testenvironment", e); 145 } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 146 e.printStackTrace(log); 147 throw new StatusException( 148 "Exception during creating Testenvironment", e); 149 } catch(com.sun.star.lang.IllegalArgumentException e) { 150 e.printStackTrace(log); 151 throw new StatusException( 152 "Exception during creating Testenvironment", e); 153 } 154 155 log.println("creating a new environment for object"); 156 TestEnvironment tEnv = new TestEnvironment(oObj); 157 tEnv.addObjRelation("ValidRange","A7:A7"); 158 return tEnv; 159 } 160 } 161 162