bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _brdgfctr / BridgeFactory.java
blob00100fb90364e0d91ff5a2b853618c483f2b6977
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._brdgfctr;
21 import java.io.PrintWriter;
23 import lib.StatusException;
24 import lib.TestCase;
25 import lib.TestEnvironment;
26 import lib.TestParameters;
27 import util.utils;
29 import com.sun.star.uno.XInterface;
31 /**
32 * Tests <code>com.sun.star.bridge.BridgeFactory</code>
33 * service. <p>
34 * @see com.sun.star.bridge.XBridgeFactory
35 * @see com.sun.star.lang.XComponent
36 * @see ifc.bridge._XBridgeFactory
37 * @see ifc.lang._XComponent
39 public class BridgeFactory extends TestCase {
41 /**
42 * Retrieves host name where StarOffice is started from test
43 * parameter <code>'CONNECTION_STRING'</code>.
45 @Override
46 protected void initialize( TestParameters tParam, PrintWriter log ) {
47 String cncstr = (String) tParam.get("CONNECTION_STRING") ;
48 int idx = cncstr.indexOf("host=") + 5 ;
49 sOfficeHost = cncstr.substring(idx, cncstr.indexOf(",", idx)) ;
52 @Override
53 protected void cleanup( TestParameters tParam, PrintWriter log ) {
56 /**
57 * Acceptor chooses the first port after <code>basePort</code>
58 * which is free.
60 protected static final int basePort = 50003 ;
61 private int curPort ;
62 private static String sOfficeHost = null ;
64 /**
65 * Creating a Testenvironment for the interfaces to be tested.
66 * Just creates <code>com.sun.star.bridge.BridgeFactory</code>
67 * service as object to be tested.
69 @Override
70 public synchronized TestEnvironment createTestEnvironment(
71 TestParameters Param, PrintWriter log ) throws StatusException {
73 XInterface oObj = null ;
75 try {
76 oObj = (XInterface) Param.getMSF().createInstance
77 ("com.sun.star.bridge.BridgeFactory") ;
78 } catch (com.sun.star.uno.Exception e) {
79 throw new StatusException("Can't create object environment", e) ;
82 if (oObj == null)
83 throw new StatusException("Can't create service",
84 new NullPointerException());
86 TestEnvironment tEnv = new TestEnvironment(oObj) ;
88 // select the port
89 curPort = utils.getNextFreePort(basePort);
90 log.println("Choose Port nr: " + curPort);
92 // adding connection string as relation
93 tEnv.addObjRelation("CNNCTSTR",
94 "socket,host=" + sOfficeHost + ",port=" + curPort) ;
96 // adding port number for freeing it.
97 tEnv.addObjRelation("Connector.Port", Integer.valueOf(curPort)) ;
99 return tEnv ;
103 * Just clears flag which indicates that port is free now.
105 @Override
106 public synchronized void disposeTestEnvironment( TestEnvironment tEnv,
107 TestParameters tParam) {
108 curPort = ((Integer)tEnv.getObjRelation("Connector.Port")).intValue() ;