1620ba73aSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3620ba73aSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4620ba73aSAndrew Rist * or more contributor license agreements. See the NOTICE file 5620ba73aSAndrew Rist * distributed with this work for additional information 6620ba73aSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7620ba73aSAndrew Rist * to you under the Apache License, Version 2.0 (the 8620ba73aSAndrew Rist * "License"); you may not use this file except in compliance 9620ba73aSAndrew Rist * with the License. You may obtain a copy of the License at 10620ba73aSAndrew Rist * 11620ba73aSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12620ba73aSAndrew Rist * 13620ba73aSAndrew Rist * Unless required by applicable law or agreed to in writing, 14620ba73aSAndrew Rist * software distributed under the License is distributed on an 15620ba73aSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16620ba73aSAndrew Rist * KIND, either express or implied. See the License for the 17620ba73aSAndrew Rist * specific language governing permissions and limitations 18620ba73aSAndrew Rist * under the License. 19620ba73aSAndrew Rist * 20620ba73aSAndrew Rist *************************************************************/ 21620ba73aSAndrew Rist 22620ba73aSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir package com.sun.star.lib.uno.bridges.javaremote; 25cdf0e10cSrcweir 26cdf0e10cSrcweir import com.sun.star.bridge.XInstanceProvider; 27cdf0e10cSrcweir import com.sun.star.lib.TestBed; 28cdf0e10cSrcweir import com.sun.star.lib.uno.typeinfo.MethodTypeInfo; 29cdf0e10cSrcweir import com.sun.star.lib.uno.typeinfo.TypeInfo; 30cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 31cdf0e10cSrcweir import com.sun.star.uno.XComponentContext; 32cdf0e10cSrcweir import com.sun.star.uno.XInterface; 33cdf0e10cSrcweir import util.WaitUnreachable; 34cdf0e10cSrcweir 35*9e878ba5SDamjan Jovanovic import org.junit.Test; 36*9e878ba5SDamjan Jovanovic import static org.junit.Assert.*; 37*9e878ba5SDamjan Jovanovic 38*9e878ba5SDamjan Jovanovic 39cdf0e10cSrcweir /** 40cdf0e10cSrcweir * Test case for bug #110892#. 41cdf0e10cSrcweir * 42cdf0e10cSrcweir * <p>Bug #110892# "Java URP bridge holds objects indefinitely" applies to cases 43cdf0e10cSrcweir * where an object is sent from server to client, then recursively back from 44cdf0e10cSrcweir * client to server. In such a case, the client should not increment its 45cdf0e10cSrcweir * internal reference count for the object, as the server will never send back a 46cdf0e10cSrcweir * corresponding release message.</p> 47cdf0e10cSrcweir * 48cdf0e10cSrcweir * <p>This test has to detect whether the spawned client process fails to 49cdf0e10cSrcweir * garbage-collect an object, which can not be done reliably. As an 50cdf0e10cSrcweir * approximation, it waits for 10 sec and considers the process failing if it 51cdf0e10cSrcweir * has not garbage-collected the object by then.</p> 52cdf0e10cSrcweir */ 53*9e878ba5SDamjan Jovanovic public final class Bug110892_Test { 54*9e878ba5SDamjan Jovanovic @Test test()55cdf0e10cSrcweir public void test() throws Exception { 56*9e878ba5SDamjan Jovanovic assertTrue("test", 57cdf0e10cSrcweir new TestBed().execute(new Provider(), false, Client.class, 58cdf0e10cSrcweir 10000)); 59cdf0e10cSrcweir } 60cdf0e10cSrcweir 61cdf0e10cSrcweir public static final class Client extends TestBed.Client { main(String[] args)62cdf0e10cSrcweir public static void main(String[] args) { 63cdf0e10cSrcweir new Client().execute(); 64cdf0e10cSrcweir } 65cdf0e10cSrcweir run(XComponentContext context)66cdf0e10cSrcweir protected boolean run(XComponentContext context) throws Throwable { 67cdf0e10cSrcweir XTest test = UnoRuntime.queryInterface( 68cdf0e10cSrcweir XTest.class, getBridge(context).getInstance("Test")); 69cdf0e10cSrcweir test.start(new ClientObject()); 70cdf0e10cSrcweir synchronized (lock) { 71cdf0e10cSrcweir unreachable.waitUnreachable(); 72cdf0e10cSrcweir } 73cdf0e10cSrcweir return true; 74cdf0e10cSrcweir } 75cdf0e10cSrcweir 76cdf0e10cSrcweir private final class ClientObject implements XClientObject { call(XServerObject server, XInterface object)77cdf0e10cSrcweir public void call(XServerObject server, XInterface object) { 78cdf0e10cSrcweir synchronized (lock) { 79cdf0e10cSrcweir unreachable = new WaitUnreachable(object); 80cdf0e10cSrcweir } 81cdf0e10cSrcweir server.call(object); 82cdf0e10cSrcweir } 83cdf0e10cSrcweir } 84cdf0e10cSrcweir 85cdf0e10cSrcweir private final Object lock = new Object(); 86cdf0e10cSrcweir private WaitUnreachable unreachable = null; 87cdf0e10cSrcweir } 88cdf0e10cSrcweir 89cdf0e10cSrcweir private static final class Provider implements XInstanceProvider { getInstance(String instanceName)90cdf0e10cSrcweir public Object getInstance(String instanceName) { 91cdf0e10cSrcweir return new XTest() { 92cdf0e10cSrcweir public void start(XClientObject client) { 93cdf0e10cSrcweir client.call( 94cdf0e10cSrcweir new XServerObject() { 95cdf0e10cSrcweir public void call(XInterface object) {} 96cdf0e10cSrcweir }, 97cdf0e10cSrcweir new XInterface() {}); 98cdf0e10cSrcweir } 99cdf0e10cSrcweir }; 100cdf0e10cSrcweir } 101cdf0e10cSrcweir } 102cdf0e10cSrcweir 103cdf0e10cSrcweir public interface XClientObject extends XInterface { 104cdf0e10cSrcweir void call(XServerObject server, XInterface object); 105cdf0e10cSrcweir 106cdf0e10cSrcweir TypeInfo[] UNOTYPEINFO = { new MethodTypeInfo("call", 0, 0) }; 107cdf0e10cSrcweir } 108cdf0e10cSrcweir 109cdf0e10cSrcweir public interface XServerObject extends XInterface { 110cdf0e10cSrcweir void call(XInterface object); 111cdf0e10cSrcweir 112cdf0e10cSrcweir TypeInfo[] UNOTYPEINFO = { new MethodTypeInfo("call", 0, 0) }; 113cdf0e10cSrcweir } 114cdf0e10cSrcweir 115cdf0e10cSrcweir public interface XTest extends XInterface { 116cdf0e10cSrcweir void start(XClientObject client); 117cdf0e10cSrcweir 118cdf0e10cSrcweir TypeInfo[] UNOTYPEINFO = { new MethodTypeInfo("start", 0, 0) }; 119cdf0e10cSrcweir } 120cdf0e10cSrcweir } 121