tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / qadevOOo / tests / java / ifc / lang / _XSingleServiceFactory.java
blobda039308ce4e8d55489c97ad0feeefcd814c734c
1 /*
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 .
19 package ifc.lang;
21 import lib.MultiMethodTest;
23 import com.sun.star.lang.XSingleServiceFactory;
24 import com.sun.star.uno.UnoRuntime;
27 /**
28 /**
29 * Testing <code>com.sun.star.</code>
30 * interface methods :lang.XSingleServiceFactory
31 * <ul>
32 * <li><code> createInstance()</code></li>
33 * <li><code> createInstanceWithArguments()</code></li>
34 * </ul> <p>
35 * This test needs the following object relations :
36 * <ul>
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
40 * supported. </li>
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 * zero 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.
49 * </li>
50 * <ul> <p>
51 * Test is <b> NOT </b> multithread compliant. <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 @Override
61 public void before() {
62 mustSupport = (Class[]) tEnv.getObjRelation
63 ("XSingleServiceFactory.MustSupport") ;
66 /**
67 * Just calls the method and check the value returned. <p>
69 * Has <b>OK</b> status in case if this method is supported
70 * by object and non null value is returned, or if
71 * this method isn't supported then the method call must
72 * rise an exception or return <code>null</code> value.
73 * If the relation exists which specifies required interfaces
74 * supported by created instance then status is <b>OK</b>
75 * if all these interfaces are supported.
77 public void _createInstance() {
78 // for some objects the method should fail.
79 // If this is required the property is set to true.
80 String negStr = (String)tEnv.getObjRelation(
81 "XSingleServiceFactory.createInstance.negative");
82 boolean negative = (negStr != null && negStr.equalsIgnoreCase("true"));
84 if (negative) {
85 log.println("Negative test: createInstance should fail");
88 try {
89 log.println("Creating Instance: ");
90 Object Inst = oObj.createInstance();
91 boolean bOK = Inst != null ;
93 if (mustSupport != null && bOK) {
94 for (int i = 0; i < mustSupport.length; i++) {
95 Object ifc = UnoRuntime.queryInterface(mustSupport[i], Inst) ;
96 if (ifc == null) {
97 log.println(" !!! Created instance doesn't support " +
98 mustSupport[i].toString()) ;
100 bOK &= ifc != null ;
104 tRes.tested("createInstance()",
105 (negative && Inst == null) || (!negative && bOK));
106 } catch (com.sun.star.uno.Exception ex) {
107 log.println("Exception occurred during createInstance()");
108 if (negative) {
109 ex.printStackTrace(log);
111 tRes.tested("createInstance()", negative);
116 * Calls the method and checks the value returned. If relation
117 * with method argument doesn't exist new zero length array
118 * is created. <p>
119 * Has <b>OK</b> status if non null value is returned.
120 * If the relation exists which specifies required interfaces
121 * supported by created instance then status is <b>OK</b>
122 * if all these interfaces are supported.
124 public void _createInstanceWithArguments() {
125 Object[] arg = (Object[])tEnv.getObjRelation(
126 "XSingleServiceFactory.arguments");
128 if (arg == null) {
129 arg = new Object[0];
132 try {
133 boolean bOK = true ;
134 log.println("Creating Instance with Argument");
135 Object Inst = oObj.createInstanceWithArguments(arg);
136 bOK &= Inst != null ;
138 if (mustSupport != null) {
139 for (int i = 0; i < mustSupport.length; i++) {
140 Object ifc = UnoRuntime.queryInterface(mustSupport[i], Inst) ;
141 if (ifc == null) {
142 log.println(" !!! Created instance doesn't support " +
143 mustSupport[i].toString()) ;
145 bOK &= ifc != null ;
149 tRes.tested("createInstanceWithArguments()", bOK);
151 catch (com.sun.star.uno.Exception ex) {
152 log.println("Exception occurred during createInstanceWithArguments()");
153 ex.printStackTrace(log);
154 tRes.tested("createInstanceWithArguments()",false);
158 } // finish class _XSingleServiceFactory