OFFIS DCMTK  Version 3.6.0
Classes | Macros | Variables
oftest.h File Reference

A simple framework for writing and running test cases. More...

Include dependency graph for oftest.h:

Go to the source code of this file.

Classes

class  OFTestTest
 A single test case which can be run. More...
 
class  OFTestManager
 The test manager singleton manages the list of available test cases and executes them. More...
 

Macros

#define OFTEST_LOG_VERBOSE(msg)   OFLOG_INFO(testLogger, msg)
 
#define OFTEST_MAIN(module)
 Implement a main() function for running tests. More...
 
#define OFTEST_CLASS(testName)
 Internal macro for generating a class definition, don't use yourself! More...
 
#define OFTEST_REGISTER_INT(testName)   OFTest ## testName OFTest ## testName ## instance
 Register a test to the test manager. More...
 
#define OFTEST_REGISTER(testName)
 Register a test to the test manager. More...
 
#define OFTEST(testName)   OFTEST_FLAGS(testName, EF_None)
 Macro to define a new test case. More...
 
#define OFTEST_FLAGS(testName, flags)
 Macro to define a new test case. More...
 
macros for checking conditions in tests

These macros can be used for doing various checks in test cases.

In case their check fails, they emit a descriptive message explaining the problem.

#define OFCHECK(condition)
 Check if a condition is true. More...
 
#define OFCHECK_EQUAL(val1, val2)
 Check if two values are equal. More...
 
#define OFCHECK_FAIL(message)
 Unconditionally add a failure. More...
 

Variables

static OFLogger testLogger = OFLog::getLogger("dcmtk.test")
 

Detailed Description

A simple framework for writing and running test cases.

Definition in file oftest.h.

Macro Definition Documentation

#define OFCHECK (   condition)
Value:
do { \
if (!(condition)) \
OFTestManager::instance().currentTest().recordFailure(__FILE__, __LINE__, #condition); \
} while (0)
void recordFailure(const OFString &file, unsigned long int line, const OFString &message)
Add a new failure to the result set.
Definition: oftest.h:118
static OFTestManager & instance()
Definition: oftest.h:145
OFTestTest & currentTest()
Definition: oftest.h:152

Check if a condition is true.

Can only be used inside OFTEST().

Parameters
conditioncondition to check

Definition at line 485 of file oftest.h.

#define OFCHECK_EQUAL (   val1,
  val2 
)
Value:
do { \
if ((val1) != (val2)) { \
OFOStringStream oss___; \
oss___ << "(" << (val1) << ") should equal (" << (val2) << ")" << OFStringStream_ends; \
OFSTRINGSTREAM_GETOFSTRING(oss___, str___) \
OFTestManager::instance().currentTest().recordFailure(__FILE__, __LINE__, str___); \
} \
} while (0)
void recordFailure(const OFString &file, unsigned long int line, const OFString &message)
Add a new failure to the result set.
Definition: oftest.h:118
static OFTestManager & instance()
Definition: oftest.h:145
OFTestTest & currentTest()
Definition: oftest.h:152

Check if two values are equal.

Can only be used inside OFTEST(). Both arguments must be compatible with OFOStringStream's operator<<.

Parameters
val1first value to compare
val2second value to compare

Definition at line 496 of file oftest.h.

#define OFCHECK_FAIL (   message)
Value:
do { \
OFOStringStream oss___; \
oss___ << message << OFStringStream_ends; \
OFSTRINGSTREAM_GETOFSTRING(oss___, str___) \
OFTestManager::instance().currentTest().recordFailure(__FILE__, __LINE__, str___); \
} while (0)
void recordFailure(const OFString &file, unsigned long int line, const OFString &message)
Add a new failure to the result set.
Definition: oftest.h:118
static OFTestManager & instance()
Definition: oftest.h:145
OFTestTest & currentTest()
Definition: oftest.h:152

Unconditionally add a failure.

Parameters
messagestring describing the failure

Definition at line 509 of file oftest.h.

#define OFTEST (   testName)    OFTEST_FLAGS(testName, EF_None)

Macro to define a new test case.

Internally this defines a new class inheriting from OFTest. This is equivalent to OFTEST_FLAGS(testName, EF_None).

Parameters
testNamename describing the test
See also
OFTEST_FLAGS

Definition at line 459 of file oftest.h.

#define OFTEST_CLASS (   testName)
Value:
class OFTest ## testName : public OFTestTest \
{ \
public: \
OFTest ## testName(); \
void run(); \
}
virtual void run()=0
Execute this test case.
A single test case which can be run.
Definition: oftest.h:60

Internal macro for generating a class definition, don't use yourself!

Definition at line 430 of file oftest.h.

#define OFTEST_FLAGS (   testName,
  flags 
)
Value:
OFTEST_CLASS(testName); \
OFTest ## testName::OFTest ## testName() \
: OFTestTest(#testName, flags) \
{ \
} \
void OFTest ## testName ::run()
A single test case which can be run.
Definition: oftest.h:60
void addTest(OFTestTest *test)
Register a test with this test manager.
Definition: oftest.h:162
#define OFTEST_CLASS(testName)
Internal macro for generating a class definition, don't use yourself!
Definition: oftest.h:430
static OFTestManager & instance()
Definition: oftest.h:145

Macro to define a new test case.

Internally this defines a new class inheriting from OFTest.

Parameters
flagsflags that should be set for this test
testNamename describing the test
See also
OFTEST

Definition at line 467 of file oftest.h.

#define OFTEST_MAIN (   module)
Value:
int main(int argc, char* argv[]) \
{ \
return OFTestManager::instance().run(argc, argv, module); \
}
int run(int argc, char *argv[], const char *module)
Handle the given arguments and run the requested test case.
Definition: oftest.h:219
static OFTestManager & instance()
Definition: oftest.h:145

Implement a main() function for running tests.

The main function will return the number of failed tests or -1 if an invalid test name was given.

Parameters
modulethe name of the module which is under test.

Definition at line 423 of file oftest.h.

#define OFTEST_REGISTER (   testName)
Value:
OFTEST_CLASS(testName); \
#define OFTEST_REGISTER_INT(testName)
Register a test to the test manager.
Definition: oftest.h:443
#define OFTEST_CLASS(testName)
Internal macro for generating a class definition, don't use yourself!
Definition: oftest.h:430

Register a test to the test manager.

Parameters
testNamename of the test to register

Definition at line 449 of file oftest.h.

#define OFTEST_REGISTER_INT (   testName)    OFTest ## testName OFTest ## testName ## instance

Register a test to the test manager.

Normally you should use OFTEST_REGISTER instead, but that macro doesn't work if OFTEST and OFTEST_REGISTER are called in the same source file.

Parameters
testNamename of the test to register

Definition at line 443 of file oftest.h.


Generated on Wed Dec 28 2016 for OFFIS DCMTK Version 3.6.0 by Doxygen 1.8.8