Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / qadevOOo / runner / org / openoffice / RunnerService.java
blobcbe1787f2de16dd453a31f71b2008292dad4f0a7
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 ************************************************************************/
28 package org.openoffice;
30 import share.LogWriter;
31 import stats.InternalLogWriter;
32 import lib.TestParameters;
33 import util.DynamicClassLoader;
34 import base.TestBase;
35 import helper.ClParser;
36 import helper.CfgParser;
37 import com.sun.star.beans.XPropertyAccess;
38 import com.sun.star.beans.PropertyValue;
39 import com.sun.star.task.XJob;
40 import com.sun.star.uno.XInterface;
41 import com.sun.star.comp.loader.FactoryHelper;
42 import com.sun.star.lang.XMultiServiceFactory;
43 import com.sun.star.lang.XServiceInfo;
44 import com.sun.star.lang.XSingleServiceFactory;
45 import com.sun.star.lang.XTypeProvider;
46 import com.sun.star.uno.Type;
47 import com.sun.star.registry.XRegistryKey;
48 import com.sun.star.beans.NamedValue;
50 import java.util.Vector;
52 /**
53 * The main class, will call ClParser and CfgParser to <br>
54 * fill the TestParameters.<br>
55 * Will then call the appropriate Testbase to run the tests.
57 public class RunnerService implements XJob, XServiceInfo,
58 XTypeProvider, XPropertyAccess {
60 static public final String __serviceName = "org.openoffice.Runner";
61 static public final String __implName = "org.openoffice.RunnerService";
62 static private XMultiServiceFactory xMSF = null;
64 /**
65 * ct'tor
66 * Construct an own office provider for tests
68 public RunnerService(XMultiServiceFactory xMSF) {
71 public Object execute(NamedValue[] args) {
72 // construct valid arguments from the given stuff
73 int arg_length=args.length;
74 String[] arguments = new String[arg_length*2];
75 for ( int i=0; i< arg_length; i++ ) {
76 arguments[i*2] = args[i].Name;
77 Object o = args[i].Value;
78 arguments[i*2+1] = o.toString();
81 TestParameters param = new TestParameters();
82 DynamicClassLoader dcl = new DynamicClassLoader();
85 // take the standard log writer
86 String standardLogWriter = param.LogWriter;
87 String standardOutProducer = param.OutProducer;
89 ClParser cli = new ClParser();
91 //parse the arguments if an ini-parameter is given
92 String iniFile = cli.getIniPath(arguments);
94 //initialize cfgParser with ini-path
95 CfgParser ini = new CfgParser(iniFile);
97 //parse ConfigFile
98 ini.getIniParameters(param);
101 //parse the commandline arguments if an runnerprops-parameter is given
102 String runnerIniFile = cli.getRunnerIniPath(arguments);
104 //initialize cfgParser with ini-path
105 CfgParser runnerIni = new CfgParser(runnerIniFile);
107 //parse ConfigFile
108 runnerIni.getIniParameters(param);
110 //parse the commandline arguments
111 cli.getCommandLineParameter(param,arguments);
113 // now compare the standard log writer with the parameters:
114 // if we have a new one, use the new, else use the internal
115 // log writer
116 if (((String)param.get("LogWriter")).equals(standardLogWriter))
117 param.put("LogWriter", "stats.InternalLogWriter");
118 if (((String)param.get("OutProducer")).equals(standardOutProducer))
119 param.put("OutProducer", "stats.InternalLogWriter");
120 LogWriter log = (LogWriter) dcl.getInstance(
121 (String)param.get("LogWriter"));
123 param.put("ServiceFactory", xMSF);
125 param.ServiceFactory = xMSF; //(XMultiServiceFactory)
126 // appProvider.getManager(param);
128 log.println("TestJob: "+param.get("TestJob"));
130 TestBase toExecute = (TestBase)dcl.getInstance("base.java_fat_service");
132 boolean worked = toExecute.executeTest(param);
133 if (!worked)
134 log.println("Test did not execute correctly.");
136 String returnString = "";
137 if (log instanceof InternalLogWriter)
138 returnString = ((InternalLogWriter)log).getLog();
139 return returnString;
143 * This function provides the service name
144 * @return the service name
146 public String getServiceName() {
147 return __serviceName;
151 * Get all implemented types of this class.
152 * @return An array of implemented interface types.
153 * @see com.sun.star.lang.XTypeProvider
155 public Type[] getTypes() {
156 Type[] type = new Type[5];
157 type[0] = new Type(XInterface.class);
158 type[1] = new Type(XTypeProvider.class);
159 type[2] = new Type(XJob.class);
160 type[3] = new Type(XServiceInfo.class);
161 type[4] = new Type(XPropertyAccess.class);
162 return type;
166 * Get the implementation id.
167 * @return An empty implementation id.
168 * @see com.sun.star.lang.XTypeProvider
170 public byte[] getImplementationId() {
171 return new byte[0];
174 * Function for reading the implementation name.
176 * @return the implementation name
177 * @see com.sun.star.lang.XServiceInfo
179 public String getImplementationName() {
180 return __implName;
184 * Does the implementation support this service?
186 * @param serviceName The name of the service in question
187 * @return true, if service is supported, false otherwise
188 * @see com.sun.star.lang.XServiceInfo
190 public boolean supportsService(String serviceName) {
191 if(serviceName.equals(__serviceName))
192 return true;
193 return false;
197 * Function for reading all supported services
199 * @return An aaray with all supported service names
200 * @see com.sun.star.lang.XServiceInfo
202 public String[] getSupportedServiceNames() {
203 String[] supServiceNames = {__serviceName};
204 return supServiceNames;
208 * Return all valid testcases from the object descriptions
209 * @return The valid testcases as property values
211 public PropertyValue[] getPropertyValues() {
212 PropertyValue[] pVal = null;
213 java.net.URL url = this.getClass().getResource("/objdsc");
214 if (url == null) {
215 pVal = new PropertyValue[1];
216 pVal[0] = new PropertyValue();
217 pVal[0].Name = "Error";
218 pVal[0].Value = "OOoRunner.jar file doesn't contain object " +
219 "descriptions: don't know what to test.";
220 return pVal;
223 Vector v = new Vector(600);
224 try {
225 // open connection to Jar
226 java.net.JarURLConnection con =
227 (java.net.JarURLConnection)url.openConnection();
228 // get Jar file from connection
229 java.util.jar.JarFile f = con.getJarFile();
230 // Enumerate over all entries
231 java.util.Enumeration aEnum = f.entries();
233 while (aEnum.hasMoreElements()) {
234 String entry = aEnum.nextElement().toString();
235 if (entry.endsWith(".csv")) {
237 String module = null;
238 String object = null;
240 int startIndex = entry.indexOf("objdsc/") + 7;
241 int endIndex = entry.lastIndexOf('/');
242 /* int endIndex = entry.indexOf('.');
243 module = entry.substring(startIndex, endIndex);
244 startIndex = 0;
245 endIndex = module.lastIndexOf('/'); */
246 module = entry.substring(startIndex, endIndex);
248 // special cases
249 if (entry.indexOf("/file/") != -1 || entry.indexOf("/xmloff/") != -1) {
250 endIndex = entry.indexOf(".csv");
251 object = entry.substring(0, endIndex);
252 endIndex = object.lastIndexOf('.');
253 startIndex = object.indexOf('.');
254 while (startIndex != endIndex) {
255 object = object.substring(startIndex+1);
256 startIndex = object.indexOf('.');
257 endIndex = object.lastIndexOf('.');
260 /* else if (entry.indexOf("/xmloff/") != -1) {
261 endIndex = entry.indexOf(".csv");
262 object = entry.substring(0, endIndex);
263 endIndex = entry.lastIndexOf('.');
264 while (object.indexOf('.') != endIndex) {
265 object = object.substring(object.indexOf('.')+1);
267 } */
268 else {
269 startIndex = 0;
270 endIndex = entry.indexOf(".csv");
271 object = entry.substring(startIndex, endIndex);
272 startIndex = object.lastIndexOf('.');
273 object = object.substring(startIndex+1);
275 v.add(module+"."+object);
279 catch(java.io.IOException e) {
280 e.printStackTrace();
283 int size = v.size();
285 String[] sTestCases = new String[size];
286 v.toArray(sTestCases);
287 java.util.Arrays.sort(sTestCases);
289 pVal = new PropertyValue[size];
290 for (int i=0; i<size; i++) {
291 pVal[i] = new PropertyValue();
292 pVal[i].Name = "TestCase"+i;
293 pVal[i].Value = sTestCases[i];
295 return pVal;
301 * Gives a factory for creating the service.
302 * This method is called by the <code>JavaLoader</code>
303 * <p>
304 * @return returns a <code>XSingleServiceFactory</code> for creating the component
305 * @param implName the name of the implementation for which a service is desired
306 * @param multiFactory the service manager to be used if needed
307 * @param regKey the registryKey
308 * @see com.sun.star.comp.loader.JavaLoader
310 public static XSingleServiceFactory __getServiceFactory(String implName,
311 XMultiServiceFactory multiFactory, XRegistryKey regKey)
313 XSingleServiceFactory xSingleServiceFactory = null;
315 if (implName.equals(RunnerService.class.getName()))
316 xSingleServiceFactory = FactoryHelper.getServiceFactory(
317 RunnerService.class, __serviceName, multiFactory, regKey);
318 xMSF = multiFactory;
319 return xSingleServiceFactory;
323 * Writes the service information into the given registry key.
324 * This method is called by the <code>JavaLoader</code>
325 * <p>
326 * @return returns true if the operation succeeded
327 * @param regKey the registryKey
328 * @see com.sun.star.comp.loader.JavaLoader
330 public static boolean __writeRegistryServiceInfo(XRegistryKey regKey) {
331 return FactoryHelper.writeRegistryServiceInfo(RunnerService.class.getName(),
332 __serviceName, regKey);
336 * empty: not needed here.
338 public void setPropertyValues(PropertyValue[] propertyValue)
339 throws com.sun.star.beans.UnknownPropertyException,
340 com.sun.star.beans.PropertyVetoException,
341 com.sun.star.lang.IllegalArgumentException,
342 com.sun.star.lang.WrappedTargetException {
343 // empty implementation