merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _acceptor / Acceptor.java
blobc4bef971d3b0fd8c6a46e198b9a264b68c7b1ac4
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: Acceptor.java,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package mod._acceptor;
33 import java.io.PrintWriter;
35 import lib.StatusException;
36 import lib.TestCase;
37 import lib.TestEnvironment;
38 import lib.TestParameters;
39 import util.utils;
41 import com.sun.star.lang.XMultiServiceFactory;
42 import com.sun.star.uno.XInterface;
44 /**
45 * Here <code>com.sun.star.connection.Acceptor</code> service is tested.<p>
46 * Test allows to run object tests in several threads concurently.
47 * @see com.sun.star.connection.Acceptor
48 * @see com.sun.star.connection.XAcceptor
49 * @see com.sun.star.connection.XConnector
50 * @see ifc.connection._XAcceptor
52 public class Acceptor extends TestCase {
55 /**
56 * Acceptor chooses the first port after <code>basePort</code>
57 * which is free.
59 protected static final int basePort = 10000;
60 private int curPort ;
61 private static String sOfficeHost = null ;
63 /**
64 * Retrieves host name where StarOffice is started from test
65 * parameter <code>'CNCSTR'</code>.
67 public void initialize( TestParameters tParam, PrintWriter log ) {
68 String cncstr = (String) tParam.get("CNCSTR") ;
69 int idx = cncstr.indexOf("host=") + 5 ;
70 sOfficeHost = cncstr.substring(idx, cncstr.indexOf(",", idx)) ;
73 /**
74 * Creating a Testenvironment for the interfaces to be tested. <p>
75 * Creates <code>Acceptor</code> service and passed as relation
76 * connection string where port for accepting is unique among
77 * different object test threads. <p>
78 * The following object relations are created :
79 * <ul>
80 * <li> <code>'XAcceptor.connectStr'</code> : String variable for
81 * <code>XAcceptor</code> interface test. Has the following format :
82 * <code>'socket,host=<SOHost>,port=<UniquePort>' where <SOHost> is
83 * the host where StarOffice is started. </li>
84 * <li> <code>'Acceptor.Port'</code> : Integer value which specifies
85 * port on which Acceptor must listen, and which is required
86 * when disposing environment, to free this port number. </li>
87 * <ul>
89 public synchronized TestEnvironment createTestEnvironment(
90 TestParameters Param, PrintWriter log ) throws StatusException {
92 XInterface oObj = null;
93 XInterface acceptor = null;
95 try {
96 acceptor = (XInterface)
97 ((XMultiServiceFactory)Param.getMSF()).createInstance
98 ("com.sun.star.connection.Acceptor");
99 } catch (com.sun.star.uno.Exception e) {
100 throw new StatusException("Can't create object environment", e) ;
103 // select the port
104 curPort = utils.getNextFreePort(basePort);
105 log.println("Choose Port nr: " + curPort);
106 oObj = acceptor;
108 TestEnvironment tEnv = new TestEnvironment(oObj) ;
110 // adding connection string as relation
111 tEnv.addObjRelation("XAcceptor.connectStr",
112 "socket,host=" + sOfficeHost + ",port=" + curPort) ;
114 // adding port number for freeing it.
115 tEnv.addObjRelation("Acceptor.Port", new Integer(curPort)) ;
117 return tEnv ;
121 * Just clears flag which indicates that port is free now.
123 public synchronized void disposeTestEnvironment( TestEnvironment tEnv,
124 TestParameters tParam) {
126 curPort = ((Integer)tEnv.getObjRelation("Acceptor.Port")).intValue();