michael@0: /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #pragma once michael@0: michael@0: #include michael@0: #include michael@0: michael@0: #ifdef _MSC_VER michael@0: // On MSVC otherwise our generic member pointer trick doesn't work. michael@0: #pragma pointers_to_members(full_generality, single_inheritance) michael@0: #endif michael@0: michael@0: #define VERIFY(arg) if (!(arg)) { \ michael@0: LogMessage("VERIFY FAILED: "#arg"\n"); \ michael@0: mTestFailed = true; \ michael@0: } michael@0: michael@0: #define REGISTER_TEST(className, testName) \ michael@0: mTests.push_back(Test(static_cast(&className::testName), #testName, this)) michael@0: michael@0: class TestBase michael@0: { michael@0: public: michael@0: TestBase() {} michael@0: michael@0: typedef void (TestBase::*TestCall)(); michael@0: michael@0: int RunTests(int *aFailures); michael@0: michael@0: protected: michael@0: static void LogMessage(std::string aMessage); michael@0: michael@0: struct Test { michael@0: Test(TestCall aCall, std::string aName, void *aImplPointer) michael@0: : funcCall(aCall) michael@0: , name(aName) michael@0: , implPointer(aImplPointer) michael@0: { michael@0: } michael@0: TestCall funcCall; michael@0: std::string name; michael@0: void *implPointer; michael@0: }; michael@0: std::vector mTests; michael@0: michael@0: bool mTestFailed; michael@0: michael@0: private: michael@0: // This doesn't really work with our generic member pointer trick. michael@0: TestBase(const TestBase &aOther); michael@0: };