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