1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
29 import lib
.MultiMethodTest
;
31 import com
.sun
.star
.lang
.XMultiServiceFactory
;
35 * Testing <code>com.sun.star.lang.XMultiServiceFactory</code>
38 * <li><code>createInstance()</code></li>
39 * <li><code>createInstanceWithArguments()</code></li>
40 * <li><code>getAvailableServiceNames()</code></li>
43 * This test needs the following object relations :
45 * <li> <code>'XMSF.serviceNames'</code> (of type <code>String[]</code>)
47 * the relation used when service names are obtained the way
48 * other than calling <code>getAvailableServiceNames()</code>
51 * <li> <code>'XMSF.serviceNamesWithArgs'</code> (of type <code>String[]</code>)
53 * the relation used when service names are obtained the way
54 * other than calling <code>getAvailableServiceNames()</code>
55 * method for testing <code>createInstanceWithArguments</code> method.
57 * <li> <code>'XMSF.Args'</code> (of type <code>Object[][]</code>)
59 * if this relation exists than the method
60 * <code>createInstanceWithArguments</code> is tested. This relation
61 * supplies arguments for creating instances. If the relation
62 * <code>'XMSF.serviceNamesWithArgs'</code> is also specified
63 * then for each service name from that relation appropriate arguments
64 * are used from arguments array. If not than arguments with index
65 * 0 are used for services creation obtained by
66 * <code>getAvailableServiceNames</code> method.
70 * @see com.sun.star.lang.XMultiServiceFactory
72 public class _XMultiServiceFactory
extends MultiMethodTest
{
73 public XMultiServiceFactory oObj
= null;
74 public String
[] services
= null;
77 * Test calls the method and checks returned value. <p>
78 * Has <b> OK </b> status if returned value isn't null. <p>
80 public void _getAvailableServiceNames() {
81 services
= oObj
.getAvailableServiceNames();
83 for (int i
= 0; i
< services
.length
; i
++) {
84 log
.println("Service" + i
+ ": " + services
[i
]);
87 tRes
.tested("getAvailableServiceNames()", services
!= null);
91 * Test creates instance of the first service from names array
92 * get by <code>getAvailableServiceNames()</code>. If the array
93 * is empty than test looks for names from relation. <p>
95 * Has <b> OK </b> status if created instance isn't null. <p>
97 * The following method tests are to be completed successfully before :
99 * <li> <code> getAvailableServiceNames() </code> : to have list of
100 * supported services </li>
103 public void _createInstance() {
104 requiredMethod("getAvailableServiceNames()");
106 if (services
.length
== 0) {
107 services
= (String
[]) tEnv
.getObjRelation("XMSF.serviceNames");
109 if (services
== null) {
110 log
.println("No service to create.");
111 tRes
.tested("createInstance()", true);
117 String needArgs
= (String
) tEnv
.getObjRelation("needArgs");
119 if (needArgs
!= null) {
120 log
.println("The " + needArgs
+
121 " doesn't support createInstance without arguments");
122 tRes
.tested("createInstance()", true);
129 for (int k
= 0; k
< services
.length
; k
++) {
131 log
.println("Creating Instance: " + services
[k
]);
133 Object Inst
= oObj
.createInstance(services
[k
]);
134 res
= (Inst
!= null);
135 } catch (com
.sun
.star
.uno
.Exception ex
) {
136 log
.println("Exception occurred during createInstance()");
137 ex
.printStackTrace(log
);
142 tRes
.tested("createInstance()", res
);
146 * If the relation with arguments is not specified test does nothing.
147 * In other case it tries to create instance by its name from
148 * relation of from array <code>getAvailableServiceNames()</code>
149 * method supplied. <p>
151 * Has <b> OK </b> status if the created instance is not null. <p>
153 * The following method tests are to be completed successfully before :
155 * <li> <code> getAvailableServiceNames() </code> : to have list of
156 * supported services </li>
159 public void _createInstanceWithArguments() {
160 requiredMethod("getAvailableServiceNames()");
162 Object
[][] args
= (Object
[][]) tEnv
.getObjRelation("XMSF.Args");
163 String
[] sNames
= (String
[]) tEnv
.getObjRelation(
164 "XMSF.serviceNamesWithArgs");
167 log
.println("Relation 'XMSF.serviceNamesWithArgs' not found");
168 log
.println("The component assumed not support " +
169 "createInstanceWithArguments()");
170 tRes
.tested("createInstanceWithArguments()", true);
172 if (sNames
== null) {
178 for (int k
= 0; k
< sNames
.length
; k
++) {
179 log
.println("Creating service '" + sNames
[k
] +
183 Object Inst
= oObj
.createInstanceWithArguments(sNames
[k
],
185 res
&= (Inst
!= null);
186 } catch (com
.sun
.star
.uno
.Exception ex
) {
188 "Exception occurred during createInstanceWithArguments()");
189 ex
.printStackTrace(log
);
194 tRes
.tested("createInstanceWithArguments()", res
);
197 } // finish class _XMultiServiceFactory