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 .
20 import lib
.MultiMethodTest
;
22 import com
.sun
.star
.lang
.XMultiServiceFactory
;
26 * Testing <code>com.sun.star.lang.XMultiServiceFactory</code>
29 * <li><code>createInstance()</code></li>
30 * <li><code>createInstanceWithArguments()</code></li>
31 * <li><code>getAvailableServiceNames()</code></li>
34 * This test needs the following object relations :
36 * <li> <code>'XMSF.serviceNames'</code> (of type <code>String[]</code>)
38 * the relation used when service names are obtained the way
39 * other than calling <code>getAvailableServiceNames()</code>
42 * <li> <code>'XMSF.serviceNamesWithArgs'</code> (of type <code>String[]</code>)
44 * the relation used when service names are obtained the way
45 * other than calling <code>getAvailableServiceNames()</code>
46 * method for testing <code>createInstanceWithArguments</code> method.
48 * <li> <code>'XMSF.Args'</code> (of type <code>Object[][]</code>)
50 * if this relation exists than the method
51 * <code>createInstanceWithArguments</code> is tested. This relation
52 * supplies arguments for creating instances. If the relation
53 * <code>'XMSF.serviceNamesWithArgs'</code> is also specified
54 * then for each service name from that relation appropriate arguments
55 * are used from arguments array. If not than arguments with index
56 * 0 are used for services creation obtained by
57 * <code>getAvailableServiceNames</code> method.
61 * @see com.sun.star.lang.XMultiServiceFactory
63 public class _XMultiServiceFactory
extends MultiMethodTest
{
64 public XMultiServiceFactory oObj
= null;
65 public String
[] services
= null;
68 * Test calls the method and checks returned value. <p>
69 * Has <b> OK </b> status if returned value isn't null. <p>
71 public void _getAvailableServiceNames() {
72 services
= oObj
.getAvailableServiceNames();
74 for (int i
= 0; i
< services
.length
; i
++) {
75 log
.println("Service" + i
+ ": " + services
[i
]);
78 tRes
.tested("getAvailableServiceNames()", true);
82 * Test creates instance of the first service from names array
83 * get by <code>getAvailableServiceNames()</code>. If the array
84 * is empty than test looks for names from relation. <p>
86 * Has <b> OK </b> status if created instance isn't null. <p>
88 * The following method tests are to be completed successfully before :
90 * <li> <code> getAvailableServiceNames() </code> : to have list of
91 * supported services </li>
94 public void _createInstance() {
95 requiredMethod("getAvailableServiceNames()");
97 if (services
.length
== 0) {
98 services
= (String
[]) tEnv
.getObjRelation("XMSF.serviceNames");
100 if (services
== null) {
101 log
.println("No service to create.");
102 tRes
.tested("createInstance()", true);
108 String needArgs
= (String
) tEnv
.getObjRelation("needArgs");
110 if (needArgs
!= null) {
111 log
.println("The " + needArgs
+
112 " doesn't support createInstance without arguments");
113 tRes
.tested("createInstance()", true);
120 for (int k
= 0; k
< services
.length
; k
++) {
122 log
.println("Creating Instance: " + services
[k
]);
124 Object Inst
= oObj
.createInstance(services
[k
]);
125 res
= (Inst
!= null);
126 } catch (com
.sun
.star
.uno
.Exception ex
) {
127 log
.println("Exception occurred during createInstance()");
128 ex
.printStackTrace(log
);
133 tRes
.tested("createInstance()", res
);
137 * If the relation with arguments is not specified test does nothing.
138 * In other case it tries to create instance by its name from
139 * relation of from array <code>getAvailableServiceNames()</code>
140 * method supplied. <p>
142 * Has <b> OK </b> status if the created instance is not null. <p>
144 * The following method tests are to be completed successfully before :
146 * <li> <code> getAvailableServiceNames() </code> : to have list of
147 * supported services </li>
150 public void _createInstanceWithArguments() {
151 requiredMethod("getAvailableServiceNames()");
153 Object
[][] args
= (Object
[][]) tEnv
.getObjRelation("XMSF.Args");
154 String
[] sNames
= (String
[]) tEnv
.getObjRelation(
155 "XMSF.serviceNamesWithArgs");
158 log
.println("Relation 'XMSF.serviceNamesWithArgs' not found");
159 log
.println("The component assumed not support " +
160 "createInstanceWithArguments()");
161 tRes
.tested("createInstanceWithArguments()", true);
163 if (sNames
== null) {
169 for (int k
= 0; k
< sNames
.length
; k
++) {
170 log
.println("Creating service '" + sNames
[k
] +
174 Object Inst
= oObj
.createInstanceWithArguments(sNames
[k
],
176 res
&= (Inst
!= null);
177 } catch (com
.sun
.star
.uno
.Exception ex
) {
179 "Exception occurred during createInstanceWithArguments()");
180 ex
.printStackTrace(log
);
185 tRes
.tested("createInstanceWithArguments()", res
);
188 } // finish class _XMultiServiceFactory