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: _XSingleServiceFactory.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
.XSingleServiceFactory
;
36 import com
.sun
.star
.uno
.UnoRuntime
;
41 * Testing <code>com.sun.star.</code>
42 * interface methods :lang.XSingleServiceFactory
44 * <li><code> createInstance()</code></li>
45 * <li><code> createInstanceWithArguments()</code></li>
47 * This test needs the following object relations :
49 * <li> <code>'XSingleServiceFactory.createInstance.negative'</code> :
50 * <code>String</code> relation; If its value 'true' then
51 * <code>createInstance</code> method for the object isn't
53 * <li> <code>'XSingleServiceFactory.arguments'</code> <b>(optional)</b>:
54 * has <code>Object[]</code> type. This relation is used as
55 * a parameter for <code>createInstanceWithArguments</code>
56 * method call. If this relation doesn't exist test pass
57 * zerro length array as argument. </li>
58 * <li> <code>'XSingleServiceFactory.MustSupport'</code> <b>(optional)</b>:
59 * of type <code>java.lang.Class[]</code>. This is an array of UNO
60 * interface classes which must be supported by created instance.
63 * Test is <b> NOT </b> multithread compilant. <p>
64 * After test completion object environment has to be recreated.
65 * @see com.sun.star.lang.XSingleServiceFactory
67 public class _XSingleServiceFactory
extends MultiMethodTest
{
69 public XSingleServiceFactory oObj
= null;
70 private Class
[] mustSupport
= null ;
72 public void before() {
73 mustSupport
= (Class
[]) tEnv
.getObjRelation
74 ("XSingleServiceFactory.MustSupport") ;
78 * Just calls the method and check the value returned. <p>
80 * Has <b>OK</b> status in case if this method is supported
81 * by object and non null value is returned, or if
82 * this method isn't supported then the method call must
83 * rise an exception or return <code>null</code> value.
84 * If the relation exists which specifies required interfaces
85 * supported by created instance then status is <b>OK</b>
86 * if all these interfaces are supported.
88 public void _createInstance() {
89 // for some objects the method should fail.
90 // If thi is required the property is set to true.
91 String negStr
= (String
)tEnv
.getObjRelation(
92 "XSingleServiceFactory.createInstance.negative");
93 boolean negative
= (negStr
!= null && negStr
.equalsIgnoreCase("true"));
96 log
.println("Negative test: createInstance should fail");
100 log
.println("Creating Instance: ");
101 Object Inst
= oObj
.createInstance();
102 boolean bOK
= Inst
!= null ;
104 if (mustSupport
!= null && bOK
) {
105 for (int i
= 0; i
< mustSupport
.length
; i
++) {
106 Object ifc
= UnoRuntime
.queryInterface(mustSupport
[i
], Inst
) ;
108 log
.println(" !!! Created instance doesn't support " +
109 mustSupport
[i
].toString()) ;
115 tRes
.tested("createInstance()",
116 (negative
&& Inst
== null) || (!negative
&& bOK
));
117 } catch (com
.sun
.star
.uno
.Exception ex
) {
118 log
.println("Exception occured during createInstance()");
120 ex
.printStackTrace(log
);
122 tRes
.tested("createInstance()", negative
);
127 * Calls the method and checks the value returned. If relation
128 * with method argument doesn't exist new zerro length array
130 * Has <b>OK</b> status if non null value is returned.
131 * If the relation exists which specifies required interfaces
132 * supported by created instance then status is <b>OK</b>
133 * if all these interfaces are supported.
135 public void _createInstanceWithArguments() {
136 Object
[] arg
= (Object
[])tEnv
.getObjRelation(
137 "XSingleServiceFactory.arguments");
145 log
.println("Creating Instance with Argument");
146 Object Inst
= oObj
.createInstanceWithArguments(arg
);
147 bOK
&= Inst
!= null ;
149 if (mustSupport
!= null) {
150 for (int i
= 0; i
< mustSupport
.length
; i
++) {
151 Object ifc
= UnoRuntime
.queryInterface(mustSupport
[i
], Inst
) ;
153 log
.println(" !!! Created instance doesn't support " +
154 mustSupport
[i
].toString()) ;
160 tRes
.tested("createInstanceWithArguments()", bOK
);
162 catch (com
.sun
.star
.uno
.Exception ex
) {
163 log
.println("Exception occured during createInstanceWithArguments()");
164 ex
.printStackTrace(log
);
165 tRes
.tested("createInstanceWithArguments()",false);
169 } // finish class _XSingleServiceFactory