1*ef39d40dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*ef39d40dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*ef39d40dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*ef39d40dSAndrew Rist * distributed with this work for additional information 6*ef39d40dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*ef39d40dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*ef39d40dSAndrew Rist * "License"); you may not use this file except in compliance 9*ef39d40dSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*ef39d40dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*ef39d40dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*ef39d40dSAndrew Rist * software distributed under the License is distributed on an 15*ef39d40dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*ef39d40dSAndrew Rist * KIND, either express or implied. See the License for the 17*ef39d40dSAndrew Rist * specific language governing permissions and limitations 18*ef39d40dSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*ef39d40dSAndrew Rist *************************************************************/ 21*ef39d40dSAndrew Rist 22*ef39d40dSAndrew Rist 23cdf0e10cSrcweir package ifc.lang; 24cdf0e10cSrcweir 25cdf0e10cSrcweir import lib.MultiMethodTest; 26cdf0e10cSrcweir 27cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 28cdf0e10cSrcweir 29cdf0e10cSrcweir 30cdf0e10cSrcweir /** 31cdf0e10cSrcweir * Testing <code>com.sun.star.lang.XMultiServiceFactory</code> 32cdf0e10cSrcweir * interface methods: 33cdf0e10cSrcweir * <ul> 34cdf0e10cSrcweir * <li><code>createInstance()</code></li> 35cdf0e10cSrcweir * <li><code>createInstanceWithArguments()</code></li> 36cdf0e10cSrcweir * <li><code>getAvailableServiceNames()</code></li> 37cdf0e10cSrcweir * </ul> <p> 38cdf0e10cSrcweir * 39cdf0e10cSrcweir * This test needs the following object relations : 40cdf0e10cSrcweir * <ul> 41cdf0e10cSrcweir * <li> <code>'XMSF.serviceNames'</code> (of type <code>String[]</code>) 42cdf0e10cSrcweir * <b>optional</b>: 43cdf0e10cSrcweir * the relation used when service names are obtained the way 44cdf0e10cSrcweir * other than calling <code>getAvailableServiceNames()</code> 45cdf0e10cSrcweir * method. 46cdf0e10cSrcweir * </li> 47cdf0e10cSrcweir * <li> <code>'XMSF.serviceNamesWithArgs'</code> (of type <code>String[]</code>) 48cdf0e10cSrcweir * <b>optional</b>: 49cdf0e10cSrcweir * the relation used when service names are obtained the way 50cdf0e10cSrcweir * other than calling <code>getAvailableServiceNames()</code> 51cdf0e10cSrcweir * method for testing <code>createInstanceWithArguments</code> method. 52cdf0e10cSrcweir * </li> 53cdf0e10cSrcweir * <li> <code>'XMSF.Args'</code> (of type <code>Object[][]</code>) 54cdf0e10cSrcweir * <b>optional</b>: 55cdf0e10cSrcweir * if this relation exists than the method 56cdf0e10cSrcweir * <code>createInstanceWithArguments</code> is tested. This relation 57cdf0e10cSrcweir * supplies arguments for creating instances. If the relation 58cdf0e10cSrcweir * <code>'XMSF.serviceNamesWithArgs'</code> is also specified 59cdf0e10cSrcweir * then for each service name from that relation appropriate arguments 60cdf0e10cSrcweir * are used from arguments array. If not than arguments with index 61cdf0e10cSrcweir * 0 are used for services creation obtained by 62cdf0e10cSrcweir * <code>getAvailableServiceNames</code> method. 63cdf0e10cSrcweir * </li> 64cdf0e10cSrcweir * </ul> <p> 65cdf0e10cSrcweir * 66cdf0e10cSrcweir * @see com.sun.star.lang.XMultiServiceFactory 67cdf0e10cSrcweir */ 68cdf0e10cSrcweir public class _XMultiServiceFactory extends MultiMethodTest { 69cdf0e10cSrcweir public XMultiServiceFactory oObj = null; 70cdf0e10cSrcweir public String[] services = null; 71cdf0e10cSrcweir 72cdf0e10cSrcweir /** 73cdf0e10cSrcweir * Test calls the method and checks returned value. <p> 74cdf0e10cSrcweir * Has <b> OK </b> status if returned value isn't null. <p> 75cdf0e10cSrcweir */ _getAvailableServiceNames()76cdf0e10cSrcweir public void _getAvailableServiceNames() { 77cdf0e10cSrcweir services = oObj.getAvailableServiceNames(); 78cdf0e10cSrcweir 79cdf0e10cSrcweir for (int i = 0; i < services.length; i++) { 80cdf0e10cSrcweir log.println("Service" + i + ": " + services[i]); 81cdf0e10cSrcweir } 82cdf0e10cSrcweir 83cdf0e10cSrcweir tRes.tested("getAvailableServiceNames()", services != null); 84cdf0e10cSrcweir } 85cdf0e10cSrcweir 86cdf0e10cSrcweir /** 87cdf0e10cSrcweir * Test creates instance of the first service from names array 88cdf0e10cSrcweir * get by <code>getAvailableServiceNames()</code>. If the array 89cdf0e10cSrcweir * is empty than test looks for names from relation. <p> 90cdf0e10cSrcweir * 91cdf0e10cSrcweir * Has <b> OK </b> status if created instance isn't null. <p> 92cdf0e10cSrcweir * 93cdf0e10cSrcweir * The following method tests are to be completed successfully before : 94cdf0e10cSrcweir * <ul> 95cdf0e10cSrcweir * <li> <code> getAvailableServiceNames() </code> : to have list of 96cdf0e10cSrcweir * supported services </li> 97cdf0e10cSrcweir * </ul> 98cdf0e10cSrcweir */ _createInstance()99cdf0e10cSrcweir public void _createInstance() { 100cdf0e10cSrcweir requiredMethod("getAvailableServiceNames()"); 101cdf0e10cSrcweir 102cdf0e10cSrcweir if (services.length == 0) { 103cdf0e10cSrcweir services = (String[]) tEnv.getObjRelation("XMSF.serviceNames"); 104cdf0e10cSrcweir 105cdf0e10cSrcweir if (services == null) { 106cdf0e10cSrcweir log.println("No service to create."); 107cdf0e10cSrcweir tRes.tested("createInstance()", true); 108cdf0e10cSrcweir 109cdf0e10cSrcweir return; 110cdf0e10cSrcweir } 111cdf0e10cSrcweir } 112cdf0e10cSrcweir 113cdf0e10cSrcweir String needArgs = (String) tEnv.getObjRelation("needArgs"); 114cdf0e10cSrcweir 115cdf0e10cSrcweir if (needArgs != null) { 116cdf0e10cSrcweir log.println("The " + needArgs + 117cdf0e10cSrcweir " doesn't support createInstance without arguments"); 118cdf0e10cSrcweir tRes.tested("createInstance()", true); 119cdf0e10cSrcweir 120cdf0e10cSrcweir return; 121cdf0e10cSrcweir } 122cdf0e10cSrcweir 123cdf0e10cSrcweir boolean res = true; 124cdf0e10cSrcweir 125cdf0e10cSrcweir for (int k = 0; k < services.length; k++) { 126cdf0e10cSrcweir try { 127cdf0e10cSrcweir log.println("Creating Instance: " + services[k]); 128cdf0e10cSrcweir 129cdf0e10cSrcweir Object Inst = oObj.createInstance(services[k]); 130cdf0e10cSrcweir res = (Inst != null); 131cdf0e10cSrcweir } catch (com.sun.star.uno.Exception ex) { 132cdf0e10cSrcweir log.println("Exception occured during createInstance()"); 133cdf0e10cSrcweir ex.printStackTrace(log); 134cdf0e10cSrcweir res = false; 135cdf0e10cSrcweir } 136cdf0e10cSrcweir } 137cdf0e10cSrcweir 138cdf0e10cSrcweir tRes.tested("createInstance()", res); 139cdf0e10cSrcweir } 140cdf0e10cSrcweir 141cdf0e10cSrcweir /** 142cdf0e10cSrcweir * If the relation with arguments is not specified test does nothing. 143cdf0e10cSrcweir * In other case it tries to create instance by its name from 144cdf0e10cSrcweir * relation of from array <code>getAvailableServiceNames()</code> 145cdf0e10cSrcweir * method supplied. <p> 146cdf0e10cSrcweir * 147cdf0e10cSrcweir * Has <b> OK </b> status if the created instance is not null. <p> 148cdf0e10cSrcweir * 149cdf0e10cSrcweir * The following method tests are to be completed successfully before : 150cdf0e10cSrcweir * <ul> 151cdf0e10cSrcweir * <li> <code> getAvailableServiceNames() </code> : to have list of 152cdf0e10cSrcweir * supported services </li> 153cdf0e10cSrcweir * </ul> 154cdf0e10cSrcweir */ _createInstanceWithArguments()155cdf0e10cSrcweir public void _createInstanceWithArguments() { 156cdf0e10cSrcweir requiredMethod("getAvailableServiceNames()"); 157cdf0e10cSrcweir 158cdf0e10cSrcweir Object[][] args = (Object[][]) tEnv.getObjRelation("XMSF.Args"); 159cdf0e10cSrcweir String[] sNames = (String[]) tEnv.getObjRelation( 160cdf0e10cSrcweir "XMSF.serviceNamesWithArgs"); 161cdf0e10cSrcweir 162cdf0e10cSrcweir if (args == null) { 163cdf0e10cSrcweir log.println("Relation 'XMSF.serviceNamesWithArgs' not found"); 164cdf0e10cSrcweir log.println("The component assumed not support " + 165cdf0e10cSrcweir "createInstanceWithArguments()"); 166cdf0e10cSrcweir tRes.tested("createInstanceWithArguments()", true); 167cdf0e10cSrcweir } else { 168cdf0e10cSrcweir if (sNames == null) { 169cdf0e10cSrcweir sNames = services; 170cdf0e10cSrcweir } 171cdf0e10cSrcweir 172cdf0e10cSrcweir boolean res = true; 173cdf0e10cSrcweir 174cdf0e10cSrcweir for (int k = 0; k < sNames.length; k++) { 175cdf0e10cSrcweir log.println("Creating service '" + sNames[k] + 176cdf0e10cSrcweir "' with arguments"); 177cdf0e10cSrcweir 178cdf0e10cSrcweir try { 179cdf0e10cSrcweir Object Inst = oObj.createInstanceWithArguments(sNames[k], 180cdf0e10cSrcweir args[k]); 181cdf0e10cSrcweir res &= (Inst != null); 182cdf0e10cSrcweir } catch (com.sun.star.uno.Exception ex) { 183cdf0e10cSrcweir log.println( 184cdf0e10cSrcweir "Exception occured during createInstanceWithArguments()"); 185cdf0e10cSrcweir ex.printStackTrace(log); 186cdf0e10cSrcweir res = false; 187cdf0e10cSrcweir } 188cdf0e10cSrcweir } 189cdf0e10cSrcweir 190cdf0e10cSrcweir tRes.tested("createInstanceWithArguments()", res); 191cdf0e10cSrcweir } 192cdf0e10cSrcweir } 193cdf0e10cSrcweir } // finish class _XMultiServiceFactory 194