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._fwk;
25 
26 import com.sun.star.lang.XMultiServiceFactory;
27 import com.sun.star.uno.UnoRuntime;
28 import com.sun.star.uno.XInterface;
29 import java.io.PrintWriter;
30 import com.sun.star.text.XTextDocument;
31 import com.sun.star.util.XCloseable;
32 import lib.StatusException;
33 import lib.TestCase;
34 import lib.TestEnvironment;
35 import lib.TestParameters;
36 import util.WriterTools;
37 
38 /**
39  */
40 public class UIElementFactoryManager extends TestCase {
41     Object oObj = null;
42     XTextDocument xTextDoc;
43 
44     /**
45      * Cleanup: close the created document
46      * @param tParam The test parameters.
47      * @param log The log writer.
48      */
cleanup(TestParameters tParam, PrintWriter log)49     protected void cleanup(TestParameters tParam, PrintWriter log) {
50         log.println("    disposing xTextDoc ");
51 
52         try {
53             XCloseable closer = (XCloseable) UnoRuntime.queryInterface(
54             XCloseable.class, xTextDoc);
55             closer.close(true);
56         } catch (com.sun.star.util.CloseVetoException e) {
57             log.println("couldn't close document");
58         } catch (com.sun.star.lang.DisposedException e) {
59             log.println("couldn't close document");
60         }
61     }
62 
63     /**
64      * Create test environment:
65      * <ul>
66      * <li>create a text doc</li>
67      * <li>get the model from the text doc</li>
68      * <li>query model for XUIConfigurationManagerSupplier interface</li>
69      * <li>get the manager from the supplier</li>
70      * </ul>
71      * @param tParam The test parameters.
72      * @param log The log writer.
73      * @return The test environment.
74      */
createTestEnvironment(TestParameters tParam, PrintWriter log)75     protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
76         TestEnvironment tEnv = null;
77         XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF();
78 
79         log.println("Creating instance...");
80         xTextDoc = WriterTools.createTextDoc(xMSF);
81         try {
82             oObj = xMSF.createInstance("com.sun.star.ui.UIElementFactoryManager");
83         }
84         catch(com.sun.star.uno.Exception e) {
85             throw new StatusException("Cannot create test object.", e);
86         }
87         log.println("TestObject: " + util.utils.getImplName(oObj));
88 
89         tEnv = new TestEnvironment((XInterface)oObj);
90 
91 
92         return tEnv;
93     }
94 }
95 
96 
97