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