4
// $Id: //poco/1.2/CppUnit/src/TestRunner.cpp#1 $
8
#include "CppUnit/TestRunner.h"
9
#include "CppUnit/Test.h"
10
#include "CppUnit/TestSuite.h"
11
#include "CppUnit/TextTestResult.h"
18
TestRunner::TestRunner()
23
TestRunner::~TestRunner()
25
for (Mappings::iterator it = _mappings.begin(); it != _mappings.end(); ++it)
30
void TestRunner::printBanner()
33
<< "Usage: driver [-all] [-print] [-wait] [name] ..." << std::endl
34
<< " where name is the name of a test case class" << std::endl;
38
bool TestRunner::run(const std::vector<std::string>& args)
41
int numberOfTests = 0;
47
for (int i = 1; i < args.size(); i++)
49
const std::string& arg = args[i];
55
else if (arg == "-all")
60
else if (arg == "-print")
62
for (Mappings::iterator it = _mappings.begin(); it != _mappings.end(); ++it)
64
print(it->first, it->second, 0);
81
for (Mappings::iterator it = _mappings.begin(); !testToRun && it != _mappings.end(); ++it)
83
testToRun = find(testCase, it->second, it->first);
87
if (!run(testToRun)) success = false;
93
std::cout << "Test " << testCase << " not found." << std::endl;
101
for (Mappings::iterator it = _mappings.begin(); it != _mappings.end(); ++it)
103
if (!run(it->second)) success = false;
108
if (numberOfTests == 0 && !printed)
116
std::cout << "<RETURN> to continue" << std::endl;
124
bool TestRunner::run(Test* test)
126
TextTestResult result;
129
std::cout << result << std::endl;
131
return result.wasSuccessful();
135
void TestRunner::addTest(const std::string& name, Test* test)
137
_mappings.push_back(Mapping(name, test));
141
void TestRunner::print(const std::string& name, Test* pTest, int indent)
143
for (int i = 0; i < indent; ++i)
145
std::cout << name << std::endl;
146
TestSuite* pSuite = dynamic_cast<TestSuite*>(pTest);
149
const std::vector<Test*>& tests = pSuite->tests();
150
for (std::vector<Test*>::const_iterator it = tests.begin(); it != tests.end(); ++it)
152
print((*it)->toString(), *it, indent + 1);
158
Test* TestRunner::find(const std::string& name, Test* pTest, const std::string& testName)
160
if (testName.find(name) != std::string::npos)
166
TestSuite* pSuite = dynamic_cast<TestSuite*>(pTest);
169
const std::vector<Test*>& tests = pSuite->tests();
170
for (std::vector<Test*>::const_iterator it = tests.begin(); it != tests.end(); ++it)
172
Test* result = find(name, *it, (*it)->toString());
173
if (result) return result;
181
} // namespace CppUnit