Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _connector / uno / Connector.java
blobb7920b1d3a4760e945db51425acfa4923833bc0f
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._connector.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 * Test for object which is represented by service
31 * <code>com.sun.star.connection.Connector</code>. <p>
32 * Object implements the following interfaces :
33 * <ul>
34 * <li> <code>com::sun::star::connection::XConnector</code></li>
35 * </ul>
36 * Can be run in several threads.
37 * @see com.sun.star.connection.XConnector
38 * @see ifc.connection._XConnector
40 public class Connector extends TestCase {
42 /**
43 * Acceptor chooses the first port after <code>basePort</code>
44 * which is free.
46 protected static final int basePort = 10000 ;
47 private int curPort ;
48 private static String sOfficeHost = null ;
50 /**
51 * Retrieves host name where StarOffice is started from test
52 * parameter <code>'CONNECTION_STRING'</code>.
54 @Override
55 protected void initialize( TestParameters tParam, PrintWriter log ) {
56 String cncstr = (String) tParam.get("CONNECTION_STRING") ;
57 int idx = cncstr.indexOf("host=") + 5 ;
58 sOfficeHost = cncstr.substring(idx, cncstr.indexOf(",", idx)) ;
61 /**
62 * Does nothing.
64 @Override
65 protected void cleanup( TestParameters tParam, PrintWriter log ) {
69 /**
70 * Creating a Testenvironment for the interfaces to be tested.
71 * Just creates service <code>com.sun.star.connection.Connector</code>
73 @Override
74 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
76 XInterface oObj = null ;
78 try {
79 XInterface connector = (XInterface)
80 Param.getMSF().createInstance
81 ("com.sun.star.connection.Connector") ;
83 oObj = connector ;
84 } catch (com.sun.star.uno.Exception e) {
85 e.printStackTrace(log);
86 throw new StatusException("Can't create object environment", e);
89 TestEnvironment tEnv = new TestEnvironment(oObj) ;
91 // select the port
92 curPort = utils.getNextFreePort(basePort);
93 log.println("Choose Port nr: " + curPort);
95 // adding connection string as relation
96 tEnv.addObjRelation("XConnector.connectStr",
97 "socket,host=" + sOfficeHost + ",port=" + curPort) ;
99 // adding port number for freeing it.
100 tEnv.addObjRelation("Connector.Port", Integer.valueOf(curPort)) ;
102 return tEnv ;
106 * Just clears flag which indicates that port is free now.
108 @Override
109 public synchronized void disposeTestEnvironment( TestEnvironment tEnv,
110 TestParameters tParam) {
112 curPort = ((Integer)tEnv.getObjRelation("Connector.Port")).intValue();