Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / qadevOOo / tests / java / ifc / script / _XInvocationAdapterFactory2.java
blob50a56398697478972ea42e6a73cd585e452493e6
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 package ifc.script;
30 import lib.MultiMethodTest;
31 import lib.StatusException;
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;
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
51 public class _XInvocationAdapterFactory2 extends MultiMethodTest {
53 /**
54 * oObj filled by MultiMethodTest
56 public XInvocationAdapterFactory2 oObj = null;
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
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")};
79 Object oInvFac = xMSF.createInstance
80 ("com.sun.star.script.Invocation") ;
82 XSingleServiceFactory xInvFac = (XSingleServiceFactory) UnoRuntime.
83 queryInterface(XSingleServiceFactory.class, oInvFac) ;
85 Object oInv = xInvFac.createInstanceWithArguments(args) ;
87 xInv = (XInvocation) UnoRuntime.queryInterface
88 (XInvocation.class, oInv) ;
90 } catch (com.sun.star.uno.Exception e) {
91 e.printStackTrace(log) ;
92 throw new StatusException("Cann't create invocation for object", e) ;
95 XInterface xInStr = null ;
97 Type[] types = new Type[1];
98 types[0] = new Type(XInputStream.class);
100 Object adp = oObj.createAdapter(xInv,types);
102 xInStr = (XInterface) UnoRuntime.queryInterface
103 (XInputStream.class, adp) ;
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) ;