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