gfx/2d/unittest/TestBase.h

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:bee3e14ca149
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 #pragma once
7
8 #include <string>
9 #include <vector>
10
11 #ifdef _MSC_VER
12 // On MSVC otherwise our generic member pointer trick doesn't work.
13 #pragma pointers_to_members(full_generality, single_inheritance)
14 #endif
15
16 #define VERIFY(arg) if (!(arg)) { \
17 LogMessage("VERIFY FAILED: "#arg"\n"); \
18 mTestFailed = true; \
19 }
20
21 #define REGISTER_TEST(className, testName) \
22 mTests.push_back(Test(static_cast<TestCall>(&className::testName), #testName, this))
23
24 class TestBase
25 {
26 public:
27 TestBase() {}
28
29 typedef void (TestBase::*TestCall)();
30
31 int RunTests(int *aFailures);
32
33 protected:
34 static void LogMessage(std::string aMessage);
35
36 struct Test {
37 Test(TestCall aCall, std::string aName, void *aImplPointer)
38 : funcCall(aCall)
39 , name(aName)
40 , implPointer(aImplPointer)
41 {
42 }
43 TestCall funcCall;
44 std::string name;
45 void *implPointer;
46 };
47 std::vector<Test> mTests;
48
49 bool mTestFailed;
50
51 private:
52 // This doesn't really work with our generic member pointer trick.
53 TestBase(const TestBase &aOther);
54 };

mercurial