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
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, 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
)
174 numberOfFailedTests
++;
178 if (numberOfFailedTests
> 0)
179 printf("%d tests failed\n",
180 numberOfFailedTests
);
182 printf("All tests succeeded\n");
186 void GetTests ( BaseTestList
& tests
)
188 tests
.push_back(new ProjectTest());
189 tests
.push_back(new ModuleTest());
190 tests
.push_back(new DefineTest());
191 tests
.push_back(new IncludeTest());
192 tests
.push_back(new InvokeTest());
193 tests
.push_back(new LinkerFlagTest());
194 tests
.push_back(new IfTest());
195 tests
.push_back(new FunctionTest());
196 tests
.push_back(new SourceFileTest());
197 tests
.push_back(new CDFileTest());
198 tests
.push_back(new SymbolTest());
199 tests
.push_back(new CompilationUnitTest());
207 InitializeEnvironment ();
208 TestDispatcher testDispatcher
;
209 testDispatcher
.Run();