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.TableRows</code>. <p> 48 * Object implements the following interfaces : 49 * <ul> 50 * <li> <code>com::sun::star::container::XIndexAccess</code></li> 51 * <li> <code>com::sun::star::container::XElementAccess</code></li> 52 * <li> <code>com::sun::star::table::XTableRows</code></li> 53 * </ul> <p> 54 * This object test <b> is NOT </b> designed to be run in several 55 * threads concurently. 56 * @see com.sun.star.container.XIndexAccess 57 * @see com.sun.star.container.XElementAccess 58 * @see com.sun.star.table.XTableRows 59 * @see ifc.container._XIndexAccess 60 * @see ifc.container._XElementAccess 61 * @see ifc.table._XTableRows 62 */ 63 public class SwXTableRows extends TestCase { 64 XTextDocument xTextDoc; 65 66 /** 67 * Creates text document. 68 */ 69 protected void initialize( TestParameters tParam, PrintWriter log ) { 70 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() ); 71 try { 72 log.println( "creating a textdocument" ); 73 xTextDoc = SOF.createTextDoc( null ); 74 } catch ( com.sun.star.uno.Exception e ) { 75 e.printStackTrace( log ); 76 throw new StatusException( "Couldn't create document", e ); 77 } 78 } 79 80 /** 81 * Disposes text document. 82 */ 83 protected void cleanup( TestParameters tParam, PrintWriter log ) { 84 log.println( " disposing xTextDoc " ); 85 util.DesktopTools.closeDoc(xTextDoc); 86 } 87 88 /** 89 * Creating a Testenvironment for the interfaces to be tested. After creation 90 * of text table, it is inserted to text document, then rows are gotten 91 * from table. 92 */ 93 public synchronized TestEnvironment createTestEnvironment( 94 TestParameters tParam, PrintWriter log ) throws StatusException { 95 XInterface oObj = null; 96 XTextTable oTable = null; 97 98 log.println( "creating a test environment" ); 99 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() ); 100 try { 101 oTable = SOF.createTextTable( xTextDoc ); 102 } catch ( com.sun.star.uno.Exception e ) { 103 e.printStackTrace( log ); 104 throw new StatusException("Couldn't create TextTable: " 105 +e.getMessage(),e); 106 } 107 108 try { 109 SOF.insertTextContent(xTextDoc, oTable ); 110 } catch ( com.sun.star.lang.IllegalArgumentException e ) { 111 e.printStackTrace( log ); 112 throw new StatusException("Couldn't insert text content: " 113 +e.getMessage(),e); 114 } 115 oObj = oTable.getRows(); 116 117 log.println( "creating a new environment for TableColumns object" ); 118 TestEnvironment tEnv = new TestEnvironment( oObj ); 119 120 // adding relation for XTableColumns 121 tEnv.addObjRelation("XTableRows.XCellRange", 122 UnoRuntime.queryInterface(XCellRange.class, oTable)); 123 124 return tEnv; 125 } // finish method getTestEnvironment 126 127 } // finish class SwXTableRows 128 129