2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 import com
.sun
.star
.beans
.XPropertySet
;
22 import com
.sun
.star
.lang
.XMultiServiceFactory
;
23 import com
.sun
.star
.uno
.UnoRuntime
;
24 import com
.sun
.star
.uno
.XInterface
;
25 import java
.io
.PrintWriter
;
26 import com
.sun
.star
.text
.XTextDocument
;
27 import com
.sun
.star
.uno
.XComponentContext
;
28 import com
.sun
.star
.util
.XCloseable
;
29 import com
.sun
.star
.frame
.XUIControllerRegistration
;
30 import lib
.StatusException
;
32 import lib
.TestEnvironment
;
33 import lib
.TestParameters
;
34 import util
.WriterTools
;
38 public class PopupMenuControllerFactory
extends TestCase
{
39 XTextDocument xTextDoc
;
42 * Cleanup: close the created document
43 * @param tParam The test parameters.
44 * @param log The log writer.
47 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
48 log
.println(" disposing xTextDoc ");
51 XCloseable closer
= UnoRuntime
.queryInterface(
52 XCloseable
.class, xTextDoc
);
54 } catch (com
.sun
.star
.util
.CloseVetoException e
) {
55 log
.println("couldn't close document");
56 } catch (com
.sun
.star
.lang
.DisposedException e
) {
57 log
.println("couldn't close document");
63 * Create test environment:
64 * @param tParam The test parameters.
65 * @param log The log writer.
66 * @return The test environment.
69 protected TestEnvironment
createTestEnvironment(TestParameters tParam
, PrintWriter log
) {
70 TestEnvironment tEnv
= null;
71 XMultiServiceFactory xMSF
= tParam
.getMSF();
72 XInterface xInst
= null;
74 log
.println("Creating instance...");
76 xTextDoc
= WriterTools
.createTextDoc(xMSF
);
77 util
.dbg
.printInterfaces(xTextDoc
);
80 xInst
= (XInterface
)xMSF
.createInstance(
81 "com.sun.star.comp.framework.PopupMenuControllerFactory");
83 catch(com
.sun
.star
.uno
.Exception e
) {
84 throw new StatusException("Couldn't create test object", e
);
87 log
.println("TestObject: " + util
.utils
.getImplName(xInst
));
88 tEnv
= new TestEnvironment(xInst
);
89 XPropertySet xProp
= UnoRuntime
.queryInterface(XPropertySet
.class, xMSF
);
91 Object o
= xProp
.getPropertyValue("DefaultContext");
92 XComponentContext xContext
= UnoRuntime
.queryInterface(XComponentContext
.class, o
);
93 tEnv
.addObjRelation("DC", xContext
);
95 catch(com
.sun
.star
.beans
.UnknownPropertyException e
) {
96 log
.println("Cannot get the 'DefaultContext' for XMultiComponentFactory test.");
97 e
.printStackTrace(log
);
99 catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
100 log
.println("Cannot get the 'DefaultContext' for XMultiComponentFactory test.");
101 e
.printStackTrace(log
);
104 // register one controller, so it can be instantiated
105 XUIControllerRegistration xReg
= UnoRuntime
.queryInterface(XUIControllerRegistration
.class, xInst
);
107 xReg
.registerController(".uno:MyCommandUrl", "", "com.sun.star.comp.framework.FooterMenuController");
108 tEnv
.addObjRelation("XUIControllerRegistration.RegisteredController", ".uno:MyCommandUrl");
109 tEnv
.addObjRelation("XMultiComponentFactory.ServiceNames", new String
[]{".uno:MyCommandUrl"});