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
;
29 import java
.io
.PrintWriter
;
32 import lib
.TestEnvironment
;
33 import lib
.TestParameters
;
35 import com
.sun
.star
.uno
.AnyConverter
;
36 import com
.sun
.star
.uno
.Type
;
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 :
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>
54 * This object test <b> is NOT </b> designed to be run in several
55 * threads concurrently.
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
{
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 :
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
87 * <code>tools.SOConnect.createSimpleServiceManager()</code>
88 * and one of services contained in it is taken.</li>
92 protected TestEnvironment createTestEnvironment
93 (TestParameters Param
, PrintWriter log
) throws Exception
{
95 XInterface oObj
= null;
96 Object oInterface
= null;
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;
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 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();
129 newElement
= oEnum
.nextElement();
131 XPropertySet xProp
= UnoRuntime
.queryInterface(
132 XPropertySet
.class, oInterface
);
134 xContext
= (XComponentContext
) AnyConverter
.toObject(
135 new Type(XComponentContext
.class),
136 xProp
.getPropertyValue("DefaultContext"));
139 oObj
= (XInterface
) oInterface
;
141 log
.println( " creating a new environment for object" );
142 TestEnvironment tEnv
= new TestEnvironment( oObj
);
144 // adding relation for XSet interface
145 tEnv
.addObjRelation("NewElement", newElement
) ;
147 // adding relation for XPropertySet
148 tEnv
.addObjRelation("PTT",new String
[]{"DefaultContext","none","none"});
150 //adding relation for XMultiComponentFactory
151 if (xContext
!= null) {
152 tEnv
.addObjRelation("DC", xContext
);
155 } // finish method getTestEnvironment
157 } // finish class OServiceManager