| author | Pavol Marko <pavolmarko@gmail.com> |
| Sat Apr 30 15:48:46 2005 +0000 (2005-04-30) | |
| changeset 42 | 390a2aec00e4 |
| parent 41 | 534eac4c53ef |
| child 45 | 04770941f5a9 |
| permissions | -rw-r--r-- |
1 // Hello BAIL!
2 // This is a test file
4 #include <stdio.h>
5 #include <iostream>
6 #include <string>
7 #include <list>
9 using namespace std;
11 class Test
12 {
13 typedef bool (*TestProto)(std::string&);
14 TestProto m_Func;
15 std::string m_Name;
17 static std::list<Test *> ms_Tests;
18 public:
19 Test(TestProto func, const char *name) : m_Func(func), m_Name(name)
20 {
21 ms_Tests.push_back(this);
22 }
24 bool operator()()
25 {
26 std::string error;
27 if (!m_Func(error))
28 {
29 cout << "Test" << m_Name << " FAILED: " << error << endl;
30 return false;
31 }
32 else
33 {
34 cout << "Test" << m_Name << " passed" << endl;
35 return true;
36 }
37 }
39 static void DoTests()
40 {
41 int passed=0, failed=0;
42 for (std::list<Test*>::iterator iter = ms_Tests.begin(); iter != ms_Tests.end(); ++iter)
43 {
44 if ((**iter)())
45 ++passed;
46 else
47 ++failed;
49 cout << endl << "----" << endl << "Passed: " << passed << endl << "Failed: " << failed << endl;
50 cout << "Total: " << passed + failed << endl;
51 }
52 }
53 };
55 std::list<Test *> Test::ms_Tests;
57 #define DO_TEST(x) \
58 bool Test##x(std::string &error); \
59 Test g_Test##x(Test##x, #x);
61 DO_TEST(Basic);
63 int main(int argc, char *argv[])
64 {
65 std::string error;
66 int passed=0, failed=0;
68 Test::DoTests();
70 cout << "Press enter to continue" << endl;
72 char x;
73 cin.read(&x, 1);
74 }