bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _servicemgr / uno / OServiceManager.java
blob5d2f34b07201cf8e9533a95ae59b8c3eb154c3b3
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._servicemgr.uno;
21 import com.sun.star.beans.XPropertySet;
22 import com.sun.star.container.XEnumeration;
23 import com.sun.star.container.XSet;
24 import com.sun.star.lang.XMultiServiceFactory;
25 import com.sun.star.uno.UnoRuntime;
26 import com.sun.star.uno.XComponentContext;
27 import com.sun.star.uno.XInterface;
28 import java.io.PrintWriter;
29 import lib.StatusException;
30 import lib.TestCase;
31 import lib.TestEnvironment;
32 import lib.TestParameters;
33 import com.sun.star.uno.AnyConverter;
34 import com.sun.star.uno.Type;
36 /**
37 * Test for object which is represented by service
38 * <code>com.sun.star.comp.stoc.OServiceManager</code>. <p>
40 * Object implements the following interfaces :
41 * <ul>
42 * <li> <code>com::sun::star::lang::XMultiServiceFactory</code></li>
43 * <li> <code>com::sun::star::container::XContentEnumerationAccess</code></li>
44 * <li> <code>com::sun::star::container::XSet</code></li>
45 * <li> <code>com::sun::star::lang::XMultiComponentFactory</code></li>
46 * <li> <code>com::sun::star::lang::XServiceInfo</code></li>
47 * <li> <code>com::sun::star::container::XElementAccess</code></li>
48 * <li> <code>com::sun::star::container::XEnumerationAccess</code></li>
49 * <li> <code>com::sun::star::lang::XComponent</code></li>
50 * </ul> <p>
52 * This object test <b> is NOT </b> designed to be run in several
53 * threads concurently.
55 * @see com.sun.star.lang.XMultiServiceFactory
56 * @see com.sun.star.container.XContentEnumerationAccess
57 * @see com.sun.star.container.XSet
58 * @see com.sun.star.lang.XMultiComponentFactory
59 * @see com.sun.star.lang.XServiceInfo
60 * @see com.sun.star.container.XElementAccess
61 * @see com.sun.star.container.XEnumerationAccess
62 * @see com.sun.star.lang.XComponent
63 * @see ifc.lang._XMultiServiceFactory
64 * @see ifc.container._XContentEnumerationAccess
65 * @see ifc.container._XSet
66 * @see ifc.lang._XMultiComponentFactory
67 * @see ifc.lang._XServiceInfo
68 * @see ifc.container._XElementAccess
69 * @see ifc.container._XEnumerationAccess
70 * @see ifc.lang._XComponent
72 public class OServiceManager extends TestCase {
74 /**
75 * Creating a Testenvironment for the interfaces to be tested.
76 * Creates an instance of the service
77 * <code>com.sun.star.comp.stoc.OServiceManager</code>.
78 * Object relations created :
79 * <ul>
80 * <li> <code>'NewElement'</code> for
81 * {@link ifc.container._XSet} :
82 * element to be inserted into manager. Here
83 * a new <code>ServiceManager</code> implementation is
84 * create using
85 * <code>tools.SOConnect.createSimpleServiceManager()</code>
86 * and one of services contained in it is taken.</li>
87 * </ul>
89 protected TestEnvironment createTestEnvironment
90 (TestParameters Param, PrintWriter log) {
92 XInterface oObj = null;
93 Object oInterface = null;
95 try {
96 XMultiServiceFactory xMSF = (XMultiServiceFactory)Param.getMSF();
97 oInterface = xMSF.createInstance
98 ( "com.sun.star.comp.stoc.OServiceManager" );
99 } catch( com.sun.star.uno.Exception e ) {
100 log.println("ServiceManager service not available" );
103 // adding a service to the manager
104 Object newElement = null ;
105 XMultiServiceFactory srvMan = null;
106 XComponentContext xContext = null;
108 try {
110 srvMan = com.sun.star.comp.helper.Bootstrap.createSimpleServiceManager();
112 } catch ( java.lang.Exception ex) {
113 log.println("Error creating SimpleServiceManager :");
114 ex.printStackTrace(log);
117 try {
118 XSet set = UnoRuntime.queryInterface
119 (XSet.class, oInterface) ;
120 XSet set1 = UnoRuntime.queryInterface
121 (XSet.class, srvMan) ;
122 XEnumeration oEnum = set1.createEnumeration();
123 Object srv = oEnum.nextElement();
125 set.insert(srv) ;
127 newElement = oEnum.nextElement();
129 XPropertySet xProp = UnoRuntime.queryInterface(
130 XPropertySet.class, oInterface);
131 if (xProp != null) {
132 xContext = (XComponentContext) AnyConverter.toObject(
133 new Type(XComponentContext.class),
134 xProp.getPropertyValue("DefaultContext"));
136 } catch (com.sun.star.uno.Exception e) {
137 log.println("Can't insert a service to the ServiceManager") ;
138 throw new StatusException("Can't create object environment", e) ;
141 oObj = (XInterface) oInterface;
143 log.println( " creating a new environment for object" );
144 TestEnvironment tEnv = new TestEnvironment( oObj );
146 // adding relation for XSet interface
147 tEnv.addObjRelation("NewElement", newElement) ;
149 // adding relation for XPropertySet
150 tEnv.addObjRelation("PTT",new String[]{"DefaultContext","none","none"});
152 //adding relation for XMultiComponentFactory
153 if (xContext != null) {
154 tEnv.addObjRelation("DC", xContext);
156 return tEnv;
157 } // finish method getTestEnvironment
159 } // finish class OServiceManager