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.lib.uno.bridges.javaremote;
25 
26 import com.sun.star.bridge.XInstanceProvider;
27 import com.sun.star.lang.DisposedException;
28 import com.sun.star.lib.TestBed;
29 import com.sun.star.uno.UnoRuntime;
30 import com.sun.star.uno.XComponentContext;
31 import complexlib.ComplexTestCase;
32 
33 /**
34  * Test case for bug #98508#.
35  *
36  * <p>Bug #98508# "JAVA UNO bridge is not disposed when Exception occures during
37  * sendReply()" states that the server returning <code>null</code> instead of a
38  * valid <code>String</code> from <code>XServiceName.getServiceName</code>
39  * causes an exception when sending the reply, but this exception did not cause
40  * the bridge to be disposed, it rather caused both client and server to
41  * hang.</p>
42  *
43  * <p>Since null instead of a <code>String</code> no longer causes an exception
44  * in the bridge, this test has been redesigned to send a value of a wrong
45  * instantiated polymorphic struct type instead.</p>
46  *
47  * <p>This test has to detect whether the spawned client process indeed hangs,
48  * which can not be done reliably.  As an approximation, it waits for 10 sec and
49  * considers the process hanging if it has not completed by then.</p>
50  */
51 public final class Bug98508_Test extends ComplexTestCase {
getTestObjectName()52     public String getTestObjectName() {
53         return getClass().getName();
54     }
55 
getTestMethodNames()56     public String[] getTestMethodNames() {
57         return new String[] { "test" };
58     }
59 
test()60     public void test() throws Exception {
61         TestBed t = new TestBed();
62         assure("test", t.execute(new Provider(t), true, Client.class, 10000));
63     }
64 
65     public static final class Client extends TestBed.Client {
main(String[] args)66         public static void main(String[] args) {
67             new Client().execute();
68         }
69 
run(XComponentContext context)70         protected boolean run(XComponentContext context) throws Throwable {
71             Test98508Interface ifc
72                 = UnoRuntime.queryInterface(
73                     Test98508Interface.class,
74                     getBridge(context).getInstance(""));
75             try {
76                 ifc.get();
77             } catch (DisposedException e) {
78                 return true;
79             }
80             return false;
81         }
82     }
83 
84     private static final class Provider implements XInstanceProvider {
Provider(TestBed testBed)85         public Provider(TestBed testBed) {
86             this.testBed = testBed;
87         }
88 
getInstance(String instanceName)89         public Object getInstance(String instanceName) {
90             return new Test98508Interface() {
91                     public Test98508Struct get() {
92                         testBed.serverDone(true);
93                         return new Test98508Struct(Boolean.FALSE);
94                     }
95                 };
96         }
97 
98         private final TestBed testBed;
99     }
100 }
101