bump product version to 4.1.6.2
[LibreOffice.git] / bridges / test / java_remote / Bug110892_Test.java
blob3216ea96ef26945f2ae728407b02daf52c4aa034
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package test.java_remote;
21 import com.sun.star.bridge.XInstanceProvider;
22 import com.sun.star.lib.uno.typeinfo.MethodTypeInfo;
23 import com.sun.star.lib.uno.typeinfo.TypeInfo;
24 import com.sun.star.uno.UnoRuntime;
25 import com.sun.star.uno.XComponentContext;
26 import com.sun.star.uno.XInterface;
27 import complexlib.ComplexTestCase;
28 import util.WaitUnreachable;
29 import test.lib.TestBed;
31 /**
32 * Test case for bug #110892#.
34 * <p>Bug #110892# "Java URP bridge holds objects indefinitely" applies to cases
35 * where an object is sent from server to client, then recursively back from
36 * client to server. In such a case, the client should not increment its
37 * internal reference count for the object, as the server will never send back a
38 * corresponding release message.</p>
40 * <p>This test has to detect whether the spawned client process fails to
41 * garbage-collect an object, which can not be done reliably. As an
42 * approximation, it waits for 10 sec and considers the process failing if it
43 * has not garbage-collected the object by then.</p>
45 public final class Bug110892_Test extends ComplexTestCase {
46 public String[] getTestMethodNames() {
47 return new String[] { "test" };
50 public void test() throws Exception {
51 assure("test",
52 new TestBed().execute(new Provider(), false, Client.class,
53 10000));
56 public static final class Client extends TestBed.Client {
57 public static void main(String[] args) {
58 new Client().execute();
61 protected boolean run(XComponentContext context) throws Throwable {
62 XTest test = UnoRuntime.queryInterface(
63 XTest.class, getBridge(context).getInstance("Test"));
64 test.start(new ClientObject());
65 synchronized (lock) {
66 unreachable.waitUnreachable();
68 return true;
71 private final class ClientObject implements XClientObject {
72 public void call(XServerObject server, XInterface object) {
73 synchronized (lock) {
74 unreachable = new WaitUnreachable(object);
76 server.call(object);
80 private final Object lock = new Object();
81 private WaitUnreachable unreachable = null;
84 private static final class Provider implements XInstanceProvider {
85 public Object getInstance(String instanceName) {
86 return new XTest() {
87 public void start(XClientObject client) {
88 client.call(
89 new XServerObject() {
90 public void call(XInterface object) {}
92 new XInterface() {});
98 public interface XClientObject extends XInterface {
99 void call(XServerObject server, XInterface object);
101 TypeInfo[] UNOTYPEINFO = { new MethodTypeInfo("call", 0, 0) };
104 public interface XServerObject extends XInterface {
105 void call(XInterface object);
107 TypeInfo[] UNOTYPEINFO = { new MethodTypeInfo("call", 0, 0) };
110 public interface XTest extends XInterface {
111 void start(XClientObject client);
113 TypeInfo[] UNOTYPEINFO = { new MethodTypeInfo("start", 0, 0) };