tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / qadevOOo / tests / java / ifc / connection / _XConnector.java
blob5d63fafd2fc6c5d2de8a79a165d409b92c79d64b
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>XConnector</code> interface. <p>
32 * Required relations :
33 * <ul>
34 * <li> <code>'XConnector.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 _XConnector 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 * the acceptor
53 private final XAcceptor acc;
54 /**
55 * If exception occurred during method call it is
56 * stored in this field.
58 public Exception ex = null ;
59 /**
60 * If method call returns some value it stores in this field.
62 public XConnection acceptedCall = null ;
64 /**
65 * Gets an object which can call <code>accept</code> method.
67 public AcceptorThread(XAcceptor acc) {
68 this.acc = acc ;
71 /**
72 * Call <code>accept()</code> method.
74 @Override
75 public void run() {
76 try {
77 acceptedCall = acc.accept(connectString) ;
78 } catch (com.sun.star.lang.IllegalArgumentException e) {
79 ex = e ;
80 } catch (com.sun.star.connection.ConnectionSetupException e) {
81 ex = e ;
82 } catch (com.sun.star.connection.AlreadyAcceptingException e) {
83 ex = e ;
88 public XConnector oObj = null;
89 protected String connectString = null ;
91 /**
92 * Retrieves object relation.
94 @Override
95 public void before() throws StatusException {
96 connectString = (String)
97 tEnv.getObjRelation("XConnector.connectStr") ;
98 if (connectString == null)
99 throw new StatusException("No object relation found",
100 new NullPointerException()) ;
104 * Thread with acceptor is created, and it starts listening.
105 * The main thread tries to connect to acceptor. Acception thread must
106 * return and a valid connection must be returned by Acceptor. <p>
109 public void _connect() {
110 boolean result = true ;
111 AcceptorThread acceptorThread = null;
112 XAcceptor xAcceptor = null ;
113 XConnection aCon = null;
114 XInterface x = null;
116 // create the acceptor
117 try {
118 x = (XInterface) tParam.getMSF().createInstance
119 ("com.sun.star.connection.Acceptor") ;
120 } catch (com.sun.star.uno.Exception e) {
121 e.printStackTrace(log) ;
122 throw new StatusException("Can't create service", e) ;
125 xAcceptor = UnoRuntime.queryInterface(XAcceptor.class, x);
127 acceptorThread = new AcceptorThread(xAcceptor) ;
128 acceptorThread.start() ;
130 util.utils.shortWait();
132 // connect to acceptor
133 try {
134 aCon = oObj.connect(connectString);
136 if (aCon == null)
137 log.println("Connector returned: null") ;
138 else
139 log.println("Connector returned: " + aCon.getDescription()) ;
141 try {
142 acceptorThread.join(30 * 1000) ;
143 } catch(InterruptedException e) {}
145 // connection not established
146 if (acceptorThread.isAlive()) {
148 result = false ;
149 log.println("Method call hasn't returned") ;
151 if (acceptorThread.acceptedCall == null)
152 log.println("Acceptor returned : null") ;
153 else
154 log.println("Acceptor returned : " +
155 acceptorThread.acceptedCall.getDescription()) ;
156 } else {
157 if (acceptorThread.ex != null) {
158 log.println("Exception occurred in accept() thread :") ;
159 acceptorThread.ex.printStackTrace(log) ;
162 if (acceptorThread.acceptedCall == null)
163 log.println("Method returned : null") ;
164 else
165 log.println("Method returned : " +
166 acceptorThread.acceptedCall.getDescription()) ;
168 result &= acceptorThread.acceptedCall != null ;
170 } catch (com.sun.star.connection.ConnectionSetupException e) {
171 e.printStackTrace(log) ;
172 result = false ;
173 } catch (com.sun.star.connection.NoConnectException e) {
174 e.printStackTrace(log) ;
175 result = false ;
176 } finally {
177 acceptorThread.acc.stopAccepting();
178 if (acceptorThread.isAlive()) {
179 acceptorThread.interrupt();
183 tRes.tested("connect()", result) ;