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 10*ef39d40dSAndrew Rist * 11*ef39d40dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*ef39d40dSAndrew Rist * 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. 19*ef39d40dSAndrew Rist * 20*ef39d40dSAndrew Rist *************************************************************/ 21*ef39d40dSAndrew Rist 22*ef39d40dSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir package ifc.bridge; 25cdf0e10cSrcweir 26cdf0e10cSrcweir import lib.MultiMethodTest; 27cdf0e10cSrcweir import lib.Status; 28cdf0e10cSrcweir import lib.StatusException; 29cdf0e10cSrcweir 30cdf0e10cSrcweir import com.sun.star.bridge.XBridge; 31cdf0e10cSrcweir import com.sun.star.connection.XConnection; 32cdf0e10cSrcweir import com.sun.star.lang.XInitialization; 33cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 34cdf0e10cSrcweir import com.sun.star.uno.XInterface; 35cdf0e10cSrcweir 36cdf0e10cSrcweir 37cdf0e10cSrcweir /** 38cdf0e10cSrcweir * Testing <code>com.sun.star.bridge.XBridge</code> 39cdf0e10cSrcweir * interface methods : 40cdf0e10cSrcweir * <ul> 41cdf0e10cSrcweir * <li><code> getInstance()</code></li> 42cdf0e10cSrcweir * <li><code> getName()</code></li> 43cdf0e10cSrcweir * <li><code> getDescription()</code></li> 44cdf0e10cSrcweir * </ul> <p> 45cdf0e10cSrcweir * This test needs the following object relations : 46cdf0e10cSrcweir * <ul> 47cdf0e10cSrcweir * <li> <code>'XInitialization.args'</code> (of type <code>Object[]</code>): 48cdf0e10cSrcweir * relation which contains arguments for Bridge initialization. 49cdf0e10cSrcweir * It used here to check description of the bridge. This array 50cdf0e10cSrcweir * must contain : [0] - the name of the bridge, [1] - the name of 51cdf0e10cSrcweir * protocol, [2] - <code>XConnection</code> reference to bridge 52cdf0e10cSrcweir * connection. </li> 53cdf0e10cSrcweir * <ul> <p> 54cdf0e10cSrcweir * Test is <b> NOT </b> multithread compilant. <p> 55cdf0e10cSrcweir * After test completion object environment has to be recreated. 56cdf0e10cSrcweir * @see com.sun.star.bridge.XBridge 57cdf0e10cSrcweir */ 58cdf0e10cSrcweir public class _XBridge extends MultiMethodTest { 59cdf0e10cSrcweir 60cdf0e10cSrcweir public XBridge oObj; 61cdf0e10cSrcweir 62cdf0e10cSrcweir protected Object[] args;//for object relation 'XInitialization.args' 63cdf0e10cSrcweir 64cdf0e10cSrcweir /** 65cdf0e10cSrcweir * Retrieves object relations. 66cdf0e10cSrcweir * @throws StatusException If one of relations not found. 67cdf0e10cSrcweir */ before()68cdf0e10cSrcweir public void before() { 69cdf0e10cSrcweir args = (Object[])tEnv.getObjRelation("XInitialization.args"); 70cdf0e10cSrcweir 71cdf0e10cSrcweir if (args == null) throw new StatusException(Status.failed 72cdf0e10cSrcweir ("Relation 'XInitialization.args' not found")) ; 73cdf0e10cSrcweir XInitialization xInit = (XInitialization)UnoRuntime.queryInterface( 74cdf0e10cSrcweir XInitialization.class, oObj); 75cdf0e10cSrcweir try { 76cdf0e10cSrcweir xInit.initialize(args); 77cdf0e10cSrcweir } 78cdf0e10cSrcweir catch (com.sun.star.uno.Exception e) { 79cdf0e10cSrcweir e.printStackTrace(log); 80cdf0e10cSrcweir throw new StatusException("Can't initialize the bridge", e); 81cdf0e10cSrcweir } 82cdf0e10cSrcweir } 83cdf0e10cSrcweir 84cdf0e10cSrcweir /** 85cdf0e10cSrcweir * Tries to retrieve <code>ServiceManager</code> service 86cdf0e10cSrcweir * using the bridge. <p> 87cdf0e10cSrcweir * Has <b>OK</b> status if non null object returned. 88cdf0e10cSrcweir */ _getInstance()89cdf0e10cSrcweir public void _getInstance() { 90cdf0e10cSrcweir XInterface xInt = (XInterface)oObj.getInstance( 91cdf0e10cSrcweir "com.sun.star.lang.ServiceManager"); 92cdf0e10cSrcweir 93cdf0e10cSrcweir tRes.tested("getInstance()", xInt != null); 94cdf0e10cSrcweir } 95cdf0e10cSrcweir 96cdf0e10cSrcweir /** 97cdf0e10cSrcweir * Retrieves the name of the bridge from relation and compares 98cdf0e10cSrcweir * it to name returned by the method. <p> 99cdf0e10cSrcweir * Has <b>OK</b> status if names are equal. 100cdf0e10cSrcweir */ _getName()101cdf0e10cSrcweir public void _getName() { 102cdf0e10cSrcweir String expectedName = (String)args[0]; // args[0] - bridge name 103cdf0e10cSrcweir 104cdf0e10cSrcweir String name = oObj.getName(); 105cdf0e10cSrcweir 106cdf0e10cSrcweir if (!tRes.tested("getName()", name.equals(expectedName))) { 107cdf0e10cSrcweir log.println("getName() returns wrong result : \"" + name + "\""); 108cdf0e10cSrcweir log.println("expected = \"" + expectedName + "\""); 109cdf0e10cSrcweir } 110cdf0e10cSrcweir } 111cdf0e10cSrcweir 112cdf0e10cSrcweir /** 113cdf0e10cSrcweir * Retrieves the description of the bridge and compares it with 114cdf0e10cSrcweir * expected description composed using relation 115cdf0e10cSrcweir * <code> ([protocol] + ":" + [connection description]) </code>. <p> 116cdf0e10cSrcweir * Has <b>OK</b> status if description returned by the method 117cdf0e10cSrcweir * is equal to expected one. 118cdf0e10cSrcweir */ _getDescription()119cdf0e10cSrcweir public void _getDescription() { 120cdf0e10cSrcweir String protocol = (String)args[1]; // args[1] - protocol 121cdf0e10cSrcweir XConnection xConnection = (XConnection)args[2]; // args[2] - connection 122cdf0e10cSrcweir // expected description is protocol + ":" + xConnection.getDescription() 123cdf0e10cSrcweir String expectedDescription = 124cdf0e10cSrcweir protocol + ":" + xConnection.getDescription(); 125cdf0e10cSrcweir 126cdf0e10cSrcweir String description = oObj.getDescription(); 127cdf0e10cSrcweir 128cdf0e10cSrcweir if (!tRes.tested("getDescription()", 129cdf0e10cSrcweir description.equals(expectedDescription))) { 130cdf0e10cSrcweir log.println("getDescription() returns wrong result : \"" 131cdf0e10cSrcweir + description + "\""); 132cdf0e10cSrcweir log.println("expected = \"" + expectedDescription + "\""); 133cdf0e10cSrcweir } 134cdf0e10cSrcweir } 135cdf0e10cSrcweir 136cdf0e10cSrcweir /** 137cdf0e10cSrcweir * Disposes object environment. 138cdf0e10cSrcweir */ after()139cdf0e10cSrcweir public void after() { 140cdf0e10cSrcweir disposeEnvironment() ; 141cdf0e10cSrcweir } 142cdf0e10cSrcweir 143cdf0e10cSrcweir } 144cdf0e10cSrcweir 145