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.lib.TestBed;
28 import com.sun.star.lib.uno.typeinfo.MethodTypeInfo;
29 import com.sun.star.lib.uno.typeinfo.TypeInfo;
30 import com.sun.star.uno.UnoRuntime;
31 import com.sun.star.uno.XComponentContext;
32 import com.sun.star.uno.XInterface;
33 import complexlib.ComplexTestCase;
34 
35 /**
36  * Test case for bug #111153#.
37  *
38  * <P>Bug #111153# "jni_uno bridge sometimes fails to map objects
39  * correctly" describes that mapping a local object out with type XDerived and
40  * then mapping it back in with type XBase produces a proxy, instead of
41  * short-cutting to the local object.</P>
42  */
43 public final class Bug111153_Test extends ComplexTestCase {
getTestMethodNames()44     public String[] getTestMethodNames() {
45         return new String[] { "test" };
46     }
47 
test()48     public void test() throws Exception {
49         assure("test", new TestBed().execute(new Provider(), false,
50                                              Client.class, 0));
51     }
52 
53     public static final class Client extends TestBed.Client {
main(String[] args)54         public static void main(String[] args) {
55             new Client().execute();
56         }
57 
run(XComponentContext context)58         protected boolean run(XComponentContext context) throws Throwable {
59             XTransport t = UnoRuntime.queryInterface(
60                 XTransport.class, getBridge(context).getInstance("Transport"));
61             XDerived d = new XDerived() {};
62             t.setDerived(d);
63             return t.getBase() == d;
64         }
65     }
66 
67     private static final class Provider implements XInstanceProvider {
getInstance(String instanceName)68         public Object getInstance(String instanceName) {
69             return new XTransport() {
70                     public synchronized void setDerived(XDerived derived) {
71                         this.derived = derived;
72                     }
73 
74                     public synchronized XBase getBase() {
75                         return this.derived;
76                     }
77 
78                     private XDerived derived = null;
79                 };
80         }
81     }
82 
83     public interface XBase extends XInterface {
84         TypeInfo[] UNOTYPEINFO = null;
85     }
86 
87     public interface XDerived extends XBase {
88         TypeInfo[] UNOTYPEINFO = null;
89     }
90 
91     public interface XTransport extends XInterface {
92         void setDerived(XDerived derived);
93 
94         XBase getBase();
95 
96         TypeInfo[] UNOTYPEINFO = { new MethodTypeInfo("setDerived", 0, 0),
97                                    new MethodTypeInfo("getBase", 1, 0) };
98     }
99 }
100