Avoid potential negative array index access to cached text.
[LibreOffice.git] / qadevOOo / tests / java / mod / _brdgfctr / BridgeFactory.java
blob1957f9d6b9be3fc69019ba21c6e9ec1c73e05ac4
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.TestCase;
24 import lib.TestEnvironment;
25 import lib.TestParameters;
26 import util.utils;
28 import com.sun.star.uno.XInterface;
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>'CONNECTION_STRING'</code>.
44 @Override
45 protected void initialize( TestParameters tParam, PrintWriter log ) throws Exception {
46 String cncstr = (String) tParam.get("CONNECTION_STRING") ;
47 int idx = cncstr.indexOf("host=") + 5 ;
48 sOfficeHost = cncstr.substring(idx, cncstr.indexOf(",", idx)) ;
51 @Override
52 protected void cleanup( TestParameters tParam, PrintWriter log ) {
55 /**
56 * Acceptor chooses the first port after <code>basePort</code>
57 * which is free.
59 protected static final int basePort = 50003 ;
60 private int curPort ;
61 private static String sOfficeHost = null ;
63 /**
64 * Creating a TestEnvironment for the interfaces to be tested.
65 * Just creates <code>com.sun.star.bridge.BridgeFactory</code>
66 * service as object to be tested.
68 @Override
69 public TestEnvironment createTestEnvironment(
70 TestParameters Param, PrintWriter log ) throws Exception {
72 XInterface oObj = (XInterface) Param.getMSF().createInstance
73 ("com.sun.star.bridge.BridgeFactory") ;
75 TestEnvironment tEnv = new TestEnvironment(oObj) ;
77 // select the port
78 curPort = utils.getNextFreePort(basePort);
79 log.println("Choose Port nr: " + curPort);
81 // adding connection string as relation
82 tEnv.addObjRelation("CNNCTSTR",
83 "socket,host=" + sOfficeHost + ",port=" + curPort) ;
85 // adding port number for freeing it.
86 tEnv.addObjRelation("Connector.Port", Integer.valueOf(curPort)) ;
88 return tEnv ;
91 /**
92 * Just clears flag which indicates that port is free now.
94 @Override
95 public synchronized void disposeTestEnvironment( TestEnvironment tEnv,
96 TestParameters tParam) {
97 curPort = ((Integer)tEnv.getObjRelation("Connector.Port")).intValue() ;