merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _connectr / Connector.java
blobe4e7c7938f96fce4c149f2ca28193f1902d53be8
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.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._connectr;
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 * Test for object which is represented by service
46 * <code>com.sun.star.connection.Connector</code>. <p>
47 * Object implements the following interfaces :
48 * <ul>
49 * <li> <code>com::sun::star::connection::XConnector</code></li>
50 * </ul>
51 * Can be run in several threads.
52 * @see com.sun.star.connection.XConnector
53 * @see ifc.connection._XConnector
55 public class Connector extends TestCase {
57 /**
58 * Acceptor chooses the first port after <code>basePort</code>
59 * which is free.
61 protected static final int basePort = 10000 ;
62 private int curPort ;
63 private static String sOfficeHost = null ;
65 /**
66 * Retrieves host name where StarOffice is started from test
67 * parameter <code>'CNCSTR'</code>.
69 protected void initialize( TestParameters tParam, PrintWriter log ) {
70 String cncstr = (String) tParam.get("CNCSTR") ;
71 int idx = cncstr.indexOf("host=") + 5 ;
72 sOfficeHost = cncstr.substring(idx, cncstr.indexOf(",", idx)) ;
75 /**
76 * Does nothing.
78 protected void cleanup( TestParameters tParam, PrintWriter log ) {
82 /**
83 * Creating a Testenvironment for the interfaces to be tested.
84 * Just creates service <code>com.sun.star.connection.Connector</code>
86 public synchronized TestEnvironment createTestEnvironment(
87 TestParameters Param, PrintWriter log) throws StatusException {
89 XInterface oObj = null ;
91 try {
92 XInterface connector = (XInterface)
93 ((XMultiServiceFactory)Param.getMSF()).createInstance
94 ("com.sun.star.connection.Connector") ;
96 oObj = connector ;
97 } catch (com.sun.star.uno.Exception e) {
98 e.printStackTrace(log);
99 throw new StatusException("Can't create object environment", e);
102 TestEnvironment tEnv = new TestEnvironment(oObj) ;
104 // select the port
105 curPort = utils.getNextFreePort(basePort);
106 log.println("Choose Port nr: " + curPort);
108 // adding connection string as relation
109 tEnv.addObjRelation("XConnector.connectStr",
110 "socket,host=" + sOfficeHost + ",port=" + curPort) ;
112 // adding port number for freeing it.
113 tEnv.addObjRelation("Connector.Port", new Integer(curPort)) ;
115 return tEnv ;
119 * Just clears flag which indicates that port is free now.
121 public synchronized void disposeTestEnvironment( TestEnvironment tEnv,
122 TestParameters tParam) {
124 curPort = ((Integer)tEnv.getObjRelation("Connector.Port")).intValue();