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.XTableColumns; 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.TableColumn</code>. <p> 51 * Object implements the following interfaces : 52 * <ul> 53 * <li> <code>com::sun::star::container::XNamed</code></li> 54 * <li> <code>com::sun::star::table::TableColumn</code></li> 55 * <li> <code>com::sun::star::table::XCellRange</code></li> 56 * <li> <code>com::sun::star::beans::XPropertySet</code></li> 57 * </ul> 58 * @see com.sun.star.container.XNamed 59 * @see com.sun.star.table.TableColumn 60 * @see com.sun.star.table.XCellRange 61 * @see com.sun.star.beans.XPropertySet 62 * @see ifc.container._XNamed 63 * @see ifc.table._TableColumn 64 * @see ifc.table._XCellRange 65 * @see ifc.beans._XPropertySet 66 */ 67 public class ScTableColumnObj extends TestCase { 68 static XSpreadsheetDocument xSheetDoc = null; 69 70 /** 71 * Creates Spreadsheet document. 72 */ initialize( TestParameters tParam, PrintWriter log )73 protected void initialize( TestParameters tParam, PrintWriter log ) { 74 // get a soffice factory object 75 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF()); 76 77 try { 78 log.println( "creating a sheetdocument" ); 79 xSheetDoc = SOF.createCalcDoc(null); 80 } catch (com.sun.star.uno.Exception e) { 81 // Some exception occures.FAILED 82 e.printStackTrace( log ); 83 throw new StatusException( "Couldn't create document", e ); 84 } 85 } 86 87 /** 88 * Disposes Spreadsheet document. 89 */ cleanup( TestParameters tParam, PrintWriter log )90 protected void cleanup( TestParameters tParam, PrintWriter log ) { 91 log.println( " disposing xSheetDoc " ); 92 XComponent oComp = (XComponent) 93 UnoRuntime.queryInterface (XComponent.class, xSheetDoc) ; 94 util.DesktopTools.closeDoc(oComp); 95 } 96 97 /** 98 * Creating a Testenvironment for the interfaces to be tested. 99 * Retrieves a collection of spreadsheets from the document and takes one of 100 * them. Obtaines the collection of columns in the range using the interface 101 * <code>XColumnRowRange</code>. Retrieves the column with index 10 that is 102 * the instance of the service <code>com.sun.star.table.TableColumn</code>. 103 * Object relations created : 104 * <ul> 105 * <li> <code>'setName'</code> for 106 * {@link ifc.container._XNamed} </li> 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.TableColumn 112 */ createTestEnvironment(TestParameters Param, PrintWriter log)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 123 XSpreadsheets xSpreadsheets = (XSpreadsheets)xSheetDoc.getSheets(); 124 XNameAccess oNames = (XNameAccess) 125 UnoRuntime.queryInterface( XNameAccess.class, xSpreadsheets ); 126 try { 127 xSpreadsheet = (XSpreadsheet) AnyConverter.toObject( 128 new Type(XSpreadsheet.class), 129 oNames.getByName(oNames.getElementNames()[0])); 130 } catch (com.sun.star.lang.WrappedTargetException e) { 131 e.printStackTrace(log); 132 throw new StatusException("Couldn't get element by name", e); 133 } catch (com.sun.star.container.NoSuchElementException e) { 134 e.printStackTrace(log); 135 throw new StatusException("Couldn't get element by name", e); 136 } catch (com.sun.star.lang.IllegalArgumentException e) { 137 e.printStackTrace(log); 138 throw new StatusException("Couldn't get element by name", e); 139 } 140 141 XColumnRowRange oColumnRowRange = (XColumnRowRange) 142 UnoRuntime.queryInterface(XColumnRowRange.class, xSpreadsheet); 143 XTableColumns oColumns = (XTableColumns) oColumnRowRange.getColumns(); 144 XIndexAccess oIndexAccess = (XIndexAccess) 145 UnoRuntime.queryInterface(XIndexAccess.class, oColumns); 146 try { 147 oObj = (XInterface) AnyConverter.toObject( 148 new Type(XInterface.class),oIndexAccess.getByIndex(10)); 149 } catch (com.sun.star.lang.WrappedTargetException e) { 150 e.printStackTrace(log); 151 throw new StatusException("Couldn't get by index", e); 152 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 153 e.printStackTrace(log); 154 throw new StatusException("Couldn't get by index", e); 155 } catch (com.sun.star.lang.IllegalArgumentException e) { 156 e.printStackTrace(log); 157 throw new StatusException("Couldn't get by index", e); 158 } 159 160 log.println("creating a new environment for object"); 161 TestEnvironment tEnv = new TestEnvironment(oObj); 162 163 // a valid Range for XCellRange 164 tEnv.addObjRelation("ValidRange","K1:K1"); 165 166 //since TableColumnsNames are fixed XNamed::setName() should always be OK 167 tEnv.addObjRelation("setName",new Boolean(true)); 168 return tEnv; 169 } 170 } 171 172 173