bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _pcr / ObjectInspectorModel.java
blobc9846f6f4cae099526ecd92d58df900c378d1cd9
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;
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;
33 import lib.TestCase;
34 import lib.TestEnvironment;
35 import lib.TestParameters;
37 import com.sun.star.lang.XMultiServiceFactory;
38 import util.DesktopTools;
39 import util.utils;
41 /**
42 * Test for object which is represented by service
43 * <code>com.sun.star.reflection.ObjectInspectorModel</code>. <p>
44 * Object implements the following interfaces :
45 * <ul>
46 * <li> <code>com::sun::star::inspection::XObjectInspectorModel</code></li>
47 * </ul>
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 {
54 /**
55 * module variable which holds the Desktop
56 * @see com.sun.star.frame.Desktop
58 protected static Object StarDesktop = null;
60 /**
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
68 protected void initialize(TestParameters Param, PrintWriter log) {
69 log.println("create a desktop...");
70 StarDesktop = DesktopTools.createDesktop((XMultiServiceFactory) Param.getMSF());
71 if (StarDesktop == null){
72 throw new StatusException("Could not get a Desktop: null", null);
76 /**
77 * Creating a Testenvironment for the interfaces to be tested.
78 * Creates an instance of the service
79 * <code>com.sun.star.inspection.ObjectInspectorModel</code> with a <code>DefaultContext</code> and
80 * <code>PropertyHandlerFactroy[]</code> as parameter
82 * @param tParam the tests parameter
83 * @param log the logger
84 * @return the test environement
85 * @see util.DesktopTools
86 * @see helper.PropertyHandlerImpl
88 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
90 this.cleanup(tParam, log);
92 XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF();
94 XPropertySet xMSFProp = UnoRuntime.queryInterface(XPropertySet.class, xMSF);
95 XComponentContext xDefaultContext = null;
96 try{
97 // Get the default context from the office server.
98 Object oDefaultContext = xMSFProp.getPropertyValue("DefaultContext");
100 // Query for the interface XComponentContext.
101 xDefaultContext = UnoRuntime.queryInterface(
102 XComponentContext.class, oDefaultContext);
104 } catch (UnknownPropertyException e){
105 throw new StatusException("could not get DefaultContext from xMSF", e);
106 } catch (WrappedTargetException e){
107 throw new StatusException("could not get DefaultContext from xMSF", e);
108 } catch (Exception e){
109 throw new StatusException("could not get DefaultContext from xMSF", e);
112 try {
114 Object[] oHandlerFactories = new Object[1];
115 oHandlerFactories[0] = new PropertyHandlerFactroy();
117 int minHelpTextLines = 200;
118 int maxHelpTextLines = 400;
120 XObjectInspectorModel oInspectorModel = com.sun.star.inspection.ObjectInspectorModel.
121 createWithHandlerFactoriesAndHelpSection(xDefaultContext, oHandlerFactories,
122 minHelpTextLines, maxHelpTextLines);
124 log.println("ImplementationName '" + utils.getImplName(oInspectorModel) + "'");
126 TestEnvironment tEnv = new TestEnvironment(oInspectorModel);
128 // com.sun.star.inspection.XObjectInspectorModel
129 tEnv.addObjRelation("minHelpTextLines", new Integer(minHelpTextLines));
130 tEnv.addObjRelation("maxHelpTextLines", new Integer(maxHelpTextLines));
132 return tEnv;
133 } catch (com.sun.star.lang.IllegalArgumentException e) {
134 e.printStackTrace(log);
135 throw new StatusException("Unexpected exception", e);
141 * Closes the ObjectOnspector using <CODE>XCloseable</CODE>
142 * @see com.sun.star.util.XCloseable
143 * @param Param the test parameter
144 * @param log the logger
146 protected void cleanup(TestParameters Param, PrintWriter log) {
147 log.println(" Closing dialog if one exists ... ");
149 XFrame existentInspector = null;
151 XFrame xFrame = UnoRuntime.queryInterface(XFrame.class, StarDesktop);
153 existentInspector = xFrame.findFrame( "ObjectInspector", 255 );
155 if ( existentInspector != null ){
156 XCloseable closer = UnoRuntime.queryInterface(
157 XCloseable.class, existentInspector);
158 try{
159 closer.close(true);
160 } catch (CloseVetoException e){
161 log.println("Could not close inspector: " + e.toString());