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