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