1*ef39d40dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ef39d40dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ef39d40dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ef39d40dSAndrew Rist  * distributed with this work for additional information
6*ef39d40dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ef39d40dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ef39d40dSAndrew Rist  * "License"); you may not use this file except in compliance
9*ef39d40dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*ef39d40dSAndrew Rist  *
11*ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*ef39d40dSAndrew Rist  *
13*ef39d40dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ef39d40dSAndrew Rist  * software distributed under the License is distributed on an
15*ef39d40dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ef39d40dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*ef39d40dSAndrew Rist  * specific language governing permissions and limitations
18*ef39d40dSAndrew Rist  * under the License.
19*ef39d40dSAndrew Rist  *
20*ef39d40dSAndrew Rist  *************************************************************/
21*ef39d40dSAndrew Rist 
22*ef39d40dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package mod._brdgfctr;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import java.io.PrintWriter;
27cdf0e10cSrcweir 
28cdf0e10cSrcweir import lib.StatusException;
29cdf0e10cSrcweir import lib.TestCase;
30cdf0e10cSrcweir import lib.TestEnvironment;
31cdf0e10cSrcweir import lib.TestParameters;
32cdf0e10cSrcweir import util.utils;
33cdf0e10cSrcweir 
34cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
35cdf0e10cSrcweir import com.sun.star.uno.XInterface;
36cdf0e10cSrcweir 
37cdf0e10cSrcweir /**
38cdf0e10cSrcweir * Tests <code>com.sun.star.bridge.BridgeFactory</code>
39cdf0e10cSrcweir * service. <p>
40cdf0e10cSrcweir * @see com.sun.star.bridge.XBridgeFactory
41cdf0e10cSrcweir * @see com.sun.star.lang.XComponent
42cdf0e10cSrcweir * @see ifc.bridge._XBridgeFactory
43cdf0e10cSrcweir * @see ifc.lang._XComponent
44cdf0e10cSrcweir */
45cdf0e10cSrcweir public class BridgeFactory extends TestCase {
46cdf0e10cSrcweir 
47cdf0e10cSrcweir     /**
48cdf0e10cSrcweir     * Retrieves host name where StarOffice is started from test
49cdf0e10cSrcweir     * parameter <code>'CNCSTR'</code>.
50cdf0e10cSrcweir     */
initialize( TestParameters tParam, PrintWriter log )51cdf0e10cSrcweir     protected void initialize( TestParameters tParam, PrintWriter log ) {
52cdf0e10cSrcweir         String cncstr = (String) tParam.get("CNCSTR") ;
53cdf0e10cSrcweir         int idx = cncstr.indexOf("host=") + 5 ;
54cdf0e10cSrcweir         sOfficeHost = cncstr.substring(idx, cncstr.indexOf(",", idx)) ;
55cdf0e10cSrcweir     }
56cdf0e10cSrcweir 
cleanup( TestParameters tParam, PrintWriter log )57cdf0e10cSrcweir     protected void cleanup( TestParameters tParam, PrintWriter log ) {
58cdf0e10cSrcweir     }
59cdf0e10cSrcweir 
60cdf0e10cSrcweir     /**
61cdf0e10cSrcweir     * Acceptor chooses the first port after <code>basePort</code>
62cdf0e10cSrcweir     * which is free.
63cdf0e10cSrcweir     */
64cdf0e10cSrcweir     protected static final int basePort = 50003 ;
65cdf0e10cSrcweir     private int curPort ;
66cdf0e10cSrcweir     private static String sOfficeHost = null ;
67cdf0e10cSrcweir 
68cdf0e10cSrcweir     /**
69cdf0e10cSrcweir      * Creating a Testenvironment for the interfaces to be tested.
70cdf0e10cSrcweir      * Just creates <code>com.sun.star.bridge.BridgeFactory</code>
71cdf0e10cSrcweir      * service as object to be tested.
72cdf0e10cSrcweir      */
createTestEnvironment( TestParameters Param, PrintWriter log )73cdf0e10cSrcweir     public synchronized TestEnvironment createTestEnvironment(
74cdf0e10cSrcweir         TestParameters Param, PrintWriter log ) throws StatusException {
75cdf0e10cSrcweir 
76cdf0e10cSrcweir         XInterface oObj = null ;
77cdf0e10cSrcweir 
78cdf0e10cSrcweir         try {
79cdf0e10cSrcweir             oObj = (XInterface) ((XMultiServiceFactory)Param.getMSF()).createInstance
80cdf0e10cSrcweir                 ("com.sun.star.bridge.BridgeFactory") ;
81cdf0e10cSrcweir         } catch (com.sun.star.uno.Exception e) {
82cdf0e10cSrcweir             throw new StatusException("Can't create object environment", e) ;
83cdf0e10cSrcweir         }
84cdf0e10cSrcweir 
85cdf0e10cSrcweir         if (oObj == null)
86cdf0e10cSrcweir             throw new StatusException("Can't create service",
87cdf0e10cSrcweir                 new NullPointerException());
88cdf0e10cSrcweir 
89cdf0e10cSrcweir         TestEnvironment tEnv = new TestEnvironment(oObj) ;
90cdf0e10cSrcweir 
91cdf0e10cSrcweir         // select the port
92cdf0e10cSrcweir         curPort = utils.getNextFreePort(basePort);
93cdf0e10cSrcweir         log.println("Choose Port nr: " + curPort);
94cdf0e10cSrcweir 
95cdf0e10cSrcweir         // adding connection string as relation
96cdf0e10cSrcweir         tEnv.addObjRelation("CNNCTSTR",
97cdf0e10cSrcweir             "socket,host=" + sOfficeHost + ",port=" + curPort) ;
98cdf0e10cSrcweir 
99cdf0e10cSrcweir         // adding port number for freeing it.
100cdf0e10cSrcweir         tEnv.addObjRelation("Connector.Port", new Integer(curPort)) ;
101cdf0e10cSrcweir 
102cdf0e10cSrcweir         return tEnv ;
103cdf0e10cSrcweir     }
104cdf0e10cSrcweir 
105cdf0e10cSrcweir     /**
106cdf0e10cSrcweir     * Just clears flag which indicates that port is free now.
107cdf0e10cSrcweir     */
disposeTestEnvironment( TestEnvironment tEnv, TestParameters tParam)108cdf0e10cSrcweir     public synchronized void disposeTestEnvironment( TestEnvironment tEnv,
109cdf0e10cSrcweir             TestParameters tParam) {
110cdf0e10cSrcweir         curPort = ((Integer)tEnv.getObjRelation("Connector.Port")).intValue() ;
111cdf0e10cSrcweir     }
112cdf0e10cSrcweir }
113cdf0e10cSrcweir 
114cdf0e10cSrcweir 
115