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