cryptix.util.test

Class BaseTest

Known Direct Subclasses:
Test3LFSR, TestAll, TestBase64Stream, TestBlowfish, TestBR, TestCAST5, TestDES, TestDES_EDE3, TestElGamal, TestHAVAL, TestHMAC, TestIDEA, TestIJCE, TestInstall, TestLOKI91, TestMD2, TestMD4, TestMD5, TestRC2, TestRC4, TestRijndael, TestRIPEMD128, TestRIPEMD160, TestRSA, TestSAFER, TestScar, TestSHA0, TestSHA1, TestSPEED, TestSquare, TestUnixCrypt

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 $

Author:
David Hopwood
Since:
Cryptix 2.2.2

Field Summary

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

Constructor Summary

BaseTest()
Constructor for use by subclasses.

Method Summary

protected void
commandline(String[] args)
Used to run a test from the command line.
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).
String
describeOptions()
Describes the command-line options of this class.
String
describeUsage()
Describes the command-line usage of this class.
protected abstract void
engineTest()
This method should be overridden by test subclasses, to perform the actual testing.
protected void
error(Exception e)
Reports an error due to an unexpected exception.
protected void
error(String msg)
Reports an error, with the given message.
protected void
error(Throwable e)
protected void
fail(String msg)
Reports a failure, with the given message.
int
getErrors()
Returns the number of errors so far.
int
getExpectedPasses()
Returns the number of expected passes, or 0 if this has not yet been set, or is unknown.
int
getFailures()
Returns the number of failures so far.
String
getName()
Gets the name of this test (as shown to the user).
int
getPasses()
Returns the number of passes so far.
int
getSkipped()
Returns the number of skipped tests so far.
void
init()
Used when the test is running as an Applet.
boolean
isGuiEnabled()
Returns true iff a GUI interface is being used.
boolean
isOverallPass()
Returns true iff all the tests have completed successfully.
boolean
isVerbose()
Returns true iff output is to be printed even if all tests pass.
protected void
parseOption(String option)
Parses a command-line option.
void
parseOptions(String[] args, int offset)
Processes command-line arguments from args, starting at index offset.
protected void
pass(String msg)
Reports a pass, with the given message.
protected void
passIf(boolean pass, String msg)
Reports a pass if pass is true, or a failure if it is false.
protected void
report()
Forces a report of the number of passes, failures, errors, and expected passes so far.
protected void
setExpectedPasses(int n)
Sets the number of expected passes for this test class.
void
setGuiEnabled(boolean flag)
Sets whether a GUI interface is used.
void
setName(String n)
Sets the name of this test (as shown to the user).
void
setOutput(PrintWriter pw)
Sets the PrintWriter to which output is to be sent.
void
setVerbose(boolean flag)
Sets whether output is to be printed even if all tests pass.
protected void
skip(String msg)
Reports a skipped test, with the given message.
void
test()
Begins the test proper.
void
waitForExit()
Blocks until it is time to exit.

Field Details

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 Details

BaseTest

protected BaseTest()
Constructor for use by subclasses.

Method Details

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()
            throws Exception
This method should be overridden by test subclasses, to perform the actual testing.

error

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

error

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

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)
            throws TestException
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)
            throws TestException
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()
            throws TestException
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.