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