Mercurial > fife-parpg
view ext/UnitTest++/src/TestRunner.cpp @ 362:6da97ffede18
Patch by amo-ej1 (Elie de Brauwer):
* Fixes the map editor's save map as functionality
* Close #382
author | mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Sun, 18 Oct 2009 20:13:21 +0000 |
parents | 0d325e9d5953 |
children |
line wrap: on
line source
#include "TestRunner.h" #include "TestResults.h" #include "Test.h" #include "TestList.h" #include "TestReporter.h" #include "TestReporterStdout.h" #include "TimeHelpers.h" #include "MemoryOutStream.h" #include <cstring> namespace UnitTest { int RunAllTests(TestReporter& reporter, TestList const& list, char const* suiteName, int const maxTestTimeInMs ) { TestResults result(&reporter); Timer overallTimer; overallTimer.Start(); Test const* curTest = list.GetHead(); while (curTest != 0) { if (suiteName == 0 || !std::strcmp(curTest->m_details.suiteName, suiteName)) { Timer testTimer; testTimer.Start(); result.OnTestStart(curTest->m_details); curTest->Run(result); int const testTimeInMs = testTimer.GetTimeInMs(); if (maxTestTimeInMs > 0 && testTimeInMs > maxTestTimeInMs && !curTest->m_timeConstraintExempt) { MemoryOutStream stream; stream << "Global time constraint failed. Expected under " << maxTestTimeInMs << "ms but took " << testTimeInMs << "ms."; result.OnTestFailure(curTest->m_details, stream.GetText()); } result.OnTestFinish(curTest->m_details, testTimeInMs/1000.0f); } curTest = curTest->next; } float const secondsElapsed = overallTimer.GetTimeInMs() / 1000.0f; reporter.ReportSummary(result.GetTotalTestCount(), result.GetFailedTestCount(), result.GetFailureCount(), secondsElapsed); return result.GetFailureCount(); } int RunAllTests() { TestReporterStdout reporter; return RunAllTests(reporter, Test::GetTestList(), 0); } }