1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package mod._fwk; 25 26 import com.sun.star.beans.XPropertySet; 27 import com.sun.star.lang.XMultiServiceFactory; 28 import com.sun.star.uno.UnoRuntime; 29 import com.sun.star.uno.XInterface; 30 import java.io.PrintWriter; 31 import com.sun.star.text.XTextDocument; 32 import com.sun.star.uno.XComponentContext; 33 import com.sun.star.util.XCloseable; 34 import com.sun.star.frame.XUIControllerRegistration; 35 import lib.StatusException; 36 import lib.TestCase; 37 import lib.TestEnvironment; 38 import lib.TestParameters; 39 import util.WriterTools; 40 41 /** 42 */ 43 public class PopupMenuControllerFactory extends TestCase { 44 XTextDocument xTextDoc; 45 46 /** 47 * Cleanup: close the created document 48 * @param tParam The test parameters. 49 * @param The log writer. 50 * @return The test environment. 51 */ 52 protected void cleanup(TestParameters tParam, PrintWriter log) { 53 log.println(" disposing xTextDoc "); 54 55 try { 56 XCloseable closer = (XCloseable) UnoRuntime.queryInterface( 57 XCloseable.class, xTextDoc); 58 closer.close(true); 59 } catch (com.sun.star.util.CloseVetoException e) { 60 log.println("couldn't close document"); 61 } catch (com.sun.star.lang.DisposedException e) { 62 log.println("couldn't close document"); 63 } 64 } 65 66 67 /** 68 * Create test environment: 69 * @param tParam The test parameters. 70 * @param The log writer. 71 * @return The test environment. 72 */ 73 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) { 74 TestEnvironment tEnv = null; 75 XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF(); 76 XInterface xInst = null; 77 78 log.println("Creating instance..."); 79 80 xTextDoc = WriterTools.createTextDoc(xMSF); 81 util.dbg.printInterfaces(xTextDoc); 82 83 try { 84 xInst = (XInterface)xMSF.createInstance( 85 "com.sun.star.comp.framework.PopupMenuControllerFactory"); 86 } 87 catch(com.sun.star.uno.Exception e) { 88 throw new StatusException("Couldn't create test object", e); 89 } 90 91 log.println("TestObject: " + util.utils.getImplName(xInst)); 92 tEnv = new TestEnvironment(xInst); 93 XPropertySet xProp = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xMSF); 94 try { 95 Object o = xProp.getPropertyValue("DefaultContext"); 96 XComponentContext xContext = (XComponentContext)UnoRuntime.queryInterface(XComponentContext.class, o); 97 tEnv.addObjRelation("DC", xContext); 98 } 99 catch(com.sun.star.beans.UnknownPropertyException e) { 100 log.println("Cannot get the 'DefaultContext' for XMultiComponentFactory test."); 101 e.printStackTrace(log); 102 } 103 catch(com.sun.star.lang.WrappedTargetException e) { 104 log.println("Cannot get the 'DefaultContext' for XMultiComponentFactory test."); 105 e.printStackTrace(log); 106 } 107 108 // register one controller, so it can be instantiated 109 XUIControllerRegistration xReg = (XUIControllerRegistration) 110 UnoRuntime.queryInterface(XUIControllerRegistration.class, xInst); 111 112 xReg.registerController(".uno:MyCommandUrl", "", "com.sun.star.comp.framework.FooterMenuController"); 113 tEnv.addObjRelation("XUIControllerRegistration.RegisteredController", ".uno:MyCommandUrl"); 114 tEnv.addObjRelation("XMultiComponentFactory.ServiceNames", new String[]{".uno:MyCommandUrl"}); 115 116 return tEnv; 117 } 118 } 119 120 121