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.lib.uno.typeinfo.MethodTypeInfo; 30 import com.sun.star.lib.uno.typeinfo.TypeInfo; 31 import com.sun.star.uno.UnoRuntime; 32 import com.sun.star.uno.XComponentContext; 33 import com.sun.star.uno.XInterface; 34 import complexlib.ComplexTestCase; 35 36 /** 37 * Test case for bug #97697#. 38 * 39 * <p>Bug #97697# "GPF in java-uno bridge in bugdoc scenario" shows that sending 40 * a plain <code>Object</code> as an <code>Any</code> over the URP bridge lead 41 * to a <code>StackOverflowError</code> on the writer thread, which was silently 42 * discarded (and the bridge was not disposed).</p> 43 * 44 * <p>This test has to detect whether the spawned client process indeed hangs, 45 * which can not be done reliably. As an approximation, it waits for 10 sec and 46 * considers the process hanging if it has not completed by then.</p> 47 */ 48 public final class Bug97697_Test extends ComplexTestCase { getTestObjectName()49 public String getTestObjectName() { 50 return getClass().getName(); 51 } 52 getTestMethodNames()53 public String[] getTestMethodNames() { 54 return new String[] { "test" }; 55 } 56 test()57 public void test() throws Exception { 58 TestBed t = new TestBed(); 59 assure("test", t.execute(new Provider(t), true, Client.class, 10000)); 60 } 61 62 public static final class Client extends TestBed.Client { main(String[] args)63 public static void main(String[] args) { 64 new Client().execute(); 65 } 66 run(XComponentContext context)67 protected boolean run(XComponentContext context) throws Throwable { 68 XTransport transport = UnoRuntime.queryInterface( 69 XTransport.class, getBridge(context).getInstance("Transport")); 70 try { 71 transport.getAny(); 72 } catch (DisposedException e) { 73 return true; 74 } 75 return false; 76 } 77 } 78 79 private static final class Provider implements XInstanceProvider { Provider(TestBed testBed)80 public Provider(TestBed testBed) { 81 this.testBed = testBed; 82 } 83 getInstance(String instanceName)84 public Object getInstance(String instanceName) { 85 return new XTransport() { 86 public Object getAny() { 87 testBed.serverDone(true); 88 return new Object(); 89 } 90 }; 91 } 92 93 private final TestBed testBed; 94 } 95 96 public interface XTransport extends XInterface { 97 Object getAny(); 98 99 TypeInfo[] UNOTYPEINFO = { new MethodTypeInfo("getAny", 0, 0) }; 100 } 101 } 102