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 com.sun.star.comp.bridgefactory;
25 
26 import com.sun.star.bridge.BridgeExistsException;
27 import com.sun.star.bridge.XBridge;
28 import com.sun.star.comp.connections.PipedConnection;
29 import com.sun.star.connection.XConnection;
30 import com.sun.star.lang.XComponent;
31 import com.sun.star.uno.UnoRuntime;
32 import complexlib.ComplexTestCase;
33 
34 public final class BridgeFactory_Test extends ComplexTestCase {
getTestObjectName()35     public String getTestObjectName() {
36         return getClass().getName();
37     }
38 
getTestMethodNames()39     public String[] getTestMethodNames() {
40         return new String[] { "test" };
41     }
42 
test()43     public void test() throws Exception {
44         PipedConnection rightSide = new PipedConnection(new Object[0]);
45         PipedConnection leftSide = new PipedConnection(new Object[]{rightSide});
46 
47         BridgeFactory bridgeFactory = new BridgeFactory(); // create the needed bridgeFactory
48 
49         // create a bridge
50         XBridge xBridge = bridgeFactory.createBridge("testbridge", "urp", (XConnection)leftSide, null);
51 
52         // test that we get the same bridge
53         assure("", UnoRuntime.areSame(xBridge,
54                                       bridgeFactory.getBridge("testbridge")));
55 
56         // test that we can not create another bridge with same name
57         try {
58             XBridge dummy = bridgeFactory.createBridge("testbridge", "urp", (XConnection)leftSide, null);
59 
60             failed("");
61         }
62         catch(BridgeExistsException bridgeExistsException) {
63         }
64 
65 
66         // test getExistingBridges
67         XBridge xBridges[] = bridgeFactory.getExistingBridges();
68         assure("", UnoRuntime.areSame(xBridge, xBridges[0]));
69 
70         // dispose the bridge
71         XComponent xComponent = UnoRuntime.queryInterface(XComponent.class, xBridge);
72         xComponent.dispose();
73 
74 
75         // test that the bridge has been removed
76         assure("", bridgeFactory.getBridge("testbridge") == null);
77 
78 
79 
80         rightSide = new PipedConnection(new Object[0]);
81         leftSide = new PipedConnection(new Object[]{rightSide});
82 
83 
84         // test that we really get a new bridge
85         XBridge xBridge_new = bridgeFactory.createBridge("testbridge", "urp", (XConnection)leftSide, null);
86         assure("", !UnoRuntime.areSame(xBridge, xBridge_new));
87 
88         for(int i = 0; i <10000; ++ i) {
89             Object x[] = new Object[100];
90         }
91 
92         // test getExistingBridges
93         xBridges = bridgeFactory.getExistingBridges();
94         assure("",
95                xBridges.length == 1
96                && UnoRuntime.areSame(xBridge_new, xBridges[0]));
97 
98         // dispose the new bridge
99         XComponent xComponent_new = UnoRuntime.queryInterface(XComponent.class, xBridge_new);
100         xComponent_new.dispose();
101     }
102 }
103