2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package mod
._acceptor
;
21 import java
.io
.PrintWriter
;
23 import lib
.StatusException
;
25 import lib
.TestEnvironment
;
26 import lib
.TestParameters
;
29 import com
.sun
.star
.uno
.XInterface
;
32 * Here <code>com.sun.star.connection.Acceptor</code> service is tested.<p>
33 * Test allows to run object tests in several threads concurently.
34 * @see com.sun.star.connection.Acceptor
35 * @see com.sun.star.connection.XAcceptor
36 * @see com.sun.star.connection.XConnector
37 * @see ifc.connection._XAcceptor
39 public class Acceptor
extends TestCase
{
43 * Acceptor chooses the first port after <code>basePort</code>
46 protected static final int basePort
= 10000;
48 private String sOfficeHost
= null ;
51 * Retrieves host name where StarOffice is started from test
52 * parameter <code>'CONNECTION_STRING'</code>.
55 public void initialize( TestParameters tParam
, PrintWriter log
) {
56 String cncstr
= (String
) tParam
.get("CONNECTION_STRING") ;
57 int idx
= cncstr
.indexOf("host=") + 5 ;
58 sOfficeHost
= cncstr
.substring(idx
, cncstr
.indexOf(",", idx
)) ;
62 * Creating a Testenvironment for the interfaces to be tested. <p>
63 * Creates <code>Acceptor</code> service and passed as relation
64 * connection string where port for accepting is unique among
65 * different object test threads. <p>
66 * The following object relations are created :
68 * <li> <code>'XAcceptor.connectStr'</code> : String variable for
69 * <code>XAcceptor</code> interface test. Has the following format :
70 * <code>'socket,host=<SOHost>,port=<UniquePort>' where <SOHost> is
71 * the host where StarOffice is started. </li>
72 * <li> <code>'Acceptor.Port'</code> : Integer value which specifies
73 * port on which Acceptor must listen, and which is required
74 * when disposing environment, to free this port number. </li>
78 public synchronized TestEnvironment
createTestEnvironment(
79 TestParameters Param
, PrintWriter log
) throws StatusException
{
81 XInterface oObj
= null;
82 XInterface acceptor
= null;
85 acceptor
= (XInterface
)
86 Param
.getMSF().createInstance
87 ("com.sun.star.connection.Acceptor");
88 } catch (com
.sun
.star
.uno
.Exception e
) {
89 throw new StatusException("Can't create object environment", e
) ;
93 curPort
= utils
.getNextFreePort(basePort
);
94 log
.println("Choose Port nr: " + curPort
);
97 TestEnvironment tEnv
= new TestEnvironment(oObj
) ;
99 // adding connection string as relation
100 tEnv
.addObjRelation("XAcceptor.connectStr",
101 "socket,host=" + sOfficeHost
+ ",port=" + curPort
) ;
103 // adding port number for freeing it.
104 tEnv
.addObjRelation("Acceptor.Port", Integer
.valueOf(curPort
)) ;
110 * Just clears flag which indicates that port is free now.
113 public synchronized void disposeTestEnvironment( TestEnvironment tEnv
,
114 TestParameters tParam
) {
116 curPort
= ((Integer
)tEnv
.getObjRelation("Acceptor.Port")).intValue();