1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ObjectInspectorModel.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 import com
.sun
.star
.beans
.UnknownPropertyException
;
33 import com
.sun
.star
.beans
.XPropertySet
;
34 import com
.sun
.star
.frame
.XFrame
;
35 import com
.sun
.star
.inspection
.XObjectInspectorModel
;
36 import com
.sun
.star
.lang
.WrappedTargetException
;
37 import com
.sun
.star
.uno
.UnoRuntime
;
38 import com
.sun
.star
.uno
.XComponentContext
;
39 import com
.sun
.star
.util
.CloseVetoException
;
40 import com
.sun
.star
.util
.XCloseable
;
41 import helper
.PropertyHandlerFactroy
;
42 import java
.io
.PrintWriter
;
44 import lib
.StatusException
;
46 import lib
.TestEnvironment
;
47 import lib
.TestParameters
;
49 import com
.sun
.star
.lang
.XMultiServiceFactory
;
50 import util
.DesktopTools
;
54 * Test for object which is represented by service
55 * <code>com.sun.star.reflection.ObjectInspectorModel</code>. <p>
56 * Object implements the following interfaces :
58 * <li> <code>com::sun::star::inspection::XObjectInspectorModel</code></li>
60 * This object test <b> is NOT </b> designed to be run in several
61 * threads concurently.
62 * @see com.sun.star.inspection.XObjectInspectorModel
64 public class ObjectInspectorModel
extends TestCase
{
67 * module variable which holds the Desktop
68 * @see com.sun.star.frame.Desktop
70 protected static Object StarDesktop
= null;
73 * assign to the module variable <CODE>StarDesktop</CODE> the desktop
74 * @param Param the test parameters
75 * @param log the log writer
76 * @see lib.TestParameters
77 * @see share.LogWriter
78 * @see com.sun.star.frame.Desktop
80 protected void initialize(TestParameters Param
, PrintWriter log
) {
81 log
.println("create a desktop...");
82 StarDesktop
= DesktopTools
.createDesktop((XMultiServiceFactory
) Param
.getMSF());
83 if (StarDesktop
== null){
84 throw new StatusException("Could not get a Desktop: null", null);
89 * Creating a Testenvironment for the interfaces to be tested.
90 * Creates an instance of the service
91 * <code>com.sun.star.inspection.ObjectInspectorModel</code> with a <code>DefaultContext</code> and
92 * <code>PropertyHandlerFactroy[]</code> as parameter
94 * @param tParam the tests parameter
95 * @param log the logger
96 * @return the test environement
97 * @see util.DesktopTools
98 * @see helper.PropertyHandlerImpl
100 protected TestEnvironment
createTestEnvironment(TestParameters tParam
, PrintWriter log
) {
102 this.cleanup(tParam
, log
);
104 XMultiServiceFactory xMSF
= (XMultiServiceFactory
)tParam
.getMSF();
106 XPropertySet xMSFProp
= (XPropertySet
) UnoRuntime
.queryInterface(XPropertySet
.class, xMSF
);
107 XComponentContext xDefaultContext
= null;
109 // Get the default context from the office server.
110 Object oDefaultContext
= xMSFProp
.getPropertyValue("DefaultContext");
112 // Query for the interface XComponentContext.
113 xDefaultContext
= (XComponentContext
) UnoRuntime
.queryInterface(
114 XComponentContext
.class, oDefaultContext
);
116 } catch (UnknownPropertyException e
){
117 throw new StatusException("could not get DefaultContext from xMSF", e
);
118 } catch (WrappedTargetException e
){
119 throw new StatusException("could not get DefaultContext from xMSF", e
);
120 } catch (Exception e
){
121 throw new StatusException("could not get DefaultContext from xMSF", e
);
126 Object
[] oHandlerFactories
= new Object
[1];
127 oHandlerFactories
[0] = new PropertyHandlerFactroy();
129 int minHelpTextLines
= 200;
130 int maxHelpTextLines
= 400;
132 XObjectInspectorModel oInspectorModel
= com
.sun
.star
.inspection
.ObjectInspectorModel
.
133 createWithHandlerFactoriesAndHelpSection(xDefaultContext
, oHandlerFactories
,
134 minHelpTextLines
, maxHelpTextLines
);
136 log
.println("ImplementationName '" + utils
.getImplName(oInspectorModel
) + "'");
138 TestEnvironment tEnv
= new TestEnvironment(oInspectorModel
);
140 // com.sun.star.inspection.XObjectInspectorModel
141 tEnv
.addObjRelation("minHelpTextLines", new Integer(minHelpTextLines
));
142 tEnv
.addObjRelation("maxHelpTextLines", new Integer(maxHelpTextLines
));
145 } catch (com
.sun
.star
.uno
.Exception e
) {
146 e
.printStackTrace(log
);
147 throw new StatusException("Unexpected exception", e
);
153 * Closes the ObjectOnspector using <CODE>XCloseable</CODE>
154 * @see com.sun.star.util.XCloseable
155 * @param Param the test parameter
156 * @param log the logger
158 protected void cleanup(TestParameters Param
, PrintWriter log
) {
159 log
.println(" Closing dialog if one exists ... ");
161 XFrame existentInspector
= null;
163 XFrame xFrame
= (XFrame
) UnoRuntime
.queryInterface(XFrame
.class, StarDesktop
);
165 existentInspector
= xFrame
.findFrame( "ObjectInspector", 255 );
167 if ( existentInspector
!= null ){
168 XCloseable closer
= (XCloseable
) UnoRuntime
.queryInterface(
169 XCloseable
.class, existentInspector
);
172 } catch (CloseVetoException e
){
173 log
.println("Could not close inspector: " + e
.toString());