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 compliant. <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.
64 public void before() {
65 args
= (Object
[])tEnv
.getObjRelation("XInitialization.args");
67 if (args
== null) throw new StatusException(Status
.failed
68 ("Relation 'XInitialization.args' not found")) ;
69 XInitialization xInit
= UnoRuntime
.queryInterface(
70 XInitialization
.class, oObj
);
72 xInit
.initialize(args
);
74 catch (com
.sun
.star
.uno
.Exception e
) {
75 e
.printStackTrace(log
);
76 throw new StatusException("Can't initialize the bridge", e
);
81 * Tries to retrieve <code>ServiceManager</code> service
82 * using the bridge. <p>
83 * Has <b>OK</b> status if non null object returned.
85 public void _getInstance() {
86 XInterface xInt
= (XInterface
)oObj
.getInstance(
87 "com.sun.star.lang.ServiceManager");
89 tRes
.tested("getInstance()", xInt
!= null);
93 * Retrieves the name of the bridge from relation and compares
94 * it to name returned by the method. <p>
95 * Has <b>OK</b> status if names are equal.
97 public void _getName() {
98 String expectedName
= (String
)args
[0]; // args[0] - bridge name
100 String name
= oObj
.getName();
102 if (!tRes
.tested("getName()", name
.equals(expectedName
))) {
103 log
.println("getName() returns wrong result : \"" + name
+ "\"");
104 log
.println("expected = \"" + expectedName
+ "\"");
109 * Retrieves the description of the bridge and compares it with
110 * expected description composed using relation
111 * <code> ([protocol] + ":" + [connection description]) </code>. <p>
112 * Has <b>OK</b> status if description returned by the method
113 * is equal to expected one.
115 public void _getDescription() {
116 String protocol
= (String
)args
[1]; // args[1] - protocol
117 XConnection xConnection
= (XConnection
)args
[2]; // args[2] - connection
118 // expected description is protocol + ":" + xConnection.getDescription()
119 String expectedDescription
=
120 protocol
+ ":" + xConnection
.getDescription();
122 String description
= oObj
.getDescription();
124 if (!tRes
.tested("getDescription()",
125 description
.equals(expectedDescription
))) {
126 log
.println("getDescription() returns wrong result : \""
127 + description
+ "\"");
128 log
.println("expected = \"" + expectedDescription
+ "\"");
133 * Disposes object environment.
136 public void after() {
137 disposeEnvironment() ;