1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
30 import java
.util
.Hashtable
;
31 import util
.PropertyName
;
32 import com
.sun
.star
.beans
.XPropertySet
;
33 import com
.sun
.star
.uno
.XComponentContext
;
35 //import com.sun.star.lang.XMultiServiceFactory;
38 * TestParameters describes a parameters (in a form of pairs: name, value) to
39 * be passed to tests and which may affect the test behaviour. That can be,
40 * for example, standard paths, connection strings, etc. The TestParameters
41 * also provides XMultiServiceFactory for the test (tests).
43 public class TestParameters
extends Hashtable
{
46 * The ConnectionString for Office Connection<br>
47 * default is 'socket,host=localhost,port=8100'
50 public String ConnectionString
="socket,host=localhost,port=8100";
53 * The AppProvider contains the Application Provider<br>
54 * to control the ServiceFactory.
57 public Object AppProvider
=null;
60 * The Process contains the Process handler<br>
61 * to control the Application.
64 public Object ProcessHandler
=null;
67 * The AppExecutionCmd contains the full qualified<br>
68 * command to an Application to be started.
71 public String AppExecutionCommand
="";
74 * If this parameter is <CODE>true</CODE> the <CODE>OfficeProvider</CODE> tries
75 * to get the URL to the binary of the office and to fill the
76 * <CODE>AppExecutionCommand</CODE> with usefull content if needet
78 public boolean AutoRestart
= false;
81 * Shoert wait time for the Office: default is 500 milliseconds
83 public int ShortWait
= 500;
87 * The OfficeProvider contains the full qualified
88 * class that provides a connection to StarOffice<br>
89 * default is helper.OfficeProvider
92 public String OfficeProvider
= "helper.OfficeProvider";
95 * The Testbase to be executed by the runner<br>
96 * default is 'java_fat'
99 public String TestBase
="java_fat";
102 * The ServiceFactory to create instances
105 public Object ServiceFactory
;
108 * The Path to the component description
111 public String DescriptionPath
;
114 * The Path to the test documents that are loaded during the test <br>
117 public String TestDocumentPath
="unknown";
120 * 'true' is a log should be written, 'false' elsewhere <br>
121 * these will be provided by the testcases<br>
125 public boolean LoggingIsActive
=true;
128 * 'true' is a debug information should be written, 'false' elsewhere
129 * these will be provided by the framework.<br>
130 * Debug information will always be written on standard out.<br>
134 public boolean DebugIsActive
=false;
137 * This parameter contains the testjob to be executed<br>
141 public Object TestJob
;
144 * This parameter contains the class used<br>
148 public String LogWriter
="stats.SimpleLogWriter";
151 * This parameter contains the class used<br>
155 public String OutProducer
="stats.SimpleOutProducer";
158 * This parameter contains the timeout used<br>
161 public Integer TimeOut
= new Integer(3000000);
164 * This parameter contains the timeout used<br>
165 * by the complex tests
167 public Integer ThreadTimeOut
= new Integer(3000000);
170 * This parameter contains the time which the office could use to close for
171 * itself before its destroyed. Default is 15000 ms
173 public Integer OfficeCloseTimeOut
= new Integer(15000);
176 * Wraper around "get()" with some debug output
177 * @param key A key of this table.
178 * @return The value of this key.
179 * @see java.util.Hashtable
181 public Object
get(Object key
) {
182 Object val
= super.get(key
);
183 if (val
== null && DebugIsActive
) {
184 System
.out
.print("Have been asked for key \""+key
.toString());
185 System
.out
.println("\" which is not part of params.");
191 * Special get method for boolean values: for convenience.
192 * Will return 'false' if the value is not of "Boolean" type.
193 * @param key A key of this table.
194 * @return The value of this key, castet to a boolean type.
196 public boolean getBool(Object key
) {
197 Object val
= super.get(key
);
199 if (val
instanceof String
) {
200 String sVal
= (String
)val
;
201 if (sVal
.equalsIgnoreCase("true") ||
202 sVal
.equalsIgnoreCase("yes")) {
205 else if (sVal
.equalsIgnoreCase("false") ||
206 sVal
.equalsIgnoreCase("no")) {
210 if (val
instanceof Boolean
)
211 return ((Boolean
)val
).booleanValue();
217 * Special get method for integer values: for convenience.
218 * Will return 0 if the value cannot be interpreted as Integer.
219 * @param key A key of this table.
220 * @return The value of this key, castet to an int type.
222 public int getInt(Object key
) {
223 Object val
= super.get(key
);
225 if (val
instanceof Integer
) {
226 return ((Integer
)val
).intValue();
230 if ( val
instanceof String
) {
231 Integer nr
= new Integer((String
)val
);
232 if (nr
.intValue() > 0) return nr
.intValue();
234 } catch ( java
.lang
.NumberFormatException nfe
) {}
242 * Wraper around "put()"
243 * @param key A key of this table.
244 * @param val The value of the key.
245 * @return The value of this key.
246 * @see java.util.Hashtable
248 public Object
put(Object key
, Object val
) {
249 return super.put(key
,val
);
253 * Constructor, defaults for Parameters are set.
255 public TestParameters() {
256 //fill the propertyset
257 String user
= System
.getProperty("user.name");
260 String PipeConnectionString
= "pipe,name=" + user
;
261 put(PropertyName
.PIPE_CONNECTION_STRING
,PipeConnectionString
);
262 put(PropertyName
.USE_PIPE_CONNECTION
, Boolean
.TRUE
);
264 put(PropertyName
.CONNECTION_STRING
,ConnectionString
);
265 put(PropertyName
.TEST_BASE
,TestBase
);
266 put(PropertyName
.TEST_DOCUMENT_PATH
,TestDocumentPath
);
267 put(PropertyName
.LOGGING_IS_ACTIVE
,LoggingIsActive?Boolean
.TRUE
:Boolean
.FALSE
);
268 put(PropertyName
.DEBUG_IS_ACTIVE
,DebugIsActive?Boolean
.TRUE
:Boolean
.FALSE
);
269 put(PropertyName
.OUT_PRODUCER
,OutProducer
);
270 put(PropertyName
.SHORT_WAIT
,new Integer(ShortWait
));
271 put(PropertyName
.OFFICE_PROVIDER
,OfficeProvider
);
272 put(PropertyName
.LOG_WRITER
,LogWriter
);
273 put(PropertyName
.APP_EXECUTION_COMMAND
,AppExecutionCommand
);
274 put(PropertyName
.TIME_OUT
,TimeOut
);
275 put(PropertyName
.THREAD_TIME_OUT
,ThreadTimeOut
);
276 put(PropertyName
.AUTO_RESTART
,AutoRestart?Boolean
.TRUE
:Boolean
.FALSE
);
277 put(PropertyName
.OFFICE_CLOSE_TIME_OUT
, OfficeCloseTimeOut
);
279 // get the operating system
280 put(PropertyName
.OPERATING_SYSTEM
, getSOCompatibleOSName());
282 //For compatibility Reasons
283 put("CNCSTR",ConnectionString
);
284 put("DOCPTH",TestDocumentPath
);
285 System
.setProperty("DOCPTH",TestDocumentPath
);
289 * @return a XMultiServiceFactory to be used by a test (tests).
291 public Object
getMSF() {
293 ret
= get("ServiceFactory");
297 public XComponentContext
getComponentContext() {
298 Object context
= get( "ComponentContext" );
299 if ( context
== null )
301 XPropertySet factoryProps
= (XPropertySet
)com
.sun
.star
.uno
.UnoRuntime
.queryInterface(
302 XPropertySet
.class, getMSF() );
305 context
= com
.sun
.star
.uno
.UnoRuntime
.queryInterface(
306 XComponentContext
.class, factoryProps
.getPropertyValue( "DefaultContext" ) );
307 put( "ComponentContext", context
);
309 catch( com
.sun
.star
.beans
.UnknownPropertyException e
) { }
310 catch( com
.sun
.star
.lang
.WrappedTargetException e
) { }
312 return (XComponentContext
)context
;
316 * Convert the system dependent operating system name to a name according
318 * @return A valid OS name, or "" if the name is not known.
320 String
getSOCompatibleOSName() {
321 String osname
= System
.getProperty ("os.name").toLowerCase ();
322 String osarch
= System
.getProperty ("os.arch");
323 String operatingSystem
= "";
324 if (osname
.indexOf ("windows")>-1) {
325 operatingSystem
= PropertyName
.WNTMSCI
;
326 } else if (osname
.indexOf ("linux")>-1) {
327 operatingSystem
= PropertyName
.UNXLNGI
;
328 } else if (osname
.indexOf ("sunos")>-1) {
329 if (osarch
.equals ("x86")) {
330 operatingSystem
= PropertyName
.UNXSOLI
;
332 operatingSystem
= PropertyName
.UNXSOLS
;
334 } else if (osname
.indexOf ("mac")>-1) {
335 operatingSystem
= PropertyName
.UNXMACXI
;
337 System
.out
.println("ERROR: not supported platform: " + osname
);
340 return operatingSystem
;
343 }// finish class TestParamenters