xref: /AOO41X/main/qadevOOo/tests/java/mod/_sw/SwXTableCellText.java (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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.InstCreator;
37 import util.ParagraphDsc;
38 import util.SOfficeFactory;
39 import util.TextSectionDsc;
40 
41 import com.sun.star.lang.XMultiServiceFactory;
42 import com.sun.star.table.XCell;
43 import com.sun.star.text.XSimpleText;
44 import com.sun.star.text.XText;
45 import com.sun.star.text.XTextDocument;
46 import com.sun.star.text.XTextTable;
47 import com.sun.star.uno.UnoRuntime;
48 import com.sun.star.uno.XInterface;
49 
50 /**
51  * Test for object which is represented by cell text of the text table.<p>
52  * Object implements the following interfaces :
53  * <ul>
54  *  <li> <code>com::sun::star::text::XTextRangeMover</code></li>
55  *  <li> <code>com::sun::star::text::XSimpleText</code></li>
56  *  <li> <code>com::sun::star::text::XTextRange</code></li>
57  *  <li> <code>com::sun::star::text::XRelativeTextContentInsert</code></li>
58  *  <li> <code>com::sun::star::text::XTextRangeCompare</code></li>
59  *  <li> <code>com::sun::star::container::XElementAccess</code></li>
60  *  <li> <code>com::sun::star::container::XEnumerationAccess</code></li>
61  *  <li> <code>com::sun::star::text::XText</code></li>
62  * </ul> <p>
63  * This object test <b> is NOT </b> designed to be run in several
64  * threads concurently.
65  * @see com.sun.star.text.XTextRangeMover
66  * @see com.sun.star.text.XSimpleText
67  * @see com.sun.star.text.XTextRange
68  * @see com.sun.star.text.XRelativeTextContentInsert
69  * @see com.sun.star.text.XTextRangeCompare
70  * @see com.sun.star.container.XElementAccess
71  * @see com.sun.star.container.XEnumerationAccess
72  * @see com.sun.star.text.XText
73  * @see ifc.text._XTextRangeMover
74  * @see ifc.text._XSimpleText
75  * @see ifc.text._XTextRange
76  * @see ifc.text._XRelativeTextContentInsert
77  * @see ifc.text._XTextRangeCompare
78  * @see ifc.container._XElementAccess
79  * @see ifc.container._XEnumerationAccess
80  * @see ifc.text._XText
81  */
82 public class SwXTableCellText extends TestCase {
83     XTextDocument xTextDoc;
84     SOfficeFactory SOF;
85 
86     /**
87     * Creates text document.
88     */
89     protected void initialize( TestParameters tParam, PrintWriter log ) {
90         SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
91         try {
92             log.println( "creating a textdocument" );
93             xTextDoc = SOF.createTextDoc( null );
94         } catch ( com.sun.star.uno.Exception e ) {
95             e.printStackTrace( log );
96             throw new StatusException( "Couldn't create document", e );
97         }
98     }
99 
100     /**
101     * Disposes text document.
102     */
103     protected void cleanup( TestParameters tParam, PrintWriter log ) {
104         log.println( "    disposing xTextDoc " );
105         util.DesktopTools.closeDoc(xTextDoc);
106     }
107 
108     /**
109     * Creating a Testenvironment for the interfaces to be tested. After creation
110     * of text table, it is inserted to a text document. Then cell named 'A1' is
111     * obtained from table, string 'SwXTableCellText' is set to this cell, then
112     * cell text is gotten from cell obtained before and returned as a test
113     * component.
114     *     Object relations created :
115     * <ul>
116     *  <li> <code>'TEXT'</code> for
117     *      {@link ifc.text._XTextRangeCompare} : table cell text</li>
118     *  <li> <code>'PARA'</code> for
119     *      {@link ifc.text._XRelativeTextContentInsert} : paragraph creator</li>
120     *  <li> <code>'XTEXTINFO'</code> for
121     *      {@link ifc.text._XRelativeTextContentInsert},
122     *      {@link ifc.text._XText} : creates text sections</li>
123     * </ul>
124     */
125     public synchronized TestEnvironment createTestEnvironment(
126             TestParameters Param, PrintWriter log ) throws StatusException {
127         XInterface oObj = null;
128         XTextTable oTable = null;
129 
130         log.println( "Creating a test environment" );
131         try {
132             oTable = SOF.createTextTable( xTextDoc );
133         } catch ( com.sun.star.uno.Exception e ) {
134             e.printStackTrace( log );
135             throw new StatusException("Couldn't create TextTable : "
136                 +e.getMessage(),e);
137         }
138 
139         try {
140             SOF.insertTextContent(xTextDoc, oTable );
141         } catch ( com.sun.star.lang.IllegalArgumentException e ) {
142             e.printStackTrace( log );
143             throw new StatusException("Couldn't insert text content : "
144                 +e.getMessage(),e);
145         }
146 
147         XCell oCell = oTable.getCellByName("A1");
148         XSimpleText oCellText = (XSimpleText)
149             UnoRuntime.queryInterface(XSimpleText.class, oCell);
150         oCellText.setString("SwXTableCellText");
151         oObj = oCellText.getText();
152 
153         log.println( "creating a new environment for Cell object" );
154         TestEnvironment tEnv = new TestEnvironment( oObj );
155 
156         log.println( "adding TextDocument as mod relation to environment" );
157         tEnv.addObjRelation("TEXT", (XText) oObj);
158 
159         log.println( "    adding InstCreator object" );
160         TextSectionDsc tDsc = new TextSectionDsc();
161         tEnv.addObjRelation( "XTEXTINFO", new InstCreator( xTextDoc, tDsc ) );
162 
163         log.println( "    adding Paragraph" );
164         ParagraphDsc pDsc = new ParagraphDsc();
165         tEnv.addObjRelation( "PARA", new InstCreator( xTextDoc, pDsc ) );
166 
167         return tEnv;
168     } // finish method getTestEnvironment
169 
170 
171 }    // finish class SwXTableCellText
172 
173