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._brdgfctr; 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 * Tests <code>com.sun.star.bridge.BridgeFactory</code> 43 * service. <p> 44 * @see com.sun.star.bridge.XBridgeFactory 45 * @see com.sun.star.lang.XComponent 46 * @see ifc.bridge._XBridgeFactory 47 * @see ifc.lang._XComponent 48 */ 49 public class BridgeFactory extends TestCase { 50 51 /** 52 * Retrieves host name where StarOffice is started from test 53 * parameter <code>'CNCSTR'</code>. 54 */ 55 protected void initialize( TestParameters tParam, PrintWriter log ) { 56 String cncstr = (String) tParam.get("CNCSTR") ; 57 int idx = cncstr.indexOf("host=") + 5 ; 58 sOfficeHost = cncstr.substring(idx, cncstr.indexOf(",", idx)) ; 59 } 60 61 protected void cleanup( TestParameters tParam, PrintWriter log ) { 62 } 63 64 /** 65 * Acceptor chooses the first port after <code>basePort</code> 66 * which is free. 67 */ 68 protected static final int basePort = 50003 ; 69 private int curPort ; 70 private static String sOfficeHost = null ; 71 72 /** 73 * Creating a Testenvironment for the interfaces to be tested. 74 * Just creates <code>com.sun.star.bridge.BridgeFactory</code> 75 * service as object to be tested. 76 */ 77 public synchronized TestEnvironment createTestEnvironment( 78 TestParameters Param, PrintWriter log ) throws StatusException { 79 80 XInterface oObj = null ; 81 82 try { 83 oObj = (XInterface) ((XMultiServiceFactory)Param.getMSF()).createInstance 84 ("com.sun.star.bridge.BridgeFactory") ; 85 } catch (com.sun.star.uno.Exception e) { 86 throw new StatusException("Can't create object environment", e) ; 87 } 88 89 if (oObj == null) 90 throw new StatusException("Can't create service", 91 new NullPointerException()); 92 93 TestEnvironment tEnv = new TestEnvironment(oObj) ; 94 95 // select the port 96 curPort = utils.getNextFreePort(basePort); 97 log.println("Choose Port nr: " + curPort); 98 99 // adding connection string as relation 100 tEnv.addObjRelation("CNNCTSTR", 101 "socket,host=" + sOfficeHost + ",port=" + curPort) ; 102 103 // adding port number for freeing it. 104 tEnv.addObjRelation("Connector.Port", new Integer(curPort)) ; 105 106 return tEnv ; 107 } 108 109 /** 110 * Just clears flag which indicates that port is free now. 111 */ 112 public synchronized void disposeTestEnvironment( TestEnvironment tEnv, 113 TestParameters tParam) { 114 curPort = ((Integer)tEnv.getObjRelation("Connector.Port")).intValue() ; 115 } 116 } 117 118 119