1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 package mod._acceptor.uno; 29 30 import com.sun.star.uno.XInterface; 31 import com.sun.star.lang.XMultiServiceFactory; 32 import java.io.PrintWriter; 33 import lib.StatusException; 34 import lib.TestCase; 35 import lib.TestEnvironment; 36 import lib.TestParameters; 37 import util.utils; 38 39 /** 40 * Here <code>com.sun.star.connection.Acceptor</code> service is tested.<p> 41 * Test allows to run object tests in several threads concurently. 42 * @see com.sun.star.connection.Acceptor 43 * @see com.sun.star.connection.XAcceptor 44 * @see com.sun.star.connection.XConnector 45 * @see ifc.connection._XAcceptor 46 */ 47 public class Acceptor extends TestCase { 48 /** 49 * Acceptor chooses the first port after <code>basePort</code> 50 * which is free. 51 */ 52 protected static final int basePort = 10000; 53 private int curPort ; 54 private static String sOfficeHost = null ; 55 56 /** 57 * Retrieves host name where StarOffice is started from test 58 * parameter <code>'CNCSTR'</code>. 59 */ 60 public void initialize( TestParameters tParam, PrintWriter log ) { 61 String cncstr = (String) tParam.get("CNCSTR") ; 62 int idx = cncstr.indexOf("host=") + 5 ; 63 sOfficeHost = cncstr.substring(idx, cncstr.indexOf(",", idx)) ; 64 } 65 66 /** 67 * Creating a Testenvironment for the interfaces to be tested. <p> 68 * Creates <code>Acceptor</code> service and passed as relation 69 * connection string where port for accepting is unique among 70 * different object test threads. <p> 71 * The following object relations are created : 72 * <ul> 73 * <li> <code>'XAcceptor.connectStr'</code> : String variable for 74 * <code>XAcceptor</code> interface test. Has the following format : 75 * <code>'socket,host=<SOHost>,port=<UniquePort>' where <SOHost> is 76 * the host where StarOffice is started. </li> 77 * <li> <code>'Acceptor.Port'</code> : Integer value which specifies 78 * port on which Acceptor must listen, and which is required 79 * when disposing environment, to free this port number. </li> 80 * <ul> 81 */ 82 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) { 83 84 XInterface oObj = null; 85 XInterface acceptor = null; 86 87 try { 88 acceptor = (XInterface) 89 ((XMultiServiceFactory)Param.getMSF()).createInstance 90 ("com.sun.star.connection.Acceptor"); 91 } catch (com.sun.star.uno.Exception e) { 92 throw new StatusException("Can't create object environment", e) ; 93 } 94 95 // select the port 96 curPort = utils.getNextFreePort(basePort); 97 log.println("Choose Port nr: " + curPort); 98 oObj = acceptor; 99 100 TestEnvironment tEnv = new TestEnvironment(oObj) ; 101 102 // adding connection string as relation 103 tEnv.addObjRelation("XAcceptor.connectStr", 104 "socket,host=" + sOfficeHost + ",port=" + curPort) ; 105 106 // adding port number for freeing it. 107 tEnv.addObjRelation("Acceptor.Port", new Integer(curPort)) ; 108 109 return tEnv ; 110 } 111 112 /** 113 * Just clears flag which indicates that port is free now. 114 */ 115 public synchronized void disposeTestEnvironment( TestEnvironment tEnv, 116 TestParameters tParam) { 117 118 curPort = ((Integer)tEnv.getObjRelation("Acceptor.Port")).intValue(); 119 } 120 } 121 122 123