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.beans.XPropertySet;
27 import com.sun.star.lang.XMultiServiceFactory;
28 import com.sun.star.uno.UnoRuntime;
29 import com.sun.star.uno.XInterface;
30 import java.io.PrintWriter;
31 import com.sun.star.text.XTextDocument;
32 import com.sun.star.uno.XComponentContext;
33 import com.sun.star.util.XCloseable;
34 import com.sun.star.frame.XUIControllerRegistration;
35 import lib.StatusException;
36 import lib.TestCase;
37 import lib.TestEnvironment;
38 import lib.TestParameters;
39 import util.WriterTools;
40 
41 /**
42  */
43 public class PopupMenuControllerFactory extends TestCase {
44     XTextDocument xTextDoc;
45 
46     /**
47      * Cleanup: close the created document
48      * @param tParam The test parameters.
49      * @param log The log writer.
50      */
cleanup(TestParameters tParam, PrintWriter log)51     protected void cleanup(TestParameters tParam, PrintWriter log) {
52         log.println("    disposing xTextDoc ");
53 
54         try {
55             XCloseable closer = (XCloseable) UnoRuntime.queryInterface(
56             XCloseable.class, xTextDoc);
57             closer.close(true);
58         } catch (com.sun.star.util.CloseVetoException e) {
59             log.println("couldn't close document");
60         } catch (com.sun.star.lang.DisposedException e) {
61             log.println("couldn't close document");
62         }
63     }
64 
65 
66     /**
67      * Create test environment:
68      * @param tParam The test parameters.
69      * @param log The log writer.
70      * @return The test environment.
71      */
createTestEnvironment(TestParameters tParam, PrintWriter log)72     protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
73         TestEnvironment tEnv = null;
74         XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF();
75         XInterface xInst = null;
76 
77         log.println("Creating instance...");
78 
79         xTextDoc = WriterTools.createTextDoc(xMSF);
80         util.dbg.printInterfaces(xTextDoc);
81 
82         try {
83             xInst = (XInterface)xMSF.createInstance(
84                             "com.sun.star.comp.framework.PopupMenuControllerFactory");
85         }
86         catch(com.sun.star.uno.Exception e) {
87             throw new StatusException("Couldn't create test object", e);
88         }
89 
90         log.println("TestObject: " + util.utils.getImplName(xInst));
91         tEnv = new TestEnvironment(xInst);
92         XPropertySet xProp = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xMSF);
93         try {
94             Object o = xProp.getPropertyValue("DefaultContext");
95             XComponentContext xContext = (XComponentContext)UnoRuntime.queryInterface(XComponentContext.class, o);
96             tEnv.addObjRelation("DC", xContext);
97         }
98         catch(com.sun.star.beans.UnknownPropertyException e) {
99             log.println("Cannot get the 'DefaultContext' for XMultiComponentFactory test.");
100             e.printStackTrace(log);
101         }
102         catch(com.sun.star.lang.WrappedTargetException e) {
103             log.println("Cannot get the 'DefaultContext' for XMultiComponentFactory test.");
104             e.printStackTrace(log);
105         }
106 
107         // register one controller, so it can be instantiated
108         XUIControllerRegistration xReg = (XUIControllerRegistration)
109                 UnoRuntime.queryInterface(XUIControllerRegistration.class, xInst);
110 
111         xReg.registerController(".uno:MyCommandUrl", "", "com.sun.star.comp.framework.FooterMenuController");
112         tEnv.addObjRelation("XUIControllerRegistration.RegisteredController", ".uno:MyCommandUrl");
113         tEnv.addObjRelation("XMultiComponentFactory.ServiceNames", new String[]{".uno:MyCommandUrl"});
114 
115         return tEnv;
116     }
117 }
118 
119 
120