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.script;
25 
26 import lib.MultiMethodTest;
27 import lib.StatusException;
28 
29 import com.sun.star.io.XInputStream;
30 import com.sun.star.lang.XMultiServiceFactory;
31 import com.sun.star.lang.XSingleServiceFactory;
32 import com.sun.star.script.XInvocation;
33 import com.sun.star.script.XInvocationAdapterFactory;
34 import com.sun.star.uno.Type;
35 import com.sun.star.uno.UnoRuntime;
36 import com.sun.star.uno.XInterface;
37 
38 /**
39 * Testing <code>com.sun.star.script.XInvocationAdapterFactory</code>
40 * interface methods :
41 * <ul>
42 *  <li><code> createAdapter()</code></li>
43 * </ul> <p>
44 * Test is <b> NOT </b> multithread compilant. <p>
45 * @see com.sun.star.script.XInvocationAdapterFactory
46 */
47 public class _XInvocationAdapterFactory extends MultiMethodTest {
48 
49     /**
50      * oObj filled by MultiMethodTest
51      */
52     public XInvocationAdapterFactory oObj = null;
53 
54     /**
55     * First an invocation object of <code>com.sun.star.io.Pipe</code>
56     * instance is created using <code>com.sun.star.script.Invocation
57     * </code> service. Then trying to create an adapter of this
58     * invocation for <code>com.sun.star.io.XInputStream</code>
59     * interface. <p>
60     * Has <b>OK</b> status if the adapter returned is successfully
61     * queried for <code>com.sun.star.io.XInputStream</code>
62     * interface.
63     * @see com.sun.star.script.Invocation
64     * @see com.sun.star.script.XInvocation
65     * @see com.sun.star.io.Pipe
66     */
_createAdapter()67     public void _createAdapter() {
68         XInvocation xInv = null ;
69         XMultiServiceFactory xMSF = null;
70         try {
71             xMSF = (XMultiServiceFactory)tParam.getMSF();
72             Object[] args = {xMSF.createInstance
73                 ("com.sun.star.io.Pipe")};
74 
75             Object oInvFac = xMSF.createInstance
76                 ("com.sun.star.script.Invocation") ;
77 
78             XSingleServiceFactory xInvFac = (XSingleServiceFactory) UnoRuntime.
79                 queryInterface(XSingleServiceFactory.class, oInvFac) ;
80 
81             Object oInv = xInvFac.createInstanceWithArguments(args) ;
82 
83             xInv = (XInvocation) UnoRuntime.queryInterface
84                 (XInvocation.class, oInv) ;
85 
86         } catch (com.sun.star.uno.Exception e) {
87             e.printStackTrace(log) ;
88             throw new StatusException("Cann't create invocation for object", e) ;
89         }
90 
91         XInterface xInStr = null ;
92 
93         Object adp = oObj.createAdapter(xInv,
94                 new Type(XInputStream.class)) ;
95 
96         xInStr = (XInterface) UnoRuntime.queryInterface
97                 (XInputStream.class, adp) ;
98 
99 
100         if (xInStr != null)
101             tRes.tested("createAdapter()", true) ;
102         else {
103             log.println("Adapter created doesn't implement required interface") ;
104             tRes.tested("createAdapter()", false) ;
105         }
106     }
107 }
108 
109