Set svn:eol-style=native
[reactos.git] / reactos / tools / rbuild / tests / alltests.cpp
1
2 #include "pch.h"
3
4 #include "rbuild.h"
5 #include "test.h"
6
7 BaseTest::BaseTest()
8 {
9 Failed = false;
10 }
11
12 BaseTest::~BaseTest()
13 {
14 }
15
16 void BaseTest::Assert(const char *message, ...)
17 {
18 va_list args;
19 va_start ( args, message );
20 vprintf(message, args);
21 va_end ( args );
22 Fail();
23 }
24
25 void BaseTest::IsNull(void* reference,
26 const char* file,
27 int line)
28 {
29 if (reference != NULL)
30 {
31 Assert("Condition was not NULL at %s:%d\n",
32 file,
33 line);
34 }
35 }
36
37 void BaseTest::IsNotNull(void* reference,
38 const char* file,
39 int line)
40 {
41 if (reference == NULL)
42 {
43 Assert("Condition was NULL at %s:%d\n",
44 file,
45 line);
46 }
47 }
48
49 void BaseTest::IsTrue(bool condition,
50 const char* file,
51 int line)
52 {
53 if (!condition)
54 {
55 Assert("Condition was not true at %s:%d\n",
56 file,
57 line);
58 }
59 }
60
61 void BaseTest::IsFalse(bool condition,
62 const char* file,
63 int line)
64 {
65 if (condition)
66 {
67 Assert("Condition was not false at %s:%d\n",
68 file,
69 line);
70 }
71 }
72
73 void BaseTest::AreEqual(int expected,
74 int actual,
75 const char* file,
76 int line)
77 {
78 if (actual != expected)
79 {
80 Assert("Expected %d/0x%.08x was %d/0x%.08x at %s:%d\n",
81 expected,
82 expected,
83 actual,
84 actual,
85 file,
86 line);
87 }
88 }
89
90 void BaseTest::AreEqual(const std::string& expected,
91 const std::string& actual,
92 const char* file,
93 int line)
94 {
95 if (actual != expected)
96 {
97 Assert("Expected '%s' was '%s' at %s:%d\n",
98 expected.c_str(),
99 actual.c_str(),
100 file,
101 line);
102 }
103 }
104
105 void BaseTest::AreNotEqual(int expected,
106 int actual,
107 const char* file,
108 int line)
109 {
110 if (actual == expected)
111 {
112 Assert("Actual value expected to be different from %d/0x%.08x at %s:%d\n",
113 expected,
114 expected,
115 file,
116 line);
117 }
118 }
119
120 void BaseTest::Fail()
121 {
122 Failed = true;
123 }
124
125 class BaseTestList : public std::vector<BaseTest*>
126 {
127 public:
128 ~BaseTestList()
129 {
130 for ( size_t i = 0; i < size(); i++ )
131 {
132 delete (*this)[i];
133 }
134 }
135 };
136
137 class TestDispatcher
138 {
139 public:
140 void Run()
141 {
142 int numberOfFailedTests = 0;
143 BaseTestList tests;
144 GetTests(tests);
145 for (size_t i = 0; i < tests.size(); i++)
146 {
147 try
148 {
149 BaseTest& test = *tests[i];
150 test.Run();
151 if (test.Failed)
152 numberOfFailedTests++;
153 }
154 catch (Exception& ex)
155 {
156 printf("%s\n",
157 ex.Message.c_str());
158 numberOfFailedTests++;
159 }
160 }
161
162 if (numberOfFailedTests > 0)
163 printf("%d tests failed\n",
164 numberOfFailedTests);
165 else
166 printf("All tests succeeded\n");
167 }
168
169 private:
170 void GetTests ( BaseTestList& tests )
171 {
172 tests.push_back(new ProjectTest());
173 tests.push_back(new ModuleTest());
174 tests.push_back(new DefineTest());
175 tests.push_back(new IncludeTest());
176 tests.push_back(new InvokeTest());
177 tests.push_back(new LinkerFlagTest());
178 tests.push_back(new IfTest());
179 tests.push_back(new FunctionTest());
180 tests.push_back(new SourceFileTest());
181 tests.push_back(new CDFileTest());
182 tests.push_back(new SymbolTest());
183 }
184 };
185
186
187 int main(int argc,
188 char** argv)
189 {
190 TestDispatcher testDispatcher;
191 testDispatcher.Run();
192 return 0;
193 };