bump product version to 4.1.6.2
[LibreOffice.git] / bridges / test / java_remote / StopMessageDispatcherTest.java
blobd1c6a3654a8bea8a917cf7d6fa715c13dda287d4
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.lang.DisposedException;
23 import com.sun.star.lib.uno.typeinfo.MethodTypeInfo;
24 import com.sun.star.lib.uno.typeinfo.TypeInfo;
25 import com.sun.star.uno.UnoRuntime;
26 import com.sun.star.uno.XComponentContext;
27 import com.sun.star.uno.XInterface;
28 import complexlib.ComplexTestCase;
29 import test.lib.TestBed;
31 /* This test has to detect whether the spawned client process hangs, which can
32 * not be done reliably. As an approximation, it waits for 10 sec and considers
33 * the process hanging if it has not terminated by then.
35 public final class StopMessageDispatcherTest extends ComplexTestCase {
36 public StopMessageDispatcherTest() {}
38 public String[] getTestMethodNames() {
39 return new String[] { "test" };
42 public void test() throws Exception {
43 assure(
44 "test",
45 new TestBed().execute(new Provider(), false, Client.class, 10000));
48 public static final class Client extends TestBed.Client {
49 public static void main(String[] args) {
50 new Client().execute();
53 protected boolean run(XComponentContext context) throws Throwable {
54 XTest test = UnoRuntime.queryInterface(
55 XTest.class, getBridge(context).getInstance("Test"));
56 Thread[] threads = new Thread[101];
57 int n = Thread.enumerate(threads);
58 if (n > 100) {
59 System.err.println("ERROR: too many threads");
60 return false;
62 boolean stopped = false;
63 for (int i = 0; i < n; ++i) {
64 if (threads[i].getName().equals("MessageDispatcher")) {
65 threads[i].stop();
66 stopped = true;
67 break;
70 if (!stopped) {
71 System.err.println("ERROR: thread not found");
72 return false;
74 try {
75 test.call();
76 System.err.println("ERROR: no DisposedException");
77 return false;
78 } catch (DisposedException e) {
79 return true;
83 private Client() {}
86 private static final class Provider implements XInstanceProvider {
87 public Object getInstance(String instanceName) {
88 return new XTest() {
89 public void call() {}
94 public interface XTest extends XInterface {
95 void call();
97 TypeInfo[] UNOTYPEINFO = { new MethodTypeInfo("call", 0, 0) };