1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: UnoRuntime_EnvironmentTest.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package com
.sun
.star
.uno
;
33 import com
.sun
.star
.comp
.connections
.PipedConnection
;
34 import complexlib
.ComplexTestCase
;
35 import util
.WaitUnreachable
;
37 public final class UnoRuntime_EnvironmentTest
extends ComplexTestCase
{
38 public String
getTestObjectName() {
39 return getClass().getName();
42 public String
[] getTestMethodNames() {
43 return new String
[] { "test_getEnvironment", "test_getBridge" };
46 public void test_getEnvironment() throws java
.lang
.Exception
{
47 Object o1
= new Object();
48 Object o2
= new Object();
50 // get two environments with different contexts
51 WaitUnreachable java_environment1
= new WaitUnreachable(
52 UnoRuntime
.getEnvironment("java", o1
));
53 WaitUnreachable java_environment2
= new WaitUnreachable(
54 UnoRuntime
.getEnvironment("java", o2
));
56 // ensure that the environments are different
57 assure("", java_environment1
.get() != java_environment2
.get());
59 // test if we get the same environment when we reget it
61 UnoRuntime
.areSame(java_environment1
.get(),
62 UnoRuntime
.getEnvironment("java", o1
)));
64 UnoRuntime
.areSame(java_environment2
.get(),
65 UnoRuntime
.getEnvironment("java", o2
)));
67 // drop the environments and wait until they are gc
68 java_environment1
.waitUnreachable();
69 java_environment2
.waitUnreachable();
72 public void test_getBridge() throws java
.lang
.Exception
{
73 PipedConnection conn
= new PipedConnection(new Object
[0]);
74 new PipedConnection(new Object
[] { conn
});
77 IBridge iBridge
= UnoRuntime
.getBridgeByName(
78 "java", null, "remote", "testname",
79 new Object
[] { "urp", conn
, null });
81 // reget the bridge, it must be the same as above
82 IBridge iBridge_tmp
= UnoRuntime
.getBridgeByName(
83 "java", null, "remote", "testname",
84 new Object
[] { "urp", conn
, null });
85 assure("", UnoRuntime
.areSame(iBridge_tmp
, iBridge
));
87 // dispose the bridge, this removes the entry from the runtime
90 conn
= new PipedConnection(new Object
[0]);
91 new PipedConnection(new Object
[] { conn
});
93 // reget the bridge, it must be a different one
94 iBridge_tmp
= UnoRuntime
.getBridgeByName(
95 "java", null, "remote", "testname",
96 new Object
[]{ "urp", conn
, null });
97 assure("", !UnoRuntime
.areSame(iBridge_tmp
, iBridge
));