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
.XSingleServiceFactory
;
24 import com
.sun
.star
.uno
.UnoRuntime
;
29 * Testing <code>com.sun.star.</code>
30 * interface methods :lang.XSingleServiceFactory
32 * <li><code> createInstance()</code></li>
33 * <li><code> createInstanceWithArguments()</code></li>
35 * This test needs the following object relations :
37 * <li> <code>'XSingleServiceFactory.createInstance.negative'</code> :
38 * <code>String</code> relation; If its value 'true' then
39 * <code>createInstance</code> method for the object isn't
41 * <li> <code>'XSingleServiceFactory.arguments'</code> <b>(optional)</b>:
42 * has <code>Object[]</code> type. This relation is used as
43 * a parameter for <code>createInstanceWithArguments</code>
44 * method call. If this relation doesn't exist test pass
45 * zerro length array as argument. </li>
46 * <li> <code>'XSingleServiceFactory.MustSupport'</code> <b>(optional)</b>:
47 * of type <code>java.lang.Class[]</code>. This is an array of UNO
48 * interface classes which must be supported by created instance.
51 * Test is <b> NOT </b> multithread compilant. <p>
52 * After test completion object environment has to be recreated.
53 * @see com.sun.star.lang.XSingleServiceFactory
55 public class _XSingleServiceFactory
extends MultiMethodTest
{
57 public XSingleServiceFactory oObj
= null;
58 private Class
<?
>[] mustSupport
= null ;
60 public void before() {
61 mustSupport
= (Class
[]) tEnv
.getObjRelation
62 ("XSingleServiceFactory.MustSupport") ;
66 * Just calls the method and check the value returned. <p>
68 * Has <b>OK</b> status in case if this method is supported
69 * by object and non null value is returned, or if
70 * this method isn't supported then the method call must
71 * rise an exception or return <code>null</code> value.
72 * If the relation exists which specifies required interfaces
73 * supported by created instance then status is <b>OK</b>
74 * if all these interfaces are supported.
76 public void _createInstance() {
77 // for some objects the method should fail.
78 // If thi is required the property is set to true.
79 String negStr
= (String
)tEnv
.getObjRelation(
80 "XSingleServiceFactory.createInstance.negative");
81 boolean negative
= (negStr
!= null && negStr
.equalsIgnoreCase("true"));
84 log
.println("Negative test: createInstance should fail");
88 log
.println("Creating Instance: ");
89 Object Inst
= oObj
.createInstance();
90 boolean bOK
= Inst
!= null ;
92 if (mustSupport
!= null && bOK
) {
93 for (int i
= 0; i
< mustSupport
.length
; i
++) {
94 Object ifc
= UnoRuntime
.queryInterface(mustSupport
[i
], Inst
) ;
96 log
.println(" !!! Created instance doesn't support " +
97 mustSupport
[i
].toString()) ;
103 tRes
.tested("createInstance()",
104 (negative
&& Inst
== null) || (!negative
&& bOK
));
105 } catch (com
.sun
.star
.uno
.Exception ex
) {
106 log
.println("Exception occurred during createInstance()");
108 ex
.printStackTrace(log
);
110 tRes
.tested("createInstance()", negative
);
115 * Calls the method and checks the value returned. If relation
116 * with method argument doesn't exist new zerro length array
118 * Has <b>OK</b> status if non null value is returned.
119 * If the relation exists which specifies required interfaces
120 * supported by created instance then status is <b>OK</b>
121 * if all these interfaces are supported.
123 public void _createInstanceWithArguments() {
124 Object
[] arg
= (Object
[])tEnv
.getObjRelation(
125 "XSingleServiceFactory.arguments");
133 log
.println("Creating Instance with Argument");
134 Object Inst
= oObj
.createInstanceWithArguments(arg
);
135 bOK
&= Inst
!= null ;
137 if (mustSupport
!= null) {
138 for (int i
= 0; i
< mustSupport
.length
; i
++) {
139 Object ifc
= UnoRuntime
.queryInterface(mustSupport
[i
], Inst
) ;
141 log
.println(" !!! Created instance doesn't support " +
142 mustSupport
[i
].toString()) ;
148 tRes
.tested("createInstanceWithArguments()", bOK
);
150 catch (com
.sun
.star
.uno
.Exception ex
) {
151 log
.println("Exception occurred during createInstanceWithArguments()");
152 ex
.printStackTrace(log
);
153 tRes
.tested("createInstanceWithArguments()",false);
157 } // finish class _XSingleServiceFactory