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
.XSingleServiceFactory
;
33 import com
.sun
.star
.uno
.UnoRuntime
;
38 * Testing <code>com.sun.star.</code>
39 * interface methods :lang.XSingleServiceFactory
41 * <li><code> createInstance()</code></li>
42 * <li><code> createInstanceWithArguments()</code></li>
44 * This test needs the following object relations :
46 * <li> <code>'XSingleServiceFactory.createInstance.negative'</code> :
47 * <code>String</code> relation; If its value 'true' then
48 * <code>createInstance</code> method for the object isn't
50 * <li> <code>'XSingleServiceFactory.arguments'</code> <b>(optional)</b>:
51 * has <code>Object[]</code> type. This relation is used as
52 * a parameter for <code>createInstanceWithArguments</code>
53 * method call. If this relation doesn't exist test pass
54 * zerro length array as argument. </li>
55 * <li> <code>'XSingleServiceFactory.MustSupport'</code> <b>(optional)</b>:
56 * of type <code>java.lang.Class[]</code>. This is an array of UNO
57 * interface classes which must be supported by created instance.
60 * Test is <b> NOT </b> multithread compilant. <p>
61 * After test completion object environment has to be recreated.
62 * @see com.sun.star.lang.XSingleServiceFactory
64 public class _XSingleServiceFactory
extends MultiMethodTest
{
66 public XSingleServiceFactory oObj
= null;
67 private Class
[] mustSupport
= null ;
69 public void before() {
70 mustSupport
= (Class
[]) tEnv
.getObjRelation
71 ("XSingleServiceFactory.MustSupport") ;
75 * Just calls the method and check the value returned. <p>
77 * Has <b>OK</b> status in case if this method is supported
78 * by object and non null value is returned, or if
79 * this method isn't supported then the method call must
80 * rise an exception or return <code>null</code> value.
81 * If the relation exists which specifies required interfaces
82 * supported by created instance then status is <b>OK</b>
83 * if all these interfaces are supported.
85 public void _createInstance() {
86 // for some objects the method should fail.
87 // If thi is required the property is set to true.
88 String negStr
= (String
)tEnv
.getObjRelation(
89 "XSingleServiceFactory.createInstance.negative");
90 boolean negative
= (negStr
!= null && negStr
.equalsIgnoreCase("true"));
93 log
.println("Negative test: createInstance should fail");
97 log
.println("Creating Instance: ");
98 Object Inst
= oObj
.createInstance();
99 boolean bOK
= Inst
!= null ;
101 if (mustSupport
!= null && bOK
) {
102 for (int i
= 0; i
< mustSupport
.length
; i
++) {
103 Object ifc
= UnoRuntime
.queryInterface(mustSupport
[i
], Inst
) ;
105 log
.println(" !!! Created instance doesn't support " +
106 mustSupport
[i
].toString()) ;
112 tRes
.tested("createInstance()",
113 (negative
&& Inst
== null) || (!negative
&& bOK
));
114 } catch (com
.sun
.star
.uno
.Exception ex
) {
115 log
.println("Exception occurred during createInstance()");
117 ex
.printStackTrace(log
);
119 tRes
.tested("createInstance()", negative
);
124 * Calls the method and checks the value returned. If relation
125 * with method argument doesn't exist new zerro length array
127 * Has <b>OK</b> status if non null value is returned.
128 * If the relation exists which specifies required interfaces
129 * supported by created instance then status is <b>OK</b>
130 * if all these interfaces are supported.
132 public void _createInstanceWithArguments() {
133 Object
[] arg
= (Object
[])tEnv
.getObjRelation(
134 "XSingleServiceFactory.arguments");
142 log
.println("Creating Instance with Argument");
143 Object Inst
= oObj
.createInstanceWithArguments(arg
);
144 bOK
&= Inst
!= null ;
146 if (mustSupport
!= null) {
147 for (int i
= 0; i
< mustSupport
.length
; i
++) {
148 Object ifc
= UnoRuntime
.queryInterface(mustSupport
[i
], Inst
) ;
150 log
.println(" !!! Created instance doesn't support " +
151 mustSupport
[i
].toString()) ;
157 tRes
.tested("createInstanceWithArguments()", bOK
);
159 catch (com
.sun
.star
.uno
.Exception ex
) {
160 log
.println("Exception occurred during createInstanceWithArguments()");
161 ex
.printStackTrace(log
);
162 tRes
.tested("createInstanceWithArguments()",false);
166 } // finish class _XSingleServiceFactory