update dev300-m58
[ooovba.git] / qadevOOo / runner / base / basic_fat.java
blobff74c37630872b5bb243c248c0fc862c7115c793
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: basic_fat.java,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 package base;
32 import base.TestBase;
34 import basicrunner.BasicIfcTest;
35 import basicrunner.BasicTestCase;
37 import com.sun.star.lang.XMultiServiceFactory;
39 import helper.APIDescGetter;
40 import helper.AppProvider;
41 import helper.OfficeProvider;
42 import helper.OfficeWatcher;
44 import java.io.BufferedReader;
45 import java.io.FileReader;
46 import java.io.PrintWriter;
48 import java.util.Vector;
50 import lib.TestCase;
51 import lib.TestEnvironment;
52 import lib.TestParameters;
54 import share.DescEntry;
55 import share.DescGetter;
56 import share.LogWriter;
58 import stats.OutProducerFactory;
59 import stats.Summarizer;
61 import util.DynamicClassLoader;
63 /**
64 * The testbase for executing basic tests.
65 * @see lib.TestBase
67 public class basic_fat implements TestBase
70 public static boolean debug = false;
72 /**
73 * Execute a test.
74 * @param param The test parameters.
75 * @param return True, if the test was executed.
77 public boolean executeTest(TestParameters param)
79 DescGetter dg = new APIDescGetter();
80 String job = (String) param.get("TestJob");
81 OfficeProvider office = null;
82 debug = param.getBool("DebugIsActive");
85 //get Job-Descriptions
86 System.out.print("Getting Descriptions for Job: " + job + " from ");
88 DescEntry[] entries = dg.getDescriptionFor(job,
89 (String) param.get(
90 "DescriptionPath"),
91 debug);
93 if (entries == null)
95 System.out.println("Couldn't get Description for Job");
97 return false;
100 String ExclusionFile = (String) param.get("ExclusionList");
101 Vector exclusions = null;
103 if (ExclusionFile != null)
105 exclusions = getExclusionList(ExclusionFile, debug);
108 String conStr = (String) param.get("ConnectionString");
109 System.out.println("");
110 System.out.print("> Connecting the Office ");
111 System.out.println("With " + conStr);
113 for (int l = 0; l < entries.length; l++)
115 if (entries[l].hasErrorMsg)
117 System.out.println(entries[l].ErrorMsg);
119 continue;
122 office = new OfficeProvider();
124 XMultiServiceFactory msf = (XMultiServiceFactory) office.getManager(
125 param);
127 if (msf == null)
129 return false;
132 param.put("ServiceFactory", msf);
134 DescEntry entry = entries[l];
136 //get some helper classes
137 Summarizer sumIt = new Summarizer();
138 DynamicClassLoader dcl = new DynamicClassLoader();
140 TestCase tCase = null;
142 tCase = (TestCase) new BasicTestCase(entry);
144 if (tCase == null)
146 sumIt.summarizeDown(entry, entry.ErrorMsg);
148 LogWriter sumObj = OutProducerFactory.createOutProducer(param);
149 sumObj.initialize(entry, true);
150 sumObj.summary(entry);
152 continue;
155 System.out.println("Creating: " + tCase.getObjectName());
157 LogWriter log = (LogWriter) dcl.getInstance(
158 (String) param.get("LogWriter"));
159 log.initialize(entry, true);
160 entry.UserDefinedParams = param;
161 tCase.setLogWriter((PrintWriter) log);
165 tCase.initializeTestCase(param);
167 catch (RuntimeException e)
169 helper.ProcessHandler ph = (helper.ProcessHandler) param.get(
170 "AppProvider");
172 if (ph != null)
174 OfficeWatcher ow = (OfficeWatcher) param.get("Watcher");
176 if ((ow != null) && ow.isAlive())
178 ow.finish = true;
181 ph.kill();
182 shortWait(5000);
185 continue;
188 TestEnvironment tEnv = tCase.getTestEnvironment(param);
190 if (tEnv == null)
192 sumIt.summarizeDown(entry, "Unable to create testcase");
194 LogWriter sumObj = OutProducerFactory.createOutProducer(param);
195 sumObj.initialize(entry, true);
196 sumObj.summary(entry);
198 helper.ProcessHandler ph = (helper.ProcessHandler) param.get(
199 "AppProvider");
201 if (ph != null)
203 OfficeWatcher ow = (OfficeWatcher) param.get("Watcher");
205 if ((ow != null) && ow.isAlive())
207 ow.finish = true;
210 ph.kill();
211 shortWait(5000);
214 continue;
217 System.out.println("created " + tCase.getObjectName());
219 for (int j = 0; j < entry.SubEntryCount; j++)
221 if (!entry.SubEntries[j].isToTest)
223 Summarizer.summarizeDown(entry.SubEntries[j],
224 "not part of the job");
226 continue;
229 if ((exclusions != null) &&
230 (exclusions.contains(entry.SubEntries[j].longName)))
232 Summarizer.summarizeDown(entry.SubEntries[j],
233 "known issue");
235 continue;
238 System.out.println("running: " +
239 entry.SubEntries[j].entryName);
241 LogWriter ifclog = (LogWriter) dcl.getInstance(
242 (String) param.get("LogWriter"));
243 ifclog.initialize(entry.SubEntries[j], true);
244 entry.SubEntries[j].UserDefinedParams = param;
245 entry.SubEntries[j].Logger = ifclog;
247 if ((tEnv == null) || tEnv.isDisposed())
249 helper.ProcessHandler ph = (helper.ProcessHandler) param.get(
250 "AppProvider");
252 if (ph != null)
254 office.closeExistingOffice(param, true);
255 shortWait(5000);
258 tEnv = getEnv(entry, param);
261 BasicIfcTest ifc = null;
262 lib.TestResult res = null;
263 ifc = new BasicIfcTest(entry.SubEntries[j].longName);
264 res = ifc.run(entry.SubEntries[j], tEnv, param);
266 sumIt.summarizeUp(entry.SubEntries[j]);
268 LogWriter sumIfc = OutProducerFactory.createOutProducer(param);
270 sumIfc.initialize(entry.SubEntries[j], true);
271 sumIfc.summary(entry.SubEntries[j]);
276 tCase.cleanupTestCase(param);
278 catch (Exception e)
280 log.println("TestCase already gone");
282 helper.ProcessHandler ph = (helper.ProcessHandler) param.get(
283 "AppProvider");
285 if (ph != null)
287 office.closeExistingOffice(param, true);
288 shortWait(5000);
292 sumIt.summarizeUp(entry);
294 LogWriter sumObj = OutProducerFactory.createOutProducer(param);
295 sumObj.initialize(entry, true);
296 sumObj.summary(entry);
299 if (entries.length > 1)
301 System.out.println();
303 int counter = 0;
304 System.out.println(
305 "Failures that appeared during scenario execution:");
307 for (int i = 0; i < entries.length; i++)
309 if (!entries[i].State.endsWith("OK"))
311 System.out.println("\t " + entries[i].longName);
312 counter++;
316 System.out.println(counter + " of " + entries.length +
317 " tests failed");
320 helper.ProcessHandler ph = (helper.ProcessHandler) param.get(
321 "AppProvider");
323 if (ph != null)
325 office.closeExistingOffice(param, true);
328 return true;
331 protected TestEnvironment getEnv(DescEntry entry, TestParameters param)
333 DynamicClassLoader dcl = new DynamicClassLoader();
334 String officeProviderName = (String) param.get("OfficeProvider");
335 AppProvider office = (AppProvider) dcl.getInstance(officeProviderName);
337 if (office == null)
339 System.out.println("ERROR: Wrong parameter 'OfficeProvider', " +
340 " it cannot be instantiated.");
341 System.exit(-1);
344 XMultiServiceFactory msf = (XMultiServiceFactory) office.getManager(
345 param);
347 if (msf == null)
349 return null;
352 param.put("ServiceFactory", msf);
354 TestCase tCase = (TestCase) new BasicTestCase(entry);
356 System.out.println("Creating: " + tCase.getObjectName());
358 LogWriter log = (LogWriter) dcl.getInstance(
359 (String) param.get("LogWriter"));
360 log.initialize(entry, true);
361 entry.UserDefinedParams = param;
362 tCase.setLogWriter((PrintWriter) log);
364 TestEnvironment tEnv = null;
368 tCase.initializeTestCase(param);
369 tEnv = tCase.getTestEnvironment(param);
371 catch (java.lang.RuntimeException e)
373 System.out.println(e.getMessage());
375 helper.ProcessHandler ph = (helper.ProcessHandler) param.get(
376 "AppProvider");
378 if (ph != null)
380 office.closeExistingOffice(param, true);
381 shortWait(5000);
384 entry.ErrorMsg = e.getMessage();
385 entry.hasErrorMsg = true;
388 return tEnv;
391 protected void shortWait(int millis)
395 Thread.sleep(millis);
397 catch (java.lang.InterruptedException ie)
402 protected Vector getExclusionList(String url, boolean debug)
404 Vector entryList = new Vector();
405 String line = "#";
406 BufferedReader exclusion = null;
410 exclusion = new BufferedReader(new FileReader(url));
412 catch (java.io.FileNotFoundException fnfe)
414 if (debug)
416 System.out.println("Couldn't find file " + url);
419 return entryList;
422 while (line != null)
426 if (!line.startsWith("#"))
428 entryList.add(line);
431 line = exclusion.readLine();
433 catch (java.io.IOException ioe)
435 if (debug)
437 System.out.println(
438 "Exception while reading exclusion list");
441 return entryList;
447 exclusion.close();
449 catch (java.io.IOException ioe)
451 if (debug)
453 System.out.println("Couldn't close file " + url);
456 return entryList;
459 return entryList;