merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _bridgefac.uno / BridgeFactory.java
blob9dcd2d0a80ec7c6d97b47cf320cd92f2770f399e
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: BridgeFactory.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._bridgefac.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 * Tests <code>com.sun.star.bridge.BridgeFactory</code>
44 * service. <p>
45 * @see com.sun.star.bridge.XBridgeFactory
46 * @see com.sun.star.lang.XComponent
47 * @see ifc.bridge._XBridgeFactory
48 * @see ifc.lang._XComponent
50 public class BridgeFactory extends TestCase {
52 /**
53 * Retrieves host name where StarOffice is started from test
54 * parameter <code>'CNCSTR'</code>.
56 protected void initialize( TestParameters tParam, PrintWriter log ) {
57 String cncstr = (String) tParam.get("CNCSTR") ;
58 int idx = cncstr.indexOf("host=") + 5 ;
59 sOfficeHost = cncstr.substring(idx, cncstr.indexOf(",", idx)) ;
62 protected void cleanup( TestParameters tParam, PrintWriter log ) {
65 /**
66 * Acceptor chooses the first port after <code>basePort</code>
67 * which is free.
69 protected static final int basePort = 50003 ;
70 private int curPort ;
71 private static String sOfficeHost = null ;
73 /**
74 * Creating a Testenvironment for the interfaces to be tested.
75 * Just creates <code>com.sun.star.bridge.BridgeFactory</code>
76 * service as object to be tested.
78 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
80 XInterface oObj = null ;
82 try {
83 oObj = (XInterface)
84 ((XMultiServiceFactory)Param.getMSF()).createInstance
85 ("com.sun.star.bridge.BridgeFactory") ;
86 } catch (com.sun.star.uno.Exception e) {
87 throw new StatusException("Can't create object environment", e) ;
90 if (oObj == null)
91 throw new StatusException("Can't create service",
92 new NullPointerException());
94 TestEnvironment tEnv = new TestEnvironment(oObj) ;
96 // select the port
97 curPort = utils.getNextFreePort(basePort);
98 log.println("Choose Port nr: " + curPort);
100 // adding connection string as relation
101 tEnv.addObjRelation("CNNCTSTR",
102 "socket,host=" + sOfficeHost + ",port=" + curPort) ;
104 // adding port number for freeing it.
105 tEnv.addObjRelation("Connector.Port", new Integer(curPort)) ;
107 return tEnv ;
111 * Just clears flag which indicates that port is free now.
113 public synchronized void disposeTestEnvironment( TestEnvironment tEnv,
114 TestParameters tParam) {
115 curPort = ((Integer)tEnv.getObjRelation("Connector.Port")).intValue() ;