2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 import lib
.MultiMethodTest
;
23 import com
.sun
.star
.lang
.XMultiComponentFactory
;
24 import com
.sun
.star
.uno
.XComponentContext
;
25 import com
.sun
.star
.uno
.XInterface
;
28 * Testing <code>com.sun.star.lang.XMultiComponentFactory</code>
31 * <li><code> createInstanceWithContext()</code></li>
32 * <li><code> createInstanceWithArgumentsAndContext()</code></li>
33 * <li><code> getAvailableServiceNames()</code></li>
35 * Test is <b> NOT </b> multithread compilant. <p>
36 * @see com.sun.star.lang.XMultiComponentFactory
38 public class _XMultiComponentFactory
extends MultiMethodTest
{
39 public XMultiComponentFactory oObj
= null;
41 public XComponentContext xContext
= null;
42 private String
[] availableServiceNames
= null;
45 xContext
= (XComponentContext
)tEnv
.getObjRelation("DC");
46 availableServiceNames
= (String
[])tEnv
.getObjRelation("XMultiComponentFactory.ServiceNames");
50 * Calls the method with one of the available service names
51 * obtained by method getAvailableServiceNames. <p>
52 * Has <b> OK </b> status if no runtime exceptions occurred
53 * and returned value is not null.
55 public void _createInstanceWithContext() {
56 requiredMethod("getAvailableServiceNames()");
57 boolean result
= true;
60 XInterface component
= (XInterface
)
61 oObj
.createInstanceWithContext(
62 availableServiceNames
[0], xContext
);
63 result
= (component
!= null);
64 } catch (com
.sun
.star
.uno
.Exception e
) {
65 log
.println("Couldn't create instance " + availableServiceNames
[0]);
69 tRes
.tested("createInstanceWithContext()", result
);
73 * Calls the method with one of the available service names
74 * obtained by method getAvailableServiceNames. <p>
75 * Has <b> OK </b> status if no runtime exceptions occurred
76 * and returned value is not null.
78 public void _createInstanceWithArgumentsAndContext() {
79 requiredMethod("getAvailableServiceNames()");
80 boolean result
= true;
81 XInterface component
= null;
84 component
= (XInterface
)oObj
.createInstanceWithArgumentsAndContext(
85 availableServiceNames
[0], new Object
[0], xContext
);
86 result
= (component
!= null);
87 } catch (com
.sun
.star
.uno
.Exception e
) {
88 log
.println("Couldn't create instance " + availableServiceNames
[0]);
92 tRes
.tested("createInstanceWithArgumentsAndContext()", result
);
96 * Just calls the method. <p>
97 * Has <b> OK </b> status if no runtime exceptions occurred
98 * and returned value is not null.
100 public void _getAvailableServiceNames() {
101 boolean result
= true;
102 if (availableServiceNames
== null) {
103 availableServiceNames
= oObj
.getAvailableServiceNames();
104 result
= (availableServiceNames
!= null);
106 else { // if service names are given, ignore result
107 String
[]erg
= oObj
.getAvailableServiceNames();
108 result
= (erg
!= null);
111 log
.println("Available service names:");
112 for(int i
= 0; i
< availableServiceNames
.length
; i
++) {
113 log
.println(" " + availableServiceNames
[i
]);
116 tRes
.tested("getAvailableServiceNames()", result
);