1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package mod._sw; 25 26 import java.io.PrintWriter; 27 28 import lib.StatusException; 29 import lib.TestCase; 30 import lib.TestEnvironment; 31 import lib.TestParameters; 32 import util.SOfficeFactory; 33 34 import com.sun.star.lang.XMultiServiceFactory; 35 import com.sun.star.table.XCellRange; 36 import com.sun.star.text.XTextDocument; 37 import com.sun.star.text.XTextTable; 38 import com.sun.star.uno.UnoRuntime; 39 import com.sun.star.uno.XInterface; 40 41 /** 42 * Test for object which is represented by service 43 * <code>com.sun.star.table.TableColumns</code>. <p> 44 * Object implements the following interfaces : 45 * <ul> 46 * <li> <code>com::sun::star::container::XIndexAccess</code></li> 47 * <li> <code>com::sun::star::container::XElementAccess</code></li> 48 * <li> <code>com::sun::star::container::XNameAccess</code></li> 49 * <li> <code>com::sun::star::table::XTableColumns</code></li> 50 * </ul> <p> 51 * This object test <b> is NOT </b> designed to be run in several 52 * threads concurently. 53 * @see com.sun.star.container.XIndexAccess 54 * @see com.sun.star.container.XElementAccess 55 * @see com.sun.star.container.XNameAccess 56 * @see com.sun.star.table.XTableColumns 57 * @see com.sun.star.table.TableColumns 58 * @see ifc.container._XIndexAccess 59 * @see ifc.container._XElementAccess 60 * @see ifc.container._XNameAccess 61 * @see ifc.table._XTableColumns 62 */ 63 public class SwXTableColumns extends TestCase { 64 XTextDocument xTextDoc; 65 SOfficeFactory SOF; 66 67 /** 68 * Creates text document. 69 */ initialize( TestParameters tParam, PrintWriter log )70 protected void initialize( TestParameters tParam, PrintWriter log ) { 71 SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() ); 72 try { 73 log.println( "creating a textdocument" ); 74 xTextDoc = SOF.createTextDoc( null ); 75 } catch ( com.sun.star.uno.Exception e ) { 76 e.printStackTrace( log ); 77 throw new StatusException( "Couldn't create document", e ); 78 } 79 } 80 81 /** 82 * Disposes text document. 83 */ cleanup( TestParameters tParam, PrintWriter log )84 protected void cleanup( TestParameters tParam, PrintWriter log ) { 85 log.println( " disposing xTextDoc " ); 86 util.DesktopTools.closeDoc(xTextDoc); 87 } 88 89 /** 90 * Creating a Testenvironment for the interfaces to be tested. After creation 91 * of text table, it is inserted to text document, then columns are gotten 92 * from table. 93 */ createTestEnvironment( TestParameters tParam, PrintWriter log )94 public synchronized TestEnvironment createTestEnvironment( 95 TestParameters tParam, PrintWriter log ) throws StatusException { 96 XInterface oObj = null; 97 XTextTable oTable = null; 98 99 log.println( "creating a test environment" ); 100 101 try { 102 oTable = SOF.createTextTable( xTextDoc ); 103 } catch ( com.sun.star.uno.Exception e ) { 104 e.printStackTrace( log ); 105 throw new StatusException("Couldn't create TextTable: " 106 +e.getMessage(),e); 107 } 108 109 try { 110 SOF.insertTextContent(xTextDoc, oTable ); 111 } catch ( com.sun.star.lang.IllegalArgumentException e ) { 112 e.printStackTrace( log ); 113 throw new StatusException("Couldn't insert text content: " 114 +e.getMessage(),e); 115 } 116 117 oObj = oTable.getColumns(); 118 119 log.println( "creating a new environment for TableColumns object" ); 120 TestEnvironment tEnv = new TestEnvironment( oObj ); 121 122 // adding relation for XTableColumns 123 tEnv.addObjRelation("XTableColumns.XCellRange", 124 UnoRuntime.queryInterface(XCellRange.class, oTable)); 125 126 tEnv.addObjRelation("XIndexAccess.getByIndex.mustBeNull", new Boolean(true)); 127 128 return tEnv; 129 } // finish method getTestEnvironment 130 131 } // finish class SwXTableColumns 132 133