cryptix.util.test

Class BaseTest

public abstract class BaseTest extends Applet

This abstract class acts as a base for all Cryptix test classes. Its purpose is to provide a framework that will allow us to easily add new testing features. Features that have already been added include:

Planned features include:

Copyright © 1997, 1998 Systemics Ltd on behalf of the Cryptix Development Team.
All rights reserved.

$Revision: 1.5 $

Since: Cryptix 2.2.2

Author: David Hopwood

Field Summary
protected PrintWriterout
The PrintWriter to which delayed output is sent.
protected PrintWriterstatus
The PrintWriter to which immediate output is sent.
Constructor Summary
protected BaseTest()
Constructor for use by subclasses.
Method Summary
protected voidcommandline(String[] args)
Used to run a test from the command line.
protected voidcommandline(String[] args, int offset)
Used to run a test from the command line, skipping the first offset arguments (which are assumed to have been processed by the subclass).
StringdescribeOptions()
Describes the command-line options of this class.
StringdescribeUsage()
Describes the command-line usage of this class.
protected abstract voidengineTest()
This method should be overridden by test subclasses, to perform the actual testing.
protected voiderror(String msg)
Reports an error, with the given message.
protected voiderror(Exception e)
Reports an error due to an unexpected exception.
protected voiderror(Throwable e)
protected voidfail(String msg)
Reports a failure, with the given message.
intgetErrors()
Returns the number of errors so far.
intgetExpectedPasses()
Returns the number of expected passes, or 0 if this has not yet been set, or is unknown.
intgetFailures()
Returns the number of failures so far.
StringgetName()
Gets the name of this test (as shown to the user).
intgetPasses()
Returns the number of passes so far.
intgetSkipped()
Returns the number of skipped tests so far.
voidinit()
Used when the test is running as an Applet.
booleanisGuiEnabled()
Returns true iff a GUI interface is being used.
booleanisOverallPass()
Returns true iff all the tests have completed successfully.
booleanisVerbose()
Returns true iff output is to be printed even if all tests pass.
protected voidparseOption(String option)
Parses a command-line option.
voidparseOptions(String[] args, int offset)
Processes command-line arguments from args, starting at index offset.
protected voidpass(String msg)
Reports a pass, with the given message.
protected voidpassIf(boolean pass, String msg)
Reports a pass if pass is true, or a failure if it is false.
protected voidreport()
Forces a report of the number of passes, failures, errors, and expected passes so far.
protected voidsetExpectedPasses(int n)
Sets the number of expected passes for this test class.
voidsetGuiEnabled(boolean flag)
Sets whether a GUI interface is used.
voidsetName(String n)
Sets the name of this test (as shown to the user).
voidsetOutput(PrintWriter pw)
Sets the PrintWriter to which output is to be sent.
voidsetVerbose(boolean flag)
Sets whether output is to be printed even if all tests pass.
protected voidskip(String msg)
Reports a skipped test, with the given message.
voidtest()
Begins the test proper.
voidwaitForExit()
Blocks until it is time to exit.

Field Detail

out

protected PrintWriter out
The PrintWriter to which delayed output is sent.

status

protected PrintWriter status
The PrintWriter to which immediate output is sent.

Constructor Detail

BaseTest

protected BaseTest()
Constructor for use by subclasses.

Method Detail

commandline

protected void commandline(String[] args)
Used to run a test from the command line. Each test class' main method should create an instance and call the commandline method on it, passing the array of command line arguments. For example, in class TestFoo:
    public static void main(String[] args) {
        new TestFoo().commandline(args);
    }
 

commandline

protected void commandline(String[] args, int offset)
Used to run a test from the command line, skipping the first offset arguments (which are assumed to have been processed by the subclass).

describeOptions

public String describeOptions()
Describes the command-line options of this class.

describeUsage

public String describeUsage()
Describes the command-line usage of this class.

engineTest

protected abstract void engineTest()
This method should be overridden by test subclasses, to perform the actual testing.

error

protected void error(String msg)
Reports an error, with the given message.

error

protected void error(Exception e)
Reports an error due to an unexpected exception.

error

protected void error(Throwable e)

fail

protected void fail(String msg)
Reports a failure, with the given message.

getErrors

public int getErrors()
Returns the number of errors so far.

getExpectedPasses

public int getExpectedPasses()
Returns the number of expected passes, or 0 if this has not yet been set, or is unknown.

getFailures

public int getFailures()
Returns the number of failures so far.

getName

public String getName()
Gets the name of this test (as shown to the user).

getPasses

public int getPasses()
Returns the number of passes so far.

getSkipped

public int getSkipped()
Returns the number of skipped tests so far.

init

public void init()
Used when the test is running as an Applet.

isGuiEnabled

public boolean isGuiEnabled()
Returns true iff a GUI interface is being used.

isOverallPass

public boolean isOverallPass()
Returns true iff all the tests have completed successfully.

isVerbose

public boolean isVerbose()
Returns true iff output is to be printed even if all tests pass.

parseOption

protected void parseOption(String option)
Parses a command-line option. If the option is not recognised, super.parseOption(option) should be called.

Case should generally not be significant in option names.

parseOptions

public void parseOptions(String[] args, int offset)
Processes command-line arguments from args, starting at index offset.

pass

protected void pass(String msg)
Reports a pass, with the given message.

passIf

protected void passIf(boolean pass, String msg)
Reports a pass if pass is true, or a failure if it is false. In either case, the given message is used.

report

protected void report()
Forces a report of the number of passes, failures, errors, and expected passes so far.

setExpectedPasses

protected void setExpectedPasses(int n)
Sets the number of expected passes for this test class. This can be called at any time by the engineTest method, but should normally be called at the start of that method.

setGuiEnabled

public void setGuiEnabled(boolean flag)
Sets whether a GUI interface is used.

setName

public void setName(String n)
Sets the name of this test (as shown to the user). The default is the name of the class.

setOutput

public void setOutput(PrintWriter pw)
Sets the PrintWriter to which output is to be sent. In most cases this does not need to be set by the test class; the commandline method will do that automatically.

setVerbose

public void setVerbose(boolean flag)
Sets whether output is to be printed even if all tests pass.

skip

protected void skip(String msg)
Reports a skipped test, with the given message.

test

public void test()
Begins the test proper. This method is called automatically by commandline, but it can also be called directly.

waitForExit

public void waitForExit()
Blocks until it is time to exit.