1*2be43276SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*2be43276SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*2be43276SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*2be43276SAndrew Rist * distributed with this work for additional information 6*2be43276SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*2be43276SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*2be43276SAndrew Rist * "License"); you may not use this file except in compliance 9*2be43276SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*2be43276SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*2be43276SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*2be43276SAndrew Rist * software distributed under the License is distributed on an 15*2be43276SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*2be43276SAndrew Rist * KIND, either express or implied. See the License for the 17*2be43276SAndrew Rist * specific language governing permissions and limitations 18*2be43276SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*2be43276SAndrew Rist *************************************************************/ 21*2be43276SAndrew Rist 22*2be43276SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir package com.sun.star.uno; 25cdf0e10cSrcweir 26cdf0e10cSrcweir import com.sun.star.comp.connections.PipedConnection; 27cdf0e10cSrcweir import complexlib.ComplexTestCase; 28cdf0e10cSrcweir import util.WaitUnreachable; 29cdf0e10cSrcweir 30cdf0e10cSrcweir public final class UnoRuntime_EnvironmentTest extends ComplexTestCase { getTestObjectName()31cdf0e10cSrcweir public String getTestObjectName() { 32cdf0e10cSrcweir return getClass().getName(); 33cdf0e10cSrcweir } 34cdf0e10cSrcweir getTestMethodNames()35cdf0e10cSrcweir public String[] getTestMethodNames() { 36cdf0e10cSrcweir return new String[] { "test_getEnvironment", "test_getBridge" }; 37cdf0e10cSrcweir } 38cdf0e10cSrcweir test_getEnvironment()39cdf0e10cSrcweir public void test_getEnvironment() throws java.lang.Exception { 40cdf0e10cSrcweir Object o1 = new Object(); 41cdf0e10cSrcweir Object o2 = new Object(); 42cdf0e10cSrcweir 43cdf0e10cSrcweir // get two environments with different contexts 44cdf0e10cSrcweir WaitUnreachable java_environment1 = new WaitUnreachable( 45cdf0e10cSrcweir UnoRuntime.getEnvironment("java", o1)); 46cdf0e10cSrcweir WaitUnreachable java_environment2 = new WaitUnreachable( 47cdf0e10cSrcweir UnoRuntime.getEnvironment("java", o2)); 48cdf0e10cSrcweir 49cdf0e10cSrcweir // ensure that the environments are different 50cdf0e10cSrcweir assure("", java_environment1.get() != java_environment2.get()); 51cdf0e10cSrcweir 52cdf0e10cSrcweir // test if we get the same environment when we reget it 53cdf0e10cSrcweir assure("", 54cdf0e10cSrcweir UnoRuntime.areSame(java_environment1.get(), 55cdf0e10cSrcweir UnoRuntime.getEnvironment("java", o1))); 56cdf0e10cSrcweir assure("", 57cdf0e10cSrcweir UnoRuntime.areSame(java_environment2.get(), 58cdf0e10cSrcweir UnoRuntime.getEnvironment("java", o2))); 59cdf0e10cSrcweir 60cdf0e10cSrcweir // drop the environments and wait until they are gc 61cdf0e10cSrcweir java_environment1.waitUnreachable(); 62cdf0e10cSrcweir java_environment2.waitUnreachable(); 63cdf0e10cSrcweir } 64cdf0e10cSrcweir test_getBridge()65cdf0e10cSrcweir public void test_getBridge() throws java.lang.Exception { 66cdf0e10cSrcweir PipedConnection conn = new PipedConnection(new Object[0]); 67cdf0e10cSrcweir new PipedConnection(new Object[] { conn }); 68cdf0e10cSrcweir 69cdf0e10cSrcweir // get a bridge 70cdf0e10cSrcweir IBridge iBridge = UnoRuntime.getBridgeByName( 71cdf0e10cSrcweir "java", null, "remote", "testname", 72cdf0e10cSrcweir new Object[] { "urp", conn, null }); 73cdf0e10cSrcweir 74cdf0e10cSrcweir // reget the bridge, it must be the same as above 75cdf0e10cSrcweir IBridge iBridge_tmp = UnoRuntime.getBridgeByName( 76cdf0e10cSrcweir "java", null, "remote", "testname", 77cdf0e10cSrcweir new Object[] { "urp", conn, null }); 78cdf0e10cSrcweir assure("", UnoRuntime.areSame(iBridge_tmp, iBridge)); 79cdf0e10cSrcweir 80cdf0e10cSrcweir // dispose the bridge, this removes the entry from the runtime 81cdf0e10cSrcweir iBridge.dispose(); 82cdf0e10cSrcweir 83cdf0e10cSrcweir conn = new PipedConnection(new Object[0]); 84cdf0e10cSrcweir new PipedConnection(new Object[] { conn }); 85cdf0e10cSrcweir 86cdf0e10cSrcweir // reget the bridge, it must be a different one 87cdf0e10cSrcweir iBridge_tmp = UnoRuntime.getBridgeByName( 88cdf0e10cSrcweir "java", null, "remote", "testname", 89cdf0e10cSrcweir new Object[]{ "urp", conn, null }); 90cdf0e10cSrcweir assure("", !UnoRuntime.areSame(iBridge_tmp, iBridge)); 91cdf0e10cSrcweir } 92cdf0e10cSrcweir } 93