| author | David Anderson <dvander@alliedmods.net> |
| Tue Sep 13 16:47:42 2005 +0000 (2005-09-13) | |
| changeset 100 | 022428df37c9 |
| parent 99 | bfbb04d6683f |
| child 111 | aec58c99dafc |
| permissions | -rw-r--r-- |
1 // Hello BAIL!
2 // hello pm how are you
3 // This is a test file
5 #include <stdio.h>
6 #include <iostream>
7 #include <string>
8 #include <list>
9 #include <stdlib.h>
10 #include <time.h>
11 #include "sh_tinyhash.h"
12 #include "sourcehook_impl.h"
14 using namespace std;
16 bool g_Verbose;
18 class Test
19 {
20 typedef bool (*TestProto)(std::string&);
21 TestProto m_Func;
22 std::string m_Name;
24 static std::list<Test *> ms_Tests;
25 public:
26 Test(TestProto func, const char *name) : m_Func(func), m_Name(name)
27 {
28 ms_Tests.push_back(this);
29 }
31 bool operator()()
32 {
33 std::string error;
34 if (!m_Func(error))
35 {
36 cout << "Test" << m_Name << " FAILED: " << error << endl;
37 return false;
38 }
39 else
40 {
41 cout << "Test" << m_Name << " passed" << endl;
42 return true;
43 }
44 }
46 static void DoTests()
47 {
48 int passed=0, failed=0;
49 for (std::list<Test*>::iterator iter = ms_Tests.begin(); iter != ms_Tests.end(); ++iter)
50 {
51 if ((**iter)())
52 ++passed;
53 else
54 ++failed;
55 }
56 cout << endl << "----" << endl << "Passed: " << passed << endl << "Failed: " << failed << endl;
57 cout << "Total: " << passed + failed << endl;
58 }
59 };
61 std::list<Test *> Test::ms_Tests;
63 #define DO_TEST(x) \
64 bool Test##x(std::string &error); \
65 Test g_Test##x(Test##x, #x);
67 DO_TEST(Basic);
68 DO_TEST(VafmtAndOverload);
69 DO_TEST(ThisPtrOffs);
70 DO_TEST(PlugSys);
71 DO_TEST(Bail);
73 template <>
74 int SourceHook::HashFunction<int>(const int & k)
75 {
76 return k;
77 }
79 template <>
80 int SourceHook::Compare<int>(const int & v1, const int & v2)
81 {
82 if (v1 == v2)
83 return 0;
84 if (v1 < v2)
85 return -1;
86 if (v1 > v2)
87 return 1;
88 return 0;
89 }
91 int main(int argc, char *argv[])
92 {
93 std::string error;
94 int passed=0, failed=0;
96 g_Verbose = argc > 1 && strcmp(argv[1], "-v") == 0;
98 Test::DoTests();
100 cout << "Press enter to continue" << endl;
102 char x;
103 cin.read(&x, 1);
104 }