tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / qadevOOo / tests / java / ifc / connection / _XAcceptor.java
blob2e69eab9592d035e6cff64bc23ab884436e24001
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.connection;
21 import lib.MultiMethodTest;
22 import lib.StatusException;
24 import com.sun.star.connection.XAcceptor;
25 import com.sun.star.connection.XConnection;
26 import com.sun.star.connection.XConnector;
27 import com.sun.star.uno.UnoRuntime;
28 import com.sun.star.uno.XInterface;
30 /**
31 * Tests methods of <code>XAcceptor</code> interface. <p>
32 * Required relations :
33 * <ul>
34 * <li> <code>'XAcceptor.connectStr'</code> : String variable. Has
35 * the following format :
36 * <code>'socket,host=<SOHost>,port=<UniquePort>' where <SOHost> is
37 * the host where StarOffice is started. This string must be passed
38 * as parameter to <code>accept()</code> method. </li>
39 * <ul> <p>
40 * This test <b>can not</b> be run in multiply threads.
42 public class _XAcceptor extends MultiMethodTest {
44 /**
45 * Calls <code>accept()</code> method in a separate thread.
46 * Then stores exception thrown by call if it occurred, or
47 * return value.
49 protected class AcceptorThread extends Thread {
50 /**
51 * If exception occurred during method call it is
52 * stored in this field.
54 public Exception ex = null ;
55 private final XAcceptor acc;
56 /**
57 * If method call returns some value it stores in this field.
59 public XConnection acceptedCall = null ;
61 /**
62 * Creates object which can call <code>accept</code> method
63 * of the Acceptor object specified.
65 public AcceptorThread(XAcceptor acc) {
66 this.acc = acc ;
69 /**
70 * Call <code>accept()</code> method.
72 @Override
73 public void run() {
74 try {
75 acceptedCall = acc.accept(connectString) ;
76 } catch (com.sun.star.lang.IllegalArgumentException e) {
77 ex = e ;
78 } catch (com.sun.star.connection.ConnectionSetupException e) {
79 ex = e ;
80 } catch (com.sun.star.connection.AlreadyAcceptingException e) {
81 ex = e ;
86 public XAcceptor oObj = null;
87 protected String connectString = null ;
89 /**
90 * Retrieves object relation.
92 @Override
93 public void before() throws StatusException {
94 connectString = (String)
95 tEnv.getObjRelation("XAcceptor.connectStr") ;
97 if (connectString == null)
98 throw new StatusException("No object relation found",
99 new NullPointerException()) ;
103 * First part : Thread with acceptor created, and it starts listening.
104 * The main thread tries to connect to acceptor. Acception thread must
105 * return and valid connection must be returned by Acceptor. <p>
107 * Second part : Trying to create second acceptor which listen on
108 * the same port. Calling <code>accept()</code> method of the second
109 * Acceptor must rise appropriate exception. <p>
111 * Has OK status if both test parts executed properly.
113 public void _accept() {
114 boolean result = true ;
115 AcceptorThread acception = null,
116 dupAcception = null ;
117 XAcceptor dupAcceptor = null ;
118 XConnector xConnector = null ;
120 // creating services required
121 try {
122 Object oConnector = tParam.getMSF().createInstance("com.sun.star.connection.Connector") ;
124 xConnector = UnoRuntime.queryInterface
125 (XConnector.class, oConnector) ;
127 XInterface acceptor = (XInterface) tParam.getMSF().createInstance
128 ("com.sun.star.connection.Acceptor") ;
130 dupAcceptor = UnoRuntime.queryInterface
131 (XAcceptor.class, acceptor) ;
132 } catch (com.sun.star.uno.Exception e) {
133 e.printStackTrace(log) ;
134 throw new StatusException("Can't create service", e) ;
137 // Testing connection to the acceptor
138 try {
139 acception = new AcceptorThread(oObj) ;
140 acception.start() ;
142 util.utils.shortWait();
144 XConnection con = xConnector.connect(connectString) ;
146 if (con == null)
147 log.println("Connector returned : null") ;
148 else
149 log.println("Connector returned : " + con.getDescription()) ;
151 try {
152 acception.join(5 * 1000) ;
153 } catch(InterruptedException e) {}
155 if (acception.isAlive()) {
157 result = false ;
158 log.println("Method call haven't returned") ;
160 if (acception.acceptedCall == null)
161 log.println("Acceptor returned : null") ;
162 else
163 log.println("Acceptor returned : " +
164 acception.acceptedCall.getDescription()) ;
165 } else {
166 if (acception.ex != null) {
167 log.println("Exception occurred in accept() thread :") ;
168 acception.ex.printStackTrace(log) ;
171 if (acception.acceptedCall == null)
172 log.println("Method returned : null") ;
173 else
174 log.println("Method returned : " +
175 acception.acceptedCall.getDescription()) ;
177 result &= acception.acceptedCall != null ;
179 } catch (com.sun.star.connection.ConnectionSetupException e) {
180 e.printStackTrace(log) ;
181 result = false ;
182 } catch (com.sun.star.connection.NoConnectException e) {
183 e.printStackTrace(log) ;
184 result = false ;
185 } finally {
186 oObj.stopAccepting();
187 if (acception.isAlive()) {
188 acception.interrupt();
192 // duplicate acceptor test
193 // creating the additional acceptor which listens
194 // on the same port
196 log.println("___ Testing for accepting on the same port ...") ;
198 try {
199 dupAcception = new AcceptorThread(dupAcceptor) ;
200 dupAcception.start() ;
202 try {
203 dupAcception.join(1 * 1000) ;
204 } catch(InterruptedException e) {}
207 if (dupAcception.isAlive()) {
208 log.println("Duplicate acceptor is listening ...") ;
210 // now trying to accept on the same port as additional
211 // acceptor
212 acception = new AcceptorThread(oObj) ;
213 acception.start() ;
215 try {
216 acception.join(3 * 1000) ;
217 } catch(InterruptedException e) {}
219 if (acception.isAlive()) {
220 oObj.stopAccepting() ;
221 acception.interrupt() ;
223 log.println("Acceptor with the same port must cause"+
224 " an error but didn't") ;
225 result = false ;
226 } else {
227 log.println("Accepted call = " + acception.acceptedCall) ;
228 if (acception.ex == null) {
229 //result = false ;
230 log.println("No exception was thrown when trying"+
231 " to listen on the same port") ;
232 } else {
233 if (acception.ex instanceof
234 com.sun.star.connection.AlreadyAcceptingException ||
235 acception.ex instanceof
236 com.sun.star.connection.ConnectionSetupException) {
238 log.println("Right exception was thrown when trying"+
239 " to listen on the same port") ;
240 } else {
241 result = false ;
242 log.println("Wrong exception was thrown when trying"+
243 " to listen on the same port :") ;
244 acception.ex.printStackTrace(log) ;
249 } finally {
250 dupAcceptor.stopAccepting() ;
251 if (dupAcception.isAlive()) {
252 dupAcception.interrupt() ;
256 tRes.tested("accept()", result) ;
260 * Starts thread with Acceptor and then calls <code>stopListening</code>
261 * method. <p>
262 * Has OK status if <code>accept</code> method successfully returns and
263 * rises no exceptions.
265 public void _stopAccepting() {
266 boolean result = true ;
269 AcceptorThread acception = new AcceptorThread(oObj) ;
271 acception.start() ;
273 oObj.stopAccepting() ;
275 try {
276 acception.join(3 * 1000) ;
277 } catch (InterruptedException e) {}
279 if (acception.isAlive()) {
280 acception.interrupt() ;
282 result = false ;
283 log.println("Method call haven't returned") ;
285 } else {
286 if (acception.ex != null) {
287 log.println("Exception occurred in accept() thread :") ;
288 acception.ex.printStackTrace(log) ;
289 result = false ;
290 } else {
291 result = true ;
294 if (acception.acceptedCall == null)
295 log.println("accept() returned : null") ;
296 else
297 log.println("accept() returned : " +
298 acception.acceptedCall.getDescription()) ;
301 tRes.tested("stopAccepting()", result) ;