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