1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir package org.openoffice; 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir import share.LogWriter; 31*cdf0e10cSrcweir import stats.InternalLogWriter; 32*cdf0e10cSrcweir import lib.TestParameters; 33*cdf0e10cSrcweir import util.DynamicClassLoader; 34*cdf0e10cSrcweir import base.TestBase; 35*cdf0e10cSrcweir import helper.ClParser; 36*cdf0e10cSrcweir import helper.CfgParser; 37*cdf0e10cSrcweir import com.sun.star.beans.XPropertyAccess; 38*cdf0e10cSrcweir import com.sun.star.beans.PropertyValue; 39*cdf0e10cSrcweir import com.sun.star.task.XJob; 40*cdf0e10cSrcweir import com.sun.star.uno.XInterface; 41*cdf0e10cSrcweir import com.sun.star.comp.loader.FactoryHelper; 42*cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 43*cdf0e10cSrcweir import com.sun.star.lang.XServiceInfo; 44*cdf0e10cSrcweir import com.sun.star.lang.XSingleServiceFactory; 45*cdf0e10cSrcweir import com.sun.star.lang.XTypeProvider; 46*cdf0e10cSrcweir import com.sun.star.uno.Type; 47*cdf0e10cSrcweir import com.sun.star.registry.XRegistryKey; 48*cdf0e10cSrcweir import com.sun.star.beans.NamedValue; 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir import java.util.Vector; 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir /** 53*cdf0e10cSrcweir * The main class, will call ClParser and CfgParser to <br> 54*cdf0e10cSrcweir * fill the TestParameters.<br> 55*cdf0e10cSrcweir * Will then call the appropriate Testbase to run the tests. 56*cdf0e10cSrcweir */ 57*cdf0e10cSrcweir public class RunnerService implements XJob, XServiceInfo, 58*cdf0e10cSrcweir XTypeProvider, XPropertyAccess { 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir static public final String __serviceName = "org.openoffice.Runner"; 61*cdf0e10cSrcweir static public final String __implName = "org.openoffice.RunnerService"; 62*cdf0e10cSrcweir static private XMultiServiceFactory xMSF = null; 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir /** 65*cdf0e10cSrcweir * ct'tor 66*cdf0e10cSrcweir * Construct an own office provider for tests 67*cdf0e10cSrcweir */ 68*cdf0e10cSrcweir public RunnerService(XMultiServiceFactory xMSF) { 69*cdf0e10cSrcweir } 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir public Object execute(NamedValue[] args) { 72*cdf0e10cSrcweir // construct valid arguments from the given stuff 73*cdf0e10cSrcweir int arg_length=args.length; 74*cdf0e10cSrcweir String[] arguments = new String[arg_length*2]; 75*cdf0e10cSrcweir for ( int i=0; i< arg_length; i++ ) { 76*cdf0e10cSrcweir arguments[i*2] = args[i].Name; 77*cdf0e10cSrcweir Object o = args[i].Value; 78*cdf0e10cSrcweir arguments[i*2+1] = o.toString(); 79*cdf0e10cSrcweir } 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir TestParameters param = new TestParameters(); 82*cdf0e10cSrcweir DynamicClassLoader dcl = new DynamicClassLoader(); 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir // take the standard log writer 86*cdf0e10cSrcweir String standardLogWriter = param.LogWriter; 87*cdf0e10cSrcweir String standardOutProducer = param.OutProducer; 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir ClParser cli = new ClParser(); 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir //parse the arguments if an ini-parameter is given 92*cdf0e10cSrcweir String iniFile = cli.getIniPath(arguments); 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir //initialize cfgParser with ini-path 95*cdf0e10cSrcweir CfgParser ini = new CfgParser(iniFile); 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir //parse ConfigFile 98*cdf0e10cSrcweir ini.getIniParameters(param); 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir //parse the commandline arguments if an runnerprops-parameter is given 102*cdf0e10cSrcweir String runnerIniFile = cli.getRunnerIniPath(arguments); 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir //initialize cfgParser with ini-path 105*cdf0e10cSrcweir CfgParser runnerIni = new CfgParser(runnerIniFile); 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir //parse ConfigFile 108*cdf0e10cSrcweir runnerIni.getIniParameters(param); 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir //parse the commandline arguments 111*cdf0e10cSrcweir cli.getCommandLineParameter(param,arguments); 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir // now compare the standard log writer with the parameters: 114*cdf0e10cSrcweir // if we have a new one, use the new, else use the internal 115*cdf0e10cSrcweir // log writer 116*cdf0e10cSrcweir if (((String)param.get("LogWriter")).equals(standardLogWriter)) 117*cdf0e10cSrcweir param.put("LogWriter", "stats.InternalLogWriter"); 118*cdf0e10cSrcweir if (((String)param.get("OutProducer")).equals(standardOutProducer)) 119*cdf0e10cSrcweir param.put("OutProducer", "stats.InternalLogWriter"); 120*cdf0e10cSrcweir LogWriter log = (LogWriter) dcl.getInstance( 121*cdf0e10cSrcweir (String)param.get("LogWriter")); 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir param.put("ServiceFactory", xMSF); 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir param.ServiceFactory = xMSF; //(XMultiServiceFactory) 126*cdf0e10cSrcweir // appProvider.getManager(param); 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir log.println("TestJob: "+param.get("TestJob")); 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir TestBase toExecute = (TestBase)dcl.getInstance("base.java_fat_service"); 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir boolean worked = toExecute.executeTest(param); 133*cdf0e10cSrcweir if (!worked) 134*cdf0e10cSrcweir log.println("Test did not execute correctly."); 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir String returnString = ""; 137*cdf0e10cSrcweir if (log instanceof InternalLogWriter) 138*cdf0e10cSrcweir returnString = ((InternalLogWriter)log).getLog(); 139*cdf0e10cSrcweir return returnString; 140*cdf0e10cSrcweir } 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir /** 143*cdf0e10cSrcweir * This function provides the service name 144*cdf0e10cSrcweir * @return the service name 145*cdf0e10cSrcweir */ 146*cdf0e10cSrcweir public String getServiceName() { 147*cdf0e10cSrcweir return __serviceName; 148*cdf0e10cSrcweir } 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir /** 151*cdf0e10cSrcweir * Get all implemented types of this class. 152*cdf0e10cSrcweir * @return An array of implemented interface types. 153*cdf0e10cSrcweir * @see com.sun.star.lang.XTypeProvider 154*cdf0e10cSrcweir */ 155*cdf0e10cSrcweir public Type[] getTypes() { 156*cdf0e10cSrcweir Type[] type = new Type[5]; 157*cdf0e10cSrcweir type[0] = new Type(XInterface.class); 158*cdf0e10cSrcweir type[1] = new Type(XTypeProvider.class); 159*cdf0e10cSrcweir type[2] = new Type(XJob.class); 160*cdf0e10cSrcweir type[3] = new Type(XServiceInfo.class); 161*cdf0e10cSrcweir type[4] = new Type(XPropertyAccess.class); 162*cdf0e10cSrcweir return type; 163*cdf0e10cSrcweir } 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir /** 166*cdf0e10cSrcweir * Get the implementation id. 167*cdf0e10cSrcweir * @return An empty implementation id. 168*cdf0e10cSrcweir * @see com.sun.star.lang.XTypeProvider 169*cdf0e10cSrcweir */ 170*cdf0e10cSrcweir public byte[] getImplementationId() { 171*cdf0e10cSrcweir return new byte[0]; 172*cdf0e10cSrcweir } 173*cdf0e10cSrcweir /** 174*cdf0e10cSrcweir * Function for reading the implementation name. 175*cdf0e10cSrcweir * 176*cdf0e10cSrcweir * @return the implementation name 177*cdf0e10cSrcweir * @see com.sun.star.lang.XServiceInfo 178*cdf0e10cSrcweir */ 179*cdf0e10cSrcweir public String getImplementationName() { 180*cdf0e10cSrcweir return __implName; 181*cdf0e10cSrcweir } 182*cdf0e10cSrcweir 183*cdf0e10cSrcweir /** 184*cdf0e10cSrcweir * Does the implementation support this service? 185*cdf0e10cSrcweir * 186*cdf0e10cSrcweir * @param serviceName The name of the service in question 187*cdf0e10cSrcweir * @return true, if service is supported, false otherwise 188*cdf0e10cSrcweir * @see com.sun.star.lang.XServiceInfo 189*cdf0e10cSrcweir */ 190*cdf0e10cSrcweir public boolean supportsService(String serviceName) { 191*cdf0e10cSrcweir if(serviceName.equals(__serviceName)) 192*cdf0e10cSrcweir return true; 193*cdf0e10cSrcweir return false; 194*cdf0e10cSrcweir } 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir /** 197*cdf0e10cSrcweir * Function for reading all supported services 198*cdf0e10cSrcweir * 199*cdf0e10cSrcweir * @return An aaray with all supported service names 200*cdf0e10cSrcweir * @see com.sun.star.lang.XServiceInfo 201*cdf0e10cSrcweir */ 202*cdf0e10cSrcweir public String[] getSupportedServiceNames() { 203*cdf0e10cSrcweir String[] supServiceNames = {__serviceName}; 204*cdf0e10cSrcweir return supServiceNames; 205*cdf0e10cSrcweir } 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir /** 208*cdf0e10cSrcweir * Return all valid testcases from the object descriptions 209*cdf0e10cSrcweir * @return The valid testcases as property values 210*cdf0e10cSrcweir */ 211*cdf0e10cSrcweir public PropertyValue[] getPropertyValues() { 212*cdf0e10cSrcweir PropertyValue[] pVal = null; 213*cdf0e10cSrcweir java.net.URL url = this.getClass().getResource("/objdsc"); 214*cdf0e10cSrcweir if (url == null) { 215*cdf0e10cSrcweir pVal = new PropertyValue[1]; 216*cdf0e10cSrcweir pVal[0] = new PropertyValue(); 217*cdf0e10cSrcweir pVal[0].Name = "Error"; 218*cdf0e10cSrcweir pVal[0].Value = "OOoRunner.jar file doesn't contain object " + 219*cdf0e10cSrcweir "descriptions: don't know what to test."; 220*cdf0e10cSrcweir return pVal; 221*cdf0e10cSrcweir } 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir Vector v = new Vector(600); 224*cdf0e10cSrcweir try { 225*cdf0e10cSrcweir // open connection to Jar 226*cdf0e10cSrcweir java.net.JarURLConnection con = 227*cdf0e10cSrcweir (java.net.JarURLConnection)url.openConnection(); 228*cdf0e10cSrcweir // get Jar file from connection 229*cdf0e10cSrcweir java.util.jar.JarFile f = con.getJarFile(); 230*cdf0e10cSrcweir // Enumerate over all entries 231*cdf0e10cSrcweir java.util.Enumeration aEnum = f.entries(); 232*cdf0e10cSrcweir 233*cdf0e10cSrcweir while (aEnum.hasMoreElements()) { 234*cdf0e10cSrcweir String entry = aEnum.nextElement().toString(); 235*cdf0e10cSrcweir if (entry.endsWith(".csv")) { 236*cdf0e10cSrcweir 237*cdf0e10cSrcweir String module = null; 238*cdf0e10cSrcweir String object = null; 239*cdf0e10cSrcweir 240*cdf0e10cSrcweir int startIndex = entry.indexOf("objdsc/") + 7; 241*cdf0e10cSrcweir int endIndex = entry.lastIndexOf('/'); 242*cdf0e10cSrcweir /* int endIndex = entry.indexOf('.'); 243*cdf0e10cSrcweir module = entry.substring(startIndex, endIndex); 244*cdf0e10cSrcweir startIndex = 0; 245*cdf0e10cSrcweir endIndex = module.lastIndexOf('/'); */ 246*cdf0e10cSrcweir module = entry.substring(startIndex, endIndex); 247*cdf0e10cSrcweir 248*cdf0e10cSrcweir // special cases 249*cdf0e10cSrcweir if (entry.indexOf("/file/") != -1 || entry.indexOf("/xmloff/") != -1) { 250*cdf0e10cSrcweir endIndex = entry.indexOf(".csv"); 251*cdf0e10cSrcweir object = entry.substring(0, endIndex); 252*cdf0e10cSrcweir endIndex = object.lastIndexOf('.'); 253*cdf0e10cSrcweir startIndex = object.indexOf('.'); 254*cdf0e10cSrcweir while (startIndex != endIndex) { 255*cdf0e10cSrcweir object = object.substring(startIndex+1); 256*cdf0e10cSrcweir startIndex = object.indexOf('.'); 257*cdf0e10cSrcweir endIndex = object.lastIndexOf('.'); 258*cdf0e10cSrcweir } 259*cdf0e10cSrcweir } 260*cdf0e10cSrcweir /* else if (entry.indexOf("/xmloff/") != -1) { 261*cdf0e10cSrcweir endIndex = entry.indexOf(".csv"); 262*cdf0e10cSrcweir object = entry.substring(0, endIndex); 263*cdf0e10cSrcweir endIndex = entry.lastIndexOf('.'); 264*cdf0e10cSrcweir while (object.indexOf('.') != endIndex) { 265*cdf0e10cSrcweir object = object.substring(object.indexOf('.')+1); 266*cdf0e10cSrcweir } 267*cdf0e10cSrcweir } */ 268*cdf0e10cSrcweir else { 269*cdf0e10cSrcweir startIndex = 0; 270*cdf0e10cSrcweir endIndex = entry.indexOf(".csv"); 271*cdf0e10cSrcweir object = entry.substring(startIndex, endIndex); 272*cdf0e10cSrcweir startIndex = object.lastIndexOf('.'); 273*cdf0e10cSrcweir object = object.substring(startIndex+1); 274*cdf0e10cSrcweir } 275*cdf0e10cSrcweir v.add(module+"."+object); 276*cdf0e10cSrcweir } 277*cdf0e10cSrcweir } 278*cdf0e10cSrcweir } 279*cdf0e10cSrcweir catch(java.io.IOException e) { 280*cdf0e10cSrcweir e.printStackTrace(); 281*cdf0e10cSrcweir } 282*cdf0e10cSrcweir 283*cdf0e10cSrcweir int size = v.size(); 284*cdf0e10cSrcweir 285*cdf0e10cSrcweir String[] sTestCases = new String[size]; 286*cdf0e10cSrcweir v.toArray(sTestCases); 287*cdf0e10cSrcweir java.util.Arrays.sort(sTestCases); 288*cdf0e10cSrcweir 289*cdf0e10cSrcweir pVal = new PropertyValue[size]; 290*cdf0e10cSrcweir for (int i=0; i<size; i++) { 291*cdf0e10cSrcweir pVal[i] = new PropertyValue(); 292*cdf0e10cSrcweir pVal[i].Name = "TestCase"+i; 293*cdf0e10cSrcweir pVal[i].Value = sTestCases[i]; 294*cdf0e10cSrcweir } 295*cdf0e10cSrcweir return pVal; 296*cdf0e10cSrcweir } 297*cdf0e10cSrcweir 298*cdf0e10cSrcweir 299*cdf0e10cSrcweir /** 300*cdf0e10cSrcweir * 301*cdf0e10cSrcweir * Gives a factory for creating the service. 302*cdf0e10cSrcweir * This method is called by the <code>JavaLoader</code> 303*cdf0e10cSrcweir * <p> 304*cdf0e10cSrcweir * @return returns a <code>XSingleServiceFactory</code> for creating the component 305*cdf0e10cSrcweir * @param implName the name of the implementation for which a service is desired 306*cdf0e10cSrcweir * @param multiFactory the service manager to be used if needed 307*cdf0e10cSrcweir * @param regKey the registryKey 308*cdf0e10cSrcweir * @see com.sun.star.comp.loader.JavaLoader 309*cdf0e10cSrcweir */ 310*cdf0e10cSrcweir public static XSingleServiceFactory __getServiceFactory(String implName, 311*cdf0e10cSrcweir XMultiServiceFactory multiFactory, XRegistryKey regKey) 312*cdf0e10cSrcweir { 313*cdf0e10cSrcweir XSingleServiceFactory xSingleServiceFactory = null; 314*cdf0e10cSrcweir 315*cdf0e10cSrcweir if (implName.equals(RunnerService.class.getName())) 316*cdf0e10cSrcweir xSingleServiceFactory = FactoryHelper.getServiceFactory( 317*cdf0e10cSrcweir RunnerService.class, __serviceName, multiFactory, regKey); 318*cdf0e10cSrcweir xMSF = multiFactory; 319*cdf0e10cSrcweir return xSingleServiceFactory; 320*cdf0e10cSrcweir } 321*cdf0e10cSrcweir 322*cdf0e10cSrcweir /** 323*cdf0e10cSrcweir * Writes the service information into the given registry key. 324*cdf0e10cSrcweir * This method is called by the <code>JavaLoader</code> 325*cdf0e10cSrcweir * <p> 326*cdf0e10cSrcweir * @return returns true if the operation succeeded 327*cdf0e10cSrcweir * @param regKey the registryKey 328*cdf0e10cSrcweir * @see com.sun.star.comp.loader.JavaLoader 329*cdf0e10cSrcweir */ 330*cdf0e10cSrcweir public static boolean __writeRegistryServiceInfo(XRegistryKey regKey) { 331*cdf0e10cSrcweir return FactoryHelper.writeRegistryServiceInfo(RunnerService.class.getName(), 332*cdf0e10cSrcweir __serviceName, regKey); 333*cdf0e10cSrcweir } 334*cdf0e10cSrcweir 335*cdf0e10cSrcweir /** 336*cdf0e10cSrcweir * empty: not needed here. 337*cdf0e10cSrcweir */ 338*cdf0e10cSrcweir public void setPropertyValues(PropertyValue[] propertyValue) 339*cdf0e10cSrcweir throws com.sun.star.beans.UnknownPropertyException, 340*cdf0e10cSrcweir com.sun.star.beans.PropertyVetoException, 341*cdf0e10cSrcweir com.sun.star.lang.IllegalArgumentException, 342*cdf0e10cSrcweir com.sun.star.lang.WrappedTargetException { 343*cdf0e10cSrcweir // empty implementation 344*cdf0e10cSrcweir } 345*cdf0e10cSrcweir 346*cdf0e10cSrcweir } 347*cdf0e10cSrcweir 348*cdf0e10cSrcweir 349*cdf0e10cSrcweir 350*cdf0e10cSrcweir 351*cdf0e10cSrcweir 352*cdf0e10cSrcweir 353*cdf0e10cSrcweir 354*cdf0e10cSrcweir 355*cdf0e10cSrcweir 356*cdf0e10cSrcweir 357*cdf0e10cSrcweir 358*cdf0e10cSrcweir 359*cdf0e10cSrcweir 360*cdf0e10cSrcweir 361*cdf0e10cSrcweir 362*cdf0e10cSrcweir 363*cdf0e10cSrcweir 364*cdf0e10cSrcweir 365*cdf0e10cSrcweir 366*cdf0e10cSrcweir 367*cdf0e10cSrcweir 368*cdf0e10cSrcweir 369*cdf0e10cSrcweir 370*cdf0e10cSrcweir 371*cdf0e10cSrcweir 372*cdf0e10cSrcweir 373*cdf0e10cSrcweir 374*cdf0e10cSrcweir 375*cdf0e10cSrcweir 376*cdf0e10cSrcweir 377*cdf0e10cSrcweir 378*cdf0e10cSrcweir 379*cdf0e10cSrcweir 380*cdf0e10cSrcweir 381*cdf0e10cSrcweir 382*cdf0e10cSrcweir 383*cdf0e10cSrcweir 384*cdf0e10cSrcweir 385*cdf0e10cSrcweir 386*cdf0e10cSrcweir 387*cdf0e10cSrcweir 388*cdf0e10cSrcweir 389*cdf0e10cSrcweir 390*cdf0e10cSrcweir 391*cdf0e10cSrcweir 392*cdf0e10cSrcweir 393*cdf0e10cSrcweir 394*cdf0e10cSrcweir 395*cdf0e10cSrcweir 396*cdf0e10cSrcweir 397*cdf0e10cSrcweir 398