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