1ef39d40dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3ef39d40dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4ef39d40dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5ef39d40dSAndrew Rist  * distributed with this work for additional information
6ef39d40dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7ef39d40dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8ef39d40dSAndrew Rist  * "License"); you may not use this file except in compliance
9ef39d40dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10ef39d40dSAndrew Rist  *
11ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12ef39d40dSAndrew Rist  *
13ef39d40dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14ef39d40dSAndrew Rist  * software distributed under the License is distributed on an
15ef39d40dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16ef39d40dSAndrew Rist  * KIND, either express or implied.  See the License for the
17ef39d40dSAndrew Rist  * specific language governing permissions and limitations
18ef39d40dSAndrew Rist  * under the License.
19ef39d40dSAndrew Rist  *
20ef39d40dSAndrew Rist  *************************************************************/
21ef39d40dSAndrew Rist 
22ef39d40dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package ifc.lang;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import lib.MultiMethodTest;
27cdf0e10cSrcweir 
28cdf0e10cSrcweir import com.sun.star.lang.XMultiComponentFactory;
29cdf0e10cSrcweir import com.sun.star.uno.XComponentContext;
30cdf0e10cSrcweir import com.sun.star.uno.XInterface;
31cdf0e10cSrcweir 
32cdf0e10cSrcweir /**
33cdf0e10cSrcweir * Testing <code>com.sun.star.lang.XMultiComponentFactory</code>
34cdf0e10cSrcweir * interface methods :
35cdf0e10cSrcweir * <ul>
36cdf0e10cSrcweir *  <li><code> createInstanceWithContext()</code></li>
37cdf0e10cSrcweir *  <li><code> createInstanceWithArgumentsAndContext()</code></li>
38cdf0e10cSrcweir *  <li><code> getAvailableServiceNames()</code></li>
39cdf0e10cSrcweir * </ul> <p>
40cdf0e10cSrcweir * Test is <b> NOT </b> multithread compilant. <p>
41cdf0e10cSrcweir * @see com.sun.star.lang.XMultiComponentFactory
42cdf0e10cSrcweir */
43cdf0e10cSrcweir public class _XMultiComponentFactory extends MultiMethodTest {
44cdf0e10cSrcweir     public XMultiComponentFactory oObj = null;
45cdf0e10cSrcweir 
46cdf0e10cSrcweir     public XComponentContext xContext = null;
47cdf0e10cSrcweir     private String[] availableServiceNames = null;
48cdf0e10cSrcweir 
before()49cdf0e10cSrcweir     public void before(){
50cdf0e10cSrcweir         xContext = (XComponentContext)tEnv.getObjRelation("DC");
51cdf0e10cSrcweir         availableServiceNames = (String[])tEnv.getObjRelation("XMultiComponentFactory.ServiceNames");
52cdf0e10cSrcweir     }
53cdf0e10cSrcweir 
54cdf0e10cSrcweir     /**
55cdf0e10cSrcweir     * Calls the method with one of the available service names
56cdf0e10cSrcweir     * obtained by method getAvailableServiceNames. <p>
57*bb6af6bcSPedro Giffuni     * Has <b> OK </b> status if no runtime exceptions occurred
58cdf0e10cSrcweir     * and returned value is not null.
59cdf0e10cSrcweir     */
_createInstanceWithContext()60cdf0e10cSrcweir     public void _createInstanceWithContext() {
61cdf0e10cSrcweir         requiredMethod("getAvailableServiceNames()");
62cdf0e10cSrcweir         boolean result = true;
63cdf0e10cSrcweir 
64cdf0e10cSrcweir         try {
65cdf0e10cSrcweir             XInterface component = (XInterface)
66cdf0e10cSrcweir                 oObj.createInstanceWithContext(
67cdf0e10cSrcweir                     availableServiceNames[0], xContext);
68cdf0e10cSrcweir             result = (component != null);
69cdf0e10cSrcweir         } catch (com.sun.star.uno.Exception e) {
70cdf0e10cSrcweir             log.println("Couldn't create instance " + availableServiceNames[0]);
71cdf0e10cSrcweir             result = false;
72cdf0e10cSrcweir         }
73cdf0e10cSrcweir 
74cdf0e10cSrcweir         tRes.tested("createInstanceWithContext()", result);
75cdf0e10cSrcweir     }
76cdf0e10cSrcweir 
77cdf0e10cSrcweir     /**
78cdf0e10cSrcweir     * Calls the method with one of the available service names
79cdf0e10cSrcweir     * obtained by method getAvailableServiceNames. <p>
80*bb6af6bcSPedro Giffuni     * Has <b> OK </b> status if no runtime exceptions occurred
81cdf0e10cSrcweir     * and returned value is not null.
82cdf0e10cSrcweir     */
_createInstanceWithArgumentsAndContext()83cdf0e10cSrcweir     public void _createInstanceWithArgumentsAndContext() {
84cdf0e10cSrcweir         requiredMethod("getAvailableServiceNames()");
85cdf0e10cSrcweir         boolean result = true;
86cdf0e10cSrcweir         XInterface component = null;
87cdf0e10cSrcweir 
88cdf0e10cSrcweir         try {
89cdf0e10cSrcweir             component = (XInterface)oObj.createInstanceWithArgumentsAndContext(
90cdf0e10cSrcweir                     availableServiceNames[0], new Object[0], xContext);
91cdf0e10cSrcweir             result = (component != null);
92cdf0e10cSrcweir         } catch (com.sun.star.uno.Exception e) {
93cdf0e10cSrcweir             log.println("Couldn't create instance " + availableServiceNames[0]);
94cdf0e10cSrcweir             result = false;
95cdf0e10cSrcweir         }
96cdf0e10cSrcweir 
97cdf0e10cSrcweir         tRes.tested("createInstanceWithArgumentsAndContext()", result);
98cdf0e10cSrcweir     }
99cdf0e10cSrcweir 
100cdf0e10cSrcweir     /**
101cdf0e10cSrcweir     * Just calls the method. <p>
102*bb6af6bcSPedro Giffuni     * Has <b> OK </b> status if no runtime exceptions occurred
103cdf0e10cSrcweir     * and returned value is not null.
104cdf0e10cSrcweir     */
_getAvailableServiceNames()105cdf0e10cSrcweir     public void _getAvailableServiceNames() {
106cdf0e10cSrcweir         boolean result = true;
107cdf0e10cSrcweir         if (availableServiceNames == null) {
108cdf0e10cSrcweir             availableServiceNames = oObj.getAvailableServiceNames();
109cdf0e10cSrcweir             result = (availableServiceNames != null);
110cdf0e10cSrcweir         }
111cdf0e10cSrcweir         else { // if service names are given, ignore result
112cdf0e10cSrcweir             String[]erg = oObj.getAvailableServiceNames();
113cdf0e10cSrcweir             result = (erg != null);
114cdf0e10cSrcweir         }
115cdf0e10cSrcweir 
116cdf0e10cSrcweir         log.println("Available service names:");
117cdf0e10cSrcweir         for(int i = 0; i < availableServiceNames.length; i++) {
118cdf0e10cSrcweir             log.println("   " + availableServiceNames[i]);
119cdf0e10cSrcweir         }
120cdf0e10cSrcweir 
121cdf0e10cSrcweir         tRes.tested("getAvailableServiceNames()", result);
122cdf0e10cSrcweir     }
123cdf0e10cSrcweir }
124cdf0e10cSrcweir 
125