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.XNameAccess; 39 import com.sun.star.lang.XComponent; 40 import com.sun.star.lang.XMultiServiceFactory; 41 import com.sun.star.sheet.XSpreadsheet; 42 import com.sun.star.sheet.XSpreadsheetDocument; 43 import com.sun.star.sheet.XSpreadsheets; 44 import com.sun.star.table.XCellRange; 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.TableRows</code>. <p> 55 * Object implements the following interfaces : 56 * <ul> 57 * <li> <code>com::sun::star::container::XIndexAccess</code></li> 58 * <li> <code>com::sun::star::container::XElementAccess</code></li> 59 * <li> <code>com::sun::star::table::XTableRows</code></li> 60 * </ul> 61 * @see com.sun.star.table.TableRows 62 * @see com.sun.star.container.XIndexAccess 63 * @see com.sun.star.container.XElementAccess 64 * @see com.sun.star.table.XTableRows 65 * @see ifc.container._XIndexAccess 66 * @see ifc.container._XElementAccess 67 * @see ifc.table._XTableRows 68 */ 69 public class ScTableRowsObj extends TestCase { 70 XSpreadsheetDocument xSheetDoc = null; 71 72 /** 73 * Creates Spreadsheet document. 74 */ 75 protected void initialize( TestParameters tParam, PrintWriter log ) { 76 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() ); 77 78 try { 79 log.println( "creating a Spreadsheet document" ); 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>. The obtained collection is the instance of 103 * the service <code>com.sun.star.table.TableRows</code>. 104 * @see com.sun.star.table.XColumnRowRange 105 * @see com.sun.star.table.TableRows 106 */ 107 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) { 108 109 XInterface oObj = null; 110 111 log.println("getting row"); 112 XSpreadsheet xSpreadsheet = null; 113 114 XSpreadsheets xSpreadsheets = (XSpreadsheets)xSheetDoc.getSheets(); 115 XNameAccess oNames = (XNameAccess) 116 UnoRuntime.queryInterface( XNameAccess.class, xSpreadsheets ); 117 try { 118 xSpreadsheet = (XSpreadsheet) AnyConverter.toObject( 119 new Type(XSpreadsheet.class), 120 oNames.getByName(oNames.getElementNames()[0])); 121 } catch(com.sun.star.lang.WrappedTargetException e) { 122 e.printStackTrace(log); 123 throw new StatusException("Couldn't get spreadsheet", e); 124 } catch(com.sun.star.container.NoSuchElementException e) { 125 e.printStackTrace(log); 126 throw new StatusException("Couldn't get spreadsheet", e); 127 } catch(com.sun.star.lang.IllegalArgumentException e) { 128 e.printStackTrace(log); 129 throw new StatusException("Couldn't get spreadsheet", e); 130 } 131 132 XColumnRowRange oColumnRowRange = (XColumnRowRange) 133 UnoRuntime.queryInterface(XColumnRowRange.class, xSpreadsheet); 134 135 XTableRows oRows = (XTableRows) oColumnRowRange.getRows(); 136 oObj = oRows; 137 138 log.println("creating a new environment for object"); 139 TestEnvironment tEnv = new TestEnvironment(oObj); 140 141 // adding relation for XTableRows 142 tEnv.addObjRelation("XTableRows.XCellRange", 143 UnoRuntime.queryInterface(XCellRange.class, xSpreadsheet)); 144 145 return tEnv; 146 } 147 } // finish class ScTableRowsObj 148 149