1ef39d40dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3ef39d40dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4ef39d40dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5ef39d40dSAndrew Rist * distributed with this work for additional information 6ef39d40dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7ef39d40dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8ef39d40dSAndrew Rist * "License"); you may not use this file except in compliance 9ef39d40dSAndrew Rist * with the License. You may obtain a copy of the License at 10ef39d40dSAndrew Rist * 11ef39d40dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12ef39d40dSAndrew Rist * 13ef39d40dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14ef39d40dSAndrew Rist * software distributed under the License is distributed on an 15ef39d40dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16ef39d40dSAndrew Rist * KIND, either express or implied. See the License for the 17ef39d40dSAndrew Rist * specific language governing permissions and limitations 18ef39d40dSAndrew Rist * under the License. 19ef39d40dSAndrew Rist * 20ef39d40dSAndrew Rist *************************************************************/ 21ef39d40dSAndrew Rist 22ef39d40dSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir package ifc.reflection; 25cdf0e10cSrcweir 26cdf0e10cSrcweir import lib.MultiMethodTest; 27cdf0e10cSrcweir 28cdf0e10cSrcweir import com.sun.star.lang.XInitialization; 29cdf0e10cSrcweir import com.sun.star.reflection.XProxyFactory; 30cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 31cdf0e10cSrcweir import com.sun.star.uno.XAggregation; 32cdf0e10cSrcweir 33cdf0e10cSrcweir /** 34cdf0e10cSrcweir /** 35cdf0e10cSrcweir * Testing <code>com.sun.star.reflection.XProxyFactory</code> 36cdf0e10cSrcweir * interface methods : 37cdf0e10cSrcweir * <ul> 38cdf0e10cSrcweir * <li><code> createProxy()</code></li> 39cdf0e10cSrcweir * </ul> <p> 40cdf0e10cSrcweir * Test is <b> NOT </b> multithread compilant. <p> 41cdf0e10cSrcweir * @see com.sun.star.reflection.XProxyFactory 42cdf0e10cSrcweir */ 43cdf0e10cSrcweir public class _XProxyFactory extends MultiMethodTest { 44cdf0e10cSrcweir /** Is initialized in super class(using reflection API) 45cdf0e10cSrcweir * when instantiating the test. 46cdf0e10cSrcweir */ 47cdf0e10cSrcweir public XProxyFactory oObj; 48cdf0e10cSrcweir 49cdf0e10cSrcweir /** 50cdf0e10cSrcweir * First an implementation of 51cdf0e10cSrcweir * <code>com.sun.star.lang.XInitialization</code> interface 52cdf0e10cSrcweir * is made which sets a flag when its <code>initialize()</code> 53cdf0e10cSrcweir * method is called. Then an instance of this implementation 54cdf0e10cSrcweir * is created and a proxy object is created for it. Proxy 55cdf0e10cSrcweir * object is tried to query for <code>XInitialization</code> 56cdf0e10cSrcweir * interface and it's <code>initialize</code> method is 57cdf0e10cSrcweir * called. The goal is to check if the real object method 58cdf0e10cSrcweir * was called throwgh it's proxy. <p> 59cdf0e10cSrcweir * Has <b>OK</b> status if the real object method was 60*bb6af6bcSPedro Giffuni * called and parameters were passed correctly. 61cdf0e10cSrcweir */ _createProxy()62cdf0e10cSrcweir public void _createProxy() { 63cdf0e10cSrcweir class MyObject implements XInitialization { 64cdf0e10cSrcweir Object[] params; 65cdf0e10cSrcweir 66cdf0e10cSrcweir public void initialize(Object args[]) { 67cdf0e10cSrcweir params = args; 68cdf0e10cSrcweir } 69cdf0e10cSrcweir } 70cdf0e10cSrcweir 71cdf0e10cSrcweir MyObject obj = new MyObject(); 72cdf0e10cSrcweir 73cdf0e10cSrcweir XAggregation xAggr = oObj.createProxy(obj); 74cdf0e10cSrcweir 75cdf0e10cSrcweir XInitialization xInit = (XInitialization)UnoRuntime.queryInterface( 76cdf0e10cSrcweir XInitialization.class, xAggr); 77cdf0e10cSrcweir 78cdf0e10cSrcweir Object params[] = new Object[0]; 79cdf0e10cSrcweir 80cdf0e10cSrcweir try { 81cdf0e10cSrcweir xInit.initialize(params); 82cdf0e10cSrcweir } catch(com.sun.star.uno.Exception e) { 83cdf0e10cSrcweir log.println("Unexpected exception : " + e.getMessage()); 84cdf0e10cSrcweir e.printStackTrace(log); 85cdf0e10cSrcweir tRes.tested("createProxy()", false); 86cdf0e10cSrcweir return; 87cdf0e10cSrcweir } 88cdf0e10cSrcweir 89cdf0e10cSrcweir tRes.tested("createProxy()", 90cdf0e10cSrcweir util.ValueComparer.equalValue(params, obj.params)); 91cdf0e10cSrcweir } 92cdf0e10cSrcweir } 93cdf0e10cSrcweir 94