1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/2d/unittest/TestBase.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,48 @@ 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 +#include "TestBase.h" 1.10 + 1.11 +#include <sstream> 1.12 + 1.13 +using namespace std; 1.14 + 1.15 +int 1.16 +TestBase::RunTests(int *aFailures) 1.17 +{ 1.18 + int testsRun = 0; 1.19 + *aFailures = 0; 1.20 + 1.21 + for(unsigned int i = 0; i < mTests.size(); i++) { 1.22 + stringstream stream; 1.23 + stream << "Test (" << mTests[i].name << "): "; 1.24 + LogMessage(stream.str()); 1.25 + stream.str(""); 1.26 + 1.27 + mTestFailed = false; 1.28 + 1.29 + // Don't try this at home! We know these are actually pointers to members 1.30 + // of child clases, so we reinterpret cast those child class pointers to 1.31 + // TestBase and then call the functions. Because the compiler believes 1.32 + // these function calls are members of TestBase. 1.33 + ((*reinterpret_cast<TestBase*>((mTests[i].implPointer))).*(mTests[i].funcCall))(); 1.34 + 1.35 + if (!mTestFailed) { 1.36 + LogMessage("PASSED\n"); 1.37 + } else { 1.38 + LogMessage("FAILED\n"); 1.39 + (*aFailures)++; 1.40 + } 1.41 + testsRun++; 1.42 + } 1.43 + 1.44 + return testsRun; 1.45 +} 1.46 + 1.47 +void 1.48 +TestBase::LogMessage(string aMessage) 1.49 +{ 1.50 + printf("%s", aMessage.c_str()); 1.51 +}