tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _smgr / OServiceManager.java
blob797246b2ce41aa818703fbda4a859b8206bb3762
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.TestCase;
24 import lib.TestEnvironment;
25 import lib.TestParameters;
27 import com.sun.star.beans.XPropertySet;
28 import com.sun.star.container.XEnumeration;
29 import com.sun.star.container.XSet;
30 import com.sun.star.lang.XMultiServiceFactory;
31 import com.sun.star.uno.AnyConverter;
32 import com.sun.star.uno.Type;
33 import com.sun.star.uno.UnoRuntime;
34 import com.sun.star.uno.XComponentContext;
35 import com.sun.star.uno.XInterface;
37 /**
38 * Test for object which is represented by service
39 * <code>com.sun.star.comp.stoc.OServiceManager</code>. <p>
41 * Object implements the following interfaces :
42 * <ul>
43 * <li> <code>com::sun::star::lang::XMultiServiceFactory</code></li>
44 * <li> <code>com::sun::star::container::XContentEnumerationAccess</code></li>
45 * <li> <code>com::sun::star::container::XSet</code></li>
46 * <li> <code>com::sun::star::lang::XMultiComponentFactory</code></li>
47 * <li> <code>com::sun::star::lang::XServiceInfo</code></li>
48 * <li> <code>com::sun::star::container::XElementAccess</code></li>
49 * <li> <code>com::sun::star::container::XEnumerationAccess</code></li>
50 * <li> <code>com::sun::star::lang::XComponent</code></li>
51 * </ul> <p>
53 * This object test <b> is NOT </b> designed to be run in several
54 * threads concurrently.
56 * @see com.sun.star.lang.XMultiServiceFactory
57 * @see com.sun.star.container.XContentEnumerationAccess
58 * @see com.sun.star.container.XSet
59 * @see com.sun.star.lang.XMultiComponentFactory
60 * @see com.sun.star.lang.XServiceInfo
61 * @see com.sun.star.container.XElementAccess
62 * @see com.sun.star.container.XEnumerationAccess
63 * @see com.sun.star.lang.XComponent
64 * @see ifc.lang._XMultiServiceFactory
65 * @see ifc.container._XContentEnumerationAccess
66 * @see ifc.container._XSet
67 * @see ifc.lang._XMultiComponentFactory
68 * @see ifc.lang._XServiceInfo
69 * @see ifc.container._XElementAccess
70 * @see ifc.container._XEnumerationAccess
71 * @see ifc.lang._XComponent
73 public class OServiceManager extends TestCase {
75 /**
76 * Creating a TestEnvironment for the interfaces to be tested.
77 * Creates an instance of the service
78 * <code>com.sun.star.comp.stoc.OServiceManager</code>.
79 * Object relations created :
80 * <ul>
81 * <li> <code>'NewElement'</code> for
82 * {@link ifc.container._XSet} :
83 * element to be inserted into manager. Here
84 * a new <code>ServiceManager</code> implementation is
85 * create using
86 * <code>tools.SOConnect.createSimpleServiceManager()</code>
87 * and one of services contained in it is taken.</li>
88 * </ul>
90 @Override
91 protected TestEnvironment createTestEnvironment
92 (TestParameters Param, PrintWriter log) throws Exception {
94 XInterface oObj = null;
95 Object oInterface = null;
97 try {
98 XMultiServiceFactory xMSF = 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 XSet set = UnoRuntime.queryInterface
120 (XSet.class, oInterface) ;
121 XSet set1 = UnoRuntime.queryInterface
122 (XSet.class, srvMan) ;
123 XEnumeration oEnum = set1.createEnumeration();
124 Object srv = oEnum.nextElement();
126 set.insert(srv) ;
128 newElement = oEnum.nextElement();
130 XPropertySet xProp = UnoRuntime.queryInterface(
131 XPropertySet.class, oInterface);
132 if (xProp != null) {
133 xContext = (XComponentContext) AnyConverter.toObject(
134 new Type(XComponentContext.class),
135 xProp.getPropertyValue("DefaultContext"));
138 oObj = (XInterface) oInterface;
140 log.println( " creating a new environment for object" );
141 TestEnvironment tEnv = new TestEnvironment( oObj );
143 // adding relation for XSet interface
144 tEnv.addObjRelation("NewElement", newElement) ;
146 // adding relation for XPropertySet
147 tEnv.addObjRelation("PTT",new String[]{"DefaultContext","none","none"});
149 //adding relation for XMultiComponentFactory
150 if (xContext != null) {
151 tEnv.addObjRelation("DC", xContext);
153 return tEnv;
154 } // finish method getTestEnvironment
156 } // finish class OServiceManager