tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _remotebridge / various.java
blob6e11c46bad59046ee1eb4ff73fcf3b5e4554ee46
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;
21 import java.io.PrintWriter;
23 import lib.TestCase;
24 import lib.TestEnvironment;
25 import lib.TestParameters;
27 import com.sun.star.bridge.XBridgeFactory;
28 import com.sun.star.connection.XAcceptor;
29 import com.sun.star.connection.XConnection;
30 import com.sun.star.connection.XConnector;
31 import com.sun.star.lang.XComponent;
32 import com.sun.star.lang.XMultiServiceFactory;
33 import com.sun.star.uno.UnoRuntime;
34 import com.sun.star.uno.XInterface;
36 /**
37 * Test for object which is represented by service
38 * <code>com.sun.star.bridge.Bridge</code>. <p>
39 * Object implements the following interfaces :
40 * <ul>
41 * <li> <code>com::sun::star::lang::XInitialization</code></li>
42 * <li> <code>com::sun::star::lang::XComponent</code></li>
43 * <li> <code>com::sun::star::bridge::XBridge</code></li>
44 * </ul>
45 * This object test <b> is NOT </b> designed to be run in several
46 * threads concurrently.
47 * @see com.sun.star.lang.XInitialization
48 * @see com.sun.star.lang.XComponent
49 * @see com.sun.star.bridge.XBridge
50 * @see com.sun.star.bridge.Bridge
51 * @see ifc.lang._XInitialization
52 * @see ifc.lang._XComponent
53 * @see ifc.bridge._XBridge
55 public class various extends TestCase {
57 /**
58 * String for establishing a connection
60 protected String connectString = null ;
62 /**
63 * Choose the first port after <code>basePort</code>
64 * which is free.
66 protected static final int basePort = 50000;
67 private static final int curPort = 50000;
69 private XAcceptor xAcctr;
70 private XConnector xCntr;
71 private XBridgeFactory xBrdgFctr;
72 private AcceptorThread accThread;
74 public XInterface bridge = null;
76 /**
77 * Calls <code>accept()</code> method in a separate thread.
78 * Then stores exception thrown by call if it occurred, or
79 * return value.
81 private class AcceptorThread extends Thread {
82 private final XAcceptor acc;
84 /**
85 * Creates object which can call <code>accept</code> method
86 * of the Acceptor object specified.
88 private AcceptorThread(XAcceptor acc) {
89 this.acc = acc ;
92 /**
93 * Call <code>accept()</code> method and establish a bridge with an
94 * instance provider
96 @Override
97 public void run() {
98 try {
99 acc.accept(connectString) ;
100 } catch (com.sun.star.connection.ConnectionSetupException e) {
101 } catch (com.sun.star.connection.AlreadyAcceptingException e) {
106 private final boolean[] bridgeDisposed = new boolean[1] ;
109 * Creating a TestEnvironment for the interfaces to be tested.
110 * Creates an instance of the service
111 * <code>com.sun.star.bridge.Bridge</code>.
112 * Object relations created :
113 * <ul>
114 * <li> <code>'XInitialization.args'</code> for
115 * {@link ifc.lang._XInitialization} and
116 * {@link ifc.bridge._XBridge} : contains arguments
117 * for <code>initialize()</code> method test.</li>
118 * </ul>
120 @Override
121 protected TestEnvironment createTestEnvironment(TestParameters tParam,
122 PrintWriter log) throws Exception {
123 XMultiServiceFactory xMSF = tParam.getMSF();
125 XInterface xInt = (XInterface)xMSF.createInstance(
126 "com.sun.star.bridge.Bridge");
128 TestEnvironment tEnv = new TestEnvironment(xInt);
129 // creating arguments for XInitialization
130 // first, creating a connection
131 // connection string
132 String cncstr = (String) tParam.get("CONNECTION_STRING") ;
133 int idx = cncstr.indexOf("host=") + 5 ;
135 // select the port
136 log.println("Choose Port nr: " + curPort);
138 connectString = "socket,host=" +
139 cncstr.substring(idx, cncstr.indexOf(",", idx)) +
140 ",port=" + curPort;
142 // create acceptor
143 XInterface oAcctr = (XInterface)xMSF.createInstance(
144 "com.sun.star.connection.Acceptor") ;
146 xAcctr = UnoRuntime.queryInterface(
147 XAcceptor.class, oAcctr);
148 // create connector
149 XInterface oCntr = (XInterface)xMSF.createInstance(
150 "com.sun.star.connection.Connector") ;
151 xCntr = UnoRuntime.queryInterface(
152 XConnector.class, oCntr);
154 // create bridge factory
155 XInterface oBrdg = (XInterface)xMSF.createInstance(
156 "com.sun.star.bridge.BridgeFactory") ;
157 xBrdgFctr = UnoRuntime.queryInterface(XBridgeFactory.class, oBrdg);
159 // create waiting acceptor thread
160 accThread = new AcceptorThread(xAcctr);
161 accThread.start();
162 // let the thread sleep
163 util.utils.pause(500);
165 // establish the connection
166 XConnection xConnection = xCntr.connect(connectString);
168 String protocol = "urp";
169 String bridgeName = protocol + ":" + connectString;
171 tEnv.addObjRelation("XInitialization.args", new Object[] {
172 bridgeName, protocol, xConnection, null});
174 bridge = tEnv.getTestObject();
176 return tEnv;
180 * Stop the acceptor thread and dispose the bridge
182 @Override
183 protected void cleanup(TestParameters Param, PrintWriter log) {
185 System.out.println("++++++++ cleanup");
186 xAcctr.stopAccepting();
187 if (accThread.isAlive()) {
188 accThread.interrupt();
190 XComponent xComp = UnoRuntime.queryInterface(
191 XComponent.class, xAcctr);
192 if (xComp != null)
193 xComp.dispose();
194 xComp = UnoRuntime.queryInterface(
195 XComponent.class, xCntr);
196 if (xComp != null)
197 xComp.dispose();
198 xComp = UnoRuntime.queryInterface(
199 XComponent.class, xBrdgFctr);
200 if (xComp != null)
201 xComp.dispose();
203 xComp = UnoRuntime.queryInterface(
204 XComponent.class, bridge);
205 if (xComp != null) {
206 System.out.println("######## Dispose bridge");
207 bridgeDisposed[0] = true;
208 xComp.dispose();
209 // wait for dispose
210 util.utils.pause(5000);