Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _smgr / OServiceManager.java
blob7ce85c9d3414f292695b467c87a896284b962029
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 @Override
92 protected TestEnvironment createTestEnvironment
93 (TestParameters Param, PrintWriter log) {
95 XInterface oObj = null;
96 Object oInterface = null;
98 try {
99 XMultiServiceFactory xMSF = Param.getMSF();
100 oInterface = xMSF.createInstance
101 ( "com.sun.star.comp.stoc.OServiceManager" );
102 } catch( com.sun.star.uno.Exception e ) {
103 log.println("ServiceManager service not available" );
106 // adding a service to the manager
107 Object newElement = null ;
108 XMultiServiceFactory srvMan = null;
109 XComponentContext xContext = null;
111 try {
113 srvMan = com.sun.star.comp.helper.Bootstrap.createSimpleServiceManager();
115 } catch ( java.lang.Exception ex) {
116 log.println("Error creating SimpleServiceManager :");
117 ex.printStackTrace(log);
120 try {
121 XSet set = UnoRuntime.queryInterface
122 (XSet.class, oInterface) ;
123 XSet set1 = UnoRuntime.queryInterface
124 (XSet.class, srvMan) ;
125 XEnumeration oEnum = set1.createEnumeration();
126 Object srv = oEnum.nextElement();
128 set.insert(srv) ;
130 newElement = oEnum.nextElement();
132 XPropertySet xProp = UnoRuntime.queryInterface(
133 XPropertySet.class, oInterface);
134 if (xProp != null) {
135 xContext = (XComponentContext) AnyConverter.toObject(
136 new Type(XComponentContext.class),
137 xProp.getPropertyValue("DefaultContext"));
139 } catch (com.sun.star.uno.Exception e) {
140 log.println("Can't insert a service to the ServiceManager") ;
141 throw new StatusException("Can't create object environment", e) ;
144 oObj = (XInterface) oInterface;
146 log.println( " creating a new environment for object" );
147 TestEnvironment tEnv = new TestEnvironment( oObj );
149 // adding relation for XSet interface
150 tEnv.addObjRelation("NewElement", newElement) ;
152 // adding relation for XPropertySet
153 tEnv.addObjRelation("PTT",new String[]{"DefaultContext","none","none"});
155 //adding relation for XMultiComponentFactory
156 if (xContext != null) {
157 tEnv.addObjRelation("DC", xContext);
159 return tEnv;
160 } // finish method getTestEnvironment
162 } // finish class OServiceManager