1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package mod._connector.uno; 25 26 import com.sun.star.uno.XInterface; 27 import com.sun.star.lang.XMultiServiceFactory; 28 import java.io.PrintWriter; 29 import lib.StatusException; 30 import lib.TestCase; 31 import lib.TestEnvironment; 32 import lib.TestParameters; 33 import util.utils; 34 35 /** 36 * Test for object which is represented by service 37 * <code>com.sun.star.connection.Connector</code>. <p> 38 * Object implements the following interfaces : 39 * <ul> 40 * <li> <code>com::sun::star::connection::XConnector</code></li> 41 * </ul> 42 * Can be run in several threads. 43 * @see com.sun.star.connection.XConnector 44 * @see ifc.connection._XConnector 45 */ 46 public class Connector extends TestCase { 47 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 */ initialize( TestParameters tParam, PrintWriter log )60 protected 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 * Does nothing. 68 */ cleanup( TestParameters tParam, PrintWriter log )69 protected void cleanup( TestParameters tParam, PrintWriter log ) { 70 71 } 72 73 /** 74 * Creating a Testenvironment for the interfaces to be tested. 75 * Just creates service <code>com.sun.star.connection.Connector</code> 76 */ createTestEnvironment(TestParameters Param, PrintWriter log)77 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) { 78 79 XInterface oObj = null ; 80 81 try { 82 XInterface connector = (XInterface) 83 ((XMultiServiceFactory)Param.getMSF()).createInstance 84 ("com.sun.star.connection.Connector") ; 85 86 oObj = connector ; 87 } catch (com.sun.star.uno.Exception e) { 88 e.printStackTrace(log); 89 throw new StatusException("Can't create object environment", e); 90 } 91 92 TestEnvironment tEnv = new TestEnvironment(oObj) ; 93 94 // select the port 95 curPort = utils.getNextFreePort(basePort); 96 log.println("Choose Port nr: " + curPort); 97 98 // adding connection string as relation 99 tEnv.addObjRelation("XConnector.connectStr", 100 "socket,host=" + sOfficeHost + ",port=" + curPort) ; 101 102 // adding port number for freeing it. 103 tEnv.addObjRelation("Connector.Port", new Integer(curPort)) ; 104 105 return tEnv ; 106 } 107 108 /** 109 * Just clears flag which indicates that port is free now. 110 */ disposeTestEnvironment( TestEnvironment tEnv, TestParameters tParam)111 public synchronized void disposeTestEnvironment( TestEnvironment tEnv, 112 TestParameters tParam) { 113 114 curPort = ((Integer)tEnv.getObjRelation("Connector.Port")).intValue(); 115 } 116 } 117 118 119