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
.XFrame
;
24 import com
.sun
.star
.frame
.XFrames
;
25 import com
.sun
.star
.frame
.XFramesSupplier
;
26 import com
.sun
.star
.inspection
.XObjectInspector
;
27 import com
.sun
.star
.inspection
.XObjectInspectorModel
;
28 import com
.sun
.star
.lang
.XInitialization
;
29 import com
.sun
.star
.uno
.UnoRuntime
;
30 import com
.sun
.star
.util
.CloseVetoException
;
31 import com
.sun
.star
.util
.XCloseable
;
32 import helper
.PropertyHandlerImpl
;
33 import java
.io
.PrintWriter
;
35 import lib
.StatusException
;
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 concurently.
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 Object StarDesktop
= null;
69 * assign to the module variable <CODE>StarDesktop</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
) {
78 log
.println("create a desktop...");
79 StarDesktop
= DesktopTools
.createDesktop(Param
.getMSF());
80 if (StarDesktop
== null){
81 throw new StatusException("Could not get a Desktop: null", null);
86 * Creating a Testenvironment for the interfaces to be tested.
87 * Creates an instance of the service
88 * <code>com.sun.star.inspection.ObjectInspector</code> and adds it to
89 * a floating frame.<br>
90 * To test <CODE>com.sun.star.inspection.XObjectInspector.inspect()</CODE>
91 * an own implementation of
92 * <CODE>com.sun.star.inspection.XPropertyHandler</CODE> was used.
93 * @param tParam the tests parameter
94 * @param log the logger
95 * @return the test environement
96 * @see util.DesktopTools
97 * @see helper.PropertyHandlerImpl
100 protected TestEnvironment
createTestEnvironment(TestParameters tParam
, PrintWriter log
) {
102 this.cleanup(tParam
, log
);
104 XMultiServiceFactory xMSF
= tParam
.getMSF();
107 XInterface oInspector
= (XInterface
) xMSF
.createInstance("com.sun.star.inspection.ObjectInspector");
109 XObjectInspector xInspector
= UnoRuntime
.queryInterface(XObjectInspector
.class, oInspector
);
111 log
.println("ImplementationName '" + utils
.getImplName(xInspector
) + "'");
113 XInterface oInspectorModel
= (XInterface
) xMSF
.createInstance("com.sun.star.inspection.ObjectInspectorModel");
115 XObjectInspectorModel xInspectorModel
= UnoRuntime
.queryInterface(XObjectInspectorModel
.class, oInspectorModel
);
117 XInterface oInspectorModelToSet
= (XInterface
) xMSF
.createInstance("com.sun.star.inspection.ObjectInspectorModel");
119 XObjectInspectorModel xInspectorModelToSet
= UnoRuntime
.queryInterface(XObjectInspectorModel
.class, oInspectorModelToSet
);
122 log
.println("create a floating frame...");
124 XWindow xWindow
= null;
127 XWindowPeer xWindowPeer
= DesktopTools
.createFloatingWindow(xMSF
);
129 xWindow
= UnoRuntime
.queryInterface(XWindow
.class, xWindowPeer
);
131 } catch (StatusException e
){
132 throw new StatusException("Coud not create test object", e
);
135 XInterface oFrame
= (XInterface
) xMSF
.createInstance("com.sun.star.frame.Frame");
137 XFrame xFrame
= UnoRuntime
.queryInterface(XFrame
.class, oFrame
);
139 xFrame
.setName("ObjectInspector");
140 xFrame
.initialize(xWindow
);
142 XFramesSupplier xFramesSup
= UnoRuntime
.queryInterface(XFramesSupplier
.class, StarDesktop
);
144 XFrames xFrames
= xFramesSup
.getFrames();
145 xFrames
.append(xFrame
);
148 log
.println("attach ObjectInspector to floating frame...");
150 XInitialization xOII
= UnoRuntime
.queryInterface(XInitialization
.class, xInspectorModel
);
152 xOII
.initialize(new Object
[0]);
154 xInspector
.setInspectorModel(xInspectorModel
);
156 // for debug purposes the following lines could commented out. But in
157 // this case the com.sun.star.frame.XController would be failed!
158 //xInspector.attachFrame(xFrame);
159 //xWindow.setVisible(true);
161 Object
[] oInspect
= new Object
[1];
162 oInspect
[0] = new PropertyHandlerImpl();
164 TestEnvironment tEnv
= new TestEnvironment(xInspector
);
166 // com.sun.star.frame.XController
167 tEnv
.addObjRelation("Frame",xFrame
);
169 tEnv
.addObjRelation("XObjectInspector.toInspect", oInspect
);
171 tEnv
.addObjRelation("XObjectInspector.InspectorModelToSet", xInspectorModelToSet
);
174 } catch (com
.sun
.star
.uno
.Exception e
) {
175 e
.printStackTrace(log
);
176 throw new StatusException("Unexpected exception", e
);
182 * Closes the ObjectOnspector using <CODE>XCloseable</CODE>
183 * @see com.sun.star.util.XCloseable
184 * @param Param the test parameter
185 * @param log the logger
188 protected void cleanup(TestParameters Param
, PrintWriter log
) {
189 log
.println(" Closing dialog if one exists ... ");
191 XFrame existentInspector
= null;
193 XFrame xFrame
= UnoRuntime
.queryInterface(XFrame
.class, StarDesktop
);
195 existentInspector
= xFrame
.findFrame( "ObjectInspector", 255 );
197 if ( existentInspector
!= null ){
198 XCloseable closer
= UnoRuntime
.queryInterface(
199 XCloseable
.class, existentInspector
);
202 } catch (CloseVetoException e
){
203 log
.println("Could not close inspector: " + e
.toString());