1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package mod._sc; 25 26 import java.io.PrintWriter; 27 28 import lib.StatusException; 29 import lib.TestCase; 30 import lib.TestEnvironment; 31 import lib.TestParameters; 32 import util.SOfficeFactory; 33 34 import com.sun.star.container.XIndexAccess; 35 import com.sun.star.container.XNameAccess; 36 import com.sun.star.lang.XComponent; 37 import com.sun.star.lang.XMultiServiceFactory; 38 import com.sun.star.sheet.XSpreadsheet; 39 import com.sun.star.sheet.XSpreadsheetDocument; 40 import com.sun.star.sheet.XSpreadsheets; 41 import com.sun.star.table.XColumnRowRange; 42 import com.sun.star.table.XTableRows; 43 import com.sun.star.uno.AnyConverter; 44 import com.sun.star.uno.Type; 45 import com.sun.star.uno.UnoRuntime; 46 import com.sun.star.uno.XInterface; 47 48 /** 49 * Test for object which is represented by service 50 * <code>com.sun.star.table.TableRow</code>. <p> 51 * Object implements the following interfaces : 52 * <ul> 53 * <li> <code>com::sun::star::table::TableRow</code></li> 54 * <li> <code>com::sun::star::table::XCellRange</code></li> 55 * <li> <code>com::sun::star::beans::XPropertySet</code></li> 56 * </ul> 57 * @see com.sun.star.table.TableRow 58 * @see com.sun.star.table.XCellRange 59 * @see com.sun.star.beans.XPropertySet 60 * @see ifc.table._TableRow 61 * @see ifc.table._XCellRange 62 * @see ifc.beans._XPropertySet 63 */ 64 public class ScTableRowObj extends TestCase { 65 static XSpreadsheetDocument xSheetDoc = null; 66 67 /** 68 * Creates Spreadsheet document. 69 */ initialize( TestParameters tParam, PrintWriter log )70 protected void initialize( TestParameters tParam, PrintWriter log ) { 71 // get a soffice factory object 72 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF()); 73 74 try { 75 log.println( "creating a sheetdocument" ); 76 xSheetDoc = SOF.createCalcDoc(null); 77 } catch (com.sun.star.uno.Exception e) { 78 // Some exception occured.FAILED 79 e.printStackTrace( log ); 80 throw new StatusException( "Couldn't create document", e ); 81 } 82 } 83 84 /** 85 * Disposes Spreadsheet document. 86 */ cleanup( TestParameters tParam, PrintWriter log )87 protected void cleanup( TestParameters tParam, PrintWriter log ) { 88 log.println( " disposing xSheetDoc " ); 89 XComponent oComp = (XComponent) 90 UnoRuntime.queryInterface (XComponent.class, xSheetDoc) ; 91 util.DesktopTools.closeDoc(oComp); 92 } 93 94 /** 95 * Creating a Testenvironment for the interfaces to be tested. 96 * Retrieves a collection of spreadsheets from the document and takes one of 97 * them. Obtains the collection of rows using the interface 98 * <code>XColumnRowRange</code>. Obtains the row with index 6 from the 99 * collection and this is the instance of the service 100 * <code>com.sun.star.table.TableRow</code>. 101 * Object relations created : 102 * <ul> 103 * <li> <code>'ValidRange'</code> for 104 * {@link ifc.table._XCellRange} </li> 105 * </ul> 106 * @see com.sun.star.table.XColumnRowRange 107 * @see com.sun.star.table.TableRow 108 */ createTestEnvironment(TestParameters Param, PrintWriter log)109 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) { 110 111 XInterface oObj = null; 112 113 // creation of the testobject here 114 // first we write what we are intend to do to log file 115 log.println("creating a test environment"); 116 117 XSpreadsheet xSpreadsheet = null; 118 XSpreadsheets xSpreadsheets = (XSpreadsheets)xSheetDoc.getSheets(); 119 XNameAccess oNames = (XNameAccess) 120 UnoRuntime.queryInterface( XNameAccess.class, xSpreadsheets ); 121 try { 122 xSpreadsheet = (XSpreadsheet) AnyConverter.toObject( 123 new Type(XSpreadsheet.class), 124 oNames.getByName(oNames.getElementNames()[0])); 125 126 XColumnRowRange oColumnRowRange = (XColumnRowRange) 127 UnoRuntime.queryInterface(XColumnRowRange.class, xSpreadsheet); 128 XTableRows oRows = (XTableRows) oColumnRowRange.getRows(); 129 XIndexAccess oIndexAccess = (XIndexAccess) 130 UnoRuntime.queryInterface(XIndexAccess.class, oRows); 131 oObj = (XInterface) AnyConverter.toObject( 132 new Type(XInterface.class),oIndexAccess.getByIndex(6)); 133 } catch(com.sun.star.lang.WrappedTargetException e) { 134 e.printStackTrace(log); 135 throw new StatusException( 136 "Exception during creating Testenvironment", e); 137 } catch(com.sun.star.container.NoSuchElementException e) { 138 e.printStackTrace(log); 139 throw new StatusException( 140 "Exception during creating Testenvironment", e); 141 } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 142 e.printStackTrace(log); 143 throw new StatusException( 144 "Exception during creating Testenvironment", e); 145 } catch(com.sun.star.lang.IllegalArgumentException e) { 146 e.printStackTrace(log); 147 throw new StatusException( 148 "Exception during creating Testenvironment", e); 149 } 150 151 log.println("creating a new environment for object"); 152 TestEnvironment tEnv = new TestEnvironment(oObj); 153 tEnv.addObjRelation("ValidRange","A7:A7"); 154 return tEnv; 155 } 156 } 157 158