summaryrefslogtreecommitdiff
path: root/qadevOOo/runner/complexlib
diff options
context:
space:
mode:
authorVladimir Glazounov <vg@openoffice.org>2003-10-06 11:37:52 +0000
committerVladimir Glazounov <vg@openoffice.org>2003-10-06 11:37:52 +0000
commitaf8870514e214aa9fb1363fe1a7f7d98aefa20de (patch)
tree1441a670374a8c8dd79ac6b2c3cc4b0671e49224 /qadevOOo/runner/complexlib
parent3eef9d3f24e0f6ff7e79d31f1e9a42097262f853 (diff)
INTEGRATION: CWS qadev12 (1.6.16); FILE MERGED
2003/09/25 11:05:10 sg 1.6.16.2: #112259#CHG: added javadoc 2003/09/24 16:00:50 sg 1.6.16.1: #112259#CHG: adapted to new thread for test methods
Diffstat (limited to 'qadevOOo/runner/complexlib')
-rw-r--r--qadevOOo/runner/complexlib/ComplexTestCase.java177
1 files changed, 131 insertions, 46 deletions
diff --git a/qadevOOo/runner/complexlib/ComplexTestCase.java b/qadevOOo/runner/complexlib/ComplexTestCase.java
index 686ba78232da..92a759dc27e5 100644
--- a/qadevOOo/runner/complexlib/ComplexTestCase.java
+++ b/qadevOOo/runner/complexlib/ComplexTestCase.java
@@ -2,9 +2,9 @@
*
* $RCSfile: ComplexTestCase.java,v $
*
- * $Revision: 1.6 $
+ * $Revision: 1.7 $
*
- * last change: $Date: 2003-05-27 12:01:31 $
+ * last change: $Date: 2003-10-06 12:37:52 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -69,13 +69,25 @@ import share.LogWriter;
import share.ComplexTest;
import java.io.PrintWriter;
-public abstract class ComplexTestCase implements ComplexTest {
- protected static TestParameters param;
- protected static LogWriter log;
- protected DescEntry subEntry;
- protected boolean state;
- protected String message;
+/**
+ * Base class for all complex tests.
+ */
+public abstract class ComplexTestCase implements ComplexTest {
+ /** The test parameters **/
+ protected static TestParameters param = null;
+ /** Log writer **/
+ protected static LogWriter log = null;
+ /** Description entry **/
+ protected DescEntry subEntry = null;
+ /** State of the current test method **/
+ protected boolean state = true;
+ /** The message if the test did fail **/
+ protected String message = null;
+ /** Maximal time one method is allowed to execute
+ * Can be set with parameter 'ThreadTimeOut'
+ **/
+ protected int mThreadTimeOut = 0;
/**
* Call test. It is expected, that an environment is
@@ -89,9 +101,12 @@ public abstract class ComplexTestCase implements ComplexTest {
// get the environment
param = environment;
log = entry.Logger;
- String errorMsg = null;
+
+ mThreadTimeOut = param.getInt("ThreadTimeOut");
+ if (mThreadTimeOut == 0) mThreadTimeOut = 300000;
// start with the before() method
+ boolean beforeWorked = true;
try {
Method before = this.getClass().getMethod("before",null);
before.invoke(this, null);
@@ -100,58 +115,77 @@ public abstract class ComplexTestCase implements ComplexTest {
// simply ignore
}
catch(java.lang.IllegalAccessException e) {
- // simply ignore
+ log.println("Cannot access the 'before()' method, although it" +
+ " is there. Is this ok?");
}
catch(java.lang.reflect.InvocationTargetException e) {
+ beforeWorked = false;
Throwable t = e.getTargetException();
- if (t instanceof StatusException) {
- errorMsg = "Failed in before() method.";
- }
- else {
+ if (!(t instanceof RuntimeException) || state) {
log.println(t.toString());
- errorMsg = "Exception in before() method.\n\r" +
- t.getMessage();
- if (errorMsg == null)
- errorMsg = "";
- log.println("Message: " + errorMsg);
+ if ( message == null ) {
+ message = "Exception in before() method.\n\r" + t.getMessage();
+ }
+ state = false;
t.printStackTrace((PrintWriter)log);
}
}
+
//executeMethodTests
for (int i=0; i<entry.SubEntries.length; i++) {
- state = true;
- message = "";
subEntry = entry.SubEntries[i];
- // set all test methods on failed, if 'before()' did not work.
- if (errorMsg != null) {
- subEntry.State = errorMsg;
+ if (beforeWorked) {
+ state = true;
+ message = "";
+ }
+ else {
+ // set all test methods on failed, if 'before()' did not work.
+ subEntry.State = message;
subEntry.hasErrorMsg = true;
- subEntry.ErrorMsg = errorMsg;
+ subEntry.ErrorMsg = message;
continue;
}
Method testMethod = null;
try {
testMethod = this.getClass().getMethod(
subEntry.entryName,null);
- testMethod.invoke(this, null);
- }
- catch(java.lang.reflect.InvocationTargetException e) {
- Throwable t = e.getTargetException();
- if (!(t instanceof StatusException)) {
- log.println(t.toString());
- String msg = t.getMessage();
- log.println("Message: " + msg);
- t.printStackTrace((PrintWriter)log);
- subEntry.State=message + (msg == null?"":msg);
+ MethodThread th = new MethodThread(testMethod, this,
+ (java.io.PrintWriter)log);
+ th.start();
+ try {
+ int sleepingStep = 1000;
+ int factor = 0;
+ while(th.isAlive() && factor*sleepingStep<mThreadTimeOut) {
+ Thread.sleep(sleepingStep);
+ factor++;
+ }
+
+ }
+ catch(InterruptedException e) {}
+ if (th.isAlive()) {
+ log.println("Destroy " + testMethod.getName());
+ th.destroy();
+ subEntry.State="Test did sleep for " +
+ (mThreadTimeOut / 1000) +
+ " seconds and has been killed!";
subEntry.hasErrorMsg = true;
- subEntry.ErrorMsg = message + "\n" + msg;
+ subEntry.ErrorMsg = subEntry.State;
continue;
- }
+ } else {
+ System.out.println("Finished " + testMethod.getName());
+ if (th.hasErrorMessage()) {
+ subEntry.State="Test did sleep for " +
+ (mThreadTimeOut / 1000) +
+ " seconds and has been killed!";
+ subEntry.hasErrorMsg = true;
+ subEntry.ErrorMsg = subEntry.State;
+ continue;
+ }
+ }
}
catch(java.lang.Exception e) {
log.println(e.getClass().getName());
- log.println("Message: " + e.getMessage());
String msg = e.getMessage();
log.println("Message: " + msg);
e.printStackTrace((PrintWriter)log);
@@ -165,7 +199,7 @@ public abstract class ComplexTestCase implements ComplexTest {
subEntry.ErrorMsg = message;
}
- if (errorMsg == null) {
+ if (beforeWorked) {
// the after() method
try {
Method after = this.getClass().getMethod("after",null);
@@ -181,50 +215,102 @@ public abstract class ComplexTestCase implements ComplexTest {
Throwable t = e.getTargetException();
if (!(t instanceof StatusException)) {
log.println(t.toString());
- errorMsg = "Exception in 'after()' method.\n\r" +
- t.getMessage();
- if (errorMsg == null)
- errorMsg = "";
- log.println("Message: " + errorMsg);
+ if ( message == null ) {
+ message = "Exception in after() method.\n\r" + t.getMessage();
+ }
+ else {
+ message += "Exception in 'after()' method.\n\r" + t.getMessage();
+ }
+ log.println("Message: " + message);
t.printStackTrace((PrintWriter)log);
}
}
}
}
+ /**
+ * Implement this method in the Complex test.
+ * @return All test method names.
+ */
public abstract String[] getTestMethodNames();
+ /**
+ * Return a name for the test or tested object.
+ * Override to give an own name.
+ * @return As default, the name of this class.
+ */
public String getTestObjectName() {
return this.getClass().getName();
}
+ /**
+ * Assure that s is true.
+ * This function generates "Assure failed." as standard message.
+ * @param s The condition that should be true.
+ */
protected void assure(boolean s) {
assure("Assure failed.", s, false);
}
+ /**
+ * Assure that s is true.
+ * The given message will be only evaluated, if s is false.
+ * @param msg The message that is evaluated.
+ * @param s The condition that should be true.
+ */
protected void assure(String msg, boolean s) {
assure(msg, s, false);
}
+ /**
+ * Mark the currently executed method as failed.
+ * This function generates "Test did fail." as standard message.
+ */
protected void failed() {
assure("Test did fail.", false, false);
}
+ /**
+ * Mark the currently executed method as failed.
+ * with the given message.
+ * @param msg The message of the failure.
+ */
protected void failed(String msg) {
assure(msg, false, false);
}
+ /**
+ * Assure that s is true.
+ * The given message will be only evaluated, if s is false.
+ * Normally, assure() leaves the current test method, and the next one
+ * is executed. With the parameter 'cont' set to true, the current test
+ * method will continue.<br>
+ * The current method will of course marked as failed.
+ * @param msg The message that is evaluated.
+ * @param s The condition that should be true.
+ * @param cont Continue with test method, even if s is false.
+ */
protected void assure(String msg, boolean s, boolean cont) {
state &= s;
if (!s) {
message += msg + "\r\n";
log.println(msg);
if (!cont) {
- throw new StatusException(msg, new Throwable());
+ throw new RuntimeException(msg);
}
}
}
+ /**
+ * Mark the currently executed method as failed.
+ * with the given message.
+ * The given message will be only evaluated, if s is false.
+ * With the parameter 'cont' set to true, the current test
+ * method will continue.<br>
+ * The current method will of course marked as failed.
+ * @param msg The message that is evaluated.
+ * @param cont Continue with test method, even if s is false.
+ */
protected void failed(String msg, boolean cont) {
assure(msg, false, cont);
}
@@ -238,7 +324,6 @@ public abstract class ComplexTestCase implements ComplexTest {
this.message += msg + "\r\n";
log.println(msg);
}
-
}