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