tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / qadevOOo / tests / java / ifc / lang / _XMultiServiceFactory.java
blobac5898edb21c1a54418c62716654d90f70038cf9
1 /*
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 .
18 package ifc.lang;
20 import lib.MultiMethodTest;
22 import com.sun.star.lang.XMultiServiceFactory;
25 /**
26 * Testing <code>com.sun.star.lang.XMultiServiceFactory</code>
27 * interface methods:
28 * <ul>
29 * <li><code>createInstance()</code></li>
30 * <li><code>createInstanceWithArguments()</code></li>
31 * <li><code>getAvailableServiceNames()</code></li>
32 * </ul> <p>
34 * This test needs the following object relations :
35 * <ul>
36 * <li> <code>'XMSF.serviceNames'</code> (of type <code>String[]</code>)
37 * <b>optional</b>:
38 * the relation used when service names are obtained the way
39 * other than calling <code>getAvailableServiceNames()</code>
40 * method.
41 * </li>
42 * <li> <code>'XMSF.serviceNamesWithArgs'</code> (of type <code>String[]</code>)
43 * <b>optional</b>:
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.
47 * </li>
48 * <li> <code>'XMSF.Args'</code> (of type <code>Object[][]</code>)
49 * <b>optional</b>:
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.
58 * </li>
59 * </ul> <p>
61 * @see com.sun.star.lang.XMultiServiceFactory
63 public class _XMultiServiceFactory extends MultiMethodTest {
64 public XMultiServiceFactory oObj = null;
65 public String[] services = null;
67 /**
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);
81 /**
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 :
89 * <ul>
90 * <li> <code> getAvailableServiceNames() </code> : to have list of
91 * supported services </li>
92 * </ul>
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);
104 return;
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);
115 return;
118 boolean res = true;
120 for (int k = 0; k < services.length; k++) {
121 try {
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);
129 res = false;
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 :
145 * <ul>
146 * <li> <code> getAvailableServiceNames() </code> : to have list of
147 * supported services </li>
148 * </ul>
150 public void _createInstanceWithArguments() {
151 requiredMethod("getAvailableServiceNames()");
153 Object[][] args = (Object[][]) tEnv.getObjRelation("XMSF.Args");
154 String[] sNames = (String[]) tEnv.getObjRelation(
155 "XMSF.serviceNamesWithArgs");
157 if (args == null) {
158 log.println("Relation 'XMSF.serviceNamesWithArgs' not found");
159 log.println("The component assumed not support " +
160 "createInstanceWithArguments()");
161 tRes.tested("createInstanceWithArguments()", true);
162 } else {
163 if (sNames == null) {
164 sNames = services;
167 boolean res = true;
169 for (int k = 0; k < sNames.length; k++) {
170 log.println("Creating service '" + sNames[k] +
171 "' with arguments");
173 try {
174 Object Inst = oObj.createInstanceWithArguments(sNames[k],
175 args[k]);
176 res &= (Inst != null);
177 } catch (com.sun.star.uno.Exception ex) {
178 log.println(
179 "Exception occurred during createInstanceWithArguments()");
180 ex.printStackTrace(log);
181 res = false;
185 tRes.tested("createInstanceWithArguments()", res);
188 } // finish class _XMultiServiceFactory