1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 package ifc.bridge;
29 
30 import lib.MultiMethodTest;
31 import lib.Status;
32 import lib.StatusException;
33 
34 import com.sun.star.bridge.XBridge;
35 import com.sun.star.connection.XConnection;
36 import com.sun.star.lang.XInitialization;
37 import com.sun.star.uno.UnoRuntime;
38 import com.sun.star.uno.XInterface;
39 
40 
41 /**
42 * Testing <code>com.sun.star.bridge.XBridge</code>
43 * interface methods :
44 * <ul>
45 *  <li><code> getInstance()</code></li>
46 *  <li><code> getName()</code></li>
47 *  <li><code> getDescription()</code></li>
48 * </ul> <p>
49 * This test needs the following object relations :
50 * <ul>
51 *  <li> <code>'XInitialization.args'</code> (of type <code>Object[]</code>):
52 *   relation which contains arguments for Bridge initialization.
53 *   It used here to check description of the bridge. This array
54 *   must contain : [0] - the name of the bridge, [1] - the name of
55 *   protocol, [2] - <code>XConnection</code> reference to bridge
56 *   connection. </li>
57 * <ul> <p>
58 * Test is <b> NOT </b> multithread compilant. <p>
59 * After test completion object environment has to be recreated.
60 * @see com.sun.star.bridge.XBridge
61 */
62 public class _XBridge extends MultiMethodTest {
63 
64     public XBridge oObj;
65 
66     protected Object[] args;//for object relation 'XInitialization.args'
67 
68     /**
69     * Retrieves object relations.
70     * @throws StatusException If one of relations not found.
71     */
72     public void before() {
73         args = (Object[])tEnv.getObjRelation("XInitialization.args");
74 
75         if (args == null) throw new StatusException(Status.failed
76             ("Relation 'XInitialization.args' not found")) ;
77         XInitialization xInit = (XInitialization)UnoRuntime.queryInterface(
78                                        XInitialization.class, oObj);
79         try {
80             xInit.initialize(args);
81         }
82         catch (com.sun.star.uno.Exception e) {
83             e.printStackTrace(log);
84             throw new StatusException("Can't initialize the bridge", e);
85         }
86     }
87 
88     /**
89     * Tries to retrieve <code>ServiceManager</code> service
90     * using the bridge. <p>
91     * Has <b>OK</b> status if non null object returned.
92     */
93     public void _getInstance() {
94         XInterface xInt = (XInterface)oObj.getInstance(
95                 "com.sun.star.lang.ServiceManager");
96 
97         tRes.tested("getInstance()", xInt != null);
98     }
99 
100     /**
101     * Retrieves the name of the bridge from relation and compares
102     * it to name returned by the method. <p>
103     * Has <b>OK</b> status if names are equal.
104     */
105     public void _getName() {
106         String expectedName = (String)args[0]; // args[0] - bridge name
107 
108         String name = oObj.getName();
109 
110         if (!tRes.tested("getName()", name.equals(expectedName))) {
111             log.println("getName() returns wrong result : \"" + name + "\"");
112             log.println("expected = \"" + expectedName + "\"");
113         }
114     }
115 
116     /**
117     * Retrieves the description of the bridge and compares it with
118     * expected description composed using relation
119     * <code> ([protocol] + ":" + [connection description]) </code>. <p>
120     * Has <b>OK</b> status if description returned by the method
121     * is equal to expected one.
122     */
123     public void _getDescription() {
124         String protocol = (String)args[1]; // args[1] - protocol
125         XConnection xConnection = (XConnection)args[2]; // args[2] - connection
126         // expected description is protocol + ":" + xConnection.getDescription()
127         String expectedDescription =
128                 protocol + ":" + xConnection.getDescription();
129 
130         String description = oObj.getDescription();
131 
132         if (!tRes.tested("getDescription()",
133                 description.equals(expectedDescription))) {
134             log.println("getDescription() returns wrong result : \""
135                     + description + "\"");
136             log.println("expected = \"" + expectedDescription + "\"");
137         }
138     }
139 
140     /**
141     * Disposes object environment.
142     */
143     public void after() {
144         disposeEnvironment() ;
145     }
146 
147 }
148 
149