xref: /AOO41X/main/qadevOOo/tests/java/mod/_fwk/PopupMenuControllerFactory.java (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 package mod._fwk;
29 
30 import com.sun.star.beans.XPropertySet;
31 import com.sun.star.lang.XMultiServiceFactory;
32 import com.sun.star.uno.UnoRuntime;
33 import com.sun.star.uno.XInterface;
34 import java.io.PrintWriter;
35 import com.sun.star.text.XTextDocument;
36 import com.sun.star.uno.XComponentContext;
37 import com.sun.star.util.XCloseable;
38 import com.sun.star.frame.XUIControllerRegistration;
39 import lib.StatusException;
40 import lib.TestCase;
41 import lib.TestEnvironment;
42 import lib.TestParameters;
43 import util.WriterTools;
44 
45 /**
46  */
47 public class PopupMenuControllerFactory extends TestCase {
48     XTextDocument xTextDoc;
49 
50     /**
51      * Cleanup: close the created document
52      * @param tParam The test parameters.
53      * @param The log writer.
54      * @return The test environment.
55      */
56     protected void cleanup(TestParameters tParam, PrintWriter log) {
57         log.println("    disposing xTextDoc ");
58 
59         try {
60             XCloseable closer = (XCloseable) UnoRuntime.queryInterface(
61             XCloseable.class, xTextDoc);
62             closer.close(true);
63         } catch (com.sun.star.util.CloseVetoException e) {
64             log.println("couldn't close document");
65         } catch (com.sun.star.lang.DisposedException e) {
66             log.println("couldn't close document");
67         }
68     }
69 
70 
71     /**
72      * Create test environment:
73      * @param tParam The test parameters.
74      * @param The log writer.
75      * @return The test environment.
76      */
77     protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
78         TestEnvironment tEnv = null;
79         XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF();
80         XInterface xInst = null;
81 
82         log.println("Creating instance...");
83 
84         xTextDoc = WriterTools.createTextDoc(xMSF);
85         util.dbg.printInterfaces(xTextDoc);
86 
87         try {
88             xInst = (XInterface)xMSF.createInstance(
89                             "com.sun.star.comp.framework.PopupMenuControllerFactory");
90         }
91         catch(com.sun.star.uno.Exception e) {
92             throw new StatusException("Couldn't create test object", e);
93         }
94 
95         log.println("TestObject: " + util.utils.getImplName(xInst));
96         tEnv = new TestEnvironment(xInst);
97         XPropertySet xProp = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xMSF);
98         try {
99             Object o = xProp.getPropertyValue("DefaultContext");
100             XComponentContext xContext = (XComponentContext)UnoRuntime.queryInterface(XComponentContext.class, o);
101             tEnv.addObjRelation("DC", xContext);
102         }
103         catch(com.sun.star.beans.UnknownPropertyException e) {
104             log.println("Cannot get the 'DefaultContext' for XMultiComponentFactory test.");
105             e.printStackTrace(log);
106         }
107         catch(com.sun.star.lang.WrappedTargetException e) {
108             log.println("Cannot get the 'DefaultContext' for XMultiComponentFactory test.");
109             e.printStackTrace(log);
110         }
111 
112         // register one controller, so it can be instantiated
113         XUIControllerRegistration xReg = (XUIControllerRegistration)
114                 UnoRuntime.queryInterface(XUIControllerRegistration.class, xInst);
115 
116         xReg.registerController(".uno:MyCommandUrl", "", "com.sun.star.comp.framework.FooterMenuController");
117         tEnv.addObjRelation("XUIControllerRegistration.RegisteredController", ".uno:MyCommandUrl");
118         tEnv.addObjRelation("XMultiComponentFactory.ServiceNames", new String[]{".uno:MyCommandUrl"});
119 
120         return tEnv;
121     }
122 }
123 
124 
125