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