13 _writeToLog(writeToLog),
14 _deleteTestCases(deleteTestCases) {
20 if (_deleteTestCases) {
21 for (std::list<tarch::tests::TestCase*>::iterator p = _testCases.begin(); p!=_testCases.end(); p++ ) {
23 delete currentTestCase;
25 for (std::map<std::string, TreeTestCaseCollection*>::iterator p = _subTests.begin(); p!=_subTests.end(); p++ ) {
27 delete currentTestCase;
34 return testCaseName.rfind(
"::") == std::string::npos;
39 std::string result = testCaseName.substr(0, testCaseName.find(
"::"));
41 assertion2( isNameWithoutHierarchy( result), result, testCaseName );
48 assertion( !isNameWithoutHierarchy( testCaseName) );
50 std::string result = testCaseName.substr(testCaseName.find(
"::")+2);
62 std::string logInformation;
63 if ( (prefix + _testCaseName).length()>0 ) {
64 logInformation =
"running test case collection \"" + prefix + _testCaseName +
"\" ...";
67 logInformation =
"running test case collection ...";
75 logInformation +=
"... WARNING: no tests defined ... ";
79 std::string fullQualifiedName = _testCaseName.length()>0 ? prefix +_testCaseName +
"." : prefix;
80 for (std::map<std::string, TreeTestCaseCollection*>::iterator p = _subTests.begin(); p!=_subTests.end(); p++ ) {
81 (*p).second->run( fullQualifiedName );
82 _errors += (*p).second->getNumberOfErrors();
85 for (std::list<tarch::tests::TestCase*>::iterator p = _testCases.begin(); p!=_testCases.end(); p++ ) {
87 logInformation +=
".";
88 currentTestCase->
run();
90 if (additionalErrors>0) {
91 logInformation +=
"x";
95 logInformation +=
".";
99 if ( _errors==0 and _testCases.empty() and _subTests.empty() ) {
100 logInformation +=
" pass (no local tests)";
102 else if ( _errors==0 and _testCases.empty() ) {
103 logInformation +=
" pass (no local tests, subtests all successful)";
105 else if (_errors==0 and _testCases.size()==1) {
106 logInformation +=
" ok (1 test)";
108 else if (_errors==0) {
109 logInformation +=
" ok (" + std::to_string(_testCases.size()) +
" tests)";
112 logInformation +=
" failed";
115 if ( _writeToLog and _testCaseName!=
"" ) {
116 logInfo(
"run()",logInformation );
127 if ( isNameWithoutHierarchy(fullQualifiedPath) ) {
128 _testCases.push_back(testCase);
131 std::string firstPartOfIdentifier = getFirstIdentifierInHierarchy( fullQualifiedPath );
132 std::string secondPartOfIdentifier = getRemainingPathWithoutIdentifier( fullQualifiedPath );
133 if (_subTests.find(firstPartOfIdentifier) == _subTests.end() ) {
135 std::pair<std::string,TreeTestCaseCollection*>(
136 firstPartOfIdentifier,
141 _subTests[firstPartOfIdentifier]->addTestCase(secondPartOfIdentifier, testCase);
#define assertion2(expr, param0, param1)
#define assertion3(expr, param0, param1, param2)
#define logInfo(methodName, logMacroMessageStream)
Wrapper macro around tarch::tarch::logging::Log to improve logging.
Represents one test case.
int getNumberOfErrors() const
virtual void run()=0
This routine is triggered by the TestCaseCollection.
std::string getTestCaseName() const
static std::string getRemainingPathWithoutIdentifier(const std::string &testCaseName)
static bool isNameWithoutHierarchy(const std::string &testCaseName)
void addTestCase(const std::string &fullQualifiedPath, TestCase *testCase)
Adds a new test case.
virtual void run()
Runs all test cases assigned.
static tarch::logging::Log _log
Log interface the class writes to.
virtual ~TreeTestCaseCollection()
Destructor.
TreeTestCaseCollection(const std::string &testCaseCollectionName="", bool deleteTestCases=true, bool writeToLog=true)
Creates a test case collection.
static std::string getFirstIdentifierInHierarchy(const std::string &testCaseName)