gfx/2d/unittest/TestBase.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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/. */
     6 #pragma once
     8 #include <string>
     9 #include <vector>
    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
    16 #define VERIFY(arg) if (!(arg)) { \
    17   LogMessage("VERIFY FAILED: "#arg"\n"); \
    18   mTestFailed = true; \
    19   }
    21 #define REGISTER_TEST(className, testName) \
    22   mTests.push_back(Test(static_cast<TestCall>(&className::testName), #testName, this))
    24 class TestBase
    25 {
    26 public:
    27   TestBase() {}
    29   typedef void (TestBase::*TestCall)();
    31   int RunTests(int *aFailures);
    33 protected:
    34   static void LogMessage(std::string aMessage);
    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;
    49   bool mTestFailed;
    51 private:
    52   // This doesn't really work with our generic member pointer trick.
    53   TestBase(const TestBase &aOther);
    54 };

mercurial