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