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._sw; 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.lang.XMultiServiceFactory; 39 import com.sun.star.table.XCellRange; 40 import com.sun.star.text.XTextDocument; 41 import com.sun.star.text.XTextTable; 42 import com.sun.star.uno.UnoRuntime; 43 import com.sun.star.uno.XInterface; 44 45 /** 46 * Test for object which is represented by service 47 * <code>com.sun.star.table.CellRange</code>. <p> 48 * Object implements the following interfaces : 49 * <ul> 50 * <li> <code>com::sun::star::text::CellProperties</code></li> 51 * <li> <code>com::sun::star::beans::XPropertySet</code></li> 52 * </ul> <p> 53 * This object test <b> is NOT </b> designed to be run in several 54 * threads concurently. 55 * @see com.sun.star.table.CellRange 56 * @see com.sun.star.text.CellProperties 57 * @see com.sun.star.beans.XPropertySet 58 * @see ifc.text._CellProperties 59 * @see ifc.beans._XPropertySet 60 */ 61 public class SwXCellRange extends TestCase { 62 SOfficeFactory SOF; 63 XTextDocument xTextDoc; 64 65 /** 66 * Creates text document. 67 */ 68 protected void initialize( TestParameters tParam, PrintWriter log ) { 69 SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() ); 70 try { 71 log.println( "creating a textdocument" ); 72 xTextDoc = SOF.createTextDoc( null ); 73 } catch ( com.sun.star.uno.Exception e ) { 74 e.printStackTrace( log ); 75 throw new StatusException( "Couldn't create document", e ); 76 } 77 } 78 79 /** 80 * Disposes text document. 81 */ 82 protected void cleanup( TestParameters tParam, PrintWriter log ) { 83 log.println( " disposing xTextDoc " ); 84 util.DesktopTools.closeDoc(xTextDoc); 85 } 86 87 /** 88 * Creating a Testenvironment for the interfaces to be tested. At first 89 * method creates and initializes the table, then if text document has no 90 * tables, previously created table is inserted to text document. Finally, 91 * custom cell range is gotten from the table created. 92 * Object relations created : 93 * <ul> 94 * <li> <code>'CellProperties.TextSection'</code> for 95 * {@link ifc.text._CellProperties} : range of complete paragraphs 96 * within a text</li> 97 * </ul> 98 */ 99 protected synchronized TestEnvironment createTestEnvironment 100 (TestParameters tParam, PrintWriter log) { 101 102 XTextTable the_table = null; 103 XInterface oObj = null; 104 try { 105 the_table = SOF.createTextTable( xTextDoc ); 106 the_table.initialize(5, 5); 107 } catch ( com.sun.star.uno.Exception e ) { 108 e.printStackTrace( log ); 109 throw new StatusException("Couldn't create testobj: " 110 +e.getMessage(),e); 111 } 112 113 if( SOF.getTableCollection( xTextDoc ).getCount() == 0 ) { 114 try { 115 SOF.insertTextContent(xTextDoc, the_table ); 116 } catch( com.sun.star.uno.Exception e ) { 117 e.printStackTrace( log ); 118 throw new StatusException("Couldn't create TextTable : " 119 + e.getMessage(), e); 120 } 121 } 122 try { 123 XCellRange the_Range = (XCellRange) 124 UnoRuntime.queryInterface(XCellRange.class, the_table); 125 oObj = the_Range.getCellRangeByPosition(0, 0, 3, 4); 126 } catch (com.sun.star.uno.Exception e) { 127 e.printStackTrace( log ); 128 throw new StatusException("Couldn't get CellRange : " 129 + e.getMessage(), e); 130 } 131 132 log.println("Creating instance..."); 133 TestEnvironment tEnv = new TestEnvironment( oObj ); 134 log.println("ImplName: " + util.utils.getImplName(oObj)); 135 136 XMultiServiceFactory oDocMSF = (XMultiServiceFactory) 137 UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc); 138 try { 139 XInterface oTS = (XInterface) 140 oDocMSF.createInstance("com.sun.star.text.TextSection"); 141 log.println(" adding TextSection object"); 142 tEnv.addObjRelation("CellProperties.TextSection", oTS); 143 } catch (com.sun.star.uno.Exception e) { 144 log.println("Could not get instance of TextSection"); 145 e.printStackTrace(log); 146 } 147 148 Object[][] NewData = new Object[5][]; 149 NewData[0] = new Double[] 150 {new Double(2.5),new Double(5),new Double(2.5),new Double(5)}; 151 NewData[1] = new Double[] 152 {new Double(4),new Double(9),new Double(2.5),new Double(5)}; 153 NewData[2] = new Double[] 154 {new Double(2.5),new Double(5),new Double(2.5),new Double(5)}; 155 NewData[3] = new Double[] 156 {new Double(2.5),new Double(5),new Double(2.5),new Double(5)}; 157 NewData[4] = new Double[] 158 {new Double(4),new Double(9),new Double(2.5),new Double(5)}; 159 tEnv.addObjRelation("NewData",NewData); 160 161 // com::sun::star::chart::XChartDataArray 162 tEnv.addObjRelation("CRDESC", 163 "Column and RowDescriptions can't be changed for this Object"); 164 165 166 return tEnv; 167 } 168 } // finish class SwXCellRange 169 170