bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _connectr / Connector.java
blobb4bd3caf366c0b4a5c3b3aad28edb75cacd5b5e2
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._connectr;
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 * Test for object which is represented by service
33 * <code>com.sun.star.connection.Connector</code>. <p>
34 * Object implements the following interfaces :
35 * <ul>
36 * <li> <code>com::sun::star::connection::XConnector</code></li>
37 * </ul>
38 * Can be run in several threads.
39 * @see com.sun.star.connection.XConnector
40 * @see ifc.connection._XConnector
42 public class Connector extends TestCase {
44 /**
45 * Acceptor chooses the first port after <code>basePort</code>
46 * which is free.
48 protected static final int basePort = 10000 ;
49 private int curPort ;
50 private static String sOfficeHost = null ;
52 /**
53 * Retrieves host name where StarOffice is started from test
54 * parameter <code>'CONNECTION_STRING'</code>.
56 @Override
57 protected void initialize( TestParameters tParam, PrintWriter log ) {
58 String cncstr = (String) tParam.get("CONNECTION_STRING") ;
59 int idx = cncstr.indexOf("host=") + 5 ;
60 sOfficeHost = cncstr.substring(idx, cncstr.indexOf(",", idx)) ;
63 /**
64 * Does nothing.
66 @Override
67 protected void cleanup( TestParameters tParam, PrintWriter log ) {
71 /**
72 * Creating a Testenvironment for the interfaces to be tested.
73 * Just creates service <code>com.sun.star.connection.Connector</code>
75 @Override
76 public synchronized TestEnvironment createTestEnvironment(
77 TestParameters Param, PrintWriter log) throws StatusException {
79 XInterface oObj = null ;
81 try {
82 XInterface connector = (XInterface)
83 Param.getMSF().createInstance
84 ("com.sun.star.connection.Connector") ;
86 oObj = connector ;
87 } catch (com.sun.star.uno.Exception e) {
88 e.printStackTrace(log);
89 throw new StatusException("Can't create object environment", e);
92 TestEnvironment tEnv = new TestEnvironment(oObj) ;
94 // select the port
95 curPort = utils.getNextFreePort(basePort);
96 log.println("Choose Port nr: " + curPort);
98 // adding connection string as relation
99 tEnv.addObjRelation("XConnector.connectStr",
100 "socket,host=" + sOfficeHost + ",port=" + curPort) ;
102 // adding port number for freeing it.
103 tEnv.addObjRelation("Connector.Port", Integer.valueOf(curPort)) ;
105 return tEnv ;
109 * Just clears flag which indicates that port is free now.
111 @Override
112 public synchronized void disposeTestEnvironment( TestEnvironment tEnv,
113 TestParameters tParam) {
115 curPort = ((Integer)tEnv.getObjRelation("Connector.Port")).intValue();