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