TestBase.cpp (1292B)
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 #include "TestBase.h" 8 9 #include <sstream> 10 11 int TestBase::RunTests(int* aFailures) { 12 int testsRun = 0; 13 *aFailures = 0; 14 15 for (unsigned int i = 0; i < mTests.size(); i++) { 16 std::stringstream stream; 17 stream << "Test (" << mTests[i].name << "): "; 18 LogMessage(stream.str()); 19 stream.str(""); 20 21 mTestFailed = false; 22 23 // Don't try this at home! We know these are actually pointers to members 24 // of child clases, so we reinterpret cast those child class pointers to 25 // TestBase and then call the functions. Because the compiler believes 26 // these function calls are members of TestBase. 27 ((*reinterpret_cast<TestBase*>((mTests[i].implPointer))).* 28 (mTests[i].funcCall))(); 29 30 if (!mTestFailed) { 31 LogMessage("PASSED\n"); 32 } else { 33 LogMessage("FAILED\n"); 34 (*aFailures)++; 35 } 36 testsRun++; 37 } 38 39 return testsRun; 40 } 41 42 void TestBase::LogMessage(std::string aMessage) { 43 printf("%s", aMessage.c_str()); 44 }