gfx/2d/unittest/TestBase.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/2d/unittest/TestBase.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,54 @@
     1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     1.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#pragma once
    1.10 +
    1.11 +#include <string>
    1.12 +#include <vector>
    1.13 +
    1.14 +#ifdef _MSC_VER
    1.15 +// On MSVC otherwise our generic member pointer trick doesn't work.
    1.16 +#pragma pointers_to_members(full_generality, single_inheritance)
    1.17 +#endif
    1.18 +
    1.19 +#define VERIFY(arg) if (!(arg)) { \
    1.20 +  LogMessage("VERIFY FAILED: "#arg"\n"); \
    1.21 +  mTestFailed = true; \
    1.22 +  }
    1.23 +
    1.24 +#define REGISTER_TEST(className, testName) \
    1.25 +  mTests.push_back(Test(static_cast<TestCall>(&className::testName), #testName, this))
    1.26 +
    1.27 +class TestBase
    1.28 +{
    1.29 +public:
    1.30 +  TestBase() {}
    1.31 +
    1.32 +  typedef void (TestBase::*TestCall)();
    1.33 +
    1.34 +  int RunTests(int *aFailures);
    1.35 +
    1.36 +protected:
    1.37 +  static void LogMessage(std::string aMessage);
    1.38 +
    1.39 +  struct Test {
    1.40 +    Test(TestCall aCall, std::string aName, void *aImplPointer)
    1.41 +      : funcCall(aCall)
    1.42 +      , name(aName)
    1.43 +      , implPointer(aImplPointer)
    1.44 +    {
    1.45 +    }
    1.46 +    TestCall funcCall;
    1.47 +    std::string name;
    1.48 +    void *implPointer;
    1.49 +  };
    1.50 +  std::vector<Test> mTests;
    1.51 +
    1.52 +  bool mTestFailed;
    1.53 +
    1.54 +private:
    1.55 +  // This doesn't really work with our generic member pointer trick.
    1.56 +  TestBase(const TestBase &aOther);
    1.57 +};

mercurial