1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 package ifc.script;
29 
30 import lib.MultiMethodTest;
31 import lib.StatusException;
32 
33 import com.sun.star.io.XInputStream;
34 import com.sun.star.lang.XMultiServiceFactory;
35 import com.sun.star.lang.XSingleServiceFactory;
36 import com.sun.star.script.XInvocation;
37 import com.sun.star.script.XInvocationAdapterFactory2;
38 import com.sun.star.uno.Type;
39 import com.sun.star.uno.UnoRuntime;
40 import com.sun.star.uno.XInterface;
41 
42 /**
43 * Testing <code>com.sun.star.script.XInvocationAdapterFactory</code>
44 * interface methods :
45 * <ul>
46 *  <li><code> createAdapter()</code></li>
47 * </ul> <p>
48 * Test is <b> NOT </b> multithread compilant. <p>
49 * @see com.sun.star.script.XInvocationAdapterFactory
50 */
51 public class _XInvocationAdapterFactory2 extends MultiMethodTest {
52 
53     /**
54      * oObj filled by MultiMethodTest
55      */
56     public XInvocationAdapterFactory2 oObj = null;
57 
58     /**
59     * First an invocation object of <code>com.sun.star.io.Pipe</code>
60     * instance is created using <code>com.sun.star.script.Invocation
61     * </code> service. Then trying to create an adapter of this
62     * invocation for <code>com.sun.star.io.XInputStream</code>
63     * interface. <p>
64     * Has <b>OK</b> status if the adapter returned is successfully
65     * queried for <code>com.sun.star.io.XInputStream</code>
66     * interface.
67     * @see com.sun.star.script.Invocation
68     * @see com.sun.star.script.XInvocation
69     * @see com.sun.star.io.Pipe
70     */
71     public void _createAdapter() {
72         XInvocation xInv = null ;
73         XMultiServiceFactory xMSF = null;
74         try {
75             xMSF = (XMultiServiceFactory)tParam.getMSF();
76             Object[] args = {xMSF.createInstance
77                 ("com.sun.star.io.Pipe")};
78 
79             Object oInvFac = xMSF.createInstance
80                 ("com.sun.star.script.Invocation") ;
81 
82             XSingleServiceFactory xInvFac = (XSingleServiceFactory) UnoRuntime.
83                 queryInterface(XSingleServiceFactory.class, oInvFac) ;
84 
85             Object oInv = xInvFac.createInstanceWithArguments(args) ;
86 
87             xInv = (XInvocation) UnoRuntime.queryInterface
88                 (XInvocation.class, oInv) ;
89 
90         } catch (com.sun.star.uno.Exception e) {
91             e.printStackTrace(log) ;
92             throw new StatusException("Cann't create invocation for object", e) ;
93         }
94 
95         XInterface xInStr = null ;
96 
97         Type[] types = new Type[1];
98         types[0] = new Type(XInputStream.class);
99 
100         Object adp = oObj.createAdapter(xInv,types);
101 
102         xInStr = (XInterface) UnoRuntime.queryInterface
103                 (XInputStream.class, adp) ;
104 
105 
106         if (xInStr != null)
107             tRes.tested("createAdapter()", true) ;
108         else {
109             log.println("Adapter created doesn't implement required interface") ;
110             tRes.tested("createAdapter()", false) ;
111         }
112     }
113 }
114 
115