Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _bridgefac / uno / BridgeFactory.java
blob295ced13fa76edaf061e4cb4e14c6d0bd6679bc6
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 java.io.PrintWriter;
23 import lib.StatusException;
24 import lib.TestCase;
25 import lib.TestEnvironment;
26 import lib.TestParameters;
27 import util.utils;
29 /**
30 * Tests <code>com.sun.star.bridge.BridgeFactory</code>
31 * service. <p>
32 * @see com.sun.star.bridge.XBridgeFactory
33 * @see com.sun.star.lang.XComponent
34 * @see ifc.bridge._XBridgeFactory
35 * @see ifc.lang._XComponent
37 public class BridgeFactory extends TestCase {
39 /**
40 * Retrieves host name where StarOffice is started from test
41 * parameter <code>'CONNECTION_STRING'</code>.
43 @Override
44 protected void initialize( TestParameters tParam, PrintWriter log ) {
45 String cncstr = (String) tParam.get("CONNECTION_STRING") ;
46 int idx = cncstr.indexOf("host=") + 5 ;
47 sOfficeHost = cncstr.substring(idx, cncstr.indexOf(",", idx)) ;
50 @Override
51 protected void cleanup( TestParameters tParam, PrintWriter log ) {
54 /**
55 * Acceptor chooses the first port after <code>basePort</code>
56 * which is free.
58 protected static final int basePort = 50003 ;
59 private int curPort ;
60 private static String sOfficeHost = null ;
62 /**
63 * Creating a Testenvironment for the interfaces to be tested.
64 * Just creates <code>com.sun.star.bridge.BridgeFactory</code>
65 * service as object to be tested.
67 @Override
68 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
70 XInterface oObj = null ;
72 try {
73 oObj = (XInterface)
74 Param.getMSF().createInstance
75 ("com.sun.star.bridge.BridgeFactory") ;
76 } catch (com.sun.star.uno.Exception e) {
77 throw new StatusException("Can't create object environment", e) ;
80 if (oObj == null)
81 throw new StatusException("Can't create service",
82 new NullPointerException());
84 TestEnvironment tEnv = new TestEnvironment(oObj) ;
86 // select the port
87 curPort = utils.getNextFreePort(basePort);
88 log.println("Choose Port nr: " + curPort);
90 // adding connection string as relation
91 tEnv.addObjRelation("CNNCTSTR",
92 "socket,host=" + sOfficeHost + ",port=" + curPort) ;
94 // adding port number for freeing it.
95 tEnv.addObjRelation("Connector.Port", Integer.valueOf(curPort)) ;
97 return tEnv ;
101 * Just clears flag which indicates that port is free now.
103 @Override
104 public synchronized void disposeTestEnvironment( TestEnvironment tEnv,
105 TestParameters tParam) {
106 curPort = ((Integer)tEnv.getObjRelation("Connector.Port")).intValue() ;