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.uno;
29 
30 import com.sun.star.comp.connections.PipedConnection;
31 import complexlib.ComplexTestCase;
32 import util.WaitUnreachable;
33 
34 public final class UnoRuntime_EnvironmentTest extends ComplexTestCase {
35     public String getTestObjectName() {
36         return getClass().getName();
37     }
38 
39     public String[] getTestMethodNames() {
40         return new String[] { "test_getEnvironment", "test_getBridge" };
41     }
42 
43     public void test_getEnvironment() throws java.lang.Exception {
44         Object o1 = new Object();
45         Object o2 = new Object();
46 
47         // get two environments with different contexts
48         WaitUnreachable java_environment1 = new WaitUnreachable(
49             UnoRuntime.getEnvironment("java", o1));
50         WaitUnreachable java_environment2 = new WaitUnreachable(
51             UnoRuntime.getEnvironment("java", o2));
52 
53         // ensure that the environments are different
54         assure("", java_environment1.get() != java_environment2.get());
55 
56         // test if we get the same environment when we reget it
57         assure("",
58                UnoRuntime.areSame(java_environment1.get(),
59                                   UnoRuntime.getEnvironment("java", o1)));
60         assure("",
61                UnoRuntime.areSame(java_environment2.get(),
62                                   UnoRuntime.getEnvironment("java", o2)));
63 
64         // drop the environments and wait until they are gc
65         java_environment1.waitUnreachable();
66         java_environment2.waitUnreachable();
67     }
68 
69     public void test_getBridge() throws java.lang.Exception {
70         PipedConnection conn = new PipedConnection(new Object[0]);
71         new PipedConnection(new Object[] { conn });
72 
73         // get a bridge
74         IBridge iBridge = UnoRuntime.getBridgeByName(
75             "java", null, "remote", "testname",
76             new Object[] { "urp", conn, null });
77 
78         // reget the bridge, it must be the same as above
79         IBridge iBridge_tmp = UnoRuntime.getBridgeByName(
80             "java", null, "remote", "testname",
81             new Object[] { "urp", conn, null });
82         assure("", UnoRuntime.areSame(iBridge_tmp, iBridge));
83 
84         // dispose the bridge, this removes the entry from the runtime
85         iBridge.dispose();
86 
87         conn = new PipedConnection(new Object[0]);
88         new PipedConnection(new Object[] { conn });
89 
90         // reget the bridge, it must be a different one
91         iBridge_tmp = UnoRuntime.getBridgeByName(
92             "java", null, "remote", "testname",
93             new Object[]{ "urp", conn, null });
94         assure("", !UnoRuntime.areSame(iBridge_tmp, iBridge));
95     }
96 }
97