PSCF v1.1
|
UnitTest is a base class for classes that define unit tests. More...
#include <UnitTest.h>
Public Member Functions | |
UnitTest () | |
Constructor. More... | |
virtual | ~UnitTest () |
Destructor. More... | |
virtual void | setUp () |
Set up before each test method (empty default implementation). More... | |
virtual void | tearDown () |
Tear down after each test method (empty default implementation). More... | |
void | setVerbose (int verbose) |
Set verbosity level. More... | |
void | setFilePrefix (const std::string &prefix) |
Set file prefix. More... | |
const std::string & | filePrefix () |
Get file prefix string. More... | |
bool | isIoProcessor () const |
Should this processor read and write to file? More... | |
Protected Member Functions | |
void | printMethod (const char *methodName) |
Write name of a class method, iff ioProcessor. More... | |
void | printEndl () |
Write carriage return, iff isIoProcessor. More... | |
virtual void | endMarker () |
Print a line of hashes, iff isIoProcessor. More... | |
void | openInputFile (const std::string &name, std::ifstream &in) const |
Open C++ input file ifstream. More... | |
void | openOutputFile (const std::string &name, std::ofstream &out) const |
Open C++ output file ofstream. More... | |
FILE * | openFile (const std::string &name, const char *mode) const |
Open C file handle with specified mode. More... | |
int | verbose () const |
Return integer verbosity level (0 == silent). More... | |
Static Protected Member Functions | |
static bool | eq (int s1, int s2) |
Return true if two integers are equal. More... | |
static bool | eq (double s1, double s2) |
Return true if two double precision floats are equal. More... | |
UnitTest is a base class for classes that define unit tests.
Each subclass of UnitTest should define one or more test methods. Each test method must be a zero parameter function that returns void. Test methods may be given arbitrary names. Individual test methods should use the preprocessor macro TEST_ASSERT(expression) defined in TextException.h to assert the truth of logical expressions.
The test methods defined by a UnitTest are run by an associated subclass of TestRunner. Each test method of a UnitTest must be added to the associated TestRunner. The run() method of a TestRunner calls all of the associated test methods in the order in which they were added, and counts the number of successful and failed tests.
The TestRunner associated with a single UnitTest is defined by a class template UnitTestRunner, which takes a UnitTest subclass as a template argument. For example, the TestRunner associated with a UnitTest subclass named TestA is a template instantiation UnitTestRunner<TestA>.
Preprocessor macros defined in the file UnitTestRunner.h should be used to create the boiler-plate code necessary to define a unit test runner and to add test methods to it.
Definition at line 50 of file UnitTest.h.
UnitTest::UnitTest | ( | ) |
Constructor.
Definition at line 219 of file UnitTest.h.
|
virtual |
Destructor.
Definition at line 236 of file UnitTest.h.
|
virtual |
Set up before each test method (empty default implementation).
Definition at line 242 of file UnitTest.h.
|
virtual |
Tear down after each test method (empty default implementation).
Reimplemented in ParamFileTest.
Definition at line 248 of file UnitTest.h.
void UnitTest::setVerbose | ( | int | verbose | ) |
Set verbosity level.
verbose | verbosity level (0 = silent). |
Definition at line 256 of file UnitTest.h.
References verbose().
void UnitTest::setFilePrefix | ( | const std::string & | prefix | ) |
Set file prefix.
This function is called by the UnitTestRunner::method(int i) function to set the filePrefix of the unit test equal to that of the runner after construction but before running the relevant test method.
prefix | string to be prepended to input and output file names. |
Definition at line 262 of file UnitTest.h.
const std::string & UnitTest::filePrefix | ( | ) |
Get file prefix string.
Definition at line 268 of file UnitTest.h.
bool UnitTest::isIoProcessor | ( | ) | const |
Should this processor read and write to file?
Definition at line 274 of file UnitTest.h.
Referenced by endMarker(), ParamFileTest::openFile(), printEndl(), and printMethod().
|
protected |
Write name of a class method, iff ioProcessor.
methodName | name of class test method |
Definition at line 314 of file UnitTest.h.
References isIoProcessor().
|
protected |
Write carriage return, iff isIoProcessor.
Definition at line 324 of file UnitTest.h.
References isIoProcessor().
|
protectedvirtual |
Print a line of hashes, iff isIoProcessor.
Definition at line 330 of file UnitTest.h.
References isIoProcessor().
|
protected |
Open C++ input file ifstream.
This function adds the filePrefix before the name parameter. It does not check if this node isIoProcessor.
name | base file name (added to filePrefix). |
in | input file (opened on return). |
Definition at line 343 of file UnitTest.h.
Referenced by ParamFileTest::openFile().
|
protected |
Open C++ output file ofstream.
This function adds the filePrefix before the name parameter. It does not check if this node isIoProcessor.
name | base file name (added to filePrefix) |
out | output file (opened on return) |
Definition at line 361 of file UnitTest.h.
|
protected |
Open C file handle with specified mode.
This function adds the filePrefix before the name parameter. It does not check if this node isIoProcessor.
name | base file name (added to filePrefix) |
mode | string that specified read or write mode |
Definition at line 379 of file UnitTest.h.
|
inlineprotected |
Return integer verbosity level (0 == silent).
Definition at line 397 of file UnitTest.h.
Referenced by setVerbose().
|
inlinestaticprotected |
Return true if two integers are equal.
Definition at line 403 of file UnitTest.h.
|
staticprotected |
Return true if two double precision floats are equal.
Definition at line 409 of file UnitTest.h.