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.text.XTextContent;
36 import com.sun.star.text.XTextDocument;
37 import com.sun.star.uno.UnoRuntime;
38 import com.sun.star.uno.XInterface;
39 
40 /**
41  * Test for object which is a cell of the table in a text document, and
42  * represented by service <code>com.sun.star.table.Cell</code><p>
43  * Object implements the following interfaces :
44  * <ul>
45  *  <li> <code>com::sun::star::text::CellProperties</code></li>
46  *  <li> <code>com::sun::star::beans::XPropertySet</code></li>
47  * </ul> <p>
48  * This object test <b> is NOT </b> designed to be run in several
49  * threads concurently.
50  * @see com.sun.star.table.Cell
51  * @see com.sun.star.text.CellProperties
52  * @see com.sun.star.beans.XPropertySet
53  * @see ifc.text._CellProperties
54  * @see ifc.beans._XPropertySet
55  */
56 public class SwXCell extends TestCase {
57     XTextDocument xTextDoc;
58 
59     /**
60     * Creates text document.
61     */
initialize( TestParameters tParam, PrintWriter log )62     protected void initialize( TestParameters tParam, PrintWriter log ) {
63         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
64         try {
65             log.println( "creating a textdocument" );
66             xTextDoc = SOF.createTextDoc( null );
67         } catch ( com.sun.star.uno.Exception e ) {
68             e.printStackTrace( log );
69             throw new StatusException( "Couldn't create document", e );
70         }
71     }
72 
73     /**
74     * Disposes text document.
75     */
cleanup( TestParameters tParam, PrintWriter log )76     protected void cleanup( TestParameters tParam, PrintWriter log ) {
77         log.println( "    disposing xTextDoc " );
78         util.DesktopTools.closeDoc(xTextDoc);
79     }
80 
81     /**
82     * Creating a Testenvironment for the interfaces to be tested. After creating
83     * a text table, it is inserted to the text document. Finally, first cell of
84     * this table is gotten.
85     *     Object relations created :
86     * <ul>
87     *  <li> <code>'CellProperties.TextSection'</code> for
88     *    {@link ifc.text._CellProperties} : range of complete paragraphs
89     *  within a text</li>
90     * </ul>
91     */
createTestEnvironment( TestParameters tParam, PrintWriter log )92     public TestEnvironment createTestEnvironment(
93             TestParameters tParam, PrintWriter log ) throws StatusException {
94         XInterface oObj = null;
95         XTextContent oTable = null;
96 
97         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
98         log.println( "creating a test environment" );
99         try {
100             oTable = SOF.createTextTable(xTextDoc, 3, 4);
101         } catch ( com.sun.star.uno.Exception e ) {
102             log.println("Unable to create TextTable...");
103             e.printStackTrace(log);
104         }
105         try {
106             SOF.insertTextContent( xTextDoc, oTable );
107         } catch ( com.sun.star.lang.IllegalArgumentException e ) {
108             log.println("Unable to insert TextContent...");
109             e.printStackTrace(log);
110         }
111         oObj = SOF.getFirstTableCell( oTable );
112 
113         log.println( "    creating a new environment for bodytext object" );
114         TestEnvironment tEnv = new TestEnvironment( oObj );
115 
116         XMultiServiceFactory oDocMSF = (XMultiServiceFactory)
117                 UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc);
118         try {
119             XInterface oTS = (XInterface) oDocMSF.createInstance
120                 ("com.sun.star.text.TextSection");
121             log.println("  adding TextSection object");
122             tEnv.addObjRelation("CellProperties.TextSection", oTS);
123         } catch (com.sun.star.uno.Exception e) {
124             log.println("Could not get instance of TextSection");
125             e.printStackTrace(log);
126         }
127 
128         return tEnv;
129     } // finish method getTestEnvironment
130 }    // finish class SwXCell
131 
132