1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XMultiComponentFactory.java,v $
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 ************************************************************************/
33 import lib
.MultiMethodTest
;
35 import com
.sun
.star
.lang
.XMultiComponentFactory
;
36 import com
.sun
.star
.uno
.XComponentContext
;
37 import com
.sun
.star
.uno
.XInterface
;
40 * Testing <code>com.sun.star.lang.XMultiComponentFactory</code>
43 * <li><code> createInstanceWithContext()</code></li>
44 * <li><code> createInstanceWithArgumentsAndContext()</code></li>
45 * <li><code> getAvailableServiceNames()</code></li>
47 * Test is <b> NOT </b> multithread compilant. <p>
48 * @see com.sun.star.lang.XMultiComponentFactory
50 public class _XMultiComponentFactory
extends MultiMethodTest
{
51 public XMultiComponentFactory oObj
= null;
53 public XComponentContext xContext
= null;
54 private String
[] availableServiceNames
= null;
57 xContext
= (XComponentContext
)tEnv
.getObjRelation("DC");
58 availableServiceNames
= (String
[])tEnv
.getObjRelation("XMultiComponentFactory.ServiceNames");
62 * Calls the method with one of the available service names
63 * obtained by method getAvailableServiceNames. <p>
64 * Has <b> OK </b> status if no runtime exceptions occured
65 * and returned value is not null.
67 public void _createInstanceWithContext() {
68 requiredMethod("getAvailableServiceNames()");
69 boolean result
= true;
72 XInterface component
= (XInterface
)
73 oObj
.createInstanceWithContext(
74 availableServiceNames
[0], xContext
);
75 result
= (component
!= null);
76 } catch (com
.sun
.star
.uno
.Exception e
) {
77 log
.println("Couldn't create instance " + availableServiceNames
[0]);
81 tRes
.tested("createInstanceWithContext()", result
);
85 * Calls the method with one of the available service names
86 * obtained by method getAvailableServiceNames. <p>
87 * Has <b> OK </b> status if no runtime exceptions occured
88 * and returned value is not null.
90 public void _createInstanceWithArgumentsAndContext() {
91 requiredMethod("getAvailableServiceNames()");
92 boolean result
= true;
93 XInterface component
= null;
96 component
= (XInterface
)oObj
.createInstanceWithArgumentsAndContext(
97 availableServiceNames
[0], new Object
[0], xContext
);
98 result
= (component
!= null);
99 } catch (com
.sun
.star
.uno
.Exception e
) {
100 log
.println("Couldn't create instance " + availableServiceNames
[0]);
104 tRes
.tested("createInstanceWithArgumentsAndContext()", result
);
108 * Just calls the method. <p>
109 * Has <b> OK </b> status if no runtime exceptions occured
110 * and returned value is not null.
112 public void _getAvailableServiceNames() {
113 boolean result
= true;
114 if (availableServiceNames
== null) {
115 availableServiceNames
= oObj
.getAvailableServiceNames();
116 result
= (availableServiceNames
!= null);
118 else { // if service names are given, ignore result
119 String
[]erg
= oObj
.getAvailableServiceNames();
120 result
= (erg
!= null);
123 log
.println("Available service names:");
124 for(int i
= 0; i
< availableServiceNames
.length
; i
++) {
125 log
.println(" " + availableServiceNames
[i
]);
128 tRes
.tested("getAvailableServiceNames()", result
);