2005-10-12 01:46:19 +02:00
|
|
|
#include "TestRunner.hpp"
|
|
|
|
#include "textui/TextTestResult.h"
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
//////////////////////////////////////////
|
|
|
|
/*
|
|
|
|
* A command line based tool to run tests.
|
|
|
|
* TestRunner expects as its only argument the name of a TestCase class.
|
|
|
|
* TestRunner prints out a trace as the tests are executed followed by a
|
|
|
|
* summary at the end.
|
|
|
|
*
|
|
|
|
* You can add to the tests that the TestRunner knows about by
|
|
|
|
* making additional calls to "addTest (...)" in main.
|
|
|
|
*
|
|
|
|
* Here is the synopsis:
|
|
|
|
*
|
|
|
|
* TestRunner [-wait] ExampleTestCase
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
typedef pair<string, Test *> mapping;
|
|
|
|
typedef vector<pair<string, Test *> > mappings;
|
|
|
|
|
|
|
|
void TestRunner::printBanner ()
|
|
|
|
{
|
|
|
|
cout << "Usage: driver [ -wait ] testName, where name is the name of a test case class" << endl;
|
|
|
|
} // printBanner
|
|
|
|
|
2005-10-31 13:07:30 +01:00
|
|
|
void TestRunner::run(int ac, const char **av)
|
2005-10-12 01:46:19 +02:00
|
|
|
{
|
|
|
|
string testCase;
|
|
|
|
int numberOfTests = 0;
|
|
|
|
|
|
|
|
for(int i = 1; i < ac; i++)
|
|
|
|
{
|
|
|
|
if(string(av[i]) == "-wait")
|
|
|
|
{
|
|
|
|
m_wait = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
testCase = av[i];
|
|
|
|
|
|
|
|
if(testCase == "")
|
|
|
|
{
|
|
|
|
printBanner ();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Test *testToRun = NULL;
|
|
|
|
|
|
|
|
for(mappings::iterator it = m_mappings.begin();
|
|
|
|
it != m_mappings.end();
|
|
|
|
++it)
|
|
|
|
{
|
|
|
|
if((*it).first == testCase)
|
|
|
|
{
|
|
|
|
cout << (*it).first << std::endl;
|
|
|
|
testToRun = (*it).second;
|
|
|
|
run(testToRun);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
numberOfTests++;
|
|
|
|
|
|
|
|
if(!testToRun)
|
|
|
|
{
|
|
|
|
cout << "Test " << testCase << " not found." << endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} // for ...
|
|
|
|
|
|
|
|
if(ac == 1)
|
|
|
|
{
|
|
|
|
// run everything
|
|
|
|
for(mappings::iterator it = m_mappings.begin(); it != m_mappings.end(); ++it)
|
|
|
|
{
|
|
|
|
cout << (*it).first << std::endl;
|
|
|
|
run((*it).second);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(numberOfTests == 0)
|
|
|
|
{
|
|
|
|
printBanner ();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(m_wait)
|
|
|
|
{
|
|
|
|
cout << "<RETURN> to continue" << endl;
|
|
|
|
cin.get ();
|
|
|
|
}
|
|
|
|
} // run
|
|
|
|
|
|
|
|
TestRunner::~TestRunner ()
|
|
|
|
{
|
|
|
|
for(mappings::iterator it = m_mappings.begin ();
|
|
|
|
it != m_mappings.end ();
|
|
|
|
++it)
|
|
|
|
delete it->second;
|
|
|
|
} // ~TestRunner
|
|
|
|
|
|
|
|
void TestRunner::run(Test *test)
|
|
|
|
{
|
|
|
|
TextTestResult result;
|
|
|
|
test->run (&result);
|
|
|
|
cout << result << endl;
|
|
|
|
} // run
|
|
|
|
|