DCMTK Version 3.7.0 OFFIS DICOM Toolkit

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. More...
#define | OFTEST_CLASS(testName)
| Internal macro for generating a class definition, don't use yourself!
#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_MSG(condition, errorDetails)
| 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...

## 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)
OFTestManager::instance
static OFTestManager & instance()
Definition: oftest.h:170
OFTestManager::currentTest
OFTestTest & currentTest()
Definition: oftest.h:177
OFTestTest::recordFailure
void recordFailure(const OFString &file, unsigned long int line, const OFString &message)
Add a new failure to the result set.
Definition: oftest.h:125

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

  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()
OFTestManager::addTest
void addTest(OFTestTest *test)
Register a test with this test manager.
Definition: oftest.h:187
OFTestTest
A single test case which can be run.
Definition: oftest.h:70
run
OFCondition run(T_ASC_Association *assoc)
Take over incoming association that is in the state that the underlying TCP/IP connection is already ...
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::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 | ) | 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 Mon Dec 15 2025 for DCMTK Version 3.7.0 by Doxygen 1.9.1