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