1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: Connector.java,v $
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
;
37 import lib
.TestEnvironment
;
38 import lib
.TestParameters
;
41 import com
.sun
.star
.lang
.XMultiServiceFactory
;
42 import com
.sun
.star
.uno
.XInterface
;
45 * Test for object which is represented by service
46 * <code>com.sun.star.connection.Connector</code>. <p>
47 * Object implements the following interfaces :
49 * <li> <code>com::sun::star::connection::XConnector</code></li>
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
{
58 * Acceptor chooses the first port after <code>basePort</code>
61 protected static final int basePort
= 10000 ;
63 private static String sOfficeHost
= null ;
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
)) ;
78 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
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 ;
92 XInterface connector
= (XInterface
)
93 ((XMultiServiceFactory
)Param
.getMSF()).createInstance
94 ("com.sun.star.connection.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
) ;
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
)) ;
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();