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: #include "TestBase.h" michael@0: michael@0: #include michael@0: michael@0: using namespace std; michael@0: michael@0: int michael@0: TestBase::RunTests(int *aFailures) michael@0: { michael@0: int testsRun = 0; michael@0: *aFailures = 0; michael@0: michael@0: for(unsigned int i = 0; i < mTests.size(); i++) { michael@0: stringstream stream; michael@0: stream << "Test (" << mTests[i].name << "): "; michael@0: LogMessage(stream.str()); michael@0: stream.str(""); michael@0: michael@0: mTestFailed = false; michael@0: michael@0: // Don't try this at home! We know these are actually pointers to members michael@0: // of child clases, so we reinterpret cast those child class pointers to michael@0: // TestBase and then call the functions. Because the compiler believes michael@0: // these function calls are members of TestBase. michael@0: ((*reinterpret_cast((mTests[i].implPointer))).*(mTests[i].funcCall))(); michael@0: michael@0: if (!mTestFailed) { michael@0: LogMessage("PASSED\n"); michael@0: } else { michael@0: LogMessage("FAILED\n"); michael@0: (*aFailures)++; michael@0: } michael@0: testsRun++; michael@0: } michael@0: michael@0: return testsRun; michael@0: } michael@0: michael@0: void michael@0: TestBase::LogMessage(string aMessage) michael@0: { michael@0: printf("%s", aMessage.c_str()); michael@0: }