merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _connector.uno / Connector.java
blob941b365f28ebc602d0c064b1306a720e7e8bfb38
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: Connector.java,v $
10 * $Revision: 1.4 $
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._connector.uno;
33 import com.sun.star.uno.XInterface;
34 import com.sun.star.lang.XMultiServiceFactory;
35 import java.io.PrintWriter;
36 import lib.StatusException;
37 import lib.TestCase;
38 import lib.TestEnvironment;
39 import lib.TestParameters;
40 import util.utils;
42 /**
43 * Test for object which is represented by service
44 * <code>com.sun.star.connection.Connector</code>. <p>
45 * Object implements the following interfaces :
46 * <ul>
47 * <li> <code>com::sun::star::connection::XConnector</code></li>
48 * </ul>
49 * Can be run in several threads.
50 * @see com.sun.star.connection.XConnector
51 * @see ifc.connection._XConnector
53 public class Connector 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 protected 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 * Does nothing.
76 protected void cleanup( TestParameters tParam, PrintWriter log ) {
80 /**
81 * Creating a Testenvironment for the interfaces to be tested.
82 * Just creates service <code>com.sun.star.connection.Connector</code>
84 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
86 XInterface oObj = null ;
88 try {
89 XInterface connector = (XInterface)
90 ((XMultiServiceFactory)Param.getMSF()).createInstance
91 ("com.sun.star.connection.Connector") ;
93 oObj = connector ;
94 } catch (com.sun.star.uno.Exception e) {
95 e.printStackTrace(log);
96 throw new StatusException("Can't create object environment", e);
99 TestEnvironment tEnv = new TestEnvironment(oObj) ;
101 // select the port
102 curPort = utils.getNextFreePort(basePort);
103 log.println("Choose Port nr: " + curPort);
105 // adding connection string as relation
106 tEnv.addObjRelation("XConnector.connectStr",
107 "socket,host=" + sOfficeHost + ",port=" + curPort) ;
109 // adding port number for freeing it.
110 tEnv.addObjRelation("Connector.Port", new Integer(curPort)) ;
112 return tEnv ;
116 * Just clears flag which indicates that port is free now.
118 public synchronized void disposeTestEnvironment( TestEnvironment tEnv,
119 TestParameters tParam) {
121 curPort = ((Integer)tEnv.getObjRelation("Connector.Port")).intValue();