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