Feature #424 ยป oftest_exhaustive_mode.patch
ofstd/include/dcmtk/ofstd/oftest.h | ||
---|---|---|
/// This is the type used for test results.
|
||
typedef OFList<OFString> TestResult;
|
||
/** Special flags that a test can have. The flags for a test are the result
|
||
* of a bitwise or of these individual flags.
|
||
*/
|
||
enum E_Flags {
|
||
EF_None = 0x0,
|
||
/// Slow test which should only be run in exhaustive mode.
|
||
EF_Slow = 0x1
|
||
};
|
||
/** Contructor
|
||
* @param testName the name of this test case
|
||
*/
|
||
OFTestTest(const OFString& testName)
|
||
: testName_(testName),
|
||
results_()
|
||
OFTestTest(const OFString& testName, int flag)
|
||
: testName_(testName)
|
||
, results_()
|
||
, flags_(flag)
|
||
{
|
||
}
|
||
... | ... | |
{
|
||
}
|
||
/// @return the flags of this test case
|
||
int flags() const { return flags_; }
|
||
/// @return the name of this test case
|
||
const OFString& getTestName() const { return testName_; }
|
||
... | ... | |
/// The test results, empty for success.
|
||
TestResult results_;
|
||
/// Flags that this test has.
|
||
const int flags_;
|
||
};
|
||
/** The test manager singleton manages the list of available test cases
|
||
... | ... | |
cmd.addParam("tests-to-run", "names of tests to run (default: all)", OFCmdParam::PM_MultiOptional);
|
||
cmd.addGroup("general options:");
|
||
cmd.addOption("--help", "-h", "print this help text and exit", OFCommandLine::AF_Exclusive);
|
||
cmd.addOption("--list", "-l", "list available tests and exit");
|
||
cmd.addOption("--help", "-h", "print this help text and exit", OFCommandLine::AF_Exclusive);
|
||
cmd.addOption("--list", "-l", "list available tests and exit");
|
||
cmd.addOption("--exhaustive", "-x", "also run slow tests");
|
||
#ifdef OFTEST_OFSTD_ONLY
|
||
cmd.addOption("--verbose", "-v", "verbose mode, print processing details");
|
||
cmd.addOption("--verbose", "-v", "verbose mode, print processing details");
|
||
#else
|
||
OFLog::addOptions(cmd);
|
||
#endif
|
||
... | ... | |
* such messages by testing corner cases. */
|
||
OFLog::configureFromCommandLine(cmd, app, OFLogger::FATAL_LOG_LEVEL);
|
||
#endif
|
||
if (cmd.findOption("--exhaustive")) exhaustive_ = OFTrue;
|
||
if (cmd.findOption("--list")) listOnly = OFTrue;
|
||
if (!buildTestsToRun(cmd, testsToRun))
|
||
... | ... | |
if (listOnly)
|
||
{
|
||
OFListIterator(OFTestTest*) it;
|
||
COUT << "There are " << tests_.size() << " tests";
|
||
COUT << "There are " << testsToRun.size() << " tests";
|
||
if (module)
|
||
COUT << " for module '" << module << "'";
|
||
COUT << ":" << OFendl;
|
||
for (it = tests_.begin(); it != tests_.end(); ++it)
|
||
for (it = testsToRun.begin(); it != testsToRun.end(); ++it)
|
||
{
|
||
COUT << " " << (*it)->getTestName() << "\n";
|
||
}
|
||
... | ... | |
private:
|
||
/// Private constructor, this is a singleton!
|
||
OFTestManager()
|
||
: tests_(),
|
||
curTest_(NULL)
|
||
: tests_()
|
||
, curTest_(NULL)
|
||
, exhaustive_(OFFalse)
|
||
#ifdef OFTEST_OFSTD_ONLY
|
||
, verbose_(OFFalse)
|
||
#endif
|
||
... | ... | |
* @param tests will be set to the list of tests to run
|
||
* @return OFFalse if the command line could not be handled.
|
||
*/
|
||
OFBool buildTestsToRun(OFCommandLine& cmd, OFList<OFTestTest*>& tests)
|
||
OFBool buildTestsToRun(OFCommandLine& cmd, OFList<OFTestTest*>& tests) const
|
||
{
|
||
const int paramCount = cmd.getParamCount();
|
||
OFString paramString;
|
||
OFBool result = OFTrue;
|
||
if (paramCount == 0)
|
||
{
|
||
// If no arguments are given, run all possible tests
|
||
tests = tests_;
|
||
return OFTrue;
|
||
}
|
||
OFBool result = OFTrue;
|
||
for (int i = 1; i <= paramCount; i++)
|
||
else
|
||
{
|
||
cmd.getParam(i, paramString);
|
||
// Find all tests matching this argument
|
||
OFBool found = OFFalse;
|
||
OFListIterator(OFTestTest*) it;
|
||
for (it = tests_.begin(); it != tests_.end(); ++it)
|
||
for (int i = 1; i <= paramCount; i++)
|
||
{
|
||
if (testMatches(*it, paramString))
|
||
cmd.getParam(i, paramString);
|
||
// Find all tests matching this argument
|
||
OFBool found = OFFalse;
|
||
OFListIterator(OFTestTest*) it;
|
||
for (it = tests_.begin(); it != tests_.end(); ++it)
|
||
{
|
||
if (testMatches(*it, paramString))
|
||
{
|
||
tests.push_back(*it);
|
||
found = OFTrue;
|
||
}
|
||
}
|
||
if (!found)
|
||
{
|
||
tests.push_back(*it);
|
||
found = OFTrue;
|
||
CERR << "Error: No test matches '" << paramString << "'" << OFendl;
|
||
result = OFFalse;
|
||
}
|
||
}
|
||
}
|
||
if (!found)
|
||
// If we are not in exhaustive mode, remove all slow tests
|
||
if (!exhaustive_)
|
||
{
|
||
OFListIterator(OFTestTest*) it = tests.begin();
|
||
while (it != tests.end())
|
||
{
|
||
CERR << "Error: No test matches '" << paramString << "'" << OFendl;
|
||
result = OFFalse;
|
||
if ((*it)->flags() & OFTestTest::EF_Slow)
|
||
it = tests.erase(it);
|
||
else
|
||
++it;
|
||
}
|
||
}
|
||
... | ... | |
* @param str the string describing the tests
|
||
* @return OFTrue if we found a match, else OFFalse
|
||
*/
|
||
OFBool testMatches(const OFTestTest* test, const OFString& str)
|
||
OFBool testMatches(const OFTestTest* test, const OFString& str) const
|
||
{
|
||
const char* testName = test->getTestName().c_str();
|
||
const char* string = str.c_str();
|
||
... | ... | |
/// Currently running test.
|
||
OFTestTest* curTest_;
|
||
/// Should slow tests be run, too?
|
||
OFBool exhaustive_;
|
||
#ifdef OFTEST_OFSTD_ONLY
|
||
/// Are we running in verbose mode? Only used if oflog is not available.
|
||
OFBool verbose_;
|
||
... | ... | |
class OFTest ## testName : public OFTestTest \
|
||
{ \
|
||
public: \
|
||
OFTest ## testName() \
|
||
: OFTestTest(#testName) \
|
||
{ \
|
||
OFTestManager::instance().addTest(this); \
|
||
} \
|
||
OFTest ## testName(); \
|
||
void run(); \
|
||
}
|
||
... | ... | |
/** 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).
|
||
* @param testName name describing the test
|
||
* @see OFTEST_FLAGS
|
||
*/
|
||
#define OFTEST(testName) OFTEST_FLAGS(testName, EF_None)
|
||
/** Macro to define a new test case. Internally this defines a new class
|
||
* inheriting from OFTest.
|
||
* @param flags flags that should be set for this test
|
||
* @param testName name describing the test
|
||
* @see OFTEST
|
||
*/
|
||
#define OFTEST(testName) \
|
||
#define OFTEST_FLAGS(testName, flags) \
|
||
OFTEST_CLASS(testName); \
|
||
OFTest ## testName::OFTest ## testName() \
|
||
: OFTestTest(#testName, flags) \
|
||
{ \
|
||
OFTestManager::instance().addTest(this); \
|
||
} \
|
||
void OFTest ## testName ::run()
|
||
/** @name macros for checking conditions in tests
|
ofstd/tests/Makefile.in | ||
---|---|---|
test_objs = tests.o tatof.o tmap.o tvec.o tftoa.o tthread.o tbase64.o \
|
||
tstring.o tlist.o tstack.o tofdatim.o tofstd.o tmarkup.o \
|
||
tchrenc.o txml.o tuuid.o
|
||
objs = toffile.o $(test_objs)
|
||
progs = toffile tests
|
||
tchrenc.o txml.o tuuid.o toffile.o
|
||
objs = $(test_objs)
|
||
progs = tests
|
||
all: $(progs)
|
||
... | ... | |
tests: $(test_objs)
|
||
$(CXX) $(CXXFLAGS) $(LIBDIRS) $(LDFLAGS) -o $@ $(test_objs) $(LOCALLIBS) $(ICONVLIBS) $(LIBS)
|
||
toffile: toffile.o
|
||
$(CXX) $(CXXFLAGS) $(LIBDIRS) $(LDFLAGS) -o $@ $@.o $(LOCALLIBS) $(MATHLIBS) $(LIBS)
|
||
check: tests
|
||
./tests
|
ofstd/tests/tests.cc | ||
---|---|---|
OFTEST_REGISTER(ofstd_OFMap);
|
||
OFTEST_REGISTER(ofstd_OFStack);
|
||
OFTEST_REGISTER(ofstd_OFStandard_isReadWriteable);
|
||
OFTEST_REGISTER(ofstd_OFFile);
|
||
OFTEST_REGISTER(ofstd_OFString_compare);
|
||
OFTEST_REGISTER(ofstd_OFString_concatenate);
|
||
OFTEST_REGISTER(ofstd_OFString_constructor);
|
ofstd/tests/toffile.cc | ||
---|---|---|
#include "dcmtk/ofstd/ofconsol.h"
|
||
#include "dcmtk/ofstd/ofstd.h"
|
||
#define OFTEST_OFSTD_ONLY
|
||
#include "dcmtk/ofstd/oftest.h"
|
||
#define INCLUDE_CTIME
|
||
#define INCLUDE_CSTDLIB
|
||
#define INCLUDE_IOSTREAM
|
||
... | ... | |
return OFTrue;
|
||
}
|
||
int main()
|
||
OFTEST_FLAGS(ofstd_OFFile, EF_Slow)
|
||
{
|
||
COUT << "Test program for LFS support in DCMTK class OFFile\n" << OFendl;
|
||
... | ... | |
if (sizeof(offile_fpos_t) > 4) COUT << " - OK\n"; else COUT << " - too small, no LFS support\n";
|
||
if ((sizeof(offile_off_t) <= 4 || sizeof(offile_fpos_t) <= 4))
|
||
{
|
||
COUT << "No LFS support available. LFS test failed." << OFendl;
|
||
return 10;
|
||
OFCHECK_FAIL("No LFS support available. LFS test failed.");
|
||
return;
|
||
}
|
||
OFFile file;
|
||
... | ... | |
COUT << "\nCreating a 6 GByte data file." << OFendl << STD_NAMESPACE flush;
|
||
if (!file.fopen(FILENAME, "w+b"))
|
||
{
|
||
COUT << "Error: Unable to create file " << FILENAME << ". LFS test failed." << OFendl;
|
||
return 10;
|
||
OFCHECK_FAIL("Error: Unable to create file " << FILENAME << ". LFS test failed." << OFendl);
|
||
return;
|
||
}
|
||
if (! fillFile(file))
|
||
{
|
||
COUT << "Error: Unable to write 6 GByte of data. LFS test failed." << OFendl;
|
||
return 10;
|
||
OFCHECK_FAIL("Error: Unable to write 6 GByte of data. LFS test failed.");
|
||
return;
|
||
}
|
||
if (! seekFile(file))
|
||
{
|
||
COUT << "Error: fseek() tests unsuccessful. LFS test failed." << OFendl;
|
||
return 10;
|
||
OFCHECK_FAIL("Error: fseek() tests unsuccessful. LFS test failed.");
|
||
return;
|
||
}
|
||
COUT << "Closing file." << OFendl << STD_NAMESPACE flush;
|
||
... | ... | |
if (!file.fopen(FILENAME, "rb"))
|
||
{
|
||
COUT << "Error: Unable to open file " << FILENAME << ". LFS test failed." << OFendl;
|
||
return 10;
|
||
OFCHECK_FAIL("Error: Unable to open file " << FILENAME << ". LFS test failed.");
|
||
return;
|
||
}
|
||
if (! seekFile(file))
|
||
{
|
||
COUT << "Error: fseek() tests unsuccessful. LFS test failed." << OFendl;
|
||
return 10;
|
||
OFCHECK_FAIL("Error: fseek() tests unsuccessful. LFS test failed.");
|
||
return;
|
||
}
|
||
return 0;
|
||
}
|
||
/*
|