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.text.XTextFieldsSupplier;
37 import com.sun.star.uno.UnoRuntime;
38 import com.sun.star.uno.XInterface;
39 
40 /**
41  *
42  * initial description
43  * @see com.sun.star.container.XContainer
44  * @see com.sun.star.container.XElementAccess
45  * @see com.sun.star.container.XEnumerationAccess
46  *
47  */
48 public class SwXTextFieldTypes extends TestCase {
49 
50     XTextDocument xTextDoc;
51 
52     /**
53      * in general this method creates a testdocument
54      *
55      *  @param tParam    class which contains additional test parameters
56      *  @param log        class to log the test state and result
57      *
58      *
59      *  @see TestParameters
60      *    @see PrintWriter
61      *
62      */
initialize( TestParameters tParam, PrintWriter log )63     protected void initialize( TestParameters tParam, PrintWriter log ) {
64         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
65 
66         try {
67             log.println( "creating a textdocument" );
68             xTextDoc = SOF.createTextDoc( null );
69         } catch ( com.sun.star.uno.Exception e ) {
70             // Some exception occures.FAILED
71             e.printStackTrace( log );
72             throw new StatusException( "Couldn't create document", e );
73         }
74     }
75 
76     /**
77      * in general this method disposes the testenvironment and document
78      *
79      *  @param tParam    class which contains additional test parameters
80      *  @param log        class to log the test state and result
81      *
82      *
83      *  @see TestParameters
84      *    @see PrintWriter
85      *
86      */
cleanup( TestParameters tParam, PrintWriter log )87     protected void cleanup( TestParameters tParam, PrintWriter log ) {
88         log.println( "    disposing xTextDoc " );
89         util.DesktopTools.closeDoc(xTextDoc);
90     }
91 
92 
93     /**
94      *    creating a Testenvironment for the interfaces to be tested
95      *
96      *  @param tParam    class which contains additional test parameters
97      *  @param log        class to log the test state and result
98      *
99      *  @return    Status class
100      *
101      *  @see TestParameters
102      *    @see PrintWriter
103      */
createTestEnvironment( TestParameters tParam, PrintWriter log )104     public TestEnvironment createTestEnvironment( TestParameters tParam,
105                                                   PrintWriter log )
106                                                     throws StatusException {
107 
108         XInterface oObj = null;
109 
110         // creation of testobject here
111         // first we write what we are intend to do to log file
112         log.println( "creating a test environment" );
113 
114 
115         // create testobject here
116         try {
117             XTextFieldsSupplier oTFS = (XTextFieldsSupplier)
118                 UnoRuntime.queryInterface( XTextFieldsSupplier.class, xTextDoc );
119 
120             oObj = oTFS.getTextFields();
121 
122         }
123         catch (Exception ex) {
124             log.println("Couldn't create instance");
125             ex.printStackTrace(log);
126         }
127 
128         log.println( "creating a new environment for FieldTypes object" );
129         TestEnvironment tEnv = new TestEnvironment( oObj );
130 
131 
132 
133         return tEnv;
134     } // finish method getTestEnvironment
135 }    // finish class SwXTextFieldTypes
136 
137