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.TableDsc;
36 
37 import com.sun.star.lang.XMultiServiceFactory;
38 import com.sun.star.text.XTextDocument;
39 import com.sun.star.uno.XInterface;
40 
41 /**
42  * Test for object which is represented by service
43  * <code>com.sun.star.text.Text</code>.<p>
44  * Object implements the following interfaces :
45  * <ul>
46  *  <li> <code>com::sun::star::text::XTextRangeMover</code></li>
47  *  <li> <code>com::sun::star::text::XSimpleText</code></li>
48  *  <li> <code>com::sun::star::text::XTextRange</code></li>
49  *  <li> <code>com::sun::star::text::XRelativeTextContentInsert</code></li>
50  *  <li> <code>com::sun::star::text::XTextRangeCompare</code></li>
51  *  <li> <code>com::sun::star::container::XElementAccess</code></li>
52  *  <li> <code>com::sun::star::container::XEnumerationAccess</code></li>
53  *  <li> <code>com::sun::star::text::XText</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.text.XTextRangeMover
58  * @see com.sun.star.text.XSimpleText
59  * @see com.sun.star.text.XTextRange
60  * @see com.sun.star.text.XRelativeTextContentInsert
61  * @see com.sun.star.text.XTextRangeCompare
62  * @see com.sun.star.container.XElementAccess
63  * @see com.sun.star.container.XEnumerationAccess
64  * @see com.sun.star.text.XText
65  * @see ifc.text._XTextRangeMover
66  * @see ifc.text._XSimpleText
67  * @see ifc.text._XTextRange
68  * @see ifc.text._XRelativeTextContentInsert
69  * @see ifc.text._XTextRangeCompare
70  * @see ifc.container._XElementAccess
71  * @see ifc.container._XEnumerationAccess
72  * @see ifc.text._XText
73  */
74 public class SwXBodyText extends TestCase {
75     XTextDocument xTextDoc = null;
76     SOfficeFactory SOF = null;
77 
78     /**
79     * Creates text document.
80     */
initialize( TestParameters tParam, PrintWriter log )81     protected void initialize( TestParameters tParam, PrintWriter log ) {
82         SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
83         try {
84             log.println( "creating a textdocument" );
85             xTextDoc = SOF.createTextDoc( null );
86         } catch ( com.sun.star.uno.Exception e ) {
87             e.printStackTrace( log );
88             throw new StatusException( "Couldn't create document", e );
89         }
90     }
91 
92     /**
93     * Disposes text document.
94     */
cleanup( TestParameters tParam, PrintWriter log )95     protected void cleanup( TestParameters tParam, PrintWriter log ) {
96         log.println( "    disposing xTextDoc " );
97         util.DesktopTools.closeDoc(xTextDoc);
98     }
99 
100     /**
101     * Creating a Testenvironment for the interfaces to be tested.
102     * Obtains body text from text document.
103     * Object relations created :
104     * <ul>
105     *  <li> <code>'TEXT'</code> for
106     *    {@link ifc.text._XTextRangeCompare} : text</li>
107     *  <li> <code>'XTEXTINFO'</code> for
108     *    {@link ifc.text._XRelativeTextContentInsert},
109     *    {@link ifc.text._XText} : creates 6x4 tables</li>
110     *  <li> <code>'PARA'</code> for
111     *    {@link ifc.text._XRelativeTextContentInsert} : paragraph creator</li>
112     * </ul>
113     */
createTestEnvironment( TestParameters Param, PrintWriter log )114     public synchronized TestEnvironment createTestEnvironment(
115             TestParameters Param, PrintWriter log ) throws StatusException {
116         XInterface oObj = null;
117 
118         log.println( "creating a test environment" );
119 
120         // get the bodytext of textdocument here
121         log.println( "    getting the bodytext of textdocument with getText()" );
122         oObj = xTextDoc.getText();
123 
124         log.println( "    creating a new environment for bodytext object" );
125         TestEnvironment tEnv = new TestEnvironment( oObj );
126 
127         log.println(" adding Text as ObjRelation");
128         tEnv.addObjRelation("TEXT", oObj );
129 
130         log.println( "    adding InstDescriptor object" );
131         TableDsc tDsc = new TableDsc( 6, 4 );
132 
133         log.println( "    adding InstCreator object" );
134         tEnv.addObjRelation( "XTEXTINFO", new InstCreator( xTextDoc, tDsc ) );
135 
136         log.println( "    adding Paragraph" );
137         ParagraphDsc pDsc = new ParagraphDsc();
138         tEnv.addObjRelation( "PARA", new InstCreator( xTextDoc, pDsc ) );
139 
140         return tEnv;
141     } // finish method getTestEnvironment
142 
143 }    // finish class SwXBodyText
144 
145