tdf#160371: sc_subsequent_filters_test2: Add unittest
[LibreOffice.git] / qadevOOo / runner / lib / TestParameters.java
blob04467a9c85a9478ce34ff73545321d3d4f3b54bb
1 /*
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 lib;
21 import java.util.HashMap;
23 import util.PropertyName;
25 import com.sun.star.beans.XPropertySet;
26 import com.sun.star.lang.XMultiServiceFactory;
27 import com.sun.star.uno.XComponentContext;
29 /**
30 * TestParameters describes a parameters (in a form of pairs: name, value) to
31 * be passed to tests and which may affect the test behaviour. That can be,
32 * for example, standard paths, connection strings, etc. The TestParameters
33 * also provides XMultiServiceFactory for the test (tests).
35 public class TestParameters extends HashMap<String,Object> {
37 /**
38 * The ConnectionString for Office Connection<br>
39 * default is 'socket,host=localhost,port=8100'
41 private static final String DefaultConnectionString = "socket,host=localhost,port=8100";
43 /**
44 * The Path to the test documents that are loaded during the test <br>
46 private static final String DefaultTestDocumentPath = "unknown";
48 /**
49 * 'true' is a debug information should be written, 'false' elsewhere
50 * these will be provided by the framework.<br>
51 * Debug information will always be written on standard out.<br>
52 * default is true
54 private static final boolean DebugIsActive = false;
56 /**
57 * Wrapper around "get()" with some debug output
58 * @param key A key of this table.
59 * @return The value of this key.
60 * @see java.util.HashMap
62 @Override
63 public Object get(Object key) {
64 Object val = super.get(key);
65 if (val == null && DebugIsActive) {
66 System.out.print("Have been asked for key \""+key.toString());
67 System.out.println("\" which is not part of params.");
69 return val;
72 /**
73 * Special get method for boolean values: for convenience.
74 * Will return 'false' if the value is not of "Boolean" type.
75 * @param key A key of this table.
76 * @return The value of this key, cast to a boolean type.
78 public boolean getBool(Object key) {
79 final Object val = super.get(key);
80 if (val == null) {
81 return false;
83 if (val instanceof String) {
84 String sVal = (String)val;
85 if (sVal.equalsIgnoreCase("true") ||
86 sVal.equalsIgnoreCase("yes")) {
87 return true;
89 else if (sVal.equalsIgnoreCase("false") ||
90 sVal.equalsIgnoreCase("no")) {
91 return false;
94 else if (val instanceof Boolean)
95 return ((Boolean)val).booleanValue();
96 return false;
99 /**
100 * Special get method for integer values: for convenience.
101 * Will return 0 if the value cannot be interpreted as Integer.
102 * @param key A key of this table.
103 * @return The value of this key, cast to an int type.
105 public int getInt(Object key) {
106 Object val = super.get(key);
107 if ( val != null ) {
108 if (val instanceof Integer) {
109 return ((Integer)val).intValue();
111 else {
112 try {
113 if ( val instanceof String ) {
114 Integer nr = Integer.valueOf((String)val);
115 if (nr.intValue() > 0) return nr.intValue();
117 } catch ( java.lang.NumberFormatException nfe) {}
120 return 0;
125 * Wrapper around "put()"
126 * @param key A key of this table.
127 * @param val The value of the key.
128 * @return The value of this key.
129 * @see java.util.HashMap
131 @Override
132 public Object put(String key, Object val) {
133 return super.put(key,val);
137 * Constructor, defaults for Parameters are set.
139 public TestParameters() {
140 //fill the propertyset
141 String user = System.getProperty("user.name");
142 if ( user != null)
144 String PipeConnectionString = "pipe,name=" + user;
145 put(PropertyName.PIPE_CONNECTION_STRING,PipeConnectionString);
146 put(PropertyName.USE_PIPE_CONNECTION, Boolean.TRUE);
148 put(PropertyName.CONNECTION_STRING, DefaultConnectionString);
149 put(PropertyName.TEST_BASE, "java_fat");
150 put(PropertyName.TEST_DOCUMENT_PATH, DefaultTestDocumentPath);
151 put(PropertyName.LOGGING_IS_ACTIVE, Boolean.TRUE);
152 put(PropertyName.DEBUG_IS_ACTIVE, Boolean.valueOf(DebugIsActive));
153 put(PropertyName.OUT_PRODUCER, "stats.SimpleOutProducer");
154 put(PropertyName.OFFICE_PROVIDER, "helper.OfficeProvider");
155 put(PropertyName.LOG_WRITER, "stats.SimpleLogWriter");
156 put(PropertyName.APP_EXECUTION_COMMAND, "");
157 put(PropertyName.TIME_OUT, Integer.valueOf(3000000));
158 put(PropertyName.THREAD_TIME_OUT, Integer.valueOf(3000000));
159 put(PropertyName.AUTO_RESTART, Boolean.FALSE);
161 // get the operating system
162 put(PropertyName.UNORC_NAME, getUnoRcName());
164 //For compatibility Reasons
165 System.setProperty("DOCPTH", DefaultTestDocumentPath);
169 * @return a XMultiServiceFactory to be used by a test (tests).
171 public XMultiServiceFactory getMSF() {
172 Object ret = null;
173 ret = get("ServiceFactory");
174 return (XMultiServiceFactory) ret;
177 public XComponentContext getComponentContext() {
178 Object context = get( "ComponentContext" );
179 if ( context == null )
181 XPropertySet factoryProps = com.sun.star.uno.UnoRuntime.queryInterface(
182 XPropertySet.class, getMSF() );
185 context = com.sun.star.uno.UnoRuntime.queryInterface(
186 XComponentContext.class, factoryProps.getPropertyValue( "DefaultContext" ) );
187 put( "ComponentContext", context );
189 catch( com.sun.star.beans.UnknownPropertyException e ) { }
190 catch( com.sun.star.lang.WrappedTargetException e ) { }
192 return (XComponentContext)context;
196 * @return The uno rc file name uno.ini for windows and unorc for everything else
198 private String getUnoRcName() {
199 String osname = System.getProperty ("os.name").toLowerCase ();
200 if (osname.indexOf ("windows")>-1) {
201 return "uno.ini";
203 return "unorc";
206 }// finish class TestParameters