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 .
20 import com
.sun
.star
.beans
.UnknownPropertyException
;
21 import com
.sun
.star
.beans
.XPropertySet
;
22 import com
.sun
.star
.frame
.XFrame
;
23 import com
.sun
.star
.inspection
.XObjectInspectorModel
;
24 import com
.sun
.star
.lang
.WrappedTargetException
;
25 import com
.sun
.star
.uno
.UnoRuntime
;
26 import com
.sun
.star
.uno
.XComponentContext
;
27 import com
.sun
.star
.util
.CloseVetoException
;
28 import com
.sun
.star
.util
.XCloseable
;
29 import helper
.PropertyHandlerFactroy
;
30 import java
.io
.PrintWriter
;
32 import lib
.StatusException
;
34 import lib
.TestEnvironment
;
35 import lib
.TestParameters
;
37 import com
.sun
.star
.lang
.XMultiServiceFactory
;
38 import util
.DesktopTools
;
42 * Test for object which is represented by service
43 * <code>com.sun.star.reflection.ObjectInspectorModel</code>. <p>
44 * Object implements the following interfaces :
46 * <li> <code>com::sun::star::inspection::XObjectInspectorModel</code></li>
48 * This object test <b> is NOT </b> designed to be run in several
49 * threads concurently.
50 * @see com.sun.star.inspection.XObjectInspectorModel
52 public class ObjectInspectorModel
extends TestCase
{
55 * module variable which holds the Desktop
56 * @see com.sun.star.frame.Desktop
58 protected static Object StarDesktop
= null;
61 * assign to the module variable <CODE>StarDesktop</CODE> the desktop
62 * @param Param the test parameters
63 * @param log the log writer
64 * @see lib.TestParameters
65 * @see share.LogWriter
66 * @see com.sun.star.frame.Desktop
69 protected void initialize(TestParameters Param
, PrintWriter log
) {
70 log
.println("create a desktop...");
71 StarDesktop
= DesktopTools
.createDesktop(Param
.getMSF());
72 if (StarDesktop
== null){
73 throw new StatusException("Could not get a Desktop: null", null);
78 * Creating a Testenvironment for the interfaces to be tested.
79 * Creates an instance of the service
80 * <code>com.sun.star.inspection.ObjectInspectorModel</code> with a <code>DefaultContext</code> and
81 * <code>PropertyHandlerFactroy[]</code> as parameter
83 * @param tParam the tests parameter
84 * @param log the logger
85 * @return the test environement
86 * @see util.DesktopTools
87 * @see helper.PropertyHandlerImpl
90 protected TestEnvironment
createTestEnvironment(TestParameters tParam
, PrintWriter log
) {
92 this.cleanup(tParam
, log
);
94 XMultiServiceFactory xMSF
= tParam
.getMSF();
96 XPropertySet xMSFProp
= UnoRuntime
.queryInterface(XPropertySet
.class, xMSF
);
97 XComponentContext xDefaultContext
= null;
99 // Get the default context from the office server.
100 Object oDefaultContext
= xMSFProp
.getPropertyValue("DefaultContext");
102 // Query for the interface XComponentContext.
103 xDefaultContext
= UnoRuntime
.queryInterface(
104 XComponentContext
.class, oDefaultContext
);
106 } catch (UnknownPropertyException e
){
107 throw new StatusException("could not get DefaultContext from xMSF", e
);
108 } catch (WrappedTargetException e
){
109 throw new StatusException("could not get DefaultContext from xMSF", e
);
110 } catch (Exception e
){
111 throw new StatusException("could not get DefaultContext from xMSF", e
);
116 Object
[] oHandlerFactories
= new Object
[1];
117 oHandlerFactories
[0] = new PropertyHandlerFactroy();
119 int minHelpTextLines
= 200;
120 int maxHelpTextLines
= 400;
122 XObjectInspectorModel oInspectorModel
= com
.sun
.star
.inspection
.ObjectInspectorModel
.
123 createWithHandlerFactoriesAndHelpSection(xDefaultContext
, oHandlerFactories
,
124 minHelpTextLines
, maxHelpTextLines
);
126 log
.println("ImplementationName '" + utils
.getImplName(oInspectorModel
) + "'");
128 TestEnvironment tEnv
= new TestEnvironment(oInspectorModel
);
130 // com.sun.star.inspection.XObjectInspectorModel
131 tEnv
.addObjRelation("minHelpTextLines", Integer
.valueOf(minHelpTextLines
));
132 tEnv
.addObjRelation("maxHelpTextLines", Integer
.valueOf(maxHelpTextLines
));
135 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
136 e
.printStackTrace(log
);
137 throw new StatusException("Unexpected exception", e
);
143 * Closes the ObjectOnspector using <CODE>XCloseable</CODE>
144 * @see com.sun.star.util.XCloseable
145 * @param Param the test parameter
146 * @param log the logger
149 protected void cleanup(TestParameters Param
, PrintWriter log
) {
150 log
.println(" Closing dialog if one exists ... ");
152 XFrame existentInspector
= null;
154 XFrame xFrame
= UnoRuntime
.queryInterface(XFrame
.class, StarDesktop
);
156 existentInspector
= xFrame
.findFrame( "ObjectInspector", 255 );
158 if ( existentInspector
!= null ){
159 XCloseable closer
= UnoRuntime
.queryInterface(
160 XCloseable
.class, existentInspector
);
163 } catch (CloseVetoException e
){
164 log
.println("Could not close inspector: " + e
.toString());