xref: /AOO41X/main/qadevOOo/tests/java/ifc/lang/_XMultiComponentFactory.java (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 package ifc.lang;
29 
30 import lib.MultiMethodTest;
31 
32 import com.sun.star.lang.XMultiComponentFactory;
33 import com.sun.star.uno.XComponentContext;
34 import com.sun.star.uno.XInterface;
35 
36 /**
37 * Testing <code>com.sun.star.lang.XMultiComponentFactory</code>
38 * interface methods :
39 * <ul>
40 *  <li><code> createInstanceWithContext()</code></li>
41 *  <li><code> createInstanceWithArgumentsAndContext()</code></li>
42 *  <li><code> getAvailableServiceNames()</code></li>
43 * </ul> <p>
44 * Test is <b> NOT </b> multithread compilant. <p>
45 * @see com.sun.star.lang.XMultiComponentFactory
46 */
47 public class _XMultiComponentFactory extends MultiMethodTest {
48     public XMultiComponentFactory oObj = null;
49 
50     public XComponentContext xContext = null;
51     private String[] availableServiceNames = null;
52 
53     public void before(){
54         xContext = (XComponentContext)tEnv.getObjRelation("DC");
55         availableServiceNames = (String[])tEnv.getObjRelation("XMultiComponentFactory.ServiceNames");
56     }
57 
58     /**
59     * Calls the method with one of the available service names
60     * obtained by method getAvailableServiceNames. <p>
61     * Has <b> OK </b> status if no runtime exceptions occured
62     * and returned value is not null.
63     */
64     public void _createInstanceWithContext() {
65         requiredMethod("getAvailableServiceNames()");
66         boolean result = true;
67 
68         try {
69             XInterface component = (XInterface)
70                 oObj.createInstanceWithContext(
71                     availableServiceNames[0], xContext);
72             result = (component != null);
73         } catch (com.sun.star.uno.Exception e) {
74             log.println("Couldn't create instance " + availableServiceNames[0]);
75             result = false;
76         }
77 
78         tRes.tested("createInstanceWithContext()", result);
79     }
80 
81     /**
82     * Calls the method with one of the available service names
83     * obtained by method getAvailableServiceNames. <p>
84     * Has <b> OK </b> status if no runtime exceptions occured
85     * and returned value is not null.
86     */
87     public void _createInstanceWithArgumentsAndContext() {
88         requiredMethod("getAvailableServiceNames()");
89         boolean result = true;
90         XInterface component = null;
91 
92         try {
93             component = (XInterface)oObj.createInstanceWithArgumentsAndContext(
94                     availableServiceNames[0], new Object[0], xContext);
95             result = (component != null);
96         } catch (com.sun.star.uno.Exception e) {
97             log.println("Couldn't create instance " + availableServiceNames[0]);
98             result = false;
99         }
100 
101         tRes.tested("createInstanceWithArgumentsAndContext()", result);
102     }
103 
104     /**
105     * Just calls the method. <p>
106     * Has <b> OK </b> status if no runtime exceptions occured
107     * and returned value is not null.
108     */
109     public void _getAvailableServiceNames() {
110         boolean result = true;
111         if (availableServiceNames == null) {
112             availableServiceNames = oObj.getAvailableServiceNames();
113             result = (availableServiceNames != null);
114         }
115         else { // if service names are given, ignore result
116             String[]erg = oObj.getAvailableServiceNames();
117             result = (erg != null);
118         }
119 
120         log.println("Available service names:");
121         for(int i = 0; i < availableServiceNames.length; i++) {
122             log.println("   " + availableServiceNames[i]);
123         }
124 
125         tRes.tested("getAvailableServiceNames()", result);
126     }
127 }
128 
129