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._connectr; 29 30 import java.io.PrintWriter; 31 32 import lib.StatusException; 33 import lib.TestCase; 34 import lib.TestEnvironment; 35 import lib.TestParameters; 36 import util.utils; 37 38 import com.sun.star.lang.XMultiServiceFactory; 39 import com.sun.star.uno.XInterface; 40 41 /** 42 * Test for object which is represented by service 43 * <code>com.sun.star.connection.Connector</code>. <p> 44 * Object implements the following interfaces : 45 * <ul> 46 * <li> <code>com::sun::star::connection::XConnector</code></li> 47 * </ul> 48 * Can be run in several threads. 49 * @see com.sun.star.connection.XConnector 50 * @see ifc.connection._XConnector 51 */ 52 public class Connector extends TestCase { 53 54 /** 55 * Acceptor chooses the first port after <code>basePort</code> 56 * which is free. 57 */ 58 protected static final int basePort = 10000 ; 59 private int curPort ; 60 private static String sOfficeHost = null ; 61 62 /** 63 * Retrieves host name where StarOffice is started from test 64 * parameter <code>'CNCSTR'</code>. 65 */ 66 protected void initialize( TestParameters tParam, PrintWriter log ) { 67 String cncstr = (String) tParam.get("CNCSTR") ; 68 int idx = cncstr.indexOf("host=") + 5 ; 69 sOfficeHost = cncstr.substring(idx, cncstr.indexOf(",", idx)) ; 70 } 71 72 /** 73 * Does nothing. 74 */ 75 protected void cleanup( TestParameters tParam, PrintWriter log ) { 76 77 } 78 79 /** 80 * Creating a Testenvironment for the interfaces to be tested. 81 * Just creates service <code>com.sun.star.connection.Connector</code> 82 */ 83 public synchronized TestEnvironment createTestEnvironment( 84 TestParameters Param, PrintWriter log) throws StatusException { 85 86 XInterface oObj = null ; 87 88 try { 89 XInterface connector = (XInterface) 90 ((XMultiServiceFactory)Param.getMSF()).createInstance 91 ("com.sun.star.connection.Connector") ; 92 93 oObj = connector ; 94 } catch (com.sun.star.uno.Exception e) { 95 e.printStackTrace(log); 96 throw new StatusException("Can't create object environment", e); 97 } 98 99 TestEnvironment tEnv = new TestEnvironment(oObj) ; 100 101 // select the port 102 curPort = utils.getNextFreePort(basePort); 103 log.println("Choose Port nr: " + curPort); 104 105 // adding connection string as relation 106 tEnv.addObjRelation("XConnector.connectStr", 107 "socket,host=" + sOfficeHost + ",port=" + curPort) ; 108 109 // adding port number for freeing it. 110 tEnv.addObjRelation("Connector.Port", new Integer(curPort)) ; 111 112 return tEnv ; 113 } 114 115 /** 116 * Just clears flag which indicates that port is free now. 117 */ 118 public synchronized void disposeTestEnvironment( TestEnvironment tEnv, 119 TestParameters tParam) { 120 121 curPort = ((Integer)tEnv.getObjRelation("Connector.Port")).intValue(); 122 } 123 } 124 125 126