bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _fwk / PopupMenuControllerFactory.java
blobd985a0f6a73bd260fd59733be59b07224aaa5e78
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 protected void cleanup(TestParameters tParam, PrintWriter log) {
47 log.println(" disposing xTextDoc ");
49 try {
50 XCloseable closer = UnoRuntime.queryInterface(
51 XCloseable.class, xTextDoc);
52 closer.close(true);
53 } catch (com.sun.star.util.CloseVetoException e) {
54 log.println("couldn't close document");
55 } catch (com.sun.star.lang.DisposedException e) {
56 log.println("couldn't close document");
61 /**
62 * Create test environment:
63 * @param tParam The test parameters.
64 * @param log The log writer.
65 * @return The test environment.
67 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
68 TestEnvironment tEnv = null;
69 XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF();
70 XInterface xInst = null;
72 log.println("Creating instance...");
74 xTextDoc = WriterTools.createTextDoc(xMSF);
75 util.dbg.printInterfaces(xTextDoc);
77 try {
78 xInst = (XInterface)xMSF.createInstance(
79 "com.sun.star.comp.framework.PopupMenuControllerFactory");
81 catch(com.sun.star.uno.Exception e) {
82 throw new StatusException("Couldn't create test object", e);
85 log.println("TestObject: " + util.utils.getImplName(xInst));
86 tEnv = new TestEnvironment(xInst);
87 XPropertySet xProp = UnoRuntime.queryInterface(XPropertySet.class, xMSF);
88 try {
89 Object o = xProp.getPropertyValue("DefaultContext");
90 XComponentContext xContext = UnoRuntime.queryInterface(XComponentContext.class, o);
91 tEnv.addObjRelation("DC", xContext);
93 catch(com.sun.star.beans.UnknownPropertyException e) {
94 log.println("Cannot get the 'DefaultContext' for XMultiComponentFactory test.");
95 e.printStackTrace(log);
97 catch(com.sun.star.lang.WrappedTargetException e) {
98 log.println("Cannot get the 'DefaultContext' for XMultiComponentFactory test.");
99 e.printStackTrace(log);
102 // register one controller, so it can be instantiated
103 XUIControllerRegistration xReg = UnoRuntime.queryInterface(XUIControllerRegistration.class, xInst);
105 xReg.registerController(".uno:MyCommandUrl", "", "com.sun.star.comp.framework.FooterMenuController");
106 tEnv.addObjRelation("XUIControllerRegistration.RegisteredController", ".uno:MyCommandUrl");
107 tEnv.addObjRelation("XMultiComponentFactory.ServiceNames", new String[]{".uno:MyCommandUrl"});
109 return tEnv;