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