1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SwXCell.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 import java
.io
.PrintWriter
;
35 import lib
.StatusException
;
37 import lib
.TestEnvironment
;
38 import lib
.TestParameters
;
39 import util
.SOfficeFactory
;
41 import com
.sun
.star
.lang
.XMultiServiceFactory
;
42 import com
.sun
.star
.text
.XTextContent
;
43 import com
.sun
.star
.text
.XTextDocument
;
44 import com
.sun
.star
.uno
.UnoRuntime
;
45 import com
.sun
.star
.uno
.XInterface
;
48 * Test for object which is a cell of the table in a text document, and
49 * represented by service <code>com.sun.star.table.Cell</code><p>
50 * Object implements the following interfaces :
52 * <li> <code>com::sun::star::text::CellProperties</code></li>
53 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
55 * This object test <b> is NOT </b> designed to be run in several
56 * threads concurently.
57 * @see com.sun.star.table.Cell
58 * @see com.sun.star.text.CellProperties
59 * @see com.sun.star.beans.XPropertySet
60 * @see ifc.text._CellProperties
61 * @see ifc.beans._XPropertySet
63 public class SwXCell
extends TestCase
{
64 XTextDocument xTextDoc
;
67 * Creates text document.
69 protected void initialize( TestParameters tParam
, PrintWriter log
) {
70 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
72 log
.println( "creating a textdocument" );
73 xTextDoc
= SOF
.createTextDoc( null );
74 } catch ( com
.sun
.star
.uno
.Exception e
) {
75 e
.printStackTrace( log
);
76 throw new StatusException( "Couldn't create document", e
);
81 * Disposes text document.
83 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
84 log
.println( " disposing xTextDoc " );
85 util
.DesktopTools
.closeDoc(xTextDoc
);
89 * Creating a Testenvironment for the interfaces to be tested. After creating
90 * a text table, it is inserted to the text document. Finally, first cell of
91 * this table is gotten.
92 * Object relations created :
94 * <li> <code>'CellProperties.TextSection'</code> for
95 * {@link ifc.text._CellProperties} : range of complete paragraphs
99 public TestEnvironment
createTestEnvironment(
100 TestParameters tParam
, PrintWriter log
) throws StatusException
{
101 XInterface oObj
= null;
102 XTextContent oTable
= null;
104 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
105 log
.println( "creating a test environment" );
107 oTable
= SOF
.createTextTable(xTextDoc
, 3, 4);
108 } catch ( com
.sun
.star
.uno
.Exception e
) {
109 log
.println("Unable to create TextTable...");
110 e
.printStackTrace(log
);
113 SOF
.insertTextContent( xTextDoc
, oTable
);
114 } catch ( com
.sun
.star
.lang
.IllegalArgumentException e
) {
115 log
.println("Unable to insert TextContent...");
116 e
.printStackTrace(log
);
118 oObj
= SOF
.getFirstTableCell( oTable
);
120 log
.println( " creating a new environment for bodytext object" );
121 TestEnvironment tEnv
= new TestEnvironment( oObj
);
123 XMultiServiceFactory oDocMSF
= (XMultiServiceFactory
)
124 UnoRuntime
.queryInterface(XMultiServiceFactory
.class, xTextDoc
);
126 XInterface oTS
= (XInterface
) oDocMSF
.createInstance
127 ("com.sun.star.text.TextSection");
128 log
.println(" adding TextSection object");
129 tEnv
.addObjRelation("CellProperties.TextSection", oTS
);
130 } catch (com
.sun
.star
.uno
.Exception e
) {
131 log
.println("Could not get instance of TextSection");
132 e
.printStackTrace(log
);
136 } // finish method getTestEnvironment
137 } // finish class SwXCell