This source file includes following definitions.
- getName
- getDescription
- runTest
- runAllTests
- getName
- getDescription
- work
- main
#include <stdio.h>
#include <iostream>
#include <string.h>
class Test
{
public:
Test() { next=s_firstTest; s_firstTest=this; }
virtual ~Test() { }
virtual const char* getName() const { return "noname"; }
virtual const char* getDescription() const { return "no description"; }
virtual bool work(bool quiet=false) = 0;
static void runTest(const char* name) {
Test* t = s_firstTest;
while (t) {
if (strcmp(t->getName(), name)==0) {
t->work();
break;
}
t=t->next;
}
}
static void runAllTests() {
Test* t = s_firstTest;
while (t) {
printf("%s ... ",t->getName());
fflush(stdout);
if (t->work(true) == false) {
printf("*** FAILED ***\n");
}
else {
printf("passed\n");
}
t=t->next;
}
}
public:
Test* next;
static Test* s_firstTest;
};
Test* Test::s_firstTest = NULL;
class ListTests : public Test
{
public:
const char* getName() const { return "list"; }
const char* getDescription() const { return "list all available tests"; }
bool work(bool quiet) {
if (!quiet) {
Test* t = s_firstTest;
while (t) {
printf("- %s: %s\n",t->getName(), t->getDescription());
t=t->next;
}
}
return true;
}
} listtest;
int main(int argc,char** argv)
{
if (argc>=2) {
Test::runTest(argv[1]);
}
else {
Test::runAllTests();
}
return 0;
}