Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / qadevOOo / tests / java / ifc / lang / _XSingleServiceFactory.java
blobc07760be1906586a66aceccc96220410c086ef87
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 ************************************************************************/
28 package ifc.lang;
30 import lib.MultiMethodTest;
32 import com.sun.star.lang.XSingleServiceFactory;
33 import com.sun.star.uno.UnoRuntime;
36 /**
37 /**
38 * Testing <code>com.sun.star.</code>
39 * interface methods :lang.XSingleServiceFactory
40 * <ul>
41 * <li><code> createInstance()</code></li>
42 * <li><code> createInstanceWithArguments()</code></li>
43 * </ul> <p>
44 * This test needs the following object relations :
45 * <ul>
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
49 * supported. </li>
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.
58 * </li>
59 * <ul> <p>
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") ;
74 /**
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"));
92 if (negative) {
93 log.println("Negative test: createInstance should fail");
96 try {
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) ;
104 if (ifc == null) {
105 log.println(" !!! Created instance doesn't support " +
106 mustSupport[i].toString()) ;
108 bOK &= ifc != null ;
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()");
116 if (negative) {
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
126 * is created. <p>
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");
136 if (arg == null) {
137 arg = new Object[0];
140 try {
141 boolean bOK = true ;
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) ;
149 if (ifc == null) {
150 log.println(" !!! Created instance doesn't support " +
151 mustSupport[i].toString()) ;
153 bOK &= ifc != null ;
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