1*ef39d40dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*ef39d40dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*ef39d40dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*ef39d40dSAndrew Rist * distributed with this work for additional information 6*ef39d40dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*ef39d40dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*ef39d40dSAndrew Rist * "License"); you may not use this file except in compliance 9*ef39d40dSAndrew Rist * with the License. You may obtain a copy of the License at 10*ef39d40dSAndrew Rist * 11*ef39d40dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*ef39d40dSAndrew Rist * 13*ef39d40dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*ef39d40dSAndrew Rist * software distributed under the License is distributed on an 15*ef39d40dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*ef39d40dSAndrew Rist * KIND, either express or implied. See the License for the 17*ef39d40dSAndrew Rist * specific language governing permissions and limitations 18*ef39d40dSAndrew Rist * under the License. 19*ef39d40dSAndrew Rist * 20*ef39d40dSAndrew Rist *************************************************************/ 21*ef39d40dSAndrew Rist 22*ef39d40dSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir package mod._sw; 25cdf0e10cSrcweir 26cdf0e10cSrcweir import java.io.PrintWriter; 27cdf0e10cSrcweir 28cdf0e10cSrcweir import lib.StatusException; 29cdf0e10cSrcweir import lib.TestCase; 30cdf0e10cSrcweir import lib.TestEnvironment; 31cdf0e10cSrcweir import lib.TestParameters; 32cdf0e10cSrcweir import util.SOfficeFactory; 33cdf0e10cSrcweir 34cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 35cdf0e10cSrcweir import com.sun.star.table.XCellRange; 36cdf0e10cSrcweir import com.sun.star.text.XTextDocument; 37cdf0e10cSrcweir import com.sun.star.text.XTextTable; 38cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 39cdf0e10cSrcweir import com.sun.star.uno.XInterface; 40cdf0e10cSrcweir 41cdf0e10cSrcweir /** 42cdf0e10cSrcweir * Test for object which is represented by service 43cdf0e10cSrcweir * <code>com.sun.star.table.CellRange</code>. <p> 44cdf0e10cSrcweir * Object implements the following interfaces : 45cdf0e10cSrcweir * <ul> 46cdf0e10cSrcweir * <li> <code>com::sun::star::text::CellProperties</code></li> 47cdf0e10cSrcweir * <li> <code>com::sun::star::beans::XPropertySet</code></li> 48cdf0e10cSrcweir * </ul> <p> 49cdf0e10cSrcweir * This object test <b> is NOT </b> designed to be run in several 50cdf0e10cSrcweir * threads concurently. 51cdf0e10cSrcweir * @see com.sun.star.table.CellRange 52cdf0e10cSrcweir * @see com.sun.star.text.CellProperties 53cdf0e10cSrcweir * @see com.sun.star.beans.XPropertySet 54cdf0e10cSrcweir * @see ifc.text._CellProperties 55cdf0e10cSrcweir * @see ifc.beans._XPropertySet 56cdf0e10cSrcweir */ 57cdf0e10cSrcweir public class SwXCellRange extends TestCase { 58cdf0e10cSrcweir SOfficeFactory SOF; 59cdf0e10cSrcweir XTextDocument xTextDoc; 60cdf0e10cSrcweir 61cdf0e10cSrcweir /** 62cdf0e10cSrcweir * Creates text document. 63cdf0e10cSrcweir */ initialize( TestParameters tParam, PrintWriter log )64cdf0e10cSrcweir protected void initialize( TestParameters tParam, PrintWriter log ) { 65cdf0e10cSrcweir SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() ); 66cdf0e10cSrcweir try { 67cdf0e10cSrcweir log.println( "creating a textdocument" ); 68cdf0e10cSrcweir xTextDoc = SOF.createTextDoc( null ); 69cdf0e10cSrcweir } catch ( com.sun.star.uno.Exception e ) { 70cdf0e10cSrcweir e.printStackTrace( log ); 71cdf0e10cSrcweir throw new StatusException( "Couldn't create document", e ); 72cdf0e10cSrcweir } 73cdf0e10cSrcweir } 74cdf0e10cSrcweir 75cdf0e10cSrcweir /** 76cdf0e10cSrcweir * Disposes text document. 77cdf0e10cSrcweir */ cleanup( TestParameters tParam, PrintWriter log )78cdf0e10cSrcweir protected void cleanup( TestParameters tParam, PrintWriter log ) { 79cdf0e10cSrcweir log.println( " disposing xTextDoc " ); 80cdf0e10cSrcweir util.DesktopTools.closeDoc(xTextDoc); 81cdf0e10cSrcweir } 82cdf0e10cSrcweir 83cdf0e10cSrcweir /** 84cdf0e10cSrcweir * Creating a Testenvironment for the interfaces to be tested. At first 85cdf0e10cSrcweir * method creates and initializes the table, then if text document has no 86cdf0e10cSrcweir * tables, previously created table is inserted to text document. Finally, 87cdf0e10cSrcweir * custom cell range is gotten from the table created. 88cdf0e10cSrcweir * Object relations created : 89cdf0e10cSrcweir * <ul> 90cdf0e10cSrcweir * <li> <code>'CellProperties.TextSection'</code> for 91cdf0e10cSrcweir * {@link ifc.text._CellProperties} : range of complete paragraphs 92cdf0e10cSrcweir * within a text</li> 93cdf0e10cSrcweir * </ul> 94cdf0e10cSrcweir */ createTestEnvironment(TestParameters tParam, PrintWriter log)95cdf0e10cSrcweir protected synchronized TestEnvironment createTestEnvironment 96cdf0e10cSrcweir (TestParameters tParam, PrintWriter log) { 97cdf0e10cSrcweir 98cdf0e10cSrcweir XTextTable the_table = null; 99cdf0e10cSrcweir XInterface oObj = null; 100cdf0e10cSrcweir try { 101cdf0e10cSrcweir the_table = SOF.createTextTable( xTextDoc ); 102cdf0e10cSrcweir the_table.initialize(5, 5); 103cdf0e10cSrcweir } catch ( com.sun.star.uno.Exception e ) { 104cdf0e10cSrcweir e.printStackTrace( log ); 105cdf0e10cSrcweir throw new StatusException("Couldn't create testobj: " 106cdf0e10cSrcweir +e.getMessage(),e); 107cdf0e10cSrcweir } 108cdf0e10cSrcweir 109cdf0e10cSrcweir if( SOF.getTableCollection( xTextDoc ).getCount() == 0 ) { 110cdf0e10cSrcweir try { 111cdf0e10cSrcweir SOF.insertTextContent(xTextDoc, the_table ); 112cdf0e10cSrcweir } catch( com.sun.star.uno.Exception e ) { 113cdf0e10cSrcweir e.printStackTrace( log ); 114cdf0e10cSrcweir throw new StatusException("Couldn't create TextTable : " 115cdf0e10cSrcweir + e.getMessage(), e); 116cdf0e10cSrcweir } 117cdf0e10cSrcweir } 118cdf0e10cSrcweir try { 119cdf0e10cSrcweir XCellRange the_Range = (XCellRange) 120cdf0e10cSrcweir UnoRuntime.queryInterface(XCellRange.class, the_table); 121cdf0e10cSrcweir oObj = the_Range.getCellRangeByPosition(0, 0, 3, 4); 122cdf0e10cSrcweir } catch (com.sun.star.uno.Exception e) { 123cdf0e10cSrcweir e.printStackTrace( log ); 124cdf0e10cSrcweir throw new StatusException("Couldn't get CellRange : " 125cdf0e10cSrcweir + e.getMessage(), e); 126cdf0e10cSrcweir } 127cdf0e10cSrcweir 128cdf0e10cSrcweir log.println("Creating instance..."); 129cdf0e10cSrcweir TestEnvironment tEnv = new TestEnvironment( oObj ); 130cdf0e10cSrcweir log.println("ImplName: " + util.utils.getImplName(oObj)); 131cdf0e10cSrcweir 132cdf0e10cSrcweir XMultiServiceFactory oDocMSF = (XMultiServiceFactory) 133cdf0e10cSrcweir UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc); 134cdf0e10cSrcweir try { 135cdf0e10cSrcweir XInterface oTS = (XInterface) 136cdf0e10cSrcweir oDocMSF.createInstance("com.sun.star.text.TextSection"); 137cdf0e10cSrcweir log.println(" adding TextSection object"); 138cdf0e10cSrcweir tEnv.addObjRelation("CellProperties.TextSection", oTS); 139cdf0e10cSrcweir } catch (com.sun.star.uno.Exception e) { 140cdf0e10cSrcweir log.println("Could not get instance of TextSection"); 141cdf0e10cSrcweir e.printStackTrace(log); 142cdf0e10cSrcweir } 143cdf0e10cSrcweir 144cdf0e10cSrcweir Object[][] NewData = new Object[5][]; 145cdf0e10cSrcweir NewData[0] = new Double[] 146cdf0e10cSrcweir {new Double(2.5),new Double(5),new Double(2.5),new Double(5)}; 147cdf0e10cSrcweir NewData[1] = new Double[] 148cdf0e10cSrcweir {new Double(4),new Double(9),new Double(2.5),new Double(5)}; 149cdf0e10cSrcweir NewData[2] = new Double[] 150cdf0e10cSrcweir {new Double(2.5),new Double(5),new Double(2.5),new Double(5)}; 151cdf0e10cSrcweir NewData[3] = new Double[] 152cdf0e10cSrcweir {new Double(2.5),new Double(5),new Double(2.5),new Double(5)}; 153cdf0e10cSrcweir NewData[4] = new Double[] 154cdf0e10cSrcweir {new Double(4),new Double(9),new Double(2.5),new Double(5)}; 155cdf0e10cSrcweir tEnv.addObjRelation("NewData",NewData); 156cdf0e10cSrcweir 157cdf0e10cSrcweir // com::sun::star::chart::XChartDataArray 158cdf0e10cSrcweir tEnv.addObjRelation("CRDESC", 159cdf0e10cSrcweir "Column and RowDescriptions can't be changed for this Object"); 160cdf0e10cSrcweir 161cdf0e10cSrcweir 162cdf0e10cSrcweir return tEnv; 163cdf0e10cSrcweir } 164cdf0e10cSrcweir } // finish class SwXCellRange 165cdf0e10cSrcweir 166