31 #include "dcmtk/config/osconfig.h"
32 #include "dcmtk/ofstd/ofconapp.h"
33 #include "dcmtk/ofstd/ofconsol.h"
34 #include "dcmtk/ofstd/oflist.h"
35 #include "dcmtk/ofstd/ofstream.h"
36 #include "dcmtk/ofstd/ofstring.h"
37 #include "dcmtk/ofstd/oftypes.h"
39 #ifdef OFTEST_OFSTD_ONLY
41 #define OFTEST_LOG_VERBOSE(msg) do { \
43 COUT << msg << OFendl; \
48 #include "dcmtk/oflog/oflog.h"
51 #define OFTEST_LOG_VERBOSE(msg) OFLOG_INFO(testLogger, msg)
110 virtual void run() = 0;
121 oss <<
"FAILED test '" <<
testName_ <<
"' at " << file <<
":" << line
122 <<
": " << message << OFStringStream_ends;
123 OFSTRINGSTREAM_GETOFSTRING(oss, str)
172 unsigned int numFailed = 0;
176 OFTEST_LOG_VERBOSE(
"Running " << tests.
size() <<
" tests" << mod_str <<
":");
178 for (it = tests.
begin(); it != tests.
end(); ++it)
180 OFTEST_LOG_VERBOSE(
" Running test '" << (*it)->getTestName() <<
"'...");
190 for (rit = result.
begin(); rit != result.
end(); ++rit)
193 CERR << *rit << OFendl;
198 COUT <<
"Test results" << mod_str <<
": "
199 << tests.
size() - numFailed <<
" succeeded, "
200 << numFailed <<
" failed." << OFendl;
205 CERR <<
"WARNING: More than 254 tests failed!" << OFendl;
219 int run(
int argc,
char* argv[],
const char* module)
222 OFBool listOnly = OFFalse;
225 #ifdef OFTEST_OFSTD_ONLY
228 rcsid =
"$dcmtk: " +
OFString(module) +
" $";
231 rcsid += OFSTRING_GUARD(module);
242 cmd.addGroup(
"general options:");
245 cmd.addOption(
"--exhaustive",
"-x",
"also run extensive and slow tests");
246 #ifdef OFTEST_OFSTD_ONLY
247 cmd.addOption(
"--verbose",
"-v",
"verbose mode, print processing details");
253 if (app.parseCommandLine(cmd, argc, argv))
258 #ifdef OFTEST_OFSTD_ONLY
259 if (cmd.findOption(
"--verbose")) verbose_ = OFTrue;
266 if (cmd.findOption(
"--exhaustive"))
exhaustive_ = OFTrue;
267 if (cmd.findOption(
"--list")) listOnly = OFTrue;
272 if (testsToRun.
empty())
274 CERR <<
"No tests to run!" << OFendl;
281 COUT <<
"There are " << testsToRun.
size() <<
" tests";
283 COUT <<
" for module '" << module <<
"'";
284 COUT <<
":" << OFendl;
285 for (it = testsToRun.
begin(); it != testsToRun.
end(); ++it)
287 COUT <<
" " << (*it)->getTestName() <<
"\n";
292 return runTests(testsToRun, module);
301 #ifdef OFTEST_OFSTD_ONLY
322 OFBool result = OFTrue;
334 for (
int i = 1; i <= paramCount; i++)
339 OFBool found = OFFalse;
352 CERR <<
"Error: No test matches '" << paramString <<
"'" << OFendl;
362 while (it != tests.
end())
365 it = tests.
erase(it);
383 const char*
string = str.
c_str();
385 for (; *testName !=
'\0' && *
string !=
'\0'; testName++,
string++)
388 if (
string[0] !=
'?' && testName[0] !=
string[0])
394 if (
string[0] ==
'*' &&
string[1] ==
'\0')
398 if (testName[0] ==
'\0' &&
string[0] ==
'\0')
412 #ifdef OFTEST_OFSTD_ONLY
423 #define OFTEST_MAIN(module) \
424 int main(int argc, char* argv[]) \
426 return OFTestManager::instance().run(argc, argv, module); \
430 #define OFTEST_CLASS(testName) \
431 class OFTest ## testName : public OFTestTest \
434 OFTest ## testName(); \
443 #define OFTEST_REGISTER_INT(testName) \
444 OFTest ## testName OFTest ## testName ## instance
449 #define OFTEST_REGISTER(testName) \
450 OFTEST_CLASS(testName); \
451 OFTEST_REGISTER_INT(testName)
459 #define OFTEST(testName) OFTEST_FLAGS(testName, EF_None)
467 #define OFTEST_FLAGS(testName, flags) \
468 OFTEST_CLASS(testName); \
469 OFTest ## testName::OFTest ## testName() \
470 : OFTestTest(#testName, flags) \
472 OFTestManager::instance().addTest(this); \
474 void OFTest ## testName ::run()
485 #define OFCHECK(condition) \
488 OFTestManager::instance().currentTest().recordFailure(__FILE__, __LINE__, #condition); \
496 #define OFCHECK_EQUAL(val1, val2) \
498 if ((val1) != (val2)) { \
499 OFOStringStream oss___; \
500 oss___ << "(" << (val1) << ") should equal (" << (val2) << ")" << OFStringStream_ends; \
501 OFSTRINGSTREAM_GETOFSTRING(oss___, str___) \
502 OFTestManager::instance().currentTest().recordFailure(__FILE__, __LINE__, str___); \
509 #define OFCHECK_FAIL(message) \
511 OFOStringStream oss___; \
512 oss___ << message << OFStringStream_ends; \
513 OFSTRINGSTREAM_GETOFSTRING(oss___, str___) \
514 OFTestManager::instance().currentTest().recordFailure(__FILE__, __LINE__, str___); \