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.lang.XMultiServiceFactory; 27 import com.sun.star.uno.UnoRuntime; 28 import com.sun.star.uno.XInterface; 29 import java.io.PrintWriter; 30 import com.sun.star.text.XTextDocument; 31 import com.sun.star.util.XCloseable; 32 import lib.StatusException; 33 import lib.TestCase; 34 import lib.TestEnvironment; 35 import lib.TestParameters; 36 import util.WriterTools; 37 38 /** 39 */ 40 public class UIElementFactoryManager extends TestCase { 41 Object oObj = null; 42 XTextDocument xTextDoc; 43 44 /** 45 * Cleanup: close the created document 46 * @param tParam The test parameters. 47 * @param The log writer. 48 * @return The test environment. 49 */ 50 protected void cleanup(TestParameters tParam, PrintWriter log) { 51 log.println(" disposing xTextDoc "); 52 53 try { 54 XCloseable closer = (XCloseable) UnoRuntime.queryInterface( 55 XCloseable.class, xTextDoc); 56 closer.close(true); 57 } catch (com.sun.star.util.CloseVetoException e) { 58 log.println("couldn't close document"); 59 } catch (com.sun.star.lang.DisposedException e) { 60 log.println("couldn't close document"); 61 } 62 } 63 64 /** 65 * Create test environment: 66 * <ul> 67 * <li>create a text doc</li> 68 * <li>get the model from the text doc</li> 69 * <li>query model for XUIConfigurationManagerSupplier interface</li> 70 * <li>get the manager from the supplier</li> 71 * </ul> 72 * @param tParam The test parameters. 73 * @param The log writer. 74 * @return The test environment. 75 */ 76 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) { 77 TestEnvironment tEnv = null; 78 XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF(); 79 80 log.println("Creating instance..."); 81 xTextDoc = WriterTools.createTextDoc(xMSF); 82 try { 83 oObj = xMSF.createInstance("com.sun.star.ui.UIElementFactoryManager"); 84 } 85 catch(com.sun.star.uno.Exception e) { 86 throw new StatusException("Cannot create test object.", e); 87 } 88 log.println("TestObject: " + util.utils.getImplName(oObj)); 89 90 tEnv = new TestEnvironment((XInterface)oObj); 91 92 93 return tEnv; 94 } 95 } 96 97 98