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 ifc.reflection;
25 
26 import lib.MultiMethodTest;
27 
28 import com.sun.star.lang.XInitialization;
29 import com.sun.star.reflection.XProxyFactory;
30 import com.sun.star.uno.UnoRuntime;
31 import com.sun.star.uno.XAggregation;
32 
33 /**
34 /**
35 * Testing <code>com.sun.star.reflection.XProxyFactory</code>
36 * interface methods :
37 * <ul>
38 *  <li><code> createProxy()</code></li>
39 * </ul> <p>
40 * Test is <b> NOT </b> multithread compilant. <p>
41 * @see com.sun.star.reflection.XProxyFactory
42 */
43 public class _XProxyFactory extends MultiMethodTest {
44     /** Is initialized in super class(using reflection API)
45      * when instantiating the test.
46      */
47     public XProxyFactory oObj;
48 
49     /**
50     * First an implementation of
51     * <code>com.sun.star.lang.XInitialization</code> interface
52     * is made which sets a flag when its <code>initialize()</code>
53     * method is called. Then an instance of this implementation
54     * is created and a proxy object is created for it. Proxy
55     * object is tried to query for <code>XInitialization</code>
56     * interface and it's <code>initialize</code> method is
57     * called. The goal is to check if the real object method
58     * was called throwgh it's proxy. <p>
59     * Has <b>OK</b> status if the real object method was
60     * called and paramters were passed correctly.
61     */
_createProxy()62     public void _createProxy() {
63         class MyObject implements XInitialization {
64             Object[] params;
65 
66             public void initialize(Object args[]) {
67                 params = args;
68             }
69         }
70 
71         MyObject obj = new MyObject();
72 
73         XAggregation xAggr = oObj.createProxy(obj);
74 
75         XInitialization xInit = (XInitialization)UnoRuntime.queryInterface(
76                 XInitialization.class, xAggr);
77 
78         Object params[] = new Object[0];
79 
80         try {
81             xInit.initialize(params);
82         } catch(com.sun.star.uno.Exception e) {
83             log.println("Unexpected exception : " + e.getMessage());
84             e.printStackTrace(log);
85             tRes.tested("createProxy()", false);
86             return;
87         }
88 
89         tRes.tested("createProxy()",
90             util.ValueComparer.equalValue(params, obj.params));
91     }
92 }
93 
94