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.lang.XComponent; 40 import com.sun.star.lang.XMultiServiceFactory; 41 import com.sun.star.sheet.XCellRangesQuery; 42 import com.sun.star.sheet.XSheetCellRanges; 43 import com.sun.star.sheet.XSpreadsheetDocument; 44 import com.sun.star.sheet.XSpreadsheets; 45 import com.sun.star.table.XCell; 46 import com.sun.star.table.XCellRange; 47 import com.sun.star.text.XTextRange; 48 import com.sun.star.uno.AnyConverter; 49 import com.sun.star.uno.Type; 50 import com.sun.star.uno.UnoRuntime; 51 import com.sun.star.uno.XInterface; 52 53 /** 54 * Test for object which is represented by service 55 * <code>com.sun.star.sheet.Cells</code>. <p> 56 * Object implements the following interfaces : 57 * <ul> 58 * <li> <code>com::sun::star::container::XEnumerationAccess</code></li> 59 * <li> <code>com::sun::star::container::XElementAccess</code></li> 60 * </ul> 61 * @see com.sun.star.sheet.Cells 62 * @see com.sun.star.container.XEnumerationAccess 63 * @see com.sun.star.container.XElementAccess 64 * @see ifc.container._XEnumerationAccess 65 * @see ifc.container._XElementAccess 66 */ 67 public class ScCellsObj extends TestCase { 68 static XSpreadsheetDocument xSheetDoc = null; 69 70 /** 71 * Creates Spreadsheet document. 72 */ 73 protected void initialize( TestParameters tParam, PrintWriter log ) { 74 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 a document, 101 * and takes one of them. Replaces text of some cells. 102 * Retrives a cell range of the visible cells using the interface 103 * <code>XCellRangesQuery</code>. Retrieves a collection of cells from 104 * this cell range, this collection is instance of the service 105 * <code>com.sun.star.sheet.Cells</code>. 106 * @see com.sun.star.sheet.XCellRangesQuery 107 */ 108 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) { 109 110 XInterface oObj = null; 111 Object cellArr[] = new Object[3]; 112 113 // creation of testobject here 114 XSpreadsheets oSheets = (XSpreadsheets)xSheetDoc.getSheets(); 115 XIndexAccess oIndexAccess = (XIndexAccess) 116 UnoRuntime.queryInterface(XIndexAccess.class, oSheets); 117 XCellRange oSheet = null; 118 try { 119 oSheet = (XCellRange) AnyConverter.toObject( 120 new Type(XCellRange.class),oIndexAccess.getByIndex(0)); 121 122 XCell oCell_1 = (XCell)oSheet.getCellByPosition(0, 0); 123 XTextRange oTextRange = (XTextRange) 124 UnoRuntime.queryInterface(XTextRange.class, oCell_1); 125 126 oTextRange.setString("ScCellsObj test 1"); 127 128 XCell oCell_2 = (XCell)oSheet.getCellByPosition(5, 1); 129 oCell_2.setValue(15); 130 131 XCell oCell_3 = (XCell)oSheet.getCellByPosition(3, 9); 132 oTextRange = (XTextRange) 133 UnoRuntime.queryInterface(XTextRange.class, oCell_3); 134 135 oTextRange.setString("ScCellsObj test 2"); 136 137 cellArr[0] = oCell_1; 138 cellArr[2] = oCell_2; 139 cellArr[1] = oCell_3; 140 } catch(com.sun.star.lang.WrappedTargetException e) { 141 log.println ("Exception occured while creating test Object."); 142 e.printStackTrace(log); 143 throw new StatusException("Couldn't create test object", e); 144 } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 145 log.println ("Exception occured while creating test Object."); 146 e.printStackTrace(log); 147 throw new StatusException("Couldn't create test object", e); 148 } catch(com.sun.star.lang.IllegalArgumentException e) { 149 log.println ("Exception occured while creating test Object."); 150 e.printStackTrace(log); 151 throw new StatusException("Couldn't create test object", e); 152 } 153 154 XCellRangesQuery oCellRangesQuery = (XCellRangesQuery) 155 UnoRuntime.queryInterface(XCellRangesQuery.class, oSheet); 156 XSheetCellRanges oSheetCellRanges = oCellRangesQuery.queryVisibleCells(); 157 158 oObj = oSheetCellRanges.getCells(); 159 160 TestEnvironment tEnv = new TestEnvironment(oObj) ; 161 log.println ("Object created.") ; 162 163 return tEnv; 164 } 165 166 } // finish class ScCellsObj 167 168