/
TestManager.h
52 lines (42 loc) · 878 Bytes
/
TestManager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#pragma once
#include <string>
#include <map>
#include <iostream>
#include "Test.h"
class TestManager
{
private:
typedef std::map<std::string, TestPtr> TestMap;
TestMap _tests;
TestManager()
{}
public:
void registerTest(const TestPtr& test)
{
_tests.insert(TestMap::value_type(test->getName(), test));
}
void runAll()
{
for (TestMap::const_iterator i = _tests.begin(); i != _tests.end(); ++i)
{
i->second->prepare();
try
{
std::cout << "Running test: " << i->first << "...";
i->second->run();
std::cout << "done." << std::endl;
}
catch (Test::TestFailedException& ex)
{
std::cout << i->first << " failed with message: " << ex.what() << std::endl;
}
i->second->cleanup();
}
}
// Contains the singleton instance
static TestManager& Instance()
{
static TestManager _testManager;
return _testManager;
}
};