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.text.XTextDocument; 40 import com.sun.star.text.XTextTable; 41 import com.sun.star.text.XTextTablesSupplier; 42 import com.sun.star.uno.UnoRuntime; 43 import com.sun.star.uno.XInterface; 44 45 /** 46 * 47 * initial description 48 * @see com.sun.star.container.XElementAccess 49 * @see com.sun.star.container.XIndexAccess 50 * @see com.sun.star.container.XNameAccess 51 * 52 */ 53 public class SwXTextTables extends TestCase { 54 XTextDocument xTextDoc; 55 56 protected void initialize( TestParameters tParam, PrintWriter log ) { 57 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() ); 58 59 try { 60 log.println( "creating a textdocument" ); 61 xTextDoc = SOF.createTextDoc( null ); 62 } catch ( com.sun.star.uno.Exception e ) { 63 // Some exception occures.FAILED 64 e.printStackTrace( log ); 65 throw new StatusException( "Couldn't create document", e ); 66 } 67 } 68 69 protected void cleanup( TestParameters tParam, PrintWriter log ) { 70 log.println( " disposing xTextDoc " ); 71 util.DesktopTools.closeDoc(xTextDoc); 72 } 73 74 75 /** 76 * creating a Testenvironment for the interfaces to be tested 77 * 78 * @param tParam class which contains additional test parameters 79 * @param log class to log the test state and result 80 * 81 * @return Status class 82 * 83 * @see TestParameters 84 * @see PrintWriter 85 */ 86 public synchronized TestEnvironment createTestEnvironment 87 (TestParameters tParam, PrintWriter log) { 88 89 XInterface oObj = null; 90 int nRow = 4; 91 int nCol = 5; 92 93 94 // creation of testobject here 95 // first we write what we are intend to do to log file 96 log.println( "creating a test environment" ); 97 98 // get a soffice factory object 99 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() ); 100 101 // create testobject here 102 TestEnvironment tEnv = null; 103 XTextTable oTable = null; 104 try { 105 oTable = SOF.createTextTable( xTextDoc ); 106 SOF.insertTextContent(xTextDoc, oTable ); 107 } 108 catch( Exception uE ) { 109 uE.printStackTrace( log ); 110 throw new StatusException("Couldn't create TextTable : " 111 + uE.getMessage(), uE); 112 } 113 114 // Number two 115 XTextTable oTable2 = null; 116 try { 117 oTable2 = SOF.createTextTable( xTextDoc ); 118 SOF.insertTextContent(xTextDoc, oTable2 ); 119 } 120 catch( Exception uE ) { 121 uE.printStackTrace( log ); 122 throw new StatusException("Couldn't create TextTable two: " 123 + uE.getMessage(), uE); 124 } 125 126 XMultiServiceFactory msf = (XMultiServiceFactory) 127 UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc); 128 XTextTablesSupplier oTTSupp = (XTextTablesSupplier) 129 UnoRuntime.queryInterface(XTextTablesSupplier.class, msf); 130 oObj = oTTSupp.getTextTables(); 131 132 if ( oTable != null ) { 133 log.println("Creating instance..."); 134 tEnv = new TestEnvironment(oObj); 135 } 136 137 log.println( "adding TextDocument as mod relation to environment" ); 138 tEnv.addObjRelation( "TEXTDOC", xTextDoc ); 139 tEnv.addObjRelation( "ROW", new Integer( nRow ) ); 140 tEnv.addObjRelation( "COL", new Integer( nCol ) ); 141 try { 142 tEnv.addObjRelation( "INST", SOF.createTextTable( xTextDoc )); 143 } 144 catch( Exception uE ) { 145 uE.printStackTrace( log ); 146 throw new StatusException("Couldn't create TextTable : " 147 + uE.getMessage(), uE); 148 } 149 150 return tEnv; 151 } // finish method getTestEnvironment 152 153 } // finish class SwXTextTables 154 155