Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _fwk / PopupMenuControllerFactory.java
blob2e8ef4995377265d8b6bffe6de0e3362af48f48a
1 /*
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 .
19 package mod._fwk;
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;
31 import lib.TestCase;
32 import lib.TestEnvironment;
33 import lib.TestParameters;
34 import util.WriterTools;
36 /**
38 public class PopupMenuControllerFactory extends TestCase {
39 XTextDocument xTextDoc;
41 /**
42 * Cleanup: close the created document
43 * @param tParam The test parameters.
44 * @param log The log writer.
46 @Override
47 protected void cleanup(TestParameters tParam, PrintWriter log) {
48 log.println(" disposing xTextDoc ");
50 try {
51 XCloseable closer = UnoRuntime.queryInterface(
52 XCloseable.class, xTextDoc);
53 closer.close(true);
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");
62 /**
63 * Create test environment:
64 * @param tParam The test parameters.
65 * @param log The log writer.
66 * @return The test environment.
68 @Override
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);
79 try {
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);
90 try {
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"});
111 return tEnv;