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.SOfficeFactory;
33 
34 import com.sun.star.lang.XMultiServiceFactory;
35 import com.sun.star.text.XTextDocument;
36 import com.sun.star.uno.UnoRuntime;
37 import com.sun.star.uno.XInterface;
38 
39 /**
40  * Test for object which is represented by service
41  * <code>com.sun.star.text.FieldMaster.Database</code>. <p>
42  * Object implements the following interfaces :
43  * <ul>
44  *  <li> <code>com::sun::star::text::TextFieldMaster</code></li>
45  *  <li> <code>com::sun::star::beans::XPropertySet</code></li>
46  * </ul> <p>
47  * This object test <b> is NOT </b> designed to be run in several
48  * threads concurently.
49  * @see com.sun.star.text.TextFieldMaster
50  * @see com.sun.star.text.FieldMaster.Database
51  * @see com.sun.star.beans.XPropertySet
52  * @see ifc.text._TextFieldMaster
53  * @see ifc.beans._XPropertySet
54  */
55 public class SwXFieldMaster extends TestCase {
56     XTextDocument xTextDoc;
57 
58     /**
59     * Creates text document.
60     */
initialize( TestParameters tParam, PrintWriter log )61     protected void initialize( TestParameters tParam, PrintWriter log ) {
62         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
63         try {
64             log.println( "creating a textdocument" );
65             xTextDoc = SOF.createTextDoc( null );
66         } catch ( com.sun.star.uno.Exception e ) {
67             e.printStackTrace( log );
68             throw new StatusException( "Couldn't create document", e );
69         }
70     }
71 
72     /**
73     * Disposes text document.
74     */
cleanup( TestParameters tParam, PrintWriter log )75     protected void cleanup( TestParameters tParam, PrintWriter log ) {
76         log.println( "    disposing xTextDoc " );
77         util.DesktopTools.closeDoc(xTextDoc);
78     }
79 
80 
81     /**
82     * Creating a Testenvironment for the interfaces to be tested.
83     * Creates an instance of the service
84     * <code>com.sun.star.text.FieldMaster.Database</code>.
85     */
createTestEnvironment( TestParameters tParam, PrintWriter log )86     public TestEnvironment createTestEnvironment(
87             TestParameters tParam, PrintWriter log ) throws StatusException {
88         XInterface oObj = null;
89 
90         log.println( "creating a test environment" );
91         try {
92             XMultiServiceFactory oDocMSF = (XMultiServiceFactory)
93                 UnoRuntime.queryInterface( XMultiServiceFactory.class, xTextDoc );
94             oObj = (XInterface)
95                 oDocMSF.createInstance( "com.sun.star.text.FieldMaster.Database" );
96         } catch ( com.sun.star.uno.Exception e ) {
97             log.println("Couldn't create instance");
98             e.printStackTrace(log);
99         }
100 
101         log.println( "creating a new environment for FieldMaster object" );
102         TestEnvironment tEnv = new TestEnvironment( oObj );
103         return tEnv;
104     } // finish method getTestEnvironment
105 
106 }    // finish class SwXFieldMaster
107 
108