1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package ifc.bridge; 25 26 import lib.MultiMethodTest; 27 import lib.Status; 28 import lib.StatusException; 29 30 import com.sun.star.bridge.XBridge; 31 import com.sun.star.connection.XConnection; 32 import com.sun.star.lang.XInitialization; 33 import com.sun.star.uno.UnoRuntime; 34 import com.sun.star.uno.XInterface; 35 36 37 /** 38 * Testing <code>com.sun.star.bridge.XBridge</code> 39 * interface methods : 40 * <ul> 41 * <li><code> getInstance()</code></li> 42 * <li><code> getName()</code></li> 43 * <li><code> getDescription()</code></li> 44 * </ul> <p> 45 * This test needs the following object relations : 46 * <ul> 47 * <li> <code>'XInitialization.args'</code> (of type <code>Object[]</code>): 48 * relation which contains arguments for Bridge initialization. 49 * It used here to check description of the bridge. This array 50 * must contain : [0] - the name of the bridge, [1] - the name of 51 * protocol, [2] - <code>XConnection</code> reference to bridge 52 * connection. </li> 53 * <ul> <p> 54 * Test is <b> NOT </b> multithread compilant. <p> 55 * After test completion object environment has to be recreated. 56 * @see com.sun.star.bridge.XBridge 57 */ 58 public class _XBridge extends MultiMethodTest { 59 60 public XBridge oObj; 61 62 protected Object[] args;//for object relation 'XInitialization.args' 63 64 /** 65 * Retrieves object relations. 66 * @throws StatusException If one of relations not found. 67 */ before()68 public void before() { 69 args = (Object[])tEnv.getObjRelation("XInitialization.args"); 70 71 if (args == null) throw new StatusException(Status.failed 72 ("Relation 'XInitialization.args' not found")) ; 73 XInitialization xInit = (XInitialization)UnoRuntime.queryInterface( 74 XInitialization.class, oObj); 75 try { 76 xInit.initialize(args); 77 } 78 catch (com.sun.star.uno.Exception e) { 79 e.printStackTrace(log); 80 throw new StatusException("Can't initialize the bridge", e); 81 } 82 } 83 84 /** 85 * Tries to retrieve <code>ServiceManager</code> service 86 * using the bridge. <p> 87 * Has <b>OK</b> status if non null object returned. 88 */ _getInstance()89 public void _getInstance() { 90 XInterface xInt = (XInterface)oObj.getInstance( 91 "com.sun.star.lang.ServiceManager"); 92 93 tRes.tested("getInstance()", xInt != null); 94 } 95 96 /** 97 * Retrieves the name of the bridge from relation and compares 98 * it to name returned by the method. <p> 99 * Has <b>OK</b> status if names are equal. 100 */ _getName()101 public void _getName() { 102 String expectedName = (String)args[0]; // args[0] - bridge name 103 104 String name = oObj.getName(); 105 106 if (!tRes.tested("getName()", name.equals(expectedName))) { 107 log.println("getName() returns wrong result : \"" + name + "\""); 108 log.println("expected = \"" + expectedName + "\""); 109 } 110 } 111 112 /** 113 * Retrieves the description of the bridge and compares it with 114 * expected description composed using relation 115 * <code> ([protocol] + ":" + [connection description]) </code>. <p> 116 * Has <b>OK</b> status if description returned by the method 117 * is equal to expected one. 118 */ _getDescription()119 public void _getDescription() { 120 String protocol = (String)args[1]; // args[1] - protocol 121 XConnection xConnection = (XConnection)args[2]; // args[2] - connection 122 // expected description is protocol + ":" + xConnection.getDescription() 123 String expectedDescription = 124 protocol + ":" + xConnection.getDescription(); 125 126 String description = oObj.getDescription(); 127 128 if (!tRes.tested("getDescription()", 129 description.equals(expectedDescription))) { 130 log.println("getDescription() returns wrong result : \"" 131 + description + "\""); 132 log.println("expected = \"" + expectedDescription + "\""); 133 } 134 } 135 136 /** 137 * Disposes object environment. 138 */ after()139 public void after() { 140 disposeEnvironment() ; 141 } 142 143 } 144 145