1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XBridge.java,v $
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 ************************************************************************/
33 import lib
.MultiMethodTest
;
35 import lib
.StatusException
;
37 import com
.sun
.star
.bridge
.XBridge
;
38 import com
.sun
.star
.connection
.XConnection
;
39 import com
.sun
.star
.lang
.XInitialization
;
40 import com
.sun
.star
.uno
.UnoRuntime
;
41 import com
.sun
.star
.uno
.XInterface
;
45 * Testing <code>com.sun.star.bridge.XBridge</code>
48 * <li><code> getInstance()</code></li>
49 * <li><code> getName()</code></li>
50 * <li><code> getDescription()</code></li>
52 * This test needs the following object relations :
54 * <li> <code>'XInitialization.args'</code> (of type <code>Object[]</code>):
55 * relation which contains arguments for Bridge initialization.
56 * It used here to check description of the bridge. This array
57 * must contain : [0] - the name of the bridge, [1] - the name of
58 * protocol, [2] - <code>XConnection</code> reference to bridge
61 * Test is <b> NOT </b> multithread compilant. <p>
62 * After test completion object environment has to be recreated.
63 * @see com.sun.star.bridge.XBridge
65 public class _XBridge
extends MultiMethodTest
{
69 protected Object
[] args
;//for object relation 'XInitialization.args'
72 * Retrieves object relations.
73 * @throws StatusException If one of relations not found.
75 public void before() {
76 args
= (Object
[])tEnv
.getObjRelation("XInitialization.args");
78 if (args
== null) throw new StatusException(Status
.failed
79 ("Relation 'XInitialization.args' not found")) ;
80 XInitialization xInit
= (XInitialization
)UnoRuntime
.queryInterface(
81 XInitialization
.class, oObj
);
83 xInit
.initialize(args
);
85 catch (com
.sun
.star
.uno
.Exception e
) {
86 e
.printStackTrace(log
);
87 throw new StatusException("Can't initialize the bridge", e
);
92 * Tries to retrieve <code>ServiceManager</code> service
93 * using the bridge. <p>
94 * Has <b>OK</b> status if non null object returned.
96 public void _getInstance() {
97 XInterface xInt
= (XInterface
)oObj
.getInstance(
98 "com.sun.star.lang.ServiceManager");
100 tRes
.tested("getInstance()", xInt
!= null);
104 * Retrieves the name of the bridge from relation and compares
105 * it to name returned by the method. <p>
106 * Has <b>OK</b> status if names are equal.
108 public void _getName() {
109 String expectedName
= (String
)args
[0]; // args[0] - bridge name
111 String name
= oObj
.getName();
113 if (!tRes
.tested("getName()", name
.equals(expectedName
))) {
114 log
.println("getName() returns wrong result : \"" + name
+ "\"");
115 log
.println("expected = \"" + expectedName
+ "\"");
120 * Retrieves the description of the bridge and compares it with
121 * expected description composed using relation
122 * <code> ([protocol] + ":" + [connection description]) </code>. <p>
123 * Has <b>OK</b> status if description returned by the method
124 * is equal to expected one.
126 public void _getDescription() {
127 String protocol
= (String
)args
[1]; // args[1] - protocol
128 XConnection xConnection
= (XConnection
)args
[2]; // args[2] - connection
129 // expected description is protocol + ":" + xConnection.getDescription()
130 String expectedDescription
=
131 protocol
+ ":" + xConnection
.getDescription();
133 String description
= oObj
.getDescription();
135 if (!tRes
.tested("getDescription()",
136 description
.equals(expectedDescription
))) {
137 log
.println("getDescription() returns wrong result : \""
138 + description
+ "\"");
139 log
.println("expected = \"" + expectedDescription
+ "\"");
144 * Disposes object environment.
146 public void after() {
147 disposeEnvironment() ;