bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _bridgefac / uno / BridgeFactory.java
blob6ed4835b6efa444ab811530fa7f7c56d2b593879
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package mod._bridgefac.uno;
21 import com.sun.star.uno.XInterface;
22 import com.sun.star.lang.XMultiServiceFactory;
23 import java.io.PrintWriter;
24 import lib.StatusException;
25 import lib.TestCase;
26 import lib.TestEnvironment;
27 import lib.TestParameters;
28 import util.utils;
30 /**
31 * Tests <code>com.sun.star.bridge.BridgeFactory</code>
32 * service. <p>
33 * @see com.sun.star.bridge.XBridgeFactory
34 * @see com.sun.star.lang.XComponent
35 * @see ifc.bridge._XBridgeFactory
36 * @see ifc.lang._XComponent
38 public class BridgeFactory extends TestCase {
40 /**
41 * Retrieves host name where StarOffice is started from test
42 * parameter <code>'CNCSTR'</code>.
44 protected void initialize( TestParameters tParam, PrintWriter log ) {
45 String cncstr = (String) tParam.get("CNCSTR") ;
46 int idx = cncstr.indexOf("host=") + 5 ;
47 sOfficeHost = cncstr.substring(idx, cncstr.indexOf(",", idx)) ;
50 protected void cleanup( TestParameters tParam, PrintWriter log ) {
53 /**
54 * Acceptor chooses the first port after <code>basePort</code>
55 * which is free.
57 protected static final int basePort = 50003 ;
58 private int curPort ;
59 private static String sOfficeHost = null ;
61 /**
62 * Creating a Testenvironment for the interfaces to be tested.
63 * Just creates <code>com.sun.star.bridge.BridgeFactory</code>
64 * service as object to be tested.
66 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
68 XInterface oObj = null ;
70 try {
71 oObj = (XInterface)
72 ((XMultiServiceFactory)Param.getMSF()).createInstance
73 ("com.sun.star.bridge.BridgeFactory") ;
74 } catch (com.sun.star.uno.Exception e) {
75 throw new StatusException("Can't create object environment", e) ;
78 if (oObj == null)
79 throw new StatusException("Can't create service",
80 new NullPointerException());
82 TestEnvironment tEnv = new TestEnvironment(oObj) ;
84 // select the port
85 curPort = utils.getNextFreePort(basePort);
86 log.println("Choose Port nr: " + curPort);
88 // adding connection string as relation
89 tEnv.addObjRelation("CNNCTSTR",
90 "socket,host=" + sOfficeHost + ",port=" + curPort) ;
92 // adding port number for freeing it.
93 tEnv.addObjRelation("Connector.Port", new Integer(curPort)) ;
95 return tEnv ;
98 /**
99 * Just clears flag which indicates that port is free now.
101 public synchronized void disposeTestEnvironment( TestEnvironment tEnv,
102 TestParameters tParam) {
103 curPort = ((Integer)tEnv.getObjRelation("Connector.Port")).intValue() ;