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.XTableColumns; 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.TableColumns</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::container::XNameAccess</code></li> 60 * <li> <code>com::sun::star::table::XTableColumns</code></li> 61 * </ul> 62 * @see com.sun.star.table.TableColumns 63 * @see com.sun.star.container.XIndexAccess 64 * @see com.sun.star.container.XElementAccess 65 * @see com.sun.star.container.XNameAccess 66 * @see com.sun.star.table.XTableColumns 67 * @see ifc.container._XIndexAccess 68 * @see ifc.container._XElementAccess 69 * @see ifc.container._XNameAccess 70 * @see ifc.table._XTableColumns 71 */ 72 public class ScTableColumnsObj extends TestCase { 73 static XSpreadsheetDocument xSheetDoc = null; 74 75 /** 76 * Creates Spreadsheet document. 77 */ 78 protected void initialize( TestParameters tParam, PrintWriter log ) { 79 // get a soffice factory object 80 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF()); 81 82 try { 83 log.println( "creating a sheetdocument" ); 84 xSheetDoc = SOF.createCalcDoc(null);; 85 } catch (com.sun.star.uno.Exception e) { 86 // Some exception occures.FAILED 87 e.printStackTrace( log ); 88 throw new StatusException( "Couldn't create document", e ); 89 } 90 } 91 92 /** 93 * Disposes Spreadsheet document. 94 */ 95 protected void cleanup( TestParameters tParam, PrintWriter log ) { 96 log.println( " disposing xSheetDoc " ); 97 XComponent oComp = (XComponent) 98 UnoRuntime.queryInterface (XComponent.class, xSheetDoc) ; 99 util.DesktopTools.closeDoc(oComp); 100 } 101 102 /** 103 * Creating a Testenvironment for the interfaces to be tested. 104 * Retrieves a collection of spreadsheets from the document and takes one of 105 * them. Obtaines the collection of columns in the range using the interface 106 * <code>XColumnRowRange</code>. This collection is the instance of the 107 * service <code>com.sun.star.table.TableColumns</code>. 108 * @see com.sun.star.table.XColumnRowRange 109 * @see com.sun.star.table.TableColumns 110 */ 111 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) { 112 113 XInterface oObj = null; 114 115 // creation of the testobject here 116 // first we write what we are intend to do to log file 117 log.println("craeting a test environment"); 118 119 log.println("getting column"); 120 XSpreadsheets xSpreadsheets = (XSpreadsheets)xSheetDoc.getSheets(); 121 XNameAccess oNames = (XNameAccess) 122 UnoRuntime.queryInterface( XNameAccess.class, xSpreadsheets ); 123 XSpreadsheet xSpreadsheet = null; 124 try { 125 xSpreadsheet = (XSpreadsheet) AnyConverter.toObject( 126 new Type(XSpreadsheet.class), 127 oNames.getByName(oNames.getElementNames()[0])); 128 } catch (com.sun.star.lang.WrappedTargetException e) { 129 e.printStackTrace(log); 130 throw new StatusException("Couldn't get spreadsheet", e); 131 } catch (com.sun.star.container.NoSuchElementException e) { 132 e.printStackTrace(log); 133 throw new StatusException("Couldn't get spreadsheet", e); 134 } catch (com.sun.star.lang.IllegalArgumentException e) { 135 e.printStackTrace(log); 136 throw new StatusException("Couldn't get spreadsheet", e); 137 } 138 139 XColumnRowRange oColumnRowRange = (XColumnRowRange) 140 UnoRuntime.queryInterface(XColumnRowRange.class, xSpreadsheet); 141 XTableColumns oColumns = (XTableColumns) oColumnRowRange.getColumns(); 142 oObj = oColumns; 143 144 log.println("creating a new environment for object"); 145 TestEnvironment tEnv = new TestEnvironment(oObj); 146 147 // adding relation for XTableColumns 148 tEnv.addObjRelation("XTableColumns.XCellRange", 149 UnoRuntime.queryInterface(XCellRange.class, xSpreadsheet)); 150 151 return tEnv; 152 } 153 } // finish class ScTableColumnsObj 154