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 .
21 import lib
.MultiMethodTest
;
23 import lib
.StatusException
;
25 import com
.sun
.star
.bridge
.XBridge
;
26 import com
.sun
.star
.connection
.XConnection
;
27 import com
.sun
.star
.lang
.XInitialization
;
28 import com
.sun
.star
.uno
.UnoRuntime
;
29 import com
.sun
.star
.uno
.XInterface
;
33 * Testing <code>com.sun.star.bridge.XBridge</code>
36 * <li><code> getInstance()</code></li>
37 * <li><code> getName()</code></li>
38 * <li><code> getDescription()</code></li>
40 * This test needs the following object relations :
42 * <li> <code>'XInitialization.args'</code> (of type <code>Object[]</code>):
43 * relation which contains arguments for Bridge initialization.
44 * It used here to check description of the bridge. This array
45 * must contain : [0] - the name of the bridge, [1] - the name of
46 * protocol, [2] - <code>XConnection</code> reference to bridge
49 * Test is <b> NOT </b> multithread compilant. <p>
50 * After test completion object environment has to be recreated.
51 * @see com.sun.star.bridge.XBridge
53 public class _XBridge
extends MultiMethodTest
{
57 protected Object
[] args
;//for object relation 'XInitialization.args'
60 * Retrieves object relations.
61 * @throws StatusException If one of relations not found.
63 public void before() {
64 args
= (Object
[])tEnv
.getObjRelation("XInitialization.args");
66 if (args
== null) throw new StatusException(Status
.failed
67 ("Relation 'XInitialization.args' not found")) ;
68 XInitialization xInit
= UnoRuntime
.queryInterface(
69 XInitialization
.class, oObj
);
71 xInit
.initialize(args
);
73 catch (com
.sun
.star
.uno
.Exception e
) {
74 e
.printStackTrace(log
);
75 throw new StatusException("Can't initialize the bridge", e
);
80 * Tries to retrieve <code>ServiceManager</code> service
81 * using the bridge. <p>
82 * Has <b>OK</b> status if non null object returned.
84 public void _getInstance() {
85 XInterface xInt
= (XInterface
)oObj
.getInstance(
86 "com.sun.star.lang.ServiceManager");
88 tRes
.tested("getInstance()", xInt
!= null);
92 * Retrieves the name of the bridge from relation and compares
93 * it to name returned by the method. <p>
94 * Has <b>OK</b> status if names are equal.
96 public void _getName() {
97 String expectedName
= (String
)args
[0]; // args[0] - bridge name
99 String name
= oObj
.getName();
101 if (!tRes
.tested("getName()", name
.equals(expectedName
))) {
102 log
.println("getName() returns wrong result : \"" + name
+ "\"");
103 log
.println("expected = \"" + expectedName
+ "\"");
108 * Retrieves the description of the bridge and compares it with
109 * expected description composed using relation
110 * <code> ([protocol] + ":" + [connection description]) </code>. <p>
111 * Has <b>OK</b> status if description returned by the method
112 * is equal to expected one.
114 public void _getDescription() {
115 String protocol
= (String
)args
[1]; // args[1] - protocol
116 XConnection xConnection
= (XConnection
)args
[2]; // args[2] - connection
117 // expected description is protocol + ":" + xConnection.getDescription()
118 String expectedDescription
=
119 protocol
+ ":" + xConnection
.getDescription();
121 String description
= oObj
.getDescription();
123 if (!tRes
.tested("getDescription()",
124 description
.equals(expectedDescription
))) {
125 log
.println("getDescription() returns wrong result : \""
126 + description
+ "\"");
127 log
.println("expected = \"" + expectedDescription
+ "\"");
132 * Disposes object environment.
134 public void after() {
135 disposeEnvironment() ;