1 /* 2 * This file is part of the LibreOffice project. 3 * 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/. 7 * 8 * This file incorporates work covered by the following license notice: 9 * 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 . 17 */ 18 19 package mod._acceptor; 20 21 import java.io.PrintWriter; 22 23 import lib.TestCase; 24 import lib.TestEnvironment; 25 import lib.TestParameters; 26 import util.utils; 27 28 import com.sun.star.uno.XInterface; 29 30 /** 31 * Here <code>com.sun.star.connection.Acceptor</code> service is tested.<p> 32 * Test allows to run object tests in several threads concurrently. 33 * @see com.sun.star.connection.Acceptor 34 * @see com.sun.star.connection.XAcceptor 35 * @see com.sun.star.connection.XConnector 36 * @see ifc.connection._XAcceptor 37 */ 38 public class Acceptor extends TestCase { 39 40 41 /** 42 * Acceptor chooses the first port after <code>basePort</code> 43 * which is free. 44 */ 45 protected static final int basePort = 10000; 46 private int curPort ; 47 private String sOfficeHost = null ; 48 49 /** 50 * Retrieves host name where StarOffice is started from test 51 * parameter <code>'CONNECTION_STRING'</code>. 52 */ 53 @Override initialize( TestParameters tParam, PrintWriter log )54 public void initialize( TestParameters tParam, PrintWriter log ) { 55 String cncstr = (String) tParam.get("CONNECTION_STRING") ; 56 int idx = cncstr.indexOf("host=") + 5 ; 57 sOfficeHost = cncstr.substring(idx, cncstr.indexOf(",", idx)) ; 58 } 59 60 /** 61 * Creating a TestEnvironment for the interfaces to be tested. <p> 62 * Creates <code>Acceptor</code> service and passed as relation 63 * connection string where port for accepting is unique among 64 * different object test threads. <p> 65 * The following object relations are created : 66 * <ul> 67 * <li> <code>'XAcceptor.connectStr'</code> : String variable for 68 * <code>XAcceptor</code> interface test. Has the following format : 69 * <code>'socket,host=<SOHost>,port=<UniquePort>' where <SOHost> is 70 * the host where StarOffice is started. </li> 71 * <li> <code>'Acceptor.Port'</code> : Integer value which specifies 72 * port on which Acceptor must listen, and which is required 73 * when disposing environment, to free this port number. </li> 74 * <ul> 75 */ 76 @Override createTestEnvironment( TestParameters Param, PrintWriter log )77 public TestEnvironment createTestEnvironment( 78 TestParameters Param, PrintWriter log ) throws Exception { 79 80 XInterface oObj = null; 81 XInterface acceptor = null; 82 83 acceptor = (XInterface) 84 Param.getMSF().createInstance 85 ("com.sun.star.connection.Acceptor"); 86 87 // select the port 88 curPort = utils.getNextFreePort(basePort); 89 log.println("Choose Port nr: " + curPort); 90 oObj = acceptor; 91 92 TestEnvironment tEnv = new TestEnvironment(oObj) ; 93 94 // adding connection string as relation 95 tEnv.addObjRelation("XAcceptor.connectStr", 96 "socket,host=" + sOfficeHost + ",port=" + curPort) ; 97 98 // adding port number for freeing it. 99 tEnv.addObjRelation("Acceptor.Port", Integer.valueOf(curPort)) ; 100 101 return tEnv ; 102 } 103 104 /** 105 * Just clears flag which indicates that port is free now. 106 */ 107 @Override disposeTestEnvironment( TestEnvironment tEnv, TestParameters tParam)108 public synchronized void disposeTestEnvironment( TestEnvironment tEnv, 109 TestParameters tParam) { 110 111 curPort = ((Integer)tEnv.getObjRelation("Acceptor.Port")).intValue(); 112 } 113 } 114 115 116