bump product version to 4.1.6.2
[LibreOffice.git] / qadevOOo / runner / base / java_fat.java
blob031474fddd21fa93b50be2055f63d9cff61e0c25
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 .
18 package base;
20 import helper.APIDescGetter;
21 import helper.AppProvider;
23 import java.io.BufferedReader;
24 import java.io.FileReader;
25 import java.io.PrintWriter;
26 import java.util.ArrayList;
27 import lib.MultiMethodTest;
28 import lib.TestCase;
29 import lib.TestEnvironment;
30 import lib.TestParameters;
31 import lib.TestResult;
32 import share.DescEntry;
33 import share.DescGetter;
34 import share.LogWriter;
35 import stats.OutProducerFactory;
36 import stats.Summarizer;
37 import util.DynamicClassLoader;
39 import com.sun.star.lang.XMultiServiceFactory;
41 /**
43 * this class handles tests written in java and running on a fat Office
45 public class java_fat implements TestBase
48 private static boolean m_isDebug = false;
49 private static boolean keepdocument = false;
50 private static boolean logging = true;
51 private static boolean newOffice = false;
52 private DynamicClassLoader m_aDynamicClassLoader = null;
54 private lib.TestParameters m_aParams;
55 private AppProvider m_aOffice;
57 public boolean executeTest(lib.TestParameters _aParams)
59 m_aParams = _aParams;
61 m_aDynamicClassLoader = new DynamicClassLoader();
63 DescGetter dg = new APIDescGetter();
64 String job = (String) m_aParams.get("TestJob");
65 String ExclusionFile = (String) m_aParams.get("ExclusionList");
66 ArrayList<String> exclusions = null;
67 boolean retValue = true;
68 m_isDebug = m_aParams.getBool("DebugIsActive");
69 logging = m_aParams.getBool("LoggingIsActive");
70 keepdocument = m_aParams.getBool("KeepDocument");
71 newOffice = m_aParams.getBool(util.PropertyName.NEW_OFFICE_INSTANCE);
72 if (keepdocument)
74 System.setProperty("KeepDocument", "true");
76 if (ExclusionFile != null)
78 exclusions = getExclusionList(ExclusionFile, m_isDebug);
80 //get Job-Descriptions
81 // System.out.println("Getting Descriptions for Job: " + job);
83 String sDescriptionPath = (String) m_aParams.get("DescriptionPath");
84 DescEntry[] entries = dg.getDescriptionFor(job, sDescriptionPath, m_isDebug);
86 // System.out.println();
88 if (entries == null)
90 System.out.println("Couldn't get Description for Job: " + job);
92 return false;
95 // String officeProviderName = (String) m_aParams.get("OfficeProvider");
96 // AppProvider office = (AppProvider) m_aDynamicClassLoader.getInstance(officeProviderName);
98 // if (office == null) {
99 // System.out.println("ERROR: Wrong parameter 'OfficeProvider', " +
100 // " it cannot be instantiated.");
101 // System.exit(-1);
102 // }
104 m_aOffice = startOffice(m_aParams);
106 boolean firstRun = true;
108 // Run through all entries (e.g. sw.SwXBookmark.*)
110 for (int l = 0; l < entries.length; l++)
112 DescEntry entry = entries[l];
114 if (entry == null)
116 continue;
119 if (entry.hasErrorMsg)
121 System.out.println(entries[l].ErrorMsg);
122 retValue = false;
123 continue;
126 if (!firstRun && newOffice)
128 if (!m_aOffice.closeExistingOffice(m_aParams, true))
130 m_aOffice.disposeManager(m_aParams);
132 startOffice(m_aParams);
134 firstRun = false;
136 XMultiServiceFactory msf = (XMultiServiceFactory) m_aParams.getMSF();
138 if (msf == null)
140 retValue = false;
141 continue;
144 //get some helper classes
145 Summarizer sumIt = new Summarizer();
146 TestCase tCase = getTestCase(entry);
147 if (tCase == null)
149 continue;
152 // if (m_isDebug)
153 // {
154 // System.out.println("sleeping 2 seconds..");
155 // }
156 util.utils.shortWait(2000);
158 System.out.println("Creating: " + entry.entryName);
160 LogWriter log = (LogWriter) m_aDynamicClassLoader.getInstance((String) m_aParams.get("LogWriter"));
161 log.initialize(entry, logging);
162 entry.UserDefinedParams = m_aParams;
164 tCase.setLogWriter((PrintWriter) log);
165 tCase.initializeTestCase(m_aParams);
167 TestEnvironment tEnv = getTestEnvironment(tCase, entry);
168 if (tEnv == null)
170 continue;
173 tCase.getObjectName();
175 for (int j = 0; j < entry.SubEntryCount; j++)
177 DescEntry aSubEntry = entry.SubEntries[j];
178 final boolean bIsToTest = aSubEntry.isToTest;
179 if (!bIsToTest)
181 Summarizer.summarizeDown(aSubEntry, "not part of the job");
182 continue;
185 // final String sEntryName = aSubEntry.entryName;
186 final String sLongEntryName = aSubEntry.longName;
188 if ((exclusions != null) && (exclusions.contains(sLongEntryName)))
190 Summarizer.summarizeDown(aSubEntry, "known issue");
191 continue;
194 // System.out.println("running: '" + sLongEntryName + "' testcode: [" + sEntryName + "]");
195 // this will shown in test itself
197 LogWriter ifclog = (LogWriter) m_aDynamicClassLoader.getInstance( (String) m_aParams.get("LogWriter"));
199 ifclog.initialize(aSubEntry, logging);
200 aSubEntry.UserDefinedParams = m_aParams;
201 aSubEntry.Logger = ifclog;
203 if ((tEnv == null) || tEnv.isDisposed())
205 closeExistingOffice();
206 tEnv = getEnv(entry, m_aParams);
207 tCase = tEnv.getTestCase();
210 // MultiMethodTest ifc = null;
211 lib.TestResult res = null;
213 // run the interface test twice if it failed.
214 int countInterfaceTestRun = 0;
215 boolean finished = false;
216 while (!finished)
220 countInterfaceTestRun++;
221 finished = true;
222 res = executeInterfaceTest(aSubEntry, tEnv, m_aParams);
224 catch (IllegalArgumentException iae)
226 System.out.println("Couldn't load class " + aSubEntry.entryName);
227 System.out.println("**** " + iae.getMessage() + " ****");
228 Summarizer.summarizeDown(aSubEntry, iae.getMessage());
230 catch (java.lang.NoClassDefFoundError iae)
232 System.out.println("Couldn't load class " + aSubEntry.entryName);
233 System.out.println("**** " + iae.getMessage() + " ****");
234 Summarizer.summarizeDown(aSubEntry, iae.getMessage());
236 catch (java.lang.RuntimeException e)
238 closeExistingOffice();
239 tEnv = getEnv(entry, m_aParams);
240 tCase = tEnv.getTestCase();
241 if (countInterfaceTestRun < 2)
243 finished = false;
245 else
247 Summarizer.summarizeDown(aSubEntry, e.toString() + ".FAILED");
251 setState(aSubEntry, res);
253 sumIt.summarizeUp(aSubEntry);
255 LogWriter sumIfc = OutProducerFactory.createOutProducer(m_aParams);
256 aSubEntry.UserDefinedParams = m_aParams;
257 sumIfc.initialize(aSubEntry, logging);
258 sumIfc.summary(aSubEntry);
263 if (!keepdocument)
265 tCase.cleanupTestCase(m_aParams);
268 catch (Exception e)
270 System.err.println( "couldn't cleanup:" + e.toString() );
272 catch (java.lang.NoClassDefFoundError e)
274 System.err.println( "couldn't cleanup:" + e.toString() );
277 sumIt.summarizeUp(entry);
279 LogWriter sumObj = OutProducerFactory.createOutProducer(m_aParams);
281 sumObj.initialize(entry, logging);
282 sumObj.summary(entry);
285 if (entries.length > 0)
287 System.out.println();
289 int counter = 0;
290 System.out.println("Failures that appeared during scenario execution:");
292 for (int i = 0; i < entries.length; i++)
294 final String sState = entries[i].State;
295 if (!sState.endsWith("OK"))
297 System.out.println("\t " + entries[i].longName);
298 counter++;
302 System.out.println(counter + " of " + entries.length + " tests failed");
303 if (counter != 0) {
304 retValue = false;
308 closeExistingOffice();
309 return retValue;
313 private TestEnvironment getTestEnvironment(TestCase tCase, DescEntry entry)
315 TestEnvironment tEnv = null;
319 tEnv = tCase.getTestEnvironment(m_aParams);
321 catch (Exception e)
323 System.out.println("Exception while creating " + tCase.getObjectName());
324 System.out.println("Message " + e.getMessage());
325 e.printStackTrace();
326 tEnv = null;
328 catch (java.lang.UnsatisfiedLinkError e)
330 System.out.println("Exception while creating " + tCase.getObjectName());
331 System.out.println("Message " + e.getMessage());
332 tEnv = null;
334 catch (java.lang.NoClassDefFoundError e)
336 System.out.println("Exception while creating " + tCase.getObjectName());
337 System.out.println("Message " + e.getMessage());
338 tEnv = null;
341 if (tEnv == null)
343 Summarizer.summarizeDown(entry, "Couldn't create " + tCase.getObjectName());
345 LogWriter sumObj = OutProducerFactory.createOutProducer(m_aParams);
346 entry.UserDefinedParams = m_aParams;
347 sumObj.initialize(entry, logging);
348 sumObj.summary(entry);
350 return tEnv;
352 // -------------------------------------------------------------------------
353 private TestCase getTestCase(DescEntry _aEntry)
355 TestCase tCase = null;
359 tCase = (TestCase) m_aDynamicClassLoader.getInstance("mod._" + _aEntry.entryName);
361 catch (java.lang.IllegalArgumentException ie)
363 _aEntry.ErrorMsg = ie.getMessage();
364 _aEntry.hasErrorMsg = true;
366 catch (java.lang.NoClassDefFoundError ie)
368 _aEntry.ErrorMsg = ie.getMessage();
369 _aEntry.hasErrorMsg = true;
372 if (tCase == null)
374 Summarizer.summarizeDown(_aEntry, _aEntry.ErrorMsg);
376 LogWriter sumObj = OutProducerFactory.createOutProducer(m_aParams);
377 _aEntry.UserDefinedParams = m_aParams;
378 sumObj.initialize(_aEntry, logging);
379 sumObj.summary(_aEntry);
381 return tCase;
384 private void setState(DescEntry aSubEntry, lib.TestResult res)
386 if (res != null)
388 for (int k = 0; k < aSubEntry.SubEntryCount; k++)
390 DescEntry aSubSubEntry = aSubEntry.SubEntries[k];
391 if (res.hasMethod( aSubSubEntry.entryName))
393 aSubSubEntry.State = res.getStatusFor(aSubSubEntry.entryName).toString();
399 private TestEnvironment getEnv(DescEntry entry, TestParameters param)
401 // if (m_aDynamicClassLoader == null)
402 // m_aDynamicClassLoader = new DynamicClassLoader();
403 // String officeProviderName = (String) m_aParams.get("OfficeProvider");
404 // AppProvider office = (AppProvider) m_aDynamicClassLoader.getInstance(officeProviderName);
406 // if (office == null) {
407 // System.out.println("ERROR: Wrong parameter 'OfficeProvider', " +
408 // " it cannot be instantiated.");
409 // System.exit(-1);
410 // }
412 // XMultiServiceFactory msf = (XMultiServiceFactory) office.getManager(
413 // m_aParams);
415 // if (msf == null) {
416 // return null;
417 // }
419 // m_aParams.put("ServiceFactory", msf);
421 // AppProvider office = startOffice(m_aParams);
423 TestCase tCase = null;
427 tCase = (TestCase) m_aDynamicClassLoader.getInstance("mod._" + entry.entryName);
429 catch (java.lang.IllegalArgumentException ie)
431 entry.ErrorMsg = ie.getMessage();
432 entry.hasErrorMsg = true;
434 catch (java.lang.NoClassDefFoundError ie)
436 entry.ErrorMsg = ie.getMessage();
437 entry.hasErrorMsg = true;
440 System.out.println("Creating: " + entry.entryName);
442 entry.UserDefinedParams = param;
444 LogWriter log = (LogWriter) m_aDynamicClassLoader.getInstance((String) param.get("LogWriter"));
445 log.initialize(entry, logging);
446 tCase.setLogWriter((PrintWriter) log);
450 tCase.initializeTestCase(param);
451 return tCase.getTestEnvironment(param);
453 catch (com.sun.star.lang.DisposedException de)
455 System.out.println("Office disposed");
456 closeExistingOffice();
457 throw de;
459 catch (lib.StatusException e)
461 System.out.println(e.getMessage());
463 closeExistingOffice();
465 entry.ErrorMsg = e.getMessage();
466 entry.hasErrorMsg = true;
467 throw e;
471 private void closeExistingOffice()
473 helper.ProcessHandler ph = (helper.ProcessHandler) m_aParams.get("AppProvider");
475 if (ph != null)
477 m_aOffice.closeExistingOffice(m_aParams, true);
478 util.utils.shortWait(5000);
483 // private void shortWait(int millis)
484 // {
485 // try
486 // {
487 // Thread.sleep(millis);
488 // }
489 // catch (java.lang.InterruptedException ie)
490 // {
491 // }
492 // }
494 private ArrayList<String> getExclusionList(String url, boolean debug)
496 ArrayList<String> entryList = new ArrayList<String>();
497 String line = "#";
498 BufferedReader exclusion = null;
502 exclusion = new BufferedReader(new FileReader(url));
504 catch (java.io.FileNotFoundException fnfe)
506 if (debug)
508 System.out.println("Couldn't find file " + url);
511 return entryList;
516 while (line != null)
520 if (!line.startsWith("#") && (line.length() > 1))
522 entryList.add(line.trim());
525 line = exclusion.readLine();
527 catch (java.io.IOException ioe)
529 if (debug)
531 System.out.println("Exception while reading exclusion list");
534 return entryList;
538 finally
542 exclusion.close();
544 catch (java.io.IOException ioe)
549 return entryList;
552 private TestResult executeInterfaceTest(
553 DescEntry entry, TestEnvironment tEnv, TestParameters param)
554 throws IllegalArgumentException, java.lang.NoClassDefFoundError
556 MultiMethodTest ifc = (MultiMethodTest) m_aDynamicClassLoader.getInstance(entry.entryName);
557 return ifc.run(entry, tEnv, param);
560 private AppProvider startOffice(lib.TestParameters param)
563 if (m_aDynamicClassLoader == null)
565 m_aDynamicClassLoader = new DynamicClassLoader();
568 String officeProviderName = (String) param.get("OfficeProvider");
569 AppProvider office = (AppProvider) m_aDynamicClassLoader.getInstance(officeProviderName);
571 if (office == null)
573 System.out.println("ERROR: Wrong parameter 'OfficeProvider', " + " it cannot be instantiated.");
574 System.exit(-1);
577 XMultiServiceFactory msf = (XMultiServiceFactory) office.getManager(param);
579 if (msf != null)
581 param.put("ServiceFactory", msf);
584 return office;