Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _acceptor / uno / Acceptor.java
blob1431c2e97f11a3c40b3e414f1630c11766db59c9
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._acceptor.uno;
21 import com.sun.star.uno.XInterface;
22 import java.io.PrintWriter;
23 import lib.StatusException;
24 import lib.TestCase;
25 import lib.TestEnvironment;
26 import lib.TestParameters;
27 import util.utils;
29 /**
30 * Here <code>com.sun.star.connection.Acceptor</code> service is tested.<p>
31 * Test allows to run object tests in several threads concurently.
32 * @see com.sun.star.connection.Acceptor
33 * @see com.sun.star.connection.XAcceptor
34 * @see com.sun.star.connection.XConnector
35 * @see ifc.connection._XAcceptor
37 public class Acceptor extends TestCase {
38 /**
39 * Acceptor chooses the first port after <code>basePort</code>
40 * which is free.
42 protected static final int basePort = 10000;
43 private int curPort ;
44 private String sOfficeHost = null ;
46 /**
47 * Retrieves host name where StarOffice is started from test
48 * parameter <code>'CONNECTION_STRING'</code>.
50 @Override
51 public void initialize( TestParameters tParam, PrintWriter log ) {
52 String cncstr = (String) tParam.get("CONNECTION_STRING") ;
53 int idx = cncstr.indexOf("host=") + 5 ;
54 sOfficeHost = cncstr.substring(idx, cncstr.indexOf(",", idx)) ;
57 /**
58 * Creating a Testenvironment for the interfaces to be tested. <p>
59 * Creates <code>Acceptor</code> service and passed as relation
60 * connection string where port for accepting is unique among
61 * different object test threads. <p>
62 * The following object relations are created :
63 * <ul>
64 * <li> <code>'XAcceptor.connectStr'</code> : String variable for
65 * <code>XAcceptor</code> interface test. Has the following format :
66 * <code>'socket,host=<SOHost>,port=<UniquePort>' where <SOHost> is
67 * the host where StarOffice is started. </li>
68 * <li> <code>'Acceptor.Port'</code> : Integer value which specifies
69 * port on which Acceptor must listen, and which is required
70 * when disposing environment, to free this port number. </li>
71 * <ul>
73 @Override
74 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
76 XInterface oObj = null;
77 XInterface acceptor = null;
79 try {
80 acceptor = (XInterface)
81 Param.getMSF().createInstance
82 ("com.sun.star.connection.Acceptor");
83 } catch (com.sun.star.uno.Exception e) {
84 throw new StatusException("Can't create object environment", e) ;
87 // select the port
88 curPort = utils.getNextFreePort(basePort);
89 log.println("Choose Port nr: " + curPort);
90 oObj = acceptor;
92 TestEnvironment tEnv = new TestEnvironment(oObj) ;
94 // adding connection string as relation
95 tEnv.addObjRelation("XAcceptor.connectStr",
96 "socket,host=" + sOfficeHost + ",port=" + curPort) ;
98 // adding port number for freeing it.
99 tEnv.addObjRelation("Acceptor.Port", Integer.valueOf(curPort)) ;
101 return tEnv ;
105 * Just clears flag which indicates that port is free now.
107 @Override
108 public synchronized void disposeTestEnvironment( TestEnvironment tEnv,
109 TestParameters tParam) {
111 curPort = ((Integer)tEnv.getObjRelation("Acceptor.Port")).intValue();