merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / ifc / lang / _XMultiServiceFactory.java
blobdaa93eafef16733813196c398a3aa6e235118155
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XMultiServiceFactory.java,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 package ifc.lang;
32 import lib.MultiMethodTest;
34 import com.sun.star.lang.XMultiServiceFactory;
37 /**
38 * Testing <code>com.sun.star.lang.XMultiServiceFactory</code>
39 * interface methods:
40 * <ul>
41 * <li><code>createInstance()</code></li>
42 * <li><code>createInstanceWithArguments()</code></li>
43 * <li><code>getAvailableServiceNames()</code></li>
44 * </ul> <p>
46 * This test needs the following object relations :
47 * <ul>
48 * <li> <code>'XMSF.serviceNames'</code> (of type <code>String[]</code>)
49 * <b>optional</b>:
50 * the relation used when service names are obtained the way
51 * other than calling <code>getAvailableServiceNames()</code>
52 * method.
53 * </li>
54 * <li> <code>'XMSF.serviceNamesWithArgs'</code> (of type <code>String[]</code>)
55 * <b>optional</b>:
56 * the relation used when service names are obtained the way
57 * other than calling <code>getAvailableServiceNames()</code>
58 * method for testing <code>createInstanceWithArguments</code> method.
59 * </li>
60 * <li> <code>'XMSF.Args'</code> (of type <code>Object[][]</code>)
61 * <b>optional</b>:
62 * if this relation exists than the method
63 * <code>createInstanceWithArguments</code> is tested. This relation
64 * supplies arguments for creating instances. If the relation
65 * <code>'XMSF.serviceNamesWithArgs'</code> is also specified
66 * then for each service name from that relation appropriate arguments
67 * are used from arguments array. If not than arguments with index
68 * 0 are used for services creation obtained by
69 * <code>getAvailableServiceNames</code> method.
70 * </li>
71 * </ul> <p>
73 * @see com.sun.star.lang.XMultiServiceFactory
75 public class _XMultiServiceFactory extends MultiMethodTest {
76 public XMultiServiceFactory oObj = null;
77 public String[] services = null;
79 /**
80 * Test calls the method and checks returned value. <p>
81 * Has <b> OK </b> status if returned value isn't null. <p>
83 public void _getAvailableServiceNames() {
84 services = oObj.getAvailableServiceNames();
86 for (int i = 0; i < services.length; i++) {
87 log.println("Service" + i + ": " + services[i]);
90 tRes.tested("getAvailableServiceNames()", services != null);
93 /**
94 * Test creates instance of the first service from names array
95 * get by <code>getAvailableServiceNames()</code>. If the array
96 * is empty than test looks for names from relation. <p>
98 * Has <b> OK </b> status if created instance isn't null. <p>
100 * The following method tests are to be completed successfully before :
101 * <ul>
102 * <li> <code> getAvailableServiceNames() </code> : to have list of
103 * supported services </li>
104 * </ul>
106 public void _createInstance() {
107 requiredMethod("getAvailableServiceNames()");
109 if (services.length == 0) {
110 services = (String[]) tEnv.getObjRelation("XMSF.serviceNames");
112 if (services == null) {
113 log.println("No service to create.");
114 tRes.tested("createInstance()", true);
116 return;
120 String needArgs = (String) tEnv.getObjRelation("needArgs");
122 if (needArgs != null) {
123 log.println("The " + needArgs +
124 " doesn't support createInstance without arguments");
125 tRes.tested("createInstance()", true);
127 return;
130 boolean res = true;
132 for (int k = 0; k < services.length; k++) {
133 try {
134 log.println("Creating Instance: " + services[k]);
136 Object Inst = oObj.createInstance(services[k]);
137 res = (Inst != null);
138 } catch (com.sun.star.uno.Exception ex) {
139 log.println("Exception occured during createInstance()");
140 ex.printStackTrace(log);
141 res = false;
145 tRes.tested("createInstance()", res);
149 * If the relation with arguments is not specified test does nothing.
150 * In other case it tries to create instance by its name from
151 * relation of from array <code>getAvailableServiceNames()</code>
152 * method supplied. <p>
154 * Has <b> OK </b> status if the created instance is not null. <p>
156 * The following method tests are to be completed successfully before :
157 * <ul>
158 * <li> <code> getAvailableServiceNames() </code> : to have list of
159 * supported services </li>
160 * </ul>
162 public void _createInstanceWithArguments() {
163 requiredMethod("getAvailableServiceNames()");
165 Object[][] args = (Object[][]) tEnv.getObjRelation("XMSF.Args");
166 String[] sNames = (String[]) tEnv.getObjRelation(
167 "XMSF.serviceNamesWithArgs");
169 if (args == null) {
170 log.println("Relation 'XMSF.serviceNamesWithArgs' not found");
171 log.println("The component assumed not support " +
172 "createInstanceWithArguments()");
173 tRes.tested("createInstanceWithArguments()", true);
174 } else {
175 if (sNames == null) {
176 sNames = services;
179 boolean res = true;
181 for (int k = 0; k < sNames.length; k++) {
182 log.println("Creating service '" + sNames[k] +
183 "' with arguments");
185 try {
186 Object Inst = oObj.createInstanceWithArguments(sNames[k],
187 args[k]);
188 res &= (Inst != null);
189 } catch (com.sun.star.uno.Exception ex) {
190 log.println(
191 "Exception occured during createInstanceWithArguments()");
192 ex.printStackTrace(log);
193 res = false;
197 tRes.tested("createInstanceWithArguments()", res);
200 } // finish class _XMultiServiceFactory