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 #if defined(_MSC_VER) && !defined(__clang__)
13 // On MSVC otherwise our generic member pointer trick doesn't work.
14 // JYA: Do we still need this?
15 #  pragma pointers_to_members(full_generality, single_inheritance)
16 #endif
17 
18 #define VERIFY(arg)                          \
19   if (!(arg)) {                              \
20     LogMessage("VERIFY FAILED: " #arg "\n"); \
21     mTestFailed = true;                      \
22   }
23 
24 #define REGISTER_TEST(className, testName) \
25   mTests.push_back(                        \
26       Test(static_cast<TestCall>(&className::testName), #testName, this))
27 
28 class TestBase {
29  public:
30   TestBase() = default;
31 
32   typedef void (TestBase::*TestCall)();
33 
34   int RunTests(int* aFailures);
35 
36  protected:
37   static void LogMessage(std::string aMessage);
38 
39   struct Test {
TestTest40     Test(TestCall aCall, std::string aName, void* aImplPointer)
41         : funcCall(aCall), name(aName), implPointer(aImplPointer) {}
42     TestCall funcCall;
43     std::string name;
44     void* implPointer;
45   };
46   std::vector<Test> mTests;
47 
48   bool mTestFailed;
49 
50  private:
51   // This doesn't really work with our generic member pointer trick.
52   TestBase(const TestBase& aOther);
53 };
54