DCMTK Version 3.6.9 OFFIS DICOM Toolkit

Loading...
Searching...
No Matches
Classes | Macros
oftest.h File Reference

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

## 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_MAIN(module)
| Implement a main() function for running tests.
#define | OFTEST_CLASS(testName)
| Internal macro for generating a class definition, don't use yourself!
#define | OFTEST_REGISTER_INT(testName)
| Register a test to the test manager.
#define | OFTEST_REGISTER(testName)
| Register a test to the test manager.
#define | OFTEST(testName)
| Macro to define a new test case.
#define | OFTEST_FLAGS(testName, flags)
| Macro to define a new test case.
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.
#define | OFCHECK_MSG(condition, errorDetails)
| Check if a condition is true.
#define | OFCHECK_EQUAL(val1, val2)
| Check if two values are equal.
#define | OFCHECK_FAIL(message)
| Unconditionally add a failure.

## Detailed Description

A simple framework for writing and running test cases.

## Macro Definition Documentation

## ◆ OFCHECK

#define OFCHECK | ( |  | condition | ) |

Value:
do { \
if (!(condition)) \
OFTestManager::instance().currentTest().recordFailure(__FILE__, __LINE__, #condition); \
} while (0)

Check if a condition is true.

Can only be used inside OFTEST().

Parameters

  condition | condition to check

## ◆ OFCHECK_EQUAL

#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)

Check if two values are equal.

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

Parameters

  val1 | first value to compare
  val2 | second value to compare

## ◆ OFCHECK_FAIL

#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)

Unconditionally add a failure.

Parameters

  message | string describing the failure

## ◆ OFCHECK_MSG

#define OFCHECK_MSG | ( |  | condition,
|  |  | errorDetails )

Value:
do { \
if (!(condition)) \
OFTestManager::instance().currentTest().recordFailure(__FILE__, __LINE__, #condition, errorDetails); \
} while (0)

Check if a condition is true.

Can only be used inside OFTEST().

Parameters

  condition | condition to check
  errorDetails | additional error details (string) provided by caller

## ◆ OFTEST

#define OFTEST | ( |  | testName | ) |

Value:
OFTEST_FLAGS(testName, EF_None)
OFTEST_FLAGS
#define OFTEST_FLAGS(testName, flags)
Macro to define a new test case.
Definition oftest.h:504

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

  testName | name describing the test

See also
  OFTEST_FLAGS

## ◆ OFTEST_FLAGS

#define OFTEST_FLAGS | ( |  | testName,
|  |  | flags )

Value:
OFTEST_CLASS(testName); \
OFTest ## testName::OFTest ## testName() \
: OFTestTest(#testName, flags) \
{ \
OFTestManager::instance().addTest(this); \
} \
void OFTest ## testName ::run()
OFTestTest
A single test case which can be run.
Definition oftest.h:70
OFTEST_CLASS
#define OFTEST_CLASS(testName)
Internal macro for generating a class definition, don't use yourself!
Definition oftest.h:467

Macro to define a new test case.

Internally this defines a new class inheriting from OFTest.

Parameters

  flags | flags that should be set for this test
  testName | name describing the test

See also
  OFTEST

## ◆ OFTEST_MAIN

#define OFTEST_MAIN | ( |  | module | ) |

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

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

  module | the name of the module which is under test.

## ◆ OFTEST_REGISTER

#define OFTEST_REGISTER | ( |  | testName | ) |

Value:
OFTEST_CLASS(testName); \
OFTEST_REGISTER_INT(testName)

Register a test to the test manager.

Parameters

  testName | name of the test to register

## ◆ OFTEST_REGISTER_INT

#define OFTEST_REGISTER_INT | ( |  | testName | ) |

Value:
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

  testName | name of the test to register

Generated on Sat Mar 1 2025 for DCMTK Version 3.6.9 by Doxygen 1.13.2