1*ef39d40dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*ef39d40dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*ef39d40dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*ef39d40dSAndrew Rist * distributed with this work for additional information 6*ef39d40dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*ef39d40dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*ef39d40dSAndrew Rist * "License"); you may not use this file except in compliance 9*ef39d40dSAndrew Rist * with the License. You may obtain a copy of the License at 10*ef39d40dSAndrew Rist * 11*ef39d40dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*ef39d40dSAndrew Rist * 13*ef39d40dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*ef39d40dSAndrew Rist * software distributed under the License is distributed on an 15*ef39d40dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*ef39d40dSAndrew Rist * KIND, either express or implied. See the License for the 17*ef39d40dSAndrew Rist * specific language governing permissions and limitations 18*ef39d40dSAndrew Rist * under the License. 19*ef39d40dSAndrew Rist * 20*ef39d40dSAndrew Rist *************************************************************/ 21*ef39d40dSAndrew Rist 22*ef39d40dSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir package mod._pcr; 25cdf0e10cSrcweir 26cdf0e10cSrcweir import com.sun.star.awt.XWindow; 27cdf0e10cSrcweir import com.sun.star.awt.XWindowPeer; 28cdf0e10cSrcweir import com.sun.star.frame.XFrame; 29cdf0e10cSrcweir import com.sun.star.frame.XFrames; 30cdf0e10cSrcweir import com.sun.star.frame.XFramesSupplier; 31cdf0e10cSrcweir import com.sun.star.inspection.XObjectInspector; 32cdf0e10cSrcweir import com.sun.star.inspection.XObjectInspectorModel; 33cdf0e10cSrcweir import com.sun.star.lang.XInitialization; 34cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 35cdf0e10cSrcweir import com.sun.star.util.CloseVetoException; 36cdf0e10cSrcweir import com.sun.star.util.XCloseable; 37cdf0e10cSrcweir import helper.PropertyHandlerImpl; 38cdf0e10cSrcweir import java.io.PrintWriter; 39cdf0e10cSrcweir 40cdf0e10cSrcweir import lib.StatusException; 41cdf0e10cSrcweir import lib.TestCase; 42cdf0e10cSrcweir import lib.TestEnvironment; 43cdf0e10cSrcweir import lib.TestParameters; 44cdf0e10cSrcweir 45cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 46cdf0e10cSrcweir import com.sun.star.uno.XInterface; 47cdf0e10cSrcweir import util.DesktopTools; 48cdf0e10cSrcweir import util.utils; 49cdf0e10cSrcweir 50cdf0e10cSrcweir /** 51cdf0e10cSrcweir * Test for object which is represented by service 52cdf0e10cSrcweir * <code>com.sun.star.reflection.ObjectInspector</code>. <p> 53cdf0e10cSrcweir * Object implements the following interfaces : 54cdf0e10cSrcweir * <ul> 55cdf0e10cSrcweir * <li> <code>com::sun::star::lang::XComponent</code></li> 56cdf0e10cSrcweir * <li> <code>com::sun::star::inspection::XObjectInspector</code></li> 57cdf0e10cSrcweir * <li> <code>com::sun::star::frame::XController</code></li> 58cdf0e10cSrcweir * </ul> 59cdf0e10cSrcweir * This object test <b> is NOT </b> designed to be run in several 60cdf0e10cSrcweir * threads concurently. 61cdf0e10cSrcweir * @see com.sun.star.lang.XComponent 62cdf0e10cSrcweir * @see com.sun.star.inspection.XObjectInspector 63cdf0e10cSrcweir * @see com.sun.star.frame.XController 64cdf0e10cSrcweir */ 65cdf0e10cSrcweir public class ObjectInspector extends TestCase { 66cdf0e10cSrcweir 67cdf0e10cSrcweir /** 68cdf0e10cSrcweir * module variable which holds the Desktop 69cdf0e10cSrcweir * @see com.sun.star.frame.Desktop 70cdf0e10cSrcweir */ 71cdf0e10cSrcweir protected static Object StarDesktop = null; 72cdf0e10cSrcweir 73cdf0e10cSrcweir /** 74cdf0e10cSrcweir * assign to the module variable <CODE>StarDesktop</CODE> the desktop 75cdf0e10cSrcweir * @param Param the test parameters 76cdf0e10cSrcweir * @param log the log writer 77cdf0e10cSrcweir * @see lib.TestParameters 78cdf0e10cSrcweir * @see share.LogWriter 79cdf0e10cSrcweir * @see com.sun.star.frame.Desktop 80cdf0e10cSrcweir */ initialize(TestParameters Param, PrintWriter log)81cdf0e10cSrcweir protected void initialize(TestParameters Param, PrintWriter log) { 82cdf0e10cSrcweir log.println("create a desktop..."); 83cdf0e10cSrcweir StarDesktop = DesktopTools.createDesktop((XMultiServiceFactory) Param.getMSF()); 84cdf0e10cSrcweir if (StarDesktop == null){ 85cdf0e10cSrcweir throw new StatusException("Could not get a Desktop: null", null); 86cdf0e10cSrcweir } 87cdf0e10cSrcweir } 88cdf0e10cSrcweir 89cdf0e10cSrcweir /** 90cdf0e10cSrcweir * Creating a Testenvironment for the interfaces to be tested. 91cdf0e10cSrcweir * Creates an instance of the service 92cdf0e10cSrcweir * <code>com.sun.star.inspection.ObjectInspector</code> and adds it to 93cdf0e10cSrcweir * a floating frame.<br> 94cdf0e10cSrcweir * To test <CODE>com.sun.star.inspection.XObjectInspector.inspect()</CODE> 95cdf0e10cSrcweir * an own implementation of 96cdf0e10cSrcweir * <CODE>com.sun.star.inspection.XPropertyHandler</CODE> was used. 97cdf0e10cSrcweir * @param tParam the tests parameter 98cdf0e10cSrcweir * @param log the logger 99cdf0e10cSrcweir * @return the test environement 100cdf0e10cSrcweir * @see util.DesktopTools 101cdf0e10cSrcweir * @see helper.PropertyHandlerImpl 102cdf0e10cSrcweir */ createTestEnvironment(TestParameters tParam, PrintWriter log)103cdf0e10cSrcweir protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) { 104cdf0e10cSrcweir 105cdf0e10cSrcweir this.cleanup(tParam, log); 106cdf0e10cSrcweir 107cdf0e10cSrcweir XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF(); 108cdf0e10cSrcweir 109cdf0e10cSrcweir try { 110cdf0e10cSrcweir XInterface oInspector = (XInterface) xMSF.createInstance("com.sun.star.inspection.ObjectInspector"); 111cdf0e10cSrcweir 112cdf0e10cSrcweir XObjectInspector xInspector = (XObjectInspector) UnoRuntime.queryInterface(XObjectInspector.class, oInspector); 113cdf0e10cSrcweir 114cdf0e10cSrcweir log.println("ImplementationName '" + utils.getImplName(xInspector) + "'"); 115cdf0e10cSrcweir 116cdf0e10cSrcweir XInterface oInspectorModel = (XInterface) xMSF.createInstance("com.sun.star.inspection.ObjectInspectorModel"); 117cdf0e10cSrcweir 118cdf0e10cSrcweir XObjectInspectorModel xInspectorModel = (XObjectInspectorModel) 119cdf0e10cSrcweir UnoRuntime.queryInterface(XObjectInspectorModel.class, oInspectorModel); 120cdf0e10cSrcweir 121cdf0e10cSrcweir XInterface oInspectorModelToSet = (XInterface) xMSF.createInstance("com.sun.star.inspection.ObjectInspectorModel"); 122cdf0e10cSrcweir 123cdf0e10cSrcweir XObjectInspectorModel xInspectorModelToSet = (XObjectInspectorModel) 124cdf0e10cSrcweir UnoRuntime.queryInterface(XObjectInspectorModel.class, oInspectorModelToSet); 125cdf0e10cSrcweir 126cdf0e10cSrcweir 127cdf0e10cSrcweir log.println("create a floating frame..."); 128cdf0e10cSrcweir 129cdf0e10cSrcweir XWindow xWindow = null; 130cdf0e10cSrcweir try{ 131cdf0e10cSrcweir 132cdf0e10cSrcweir XWindowPeer xWindowPeer = DesktopTools.createFloatingWindow(xMSF); 133cdf0e10cSrcweir 134cdf0e10cSrcweir xWindow = (XWindow) UnoRuntime.queryInterface(XWindow.class, xWindowPeer); 135cdf0e10cSrcweir 136cdf0e10cSrcweir } catch (StatusException e){ 137cdf0e10cSrcweir throw new StatusException("Coud not create test object", e); 138cdf0e10cSrcweir } 139cdf0e10cSrcweir 140cdf0e10cSrcweir XInterface oFrame = (XInterface) xMSF.createInstance("com.sun.star.frame.Frame"); 141cdf0e10cSrcweir 142cdf0e10cSrcweir XFrame xFrame = (XFrame) UnoRuntime.queryInterface(XFrame.class, oFrame); 143cdf0e10cSrcweir 144cdf0e10cSrcweir xFrame.setName("ObjectInspector"); 145cdf0e10cSrcweir xFrame.initialize(xWindow); 146cdf0e10cSrcweir 147cdf0e10cSrcweir XFramesSupplier xFramesSup = (XFramesSupplier) UnoRuntime.queryInterface(XFramesSupplier.class, StarDesktop); 148cdf0e10cSrcweir 149cdf0e10cSrcweir XFrames xFrames = xFramesSup.getFrames(); 150cdf0e10cSrcweir xFrames.append(xFrame); 151cdf0e10cSrcweir 152cdf0e10cSrcweir 153cdf0e10cSrcweir log.println("attach ObjectInspector to floating frame..."); 154cdf0e10cSrcweir 155cdf0e10cSrcweir XInitialization xOII = (XInitialization) UnoRuntime.queryInterface(XInitialization.class, xInspectorModel); 156cdf0e10cSrcweir 157cdf0e10cSrcweir xOII.initialize(new Object[0]); 158cdf0e10cSrcweir 159cdf0e10cSrcweir xInspector.setInspectorModel(xInspectorModel); 160cdf0e10cSrcweir 161cdf0e10cSrcweir // for debug purposes the following lines could commented out. But in 162cdf0e10cSrcweir // this case the com.sun.star.frame.XController would be failed! 163cdf0e10cSrcweir //xInspector.attachFrame(xFrame); 164cdf0e10cSrcweir //xWindow.setVisible(true); 165cdf0e10cSrcweir 166cdf0e10cSrcweir Object[] oInspect = new Object[1]; 167cdf0e10cSrcweir oInspect[0] = new PropertyHandlerImpl(); 168cdf0e10cSrcweir 169cdf0e10cSrcweir TestEnvironment tEnv = new TestEnvironment(xInspector); 170cdf0e10cSrcweir 171cdf0e10cSrcweir // com.sun.star.frame.XController 172cdf0e10cSrcweir tEnv.addObjRelation("Frame",xFrame); 173cdf0e10cSrcweir 174cdf0e10cSrcweir tEnv.addObjRelation("XObjectInspector.toInspect", oInspect); 175cdf0e10cSrcweir 176cdf0e10cSrcweir tEnv.addObjRelation("XObjectInspector.InspectorModelToSet", xInspectorModelToSet); 177cdf0e10cSrcweir 178cdf0e10cSrcweir return tEnv; 179cdf0e10cSrcweir } catch (com.sun.star.uno.Exception e) { 180cdf0e10cSrcweir e.printStackTrace(log); 181cdf0e10cSrcweir throw new StatusException("Unexpected exception", e); 182cdf0e10cSrcweir } 183cdf0e10cSrcweir 184cdf0e10cSrcweir } 185cdf0e10cSrcweir 186cdf0e10cSrcweir /** 187cdf0e10cSrcweir * Closes the ObjectOnspector using <CODE>XCloseable</CODE> 188cdf0e10cSrcweir * @see com.sun.star.util.XCloseable 189cdf0e10cSrcweir * @param Param the test parameter 190cdf0e10cSrcweir * @param log the logger 191cdf0e10cSrcweir */ cleanup(TestParameters Param, PrintWriter log)192cdf0e10cSrcweir protected void cleanup(TestParameters Param, PrintWriter log) { 193cdf0e10cSrcweir log.println(" Closing dialog if one exists ... "); 194cdf0e10cSrcweir 195cdf0e10cSrcweir XFrame existentInspector = null; 196cdf0e10cSrcweir 197cdf0e10cSrcweir XFrame xFrame = (XFrame) UnoRuntime.queryInterface(XFrame.class, StarDesktop); 198cdf0e10cSrcweir 199cdf0e10cSrcweir existentInspector = xFrame.findFrame( "ObjectInspector", 255 ); 200cdf0e10cSrcweir 201cdf0e10cSrcweir if ( existentInspector != null ){ 202cdf0e10cSrcweir XCloseable closer = (XCloseable) UnoRuntime.queryInterface( 203cdf0e10cSrcweir XCloseable.class, existentInspector); 204cdf0e10cSrcweir try{ 205cdf0e10cSrcweir closer.close(true); 206cdf0e10cSrcweir } catch (CloseVetoException e){ 207cdf0e10cSrcweir log.println("Could not close inspector: " + e.toString()); 208cdf0e10cSrcweir } 209cdf0e10cSrcweir } 210cdf0e10cSrcweir } 211cdf0e10cSrcweir } 212