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 ************************************************************************/
29 import com
.sun
.star
.lang
.XMultiServiceFactory
;
31 import helper
.APIDescGetter
;
32 import helper
.AppProvider
;
34 import java
.io
.BufferedReader
;
35 import java
.io
.FileReader
;
36 import java
.io
.PrintWriter
;
38 import java
.util
.Vector
;
40 import lib
.MultiMethodTest
;
42 import lib
.TestEnvironment
;
43 import lib
.TestParameters
;
44 import lib
.TestResult
;
46 import share
.DescEntry
;
47 import share
.DescGetter
;
48 import share
.LogWriter
;
50 import stats
.OutProducerFactory
;
51 import stats
.Summarizer
;
53 import util
.DynamicClassLoader
;
57 * this class handles tests written in java and running on a fat Office
59 public class java_fat
implements TestBase
62 private static boolean m_isDebug
= false;
63 private static boolean keepdocument
= false;
64 private static boolean logging
= true;
65 private static boolean newOffice
= false;
66 private DynamicClassLoader m_aDynamicClassLoader
= null;
68 private lib
.TestParameters m_aParams
;
69 private AppProvider m_aOffice
;
71 public boolean executeTest(lib
.TestParameters _aParams
)
75 m_aDynamicClassLoader
= new DynamicClassLoader();
77 DescGetter dg
= new APIDescGetter();
78 String job
= (String
) m_aParams
.get("TestJob");
79 String ExclusionFile
= (String
) m_aParams
.get("ExclusionList");
80 Vector exclusions
= null;
81 boolean retValue
= true;
82 m_isDebug
= m_aParams
.getBool("DebugIsActive");
83 logging
= m_aParams
.getBool("LoggingIsActive");
84 keepdocument
= m_aParams
.getBool("KeepDocument");
85 newOffice
= m_aParams
.getBool(util
.PropertyName
.NEW_OFFICE_INSTANCE
);
88 System
.setProperty("KeepDocument", "true");
90 if (ExclusionFile
!= null)
92 exclusions
= getExclusionList(ExclusionFile
, m_isDebug
);
94 //get Job-Descriptions
95 // System.out.println("Getting Descriptions for Job: " + job);
97 String sDescriptionPath
= (String
) m_aParams
.get("DescriptionPath");
98 DescEntry
[] entries
= dg
.getDescriptionFor(job
, sDescriptionPath
, m_isDebug
);
100 // System.out.println();
104 System
.out
.println("Couldn't get Description for Job: " + job
);
109 // String officeProviderName = (String) m_aParams.get("OfficeProvider");
110 // AppProvider office = (AppProvider) m_aDynamicClassLoader.getInstance(officeProviderName);
112 // if (office == null) {
113 // System.out.println("ERROR: Wrong parameter 'OfficeProvider', " +
114 // " it cannot be instantiated.");
118 m_aOffice
= startOffice(m_aParams
);
120 boolean firstRun
= true;
122 // Run through all entries (e.g. sw.SwXBookmark.*)
124 for (int l
= 0; l
< entries
.length
; l
++)
126 DescEntry entry
= entries
[l
];
133 if (entry
.hasErrorMsg
)
135 System
.out
.println(entries
[l
].ErrorMsg
);
140 if (!firstRun
&& newOffice
)
142 if (!m_aOffice
.closeExistingOffice(m_aParams
, true))
144 m_aOffice
.disposeManager(m_aParams
);
146 startOffice(m_aParams
);
150 XMultiServiceFactory msf
= (XMultiServiceFactory
) m_aParams
.getMSF();
158 //get some helper classes
159 Summarizer sumIt
= new Summarizer();
160 TestCase tCase
= getTestCase(entry
);
168 // System.out.println("sleeping 2 seconds..");
170 util
.utils
.shortWait(2000);
172 System
.out
.println("Creating: " + entry
.entryName
);
174 LogWriter log
= (LogWriter
) m_aDynamicClassLoader
.getInstance((String
) m_aParams
.get("LogWriter"));
175 log
.initialize(entry
, logging
);
176 entry
.UserDefinedParams
= m_aParams
;
178 tCase
.setLogWriter((PrintWriter
) log
);
179 tCase
.initializeTestCase(m_aParams
);
181 TestEnvironment tEnv
= getTestEnvironment(tCase
, entry
);
187 final String sObjectName
= tCase
.getObjectName();
188 // System.out.println(sObjectName + " recreated ");
190 for (int j
= 0; j
< entry
.SubEntryCount
; j
++)
192 DescEntry aSubEntry
= entry
.SubEntries
[j
];
193 final boolean bIsToTest
= aSubEntry
.isToTest
;
196 Summarizer
.summarizeDown(aSubEntry
, "not part of the job");
200 // final String sEntryName = aSubEntry.entryName;
201 final String sLongEntryName
= aSubEntry
.longName
;
203 if ((exclusions
!= null) && (exclusions
.contains(sLongEntryName
)))
205 Summarizer
.summarizeDown(aSubEntry
, "known issue");
209 // System.out.println("running: '" + sLongEntryName + "' testcode: [" + sEntryName + "]");
210 // this will shown in test itself
212 LogWriter ifclog
= (LogWriter
) m_aDynamicClassLoader
.getInstance( (String
) m_aParams
.get("LogWriter"));
214 ifclog
.initialize(aSubEntry
, logging
);
215 aSubEntry
.UserDefinedParams
= m_aParams
;
216 aSubEntry
.Logger
= ifclog
;
218 if ((tEnv
== null) || tEnv
.isDisposed())
220 closeExistingOffice();
221 tEnv
= getEnv(entry
, m_aParams
);
222 tCase
= tEnv
.getTestCase();
225 // MultiMethodTest ifc = null;
226 lib
.TestResult res
= null;
228 // run the interface test twice if it failed.
229 int countInterfaceTestRun
= 0;
230 boolean finished
= false;
235 countInterfaceTestRun
++;
237 res
= executeInterfaceTest(aSubEntry
, tEnv
, m_aParams
);
239 catch (IllegalArgumentException iae
)
241 System
.out
.println("Couldn't load class " + aSubEntry
.entryName
);
242 System
.out
.println("**** " + iae
.getMessage() + " ****");
243 Summarizer
.summarizeDown(aSubEntry
, iae
.getMessage());
245 catch (java
.lang
.NoClassDefFoundError iae
)
247 System
.out
.println("Couldn't load class " + aSubEntry
.entryName
);
248 System
.out
.println("**** " + iae
.getMessage() + " ****");
249 Summarizer
.summarizeDown(aSubEntry
, iae
.getMessage());
251 catch (java
.lang
.RuntimeException e
)
253 closeExistingOffice();
254 tEnv
= getEnv(entry
, m_aParams
);
255 tCase
= tEnv
.getTestCase();
256 if (countInterfaceTestRun
< 2)
262 Summarizer
.summarizeDown(aSubEntry
, e
.toString() + ".FAILED");
266 setState(aSubEntry
, res
);
268 sumIt
.summarizeUp(aSubEntry
);
270 LogWriter sumIfc
= OutProducerFactory
.createOutProducer(m_aParams
);
271 aSubEntry
.UserDefinedParams
= m_aParams
;
272 sumIfc
.initialize(aSubEntry
, logging
);
273 sumIfc
.summary(aSubEntry
);
280 tCase
.cleanupTestCase(m_aParams
);
285 System
.err
.println( "couldn't cleanup:" + e
.toString() );
287 catch (java
.lang
.NoClassDefFoundError e
)
289 System
.err
.println( "couldn't cleanup:" + e
.toString() );
292 sumIt
.summarizeUp(entry
);
294 LogWriter sumObj
= OutProducerFactory
.createOutProducer(m_aParams
);
296 sumObj
.initialize(entry
, logging
);
297 sumObj
.summary(entry
);
300 if (entries
.length
> 0)
302 System
.out
.println();
305 System
.out
.println("Failures that appeared during scenario execution:");
307 for (int i
= 0; i
< entries
.length
; i
++)
309 final String sState
= entries
[i
].State
;
310 if (!sState
.endsWith("OK"))
312 System
.out
.println("\t " + entries
[i
].longName
);
317 System
.out
.println(counter
+ " of " + entries
.length
+ " tests failed");
323 closeExistingOffice();
328 private TestEnvironment
getTestEnvironment(TestCase tCase
, DescEntry entry
)
330 TestEnvironment tEnv
= null;
334 tEnv
= tCase
.getTestEnvironment(m_aParams
);
338 System
.out
.println("Exception while creating " + tCase
.getObjectName());
339 System
.out
.println("Message " + e
.getMessage());
343 catch (java
.lang
.UnsatisfiedLinkError e
)
345 System
.out
.println("Exception while creating " + tCase
.getObjectName());
346 System
.out
.println("Message " + e
.getMessage());
349 catch (java
.lang
.NoClassDefFoundError e
)
351 System
.out
.println("Exception while creating " + tCase
.getObjectName());
352 System
.out
.println("Message " + e
.getMessage());
358 Summarizer
.summarizeDown(entry
, "Couldn't create " + tCase
.getObjectName());
360 LogWriter sumObj
= OutProducerFactory
.createOutProducer(m_aParams
);
361 entry
.UserDefinedParams
= m_aParams
;
362 sumObj
.initialize(entry
, logging
);
363 sumObj
.summary(entry
);
367 // -------------------------------------------------------------------------
368 private TestCase
getTestCase(DescEntry _aEntry
)
370 TestCase tCase
= null;
374 tCase
= (TestCase
) m_aDynamicClassLoader
.getInstance("mod._" + _aEntry
.entryName
);
376 catch (java
.lang
.IllegalArgumentException ie
)
378 _aEntry
.ErrorMsg
= ie
.getMessage();
379 _aEntry
.hasErrorMsg
= true;
381 catch (java
.lang
.NoClassDefFoundError ie
)
383 _aEntry
.ErrorMsg
= ie
.getMessage();
384 _aEntry
.hasErrorMsg
= true;
389 Summarizer
.summarizeDown(_aEntry
, _aEntry
.ErrorMsg
);
391 LogWriter sumObj
= OutProducerFactory
.createOutProducer(m_aParams
);
392 _aEntry
.UserDefinedParams
= m_aParams
;
393 sumObj
.initialize(_aEntry
, logging
);
394 sumObj
.summary(_aEntry
);
399 private void setState(DescEntry aSubEntry
, lib
.TestResult res
)
403 for (int k
= 0; k
< aSubEntry
.SubEntryCount
; k
++)
405 DescEntry aSubSubEntry
= aSubEntry
.SubEntries
[k
];
406 if (res
.hasMethod( aSubSubEntry
.entryName
))
408 aSubSubEntry
.State
= res
.getStatusFor(aSubSubEntry
.entryName
).toString();
414 private TestEnvironment
getEnv(DescEntry entry
, TestParameters param
)
416 // if (m_aDynamicClassLoader == null)
417 // m_aDynamicClassLoader = new DynamicClassLoader();
418 // String officeProviderName = (String) m_aParams.get("OfficeProvider");
419 // AppProvider office = (AppProvider) m_aDynamicClassLoader.getInstance(officeProviderName);
421 // if (office == null) {
422 // System.out.println("ERROR: Wrong parameter 'OfficeProvider', " +
423 // " it cannot be instantiated.");
427 // XMultiServiceFactory msf = (XMultiServiceFactory) office.getManager(
430 // if (msf == null) {
434 // m_aParams.put("ServiceFactory", msf);
436 // AppProvider office = startOffice(m_aParams);
438 TestCase tCase
= null;
442 tCase
= (TestCase
) m_aDynamicClassLoader
.getInstance("mod._" + entry
.entryName
);
444 catch (java
.lang
.IllegalArgumentException ie
)
446 entry
.ErrorMsg
= ie
.getMessage();
447 entry
.hasErrorMsg
= true;
449 catch (java
.lang
.NoClassDefFoundError ie
)
451 entry
.ErrorMsg
= ie
.getMessage();
452 entry
.hasErrorMsg
= true;
455 System
.out
.println("Creating: " + entry
.entryName
);
457 entry
.UserDefinedParams
= param
;
459 LogWriter log
= (LogWriter
) m_aDynamicClassLoader
.getInstance((String
) param
.get("LogWriter"));
460 log
.initialize(entry
, logging
);
461 tCase
.setLogWriter((PrintWriter
) log
);
465 tCase
.initializeTestCase(param
);
466 return tCase
.getTestEnvironment(param
);
468 catch (com
.sun
.star
.lang
.DisposedException de
)
470 System
.out
.println("Office disposed");
471 closeExistingOffice();
474 catch (lib
.StatusException e
)
476 System
.out
.println(e
.getMessage());
478 closeExistingOffice();
480 entry
.ErrorMsg
= e
.getMessage();
481 entry
.hasErrorMsg
= true;
486 private void closeExistingOffice()
488 helper
.ProcessHandler ph
= (helper
.ProcessHandler
) m_aParams
.get("AppProvider");
492 m_aOffice
.closeExistingOffice(m_aParams
, true);
493 util
.utils
.shortWait(5000);
498 // private void shortWait(int millis)
502 // Thread.sleep(millis);
504 // catch (java.lang.InterruptedException ie)
509 private Vector
getExclusionList(String url
, boolean debug
)
511 Vector entryList
= new Vector();
513 BufferedReader exclusion
= null;
517 exclusion
= new BufferedReader(new FileReader(url
));
519 catch (java
.io
.FileNotFoundException fnfe
)
523 System
.out
.println("Couldn't find file " + url
);
533 if (!line
.startsWith("#") && (line
.length() > 1))
535 entryList
.add(line
.trim());
538 line
= exclusion
.readLine();
540 catch (java
.io
.IOException ioe
)
544 System
.out
.println("Exception while reading exclusion list");
555 catch (java
.io
.IOException ioe
)
559 System
.out
.println("Couldn't close file " + url
);
568 private TestResult
executeInterfaceTest(
569 DescEntry entry
, TestEnvironment tEnv
, TestParameters param
)
570 throws IllegalArgumentException
, java
.lang
.NoClassDefFoundError
572 MultiMethodTest ifc
= (MultiMethodTest
) m_aDynamicClassLoader
.getInstance(entry
.entryName
);
573 return ifc
.run(entry
, tEnv
, param
);
576 private AppProvider
startOffice(lib
.TestParameters param
)
579 if (m_aDynamicClassLoader
== null)
581 m_aDynamicClassLoader
= new DynamicClassLoader();
584 String officeProviderName
= (String
) param
.get("OfficeProvider");
585 AppProvider office
= (AppProvider
) m_aDynamicClassLoader
.getInstance(officeProviderName
);
589 System
.out
.println("ERROR: Wrong parameter 'OfficeProvider', " + " it cannot be instantiated.");
593 XMultiServiceFactory msf
= (XMultiServiceFactory
) office
.getManager(param
);
597 param
.put("ServiceFactory", msf
);