Set that a non-modal Popover don't auto-grab focus on popup
[LibreOffice.git] / qadevOOo / tests / java / mod / _remotebridge / uno / various.java
blobb9bc78696ecc063713cfc9194862f85fe7c151c9
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 mod._remotebridge.uno;
21 import com.sun.star.bridge.XBridgeFactory;
22 import com.sun.star.bridge.XInstanceProvider;
23 import com.sun.star.connection.XAcceptor;
24 import com.sun.star.connection.XConnection;
25 import com.sun.star.connection.XConnector;
26 import com.sun.star.lang.XComponent;
27 import com.sun.star.lang.XMultiServiceFactory;
28 import com.sun.star.uno.UnoRuntime;
29 import com.sun.star.uno.XInterface;
30 import java.io.PrintWriter;
31 import lib.StatusException;
32 import lib.TestCase;
33 import lib.TestEnvironment;
34 import lib.TestParameters;
37 /**
38 * Test for object which is represented by service
39 * <code>com.sun.star.bridge.Bridge</code>. <p>
40 * Object implements the following interfaces :
41 * <ul>
42 * <li> <code>com::sun::star::lang::XInitialization</code></li>
43 * <li> <code>com::sun::star::lang::XComponent</code></li>
44 * <li> <code>com::sun::star::bridge::XBridge</code></li>
45 * </ul>
46 * This object test <b> is NOT </b> designed to be run in several
47 * threads concurrently.
48 * @see com.sun.star.lang.XInitialization
49 * @see com.sun.star.lang.XComponent
50 * @see com.sun.star.bridge.XBridge
51 * @see com.sun.star.bridge.Bridge
52 * @see ifc.lang._XInitialization
53 * @see ifc.lang._XComponent
54 * @see ifc.bridge._XBridge
56 public class various extends TestCase {
58 /**
59 * String for establishing a connection
61 protected String connectString = null ;
63 /**
64 * Choose the first port after <code>basePort</code>
65 * which is free.
67 protected static final int basePort = 50000;
68 private static final int curPort = 50000;
70 private XAcceptor xAcctr;
71 private XConnector xCntr;
72 private XBridgeFactory xBrdgFctr;
73 private AcceptorThread accThread;
75 public XInterface bridge = null;
77 /**
78 * Implementation of interface XInstanceProvider
80 * @see com.sun.star.bridge.XInstanceProvider
82 private static class MyInstanceProvider implements XInstanceProvider {
83 /**
84 * a MultiServiceFactory for creating instances
86 * @see com.sun.star.lang.MultiServiceFactory
88 private final XMultiServiceFactory xMSF;
90 /**
91 * Construct object with a MultiServiceFactory
93 * @see com.sun.star.lang.MultiServiceFactory
95 private MyInstanceProvider(XMultiServiceFactory xMSF) {
96 this.xMSF = xMSF;
99 /**
100 * get an instance by name
102 public Object getInstance(String aInstanceName)
103 throws com.sun.star.container.NoSuchElementException
105 System.out.println("######## Try to get "+aInstanceName);
106 try {
107 return xMSF.createInstance(aInstanceName);
109 catch(com.sun.star.uno.Exception e) {
110 throw new StatusException("Unexpected exception", e);
116 * Calls <code>accept()</code> method in a separate thread.
117 * Then stores exception thrown by call if it occurred, or
118 * return value.
120 private class AcceptorThread extends Thread {
121 private final XAcceptor acc;
122 private final XInstanceProvider xInstProv;
123 private final XBridgeFactory xBrdgFctr;
125 * If method call returns some value it stores in this field.
127 private XConnection acceptedCall = null ;
130 * Creates object which can call <code>accept</code> method
131 * of the Acceptor object specified.
133 private AcceptorThread(XAcceptor acc, XInstanceProvider xInstProv,
134 XBridgeFactory xBrdgFctr) {
135 this.acc = acc ;
136 this.xInstProv = xInstProv;
137 this.xBrdgFctr = xBrdgFctr;
141 * Call <code>accept()</code> method and establish a bridge with an
142 * instance provider
144 @Override
145 public void run() {
146 try {
147 acceptedCall = acc.accept(connectString) ;
148 xBrdgFctr.createBridge("MyBridge", "urp",
149 acceptedCall, xInstProv);
150 } catch (com.sun.star.connection.ConnectionSetupException e) {
151 } catch (com.sun.star.connection.AlreadyAcceptingException e) {
152 } catch (com.sun.star.bridge.BridgeExistsException e) {
157 private final boolean[] bridgeDisposed = new boolean[1] ;
160 * Creating a TestEnvironment for the interfaces to be tested.
161 * Creates an instance of the service
162 * <code>com.sun.star.bridge.Bridge</code>.
163 * Object relations created :
164 * <ul>
165 * <li> <code>'XInitialization.args'</code> for
166 * {@link ifc.lang._XInitialization} and
167 * {@link ifc.bridge._XBridge} : contains arguments
168 * for <code>initialize()</code> method test.</li>
169 * </ul>
171 @Override
172 protected TestEnvironment createTestEnvironment(TestParameters tParam,
173 PrintWriter log) throws Exception {
174 XMultiServiceFactory xMSF = tParam.getMSF();
176 XInterface xInt = (XInterface)xMSF.createInstance(
177 "com.sun.star.bridge.Bridge");
179 TestEnvironment tEnv = new TestEnvironment(xInt);
180 // creating arguments for XInitialization
181 // first, creating a connection
182 // connection string
183 String cncstr = (String) tParam.get("CONNECTION_STRING") ;
184 int idx = cncstr.indexOf("host=") + 5 ;
186 // select the port
187 log.println("Choose Port nr: " + curPort);
189 connectString = "socket,host=" +
190 cncstr.substring(idx, cncstr.indexOf(",", idx)) +
191 ",port=" + curPort;
193 // create acceptor
194 XInterface oAcctr = (XInterface)xMSF.createInstance(
195 "com.sun.star.connection.Acceptor") ;
197 xAcctr = UnoRuntime.queryInterface(
198 XAcceptor.class, oAcctr);
199 // create connector
200 XInterface oCntr = (XInterface)xMSF.createInstance(
201 "com.sun.star.connection.Connector") ;
202 xCntr = UnoRuntime.queryInterface(
203 XConnector.class, oCntr);
205 // create bridge factory
206 XInterface oBrdg = (XInterface)xMSF.createInstance(
207 "com.sun.star.bridge.BridgeFactory") ;
208 xBrdgFctr = UnoRuntime.queryInterface(XBridgeFactory.class, oBrdg);
210 // create own implementation of XInstanceProvider
211 XInstanceProvider xInstProv = new MyInstanceProvider(xMSF);
212 // create waiting acceptor thread
213 accThread = new AcceptorThread(xAcctr, xInstProv, xBrdgFctr);
214 accThread.start();
215 // let the thread sleep
216 util.utils.pause(500);
218 // establish the connection
219 XConnection xConnection = xCntr.connect(connectString);
221 String protocol = "urp";
222 String bridgeName = protocol + ":" + connectString;
224 tEnv.addObjRelation("XInitialization.args", new Object[] {
225 bridgeName, protocol, xConnection, null});
227 bridge = tEnv.getTestObject();
229 return tEnv;
233 * Stop the acceptor thread and dispose the bridge
235 @Override
236 protected void cleanup(TestParameters Param, PrintWriter log) {
238 System.out.println("++++++++ cleanup");
239 xAcctr.stopAccepting();
240 if (accThread.isAlive()) {
241 accThread.interrupt();
243 XComponent xComp = UnoRuntime.queryInterface(
244 XComponent.class, xAcctr);
245 if (xComp != null)
246 xComp.dispose();
247 xComp = UnoRuntime.queryInterface(
248 XComponent.class, xCntr);
249 if (xComp != null)
250 xComp.dispose();
251 xComp = UnoRuntime.queryInterface(
252 XComponent.class, xBrdgFctr);
253 if (xComp != null)
254 xComp.dispose();
256 xComp = UnoRuntime.queryInterface(
257 XComponent.class, bridge);
258 if (xComp != null) {
259 System.out.println("######## Dispose bridge");
260 bridgeDisposed[0] = true;
261 xComp.dispose();
262 // wait for dispose
263 util.utils.pause(5000);