1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 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. 14 * 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). 20 * 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. 25 * 26 ************************************************************************/ 27 28 package org.openoffice; 29 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; 49 50 import java.util.Vector; 51 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. 56 */ 57 public class RunnerService implements XJob, XServiceInfo, 58 XTypeProvider, XPropertyAccess { 59 60 static public final String __serviceName = "org.openoffice.Runner"; 61 static public final String __implName = "org.openoffice.RunnerService"; 62 static private XMultiServiceFactory xMSF = null; 63 64 /** 65 * ct'tor 66 * Construct an own office provider for tests 67 */ 68 public RunnerService(XMultiServiceFactory xMSF) { 69 } 70 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(); 79 } 80 81 TestParameters param = new TestParameters(); 82 DynamicClassLoader dcl = new DynamicClassLoader(); 83 84 85 // take the standard log writer 86 String standardLogWriter = param.LogWriter; 87 String standardOutProducer = param.OutProducer; 88 89 ClParser cli = new ClParser(); 90 91 //parse the arguments if an ini-parameter is given 92 String iniFile = cli.getIniPath(arguments); 93 94 //initialize cfgParser with ini-path 95 CfgParser ini = new CfgParser(iniFile); 96 97 //parse ConfigFile 98 ini.getIniParameters(param); 99 100 101 //parse the commandline arguments if an runnerprops-parameter is given 102 String runnerIniFile = cli.getRunnerIniPath(arguments); 103 104 //initialize cfgParser with ini-path 105 CfgParser runnerIni = new CfgParser(runnerIniFile); 106 107 //parse ConfigFile 108 runnerIni.getIniParameters(param); 109 110 //parse the commandline arguments 111 cli.getCommandLineParameter(param,arguments); 112 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")); 122 123 param.put("ServiceFactory", xMSF); 124 125 param.ServiceFactory = xMSF; //(XMultiServiceFactory) 126 // appProvider.getManager(param); 127 128 log.println("TestJob: "+param.get("TestJob")); 129 130 TestBase toExecute = (TestBase)dcl.getInstance("base.java_fat_service"); 131 132 boolean worked = toExecute.executeTest(param); 133 if (!worked) 134 log.println("Test did not execute correctly."); 135 136 String returnString = ""; 137 if (log instanceof InternalLogWriter) 138 returnString = ((InternalLogWriter)log).getLog(); 139 return returnString; 140 } 141 142 /** 143 * This function provides the service name 144 * @return the service name 145 */ 146 public String getServiceName() { 147 return __serviceName; 148 } 149 150 /** 151 * Get all implemented types of this class. 152 * @return An array of implemented interface types. 153 * @see com.sun.star.lang.XTypeProvider 154 */ 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; 163 } 164 165 /** 166 * Get the implementation id. 167 * @return An empty implementation id. 168 * @see com.sun.star.lang.XTypeProvider 169 */ 170 public byte[] getImplementationId() { 171 return new byte[0]; 172 } 173 /** 174 * Function for reading the implementation name. 175 * 176 * @return the implementation name 177 * @see com.sun.star.lang.XServiceInfo 178 */ 179 public String getImplementationName() { 180 return __implName; 181 } 182 183 /** 184 * Does the implementation support this service? 185 * 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 189 */ 190 public boolean supportsService(String serviceName) { 191 if(serviceName.equals(__serviceName)) 192 return true; 193 return false; 194 } 195 196 /** 197 * Function for reading all supported services 198 * 199 * @return An aaray with all supported service names 200 * @see com.sun.star.lang.XServiceInfo 201 */ 202 public String[] getSupportedServiceNames() { 203 String[] supServiceNames = {__serviceName}; 204 return supServiceNames; 205 } 206 207 /** 208 * Return all valid testcases from the object descriptions 209 * @return The valid testcases as property values 210 */ 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; 221 } 222 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(); 232 233 while (aEnum.hasMoreElements()) { 234 String entry = aEnum.nextElement().toString(); 235 if (entry.endsWith(".csv")) { 236 237 String module = null; 238 String object = null; 239 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); 247 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('.'); 258 } 259 } 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); 266 } 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); 274 } 275 v.add(module+"."+object); 276 } 277 } 278 } 279 catch(java.io.IOException e) { 280 e.printStackTrace(); 281 } 282 283 int size = v.size(); 284 285 String[] sTestCases = new String[size]; 286 v.toArray(sTestCases); 287 java.util.Arrays.sort(sTestCases); 288 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]; 294 } 295 return pVal; 296 } 297 298 299 /** 300 * 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 309 */ 310 public static XSingleServiceFactory __getServiceFactory(String implName, 311 XMultiServiceFactory multiFactory, XRegistryKey regKey) 312 { 313 XSingleServiceFactory xSingleServiceFactory = null; 314 315 if (implName.equals(RunnerService.class.getName())) 316 xSingleServiceFactory = FactoryHelper.getServiceFactory( 317 RunnerService.class, __serviceName, multiFactory, regKey); 318 xMSF = multiFactory; 319 return xSingleServiceFactory; 320 } 321 322 /** 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 329 */ 330 public static boolean __writeRegistryServiceInfo(XRegistryKey regKey) { 331 return FactoryHelper.writeRegistryServiceInfo(RunnerService.class.getName(), 332 __serviceName, regKey); 333 } 334 335 /** 336 * empty: not needed here. 337 */ 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 344 } 345 346 } 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398