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 ************************************************************************/
30 import lib
.MultiMethodTest
;
32 import com
.sun
.star
.lang
.XMultiComponentFactory
;
33 import com
.sun
.star
.uno
.XComponentContext
;
34 import com
.sun
.star
.uno
.XInterface
;
37 * Testing <code>com.sun.star.lang.XMultiComponentFactory</code>
40 * <li><code> createInstanceWithContext()</code></li>
41 * <li><code> createInstanceWithArgumentsAndContext()</code></li>
42 * <li><code> getAvailableServiceNames()</code></li>
44 * Test is <b> NOT </b> multithread compilant. <p>
45 * @see com.sun.star.lang.XMultiComponentFactory
47 public class _XMultiComponentFactory
extends MultiMethodTest
{
48 public XMultiComponentFactory oObj
= null;
50 public XComponentContext xContext
= null;
51 private String
[] availableServiceNames
= null;
54 xContext
= (XComponentContext
)tEnv
.getObjRelation("DC");
55 availableServiceNames
= (String
[])tEnv
.getObjRelation("XMultiComponentFactory.ServiceNames");
59 * Calls the method with one of the available service names
60 * obtained by method getAvailableServiceNames. <p>
61 * Has <b> OK </b> status if no runtime exceptions occurred
62 * and returned value is not null.
64 public void _createInstanceWithContext() {
65 requiredMethod("getAvailableServiceNames()");
66 boolean result
= true;
69 XInterface component
= (XInterface
)
70 oObj
.createInstanceWithContext(
71 availableServiceNames
[0], xContext
);
72 result
= (component
!= null);
73 } catch (com
.sun
.star
.uno
.Exception e
) {
74 log
.println("Couldn't create instance " + availableServiceNames
[0]);
78 tRes
.tested("createInstanceWithContext()", result
);
82 * Calls the method with one of the available service names
83 * obtained by method getAvailableServiceNames. <p>
84 * Has <b> OK </b> status if no runtime exceptions occurred
85 * and returned value is not null.
87 public void _createInstanceWithArgumentsAndContext() {
88 requiredMethod("getAvailableServiceNames()");
89 boolean result
= true;
90 XInterface component
= null;
93 component
= (XInterface
)oObj
.createInstanceWithArgumentsAndContext(
94 availableServiceNames
[0], new Object
[0], xContext
);
95 result
= (component
!= null);
96 } catch (com
.sun
.star
.uno
.Exception e
) {
97 log
.println("Couldn't create instance " + availableServiceNames
[0]);
101 tRes
.tested("createInstanceWithArgumentsAndContext()", result
);
105 * Just calls the method. <p>
106 * Has <b> OK </b> status if no runtime exceptions occurred
107 * and returned value is not null.
109 public void _getAvailableServiceNames() {
110 boolean result
= true;
111 if (availableServiceNames
== null) {
112 availableServiceNames
= oObj
.getAvailableServiceNames();
113 result
= (availableServiceNames
!= null);
115 else { // if service names are given, ignore result
116 String
[]erg
= oObj
.getAvailableServiceNames();
117 result
= (erg
!= null);
120 log
.println("Available service names:");
121 for(int i
= 0; i
< availableServiceNames
.length
; i
++) {
122 log
.println(" " + availableServiceNames
[i
]);
125 tRes
.tested("getAvailableServiceNames()", result
);