| author | David Anderson <dvander@alliedmods.net> |
| Fri Jun 24 22:39:58 2005 +0000 (2005-06-24) | |
| changeset 78 | b5dc5deb71b8 |
| parent 75 | 8d8efeb2ecc8 |
| child 96 | e023f17b7b73 |
| 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 bool g_Verbose;
13 class Test
14 {
15 typedef bool (*TestProto)(std::string&);
16 TestProto m_Func;
17 std::string m_Name;
19 static std::list<Test *> ms_Tests;
20 public:
21 Test(TestProto func, const char *name) : m_Func(func), m_Name(name)
22 {
23 ms_Tests.push_back(this);
24 }
26 bool operator()()
27 {
28 std::string error;
29 if (!m_Func(error))
30 {
31 cout << "Test" << m_Name << " FAILED: " << error << endl;
32 return false;
33 }
34 else
35 {
36 cout << "Test" << m_Name << " passed" << endl;
37 return true;
38 }
39 }
41 static void DoTests()
42 {
43 int passed=0, failed=0;
44 for (std::list<Test*>::iterator iter = ms_Tests.begin(); iter != ms_Tests.end(); ++iter)
45 {
46 if ((**iter)())
47 ++passed;
48 else
49 ++failed;
50 }
51 cout << endl << "----" << endl << "Passed: " << passed << endl << "Failed: " << failed << endl;
52 cout << "Total: " << passed + failed << endl;
53 }
54 };
56 std::list<Test *> Test::ms_Tests;
58 #define DO_TEST(x) \
59 bool Test##x(std::string &error); \
60 Test g_Test##x(Test##x, #x);
62 DO_TEST(Basic);
63 DO_TEST(VafmtAndOverload);
64 DO_TEST(ThisPtrOffs);
65 DO_TEST(PlugSys);
66 DO_TEST(Bail);
68 int main(int argc, char *argv[])
69 {
70 std::string error;
71 int passed=0, failed=0;
73 g_Verbose = argc > 1 && strcmp(argv[1], "-v") == 0;
75 Test::DoTests();
77 cout << "Press enter to continue" << endl;
79 char x;
80 cin.read(&x, 1);
81 }