bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _pcr / ObjectInspector.java
blob9717505efffea0315cc4500ed10ae45695c45d0d
1 /*
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 .
19 package mod._pcr;
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;
36 import lib.TestCase;
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;
43 import util.utils;
45 /**
46 * Test for object which is represented by service
47 * <code>com.sun.star.reflection.ObjectInspector</code>. <p>
48 * Object implements the following interfaces :
49 * <ul>
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>
53 * </ul>
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 {
62 /**
63 * module variable which holds the Desktop
64 * @see com.sun.star.frame.Desktop
66 protected static Object StarDesktop = null;
68 /**
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
76 protected void initialize(TestParameters Param, PrintWriter log) {
77 log.println("create a desktop...");
78 StarDesktop = DesktopTools.createDesktop((XMultiServiceFactory) Param.getMSF());
79 if (StarDesktop == null){
80 throw new StatusException("Could not get a Desktop: null", null);
84 /**
85 * Creating a Testenvironment for the interfaces to be tested.
86 * Creates an instance of the service
87 * <code>com.sun.star.inspection.ObjectInspector</code> and adds it to
88 * a floating frame.<br>
89 * To test <CODE>com.sun.star.inspection.XObjectInspector.inspect()</CODE>
90 * an own implementation of
91 * <CODE>com.sun.star.inspection.XPropertyHandler</CODE> was used.
92 * @param tParam the tests parameter
93 * @param log the logger
94 * @return the test environement
95 * @see util.DesktopTools
96 * @see helper.PropertyHandlerImpl
98 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
100 this.cleanup(tParam, log);
102 XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF();
104 try {
105 XInterface oInspector = (XInterface) xMSF.createInstance("com.sun.star.inspection.ObjectInspector");
107 XObjectInspector xInspector = UnoRuntime.queryInterface(XObjectInspector.class, oInspector);
109 log.println("ImplementationName '" + utils.getImplName(xInspector) + "'");
111 XInterface oInspectorModel = (XInterface) xMSF.createInstance("com.sun.star.inspection.ObjectInspectorModel");
113 XObjectInspectorModel xInspectorModel = UnoRuntime.queryInterface(XObjectInspectorModel.class, oInspectorModel);
115 XInterface oInspectorModelToSet = (XInterface) xMSF.createInstance("com.sun.star.inspection.ObjectInspectorModel");
117 XObjectInspectorModel xInspectorModelToSet = UnoRuntime.queryInterface(XObjectInspectorModel.class, oInspectorModelToSet);
120 log.println("create a floating frame...");
122 XWindow xWindow = null;
123 try{
125 XWindowPeer xWindowPeer = DesktopTools.createFloatingWindow(xMSF);
127 xWindow = UnoRuntime.queryInterface(XWindow.class, xWindowPeer);
129 } catch (StatusException e){
130 throw new StatusException("Coud not create test object", e);
133 XInterface oFrame = (XInterface) xMSF.createInstance("com.sun.star.frame.Frame");
135 XFrame xFrame = UnoRuntime.queryInterface(XFrame.class, oFrame);
137 xFrame.setName("ObjectInspector");
138 xFrame.initialize(xWindow);
140 XFramesSupplier xFramesSup = UnoRuntime.queryInterface(XFramesSupplier.class, StarDesktop);
142 XFrames xFrames = xFramesSup.getFrames();
143 xFrames.append(xFrame);
146 log.println("attach ObjectInspector to floating frame...");
148 XInitialization xOII = UnoRuntime.queryInterface(XInitialization.class, xInspectorModel);
150 xOII.initialize(new Object[0]);
152 xInspector.setInspectorModel(xInspectorModel);
154 // for debug purposes the following lines could commented out. But in
155 // this case the com.sun.star.frame.XController would be failed!
156 //xInspector.attachFrame(xFrame);
157 //xWindow.setVisible(true);
159 Object[] oInspect = new Object[1];
160 oInspect[0] = new PropertyHandlerImpl();
162 TestEnvironment tEnv = new TestEnvironment(xInspector);
164 // com.sun.star.frame.XController
165 tEnv.addObjRelation("Frame",xFrame);
167 tEnv.addObjRelation("XObjectInspector.toInspect", oInspect);
169 tEnv.addObjRelation("XObjectInspector.InspectorModelToSet", xInspectorModelToSet);
171 return tEnv;
172 } catch (com.sun.star.uno.Exception e) {
173 e.printStackTrace(log);
174 throw new StatusException("Unexpected exception", e);
180 * Closes the ObjectOnspector using <CODE>XCloseable</CODE>
181 * @see com.sun.star.util.XCloseable
182 * @param Param the test parameter
183 * @param log the logger
185 protected void cleanup(TestParameters Param, PrintWriter log) {
186 log.println(" Closing dialog if one exists ... ");
188 XFrame existentInspector = null;
190 XFrame xFrame = UnoRuntime.queryInterface(XFrame.class, StarDesktop);
192 existentInspector = xFrame.findFrame( "ObjectInspector", 255 );
194 if ( existentInspector != null ){
195 XCloseable closer = UnoRuntime.queryInterface(
196 XCloseable.class, existentInspector);
197 try{
198 closer.close(true);
199 } catch (CloseVetoException e){
200 log.println("Could not close inspector: " + e.toString());