gfx/2d/unittest/TestBase.cpp

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

mercurial