merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _sw / SwXCell.java
blob5afcebd250d81b69f702f2bd126f60fbbb61f856
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SwXCell.java,v $
10 * $Revision: 1.7 $
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 ************************************************************************/
31 package mod._sw;
33 import java.io.PrintWriter;
35 import lib.StatusException;
36 import lib.TestCase;
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;
47 /**
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 :
51 * <ul>
52 * <li> <code>com::sun::star::text::CellProperties</code></li>
53 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
54 * </ul> <p>
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;
66 /**
67 * Creates text document.
69 protected void initialize( TestParameters tParam, PrintWriter log ) {
70 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
71 try {
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 );
80 /**
81 * Disposes text document.
83 protected void cleanup( TestParameters tParam, PrintWriter log ) {
84 log.println( " disposing xTextDoc " );
85 util.DesktopTools.closeDoc(xTextDoc);
88 /**
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 :
93 * <ul>
94 * <li> <code>'CellProperties.TextSection'</code> for
95 * {@link ifc.text._CellProperties} : range of complete paragraphs
96 * within a text</li>
97 * </ul>
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" );
106 try {
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);
112 try {
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);
125 try {
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);
135 return tEnv;
136 } // finish method getTestEnvironment
137 } // finish class SwXCell