2 * Copyright (C) 2005 Casper S. Hornstrup
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
32 void BaseTest::Assert(const char *message
, ...)
35 va_start ( args
, message
);
36 vprintf(message
, args
);
41 void BaseTest::IsNull(void* reference
,
45 if (reference
!= NULL
)
47 Assert("Condition was not NULL at %s:%d\n",
53 void BaseTest::IsNotNull(void* reference
,
57 if (reference
== NULL
)
59 Assert("Condition was NULL at %s:%d\n",
65 void BaseTest::IsTrue(bool condition
,
71 Assert("Condition was not true at %s:%d\n",
77 void BaseTest::IsFalse(bool condition
,
83 Assert("Condition was not false at %s:%d\n",
89 void BaseTest::AreEqual(int expected
,
94 if (actual
!= expected
)
96 Assert("Expected %d/0x%.08x was %d/0x%.08x at %s:%d\n",
106 void BaseTest::AreEqual(const std::string
& expected
,
107 const std::string
& actual
,
111 if (actual
!= expected
)
113 Assert("Expected '%s' was '%s' at %s:%d\n",
121 void BaseTest::AreNotEqual(int expected
,
126 if (actual
== expected
)
128 Assert("Actual value expected to be different from %d/0x%.08x at %s:%d\n",
136 void BaseTest::Fail()
141 class BaseTestList
: public std::vector
<BaseTest
*>
146 for ( size_t i
= 0; i
< size(); i
++ )
158 int numberOfFailedTests
= 0;
161 for (size_t i
= 0; i
< tests
.size(); i
++)
165 BaseTest
& test
= *tests
[i
];
168 numberOfFailedTests
++;
170 catch ( Exception
& ex
)
172 printf ( "%s\n", (*ex
).c_str () );
173 numberOfFailedTests
++;
175 catch ( XMLException
& ex
)
177 printf ( "%s\n", (*ex
).c_str () );
178 numberOfFailedTests
++;
182 if (numberOfFailedTests
> 0)
183 printf("%d tests failed\n",
184 numberOfFailedTests
);
186 printf("All tests succeeded\n");
190 void GetTests ( BaseTestList
& tests
)
192 tests
.push_back(new ProjectTest());
193 tests
.push_back(new ModuleTest());
194 tests
.push_back(new DefineTest());
195 tests
.push_back(new IncludeTest());
196 tests
.push_back(new InvokeTest());
197 tests
.push_back(new LinkerFlagTest());
198 tests
.push_back(new IfTest());
199 tests
.push_back(new FunctionTest());
200 tests
.push_back(new SourceFileTest());
201 tests
.push_back(new CDFileTest());
202 tests
.push_back(new SymbolTest());
203 tests
.push_back(new CompilationUnitTest());
211 InitializeEnvironment ();
212 TestDispatcher testDispatcher
;
213 testDispatcher
.Run();