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 .
21 import com
.sun
.star
.awt
.XWindow
;
22 import com
.sun
.star
.awt
.XWindowPeer
;
23 import com
.sun
.star
.frame
.XDesktop
;
24 import com
.sun
.star
.frame
.XFrame
;
25 import com
.sun
.star
.frame
.XFrames
;
26 import com
.sun
.star
.frame
.XFramesSupplier
;
27 import com
.sun
.star
.inspection
.XObjectInspector
;
28 import com
.sun
.star
.inspection
.XObjectInspectorModel
;
29 import com
.sun
.star
.lang
.XInitialization
;
30 import com
.sun
.star
.uno
.UnoRuntime
;
31 import com
.sun
.star
.util
.CloseVetoException
;
32 import com
.sun
.star
.util
.XCloseable
;
33 import helper
.PropertyHandlerImpl
;
34 import java
.io
.PrintWriter
;
37 import lib
.TestEnvironment
;
38 import lib
.TestParameters
;
40 import com
.sun
.star
.lang
.XMultiServiceFactory
;
41 import com
.sun
.star
.uno
.XInterface
;
42 import util
.DesktopTools
;
46 * Test for object which is represented by service
47 * <code>com.sun.star.reflection.ObjectInspector</code>. <p>
48 * Object implements the following interfaces :
50 * <li> <code>com::sun::star::lang::XComponent</code></li>
51 * <li> <code>com::sun::star::inspection::XObjectInspector</code></li>
52 * <li> <code>com::sun::star::frame::XController</code></li>
54 * This object test <b> is NOT </b> designed to be run in several
55 * threads concurrently.
56 * @see com.sun.star.lang.XComponent
57 * @see com.sun.star.inspection.XObjectInspector
58 * @see com.sun.star.frame.XController
60 public class ObjectInspector
extends TestCase
{
63 * module variable which holds the Desktop
64 * @see com.sun.star.frame.Desktop
66 protected static XDesktop xDesktop
= null;
69 * assign to the module variable <CODE>xDesktop</CODE> the desktop
70 * @param Param the test parameters
71 * @param log the log writer
72 * @see lib.TestParameters
73 * @see share.LogWriter
74 * @see com.sun.star.frame.Desktop
77 protected void initialize(TestParameters Param
, PrintWriter log
) throws Exception
{
78 log
.println("create a desktop...");
79 xDesktop
= DesktopTools
.createDesktop(Param
.getMSF());
83 * Creating a TestEnvironment for the interfaces to be tested.
84 * Creates an instance of the service
85 * <code>com.sun.star.inspection.ObjectInspector</code> and adds it to
86 * a floating frame.<br>
87 * To test <CODE>com.sun.star.inspection.XObjectInspector.inspect()</CODE>
88 * an own implementation of
89 * <CODE>com.sun.star.inspection.XPropertyHandler</CODE> was used.
90 * @param tParam the tests parameter
91 * @param log the logger
92 * @return the test environment
93 * @see util.DesktopTools
94 * @see helper.PropertyHandlerImpl
97 protected TestEnvironment
createTestEnvironment(TestParameters tParam
, PrintWriter log
) throws Exception
{
99 this.cleanup(tParam
, log
);
101 XMultiServiceFactory xMSF
= tParam
.getMSF();
103 XInterface oInspector
= (XInterface
) xMSF
.createInstance("com.sun.star.inspection.ObjectInspector");
105 XObjectInspector xInspector
= UnoRuntime
.queryInterface(XObjectInspector
.class, oInspector
);
107 log
.println("ImplementationName '" + utils
.getImplName(xInspector
) + "'");
109 XInterface oInspectorModel
= (XInterface
) xMSF
.createInstance("com.sun.star.inspection.ObjectInspectorModel");
111 XObjectInspectorModel xInspectorModel
= UnoRuntime
.queryInterface(XObjectInspectorModel
.class, oInspectorModel
);
113 XInterface oInspectorModelToSet
= (XInterface
) xMSF
.createInstance("com.sun.star.inspection.ObjectInspectorModel");
115 XObjectInspectorModel xInspectorModelToSet
= UnoRuntime
.queryInterface(XObjectInspectorModel
.class, oInspectorModelToSet
);
118 log
.println("create a floating frame...");
120 XWindowPeer xWindowPeer
= DesktopTools
.createFloatingWindow(xMSF
);
122 XWindow xWindow
= UnoRuntime
.queryInterface(XWindow
.class, xWindowPeer
);
124 XInterface oFrame
= (XInterface
) xMSF
.createInstance("com.sun.star.frame.Frame");
126 XFrame xFrame
= UnoRuntime
.queryInterface(XFrame
.class, oFrame
);
128 xFrame
.setName("ObjectInspector");
129 xFrame
.initialize(xWindow
);
131 XFramesSupplier xFramesSup
= UnoRuntime
.queryInterface(XFramesSupplier
.class, xDesktop
);
133 XFrames xFrames
= xFramesSup
.getFrames();
134 xFrames
.append(xFrame
);
137 log
.println("attach ObjectInspector to floating frame...");
139 XInitialization xOII
= UnoRuntime
.queryInterface(XInitialization
.class, xInspectorModel
);
141 xOII
.initialize(new Object
[0]);
143 xInspector
.setInspectorModel(xInspectorModel
);
145 // for debug purposes the following lines could commented out. But in
146 // this case the com.sun.star.frame.XController would be failed!
147 //xInspector.attachFrame(xFrame);
148 //xWindow.setVisible(true);
150 Object
[] oInspect
= new Object
[1];
151 oInspect
[0] = new PropertyHandlerImpl();
153 TestEnvironment tEnv
= new TestEnvironment(xInspector
);
155 // com.sun.star.frame.XController
156 tEnv
.addObjRelation("Frame",xFrame
);
158 tEnv
.addObjRelation("XObjectInspector.toInspect", oInspect
);
160 tEnv
.addObjRelation("XObjectInspector.InspectorModelToSet", xInspectorModelToSet
);
166 * Closes the ObjectOnspector using <CODE>XCloseable</CODE>
167 * @see com.sun.star.util.XCloseable
168 * @param Param the test parameter
169 * @param log the logger
172 protected void cleanup(TestParameters Param
, PrintWriter log
) {
173 log
.println(" Closing dialog if one exists ... ");
175 XFrame existentInspector
= null;
177 XFrame xFrame
= UnoRuntime
.queryInterface(XFrame
.class, xDesktop
);
179 existentInspector
= xFrame
.findFrame( "ObjectInspector", 255 );
181 if ( existentInspector
!= null ){
182 XCloseable closer
= UnoRuntime
.queryInterface(
183 XCloseable
.class, existentInspector
);
186 } catch (CloseVetoException e
){
187 log
.println("Could not close inspector: " + e
.toString());