From 72c2581719a59d3c8e701cdf08e96c564d82cc56 Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Wed, 9 Jan 2013 23:33:51 -0600 Subject: [PATCH 01/30] Renamed files with + in them to be alphanumeric and baselined to roughly r2 or http://unittestpp.googlecode.com/svn/trunk/ --- Makefile | 2 +- README | 2 +- TestUnitTest++.vsnet2003.vcproj | 2 +- TestUnitTest++.vsnet2005.vcproj | 2 +- TestUnitTestPP_vs6.dsp | 2 +- UnitTest++.vsnet2003.vcproj | 2 +- UnitTest++.vsnet2005.vcproj | 2 +- UnitTestPP_vs6.dsp | 2 +- docs/UnitTest++.html | 6 +- src/DeferredTestReporter.cpp | 56 +++---- src/DeferredTestResult.cpp | 54 ++++--- src/TestRunner.cpp | 152 +++++++++--------- src/TestRunner.h | 118 +++++++------- src/TestSuite.h | 26 ++- src/TimeConstraint.cpp | 58 +++---- src/Win32/TimeHelpers.cpp | 94 +++++------ src/tests/Main.cpp | 2 +- src/tests/TestAssertHandler.cpp | 2 +- src/tests/TestCheckMacros.cpp | 2 +- src/tests/TestChecks.cpp | 2 +- src/tests/TestCurrentTest.cpp | 2 +- src/tests/TestDeferredTestReporter.cpp | 2 +- src/tests/TestMemoryOutStream.cpp | 2 +- src/tests/TestTest.cpp | 2 +- src/tests/TestTestList.cpp | 2 +- src/tests/TestTestMacros.cpp | 2 +- src/tests/TestTestResults.cpp | 2 +- src/tests/TestTestRunner.cpp | 2 +- src/tests/TestTestSuite.cpp | 2 +- src/tests/TestTimeConstraint.cpp | 2 +- src/tests/TestTimeConstraintMacro.cpp | 2 +- ...{TestUnitTest++.cpp => TestUnitTestPP.cpp} | 2 +- src/tests/TestXmlTestReporter.cpp | 2 +- src/{UnitTest++.h => unittestpp.h} | 0 34 files changed, 308 insertions(+), 306 deletions(-) rename src/tests/{TestUnitTest++.cpp => TestUnitTestPP.cpp} (93%) rename src/{UnitTest++.h => unittestpp.h} (100%) diff --git a/Makefile b/Makefile index dfae28a..0ce613b 100644 --- a/Makefile +++ b/Makefile @@ -37,7 +37,7 @@ endif test_src = src/tests/Main.cpp \ src/tests/TestAssertHandler.cpp \ src/tests/TestChecks.cpp \ - src/tests/TestUnitTest++.cpp \ + src/tests/TestUnitTestPP.cpp \ src/tests/TestTest.cpp \ src/tests/TestTestResults.cpp \ src/tests/TestTestRunner.cpp \ diff --git a/README b/README index d1cd35c..187e69b 100644 --- a/README +++ b/README @@ -7,7 +7,7 @@ the terms of the License contained in the file COPYING distributed with this package. This license is the same as the MIT/X Consortium license. -See src/tests/TestUnitTest++.cpp for usage. +See src/tests/TestUnitTestPP.cpp for usage. Authors: Noel Llopis (llopis@convexhull.com) diff --git a/TestUnitTest++.vsnet2003.vcproj b/TestUnitTest++.vsnet2003.vcproj index 6dcd025..fbc4154 100644 --- a/TestUnitTest++.vsnet2003.vcproj +++ b/TestUnitTest++.vsnet2003.vcproj @@ -163,7 +163,7 @@ RelativePath=".\src\tests\TestTimeConstraintMacro.cpp"> + RelativePath=".\src\tests\TestUnitTestPP.cpp"> diff --git a/TestUnitTest++.vsnet2005.vcproj b/TestUnitTest++.vsnet2005.vcproj index 25d5ba6..aa8f95b 100644 --- a/TestUnitTest++.vsnet2005.vcproj +++ b/TestUnitTest++.vsnet2005.vcproj @@ -243,7 +243,7 @@ > + RelativePath=".\src\unittestpp.h"> diff --git a/UnitTest++.vsnet2005.vcproj b/UnitTest++.vsnet2005.vcproj index 4efb687..9c56365 100644 --- a/UnitTest++.vsnet2005.vcproj +++ b/UnitTest++.vsnet2005.vcproj @@ -301,7 +301,7 @@ > Packaging

You'll probably want to keep the generated library in a shared space in source control, so you can reuse it for multiple test projects. A redistributable package of UnitTest++ would consist of the generated library file, and all of the header files in UnitTest++/src/ and its per-platform subfolders. The tests directory only contains the unit tests for the library, and need not be included.

Using UnitTest++

-

The source code for UnitTest++ comes with a full test suite written using UnitTest++. This is a great place to learn techniques for testing. There is one sample .cpp file: UnitTest++/src/tests/TestUnitTest++.cpp. It covers most of UnitTest++'s features in an easy-to-grasp context, so start there if you want a quick overview of typical usage.

+

The source code for UnitTest++ comes with a full test suite written using UnitTest++. This is a great place to learn techniques for testing. There is one sample .cpp file: UnitTest++/src/tests/TestUnitTestPP.cpp. It covers most of UnitTest++'s features in an easy-to-grasp context, so start there if you want a quick overview of typical usage.

Getting started

Listed below is a minimal C++ program to run a failing test through UnitTest++.

   // test.cpp
-  #include <UnitTest++.h>
+  #include <unittestpp.h>
 
   TEST(FailSpectacularly)
   {
@@ -51,7 +51,7 @@ 

Getting started

}
-

UnitTest++.h is a facade header for UnitTest++, so including that should get you all features of the library. All classes and free functions are placed in namespace UnitTest, so you need to either qualify their full names (as with RunAllTests() in the example) or add a using namespace UnitTest; statement in your .cpp files. Note that any mention of UnitTest++ functions and classes in this document assume that the UnitTest namespace has been opened.

+

unittestpp.h is a facade header for UnitTest++, so including that should get you all features of the library. All classes and free functions are placed in namespace UnitTest, so you need to either qualify their full names (as with RunAllTests() in the example) or add a using namespace UnitTest; statement in your .cpp files. Note that any mention of UnitTest++ functions and classes in this document assume that the UnitTest namespace has been opened.

Compiling and linking this program with UnitTest++'s static library into an executable, and running it, will produce the following output (details may vary):

diff --git a/src/DeferredTestReporter.cpp b/src/DeferredTestReporter.cpp index ae77b03..fbd08db 100644 --- a/src/DeferredTestReporter.cpp +++ b/src/DeferredTestReporter.cpp @@ -1,28 +1,28 @@ -#include "DeferredTestReporter.h" -#include "TestDetails.h" - -using namespace UnitTest; - -void DeferredTestReporter::ReportTestStart(TestDetails const& details) -{ - m_results.push_back(DeferredTestResult(details.suiteName, details.testName)); -} - -void DeferredTestReporter::ReportFailure(TestDetails const& details, char const* failure) -{ - DeferredTestResult& r = m_results.back(); - r.failed = true; - r.failures.push_back(DeferredTestResult::Failure(details.lineNumber, failure)); - r.failureFile = details.filename; -} - -void DeferredTestReporter::ReportTestFinish(TestDetails const&, float secondsElapsed) -{ - DeferredTestResult& r = m_results.back(); - r.timeElapsed = secondsElapsed; -} - -DeferredTestReporter::DeferredTestResultList& DeferredTestReporter::GetResults() -{ - return m_results; -} +#include "DeferredTestReporter.h" +#include "TestDetails.h" + +using namespace UnitTest; + +void DeferredTestReporter::ReportTestStart(TestDetails const& details) +{ + m_results.push_back(DeferredTestResult(details.suiteName, details.testName)); +} + +void DeferredTestReporter::ReportFailure(TestDetails const& details, char const* failure) +{ + DeferredTestResult& r = m_results.back(); + r.failed = true; + r.failures.push_back(DeferredTestResult::Failure(details.lineNumber, failure)); + r.failureFile = details.filename; +} + +void DeferredTestReporter::ReportTestFinish(TestDetails const&, float secondsElapsed) +{ + DeferredTestResult& r = m_results.back(); + r.timeElapsed = secondsElapsed; +} + +DeferredTestReporter::DeferredTestResultList& DeferredTestReporter::GetResults() +{ + return m_results; +} diff --git a/src/DeferredTestResult.cpp b/src/DeferredTestResult.cpp index c2daa25..944f894 100644 --- a/src/DeferredTestResult.cpp +++ b/src/DeferredTestResult.cpp @@ -1,25 +1,29 @@ -#include "DeferredTestResult.h" -#include "Config.h" - -namespace UnitTest -{ - -DeferredTestResult::DeferredTestResult() - : suiteName("") - , testName("") - , failureFile("") - , timeElapsed(0.0f) - , failed(false) -{ -} - -DeferredTestResult::DeferredTestResult(char const* suite, char const* test) - : suiteName(suite) - , testName(test) - , failureFile("") - , timeElapsed(0.0f) - , failed(false) -{ -} - -} +#include "DeferredTestResult.h" +#include "Config.h" + +namespace UnitTest +{ + +DeferredTestResult::DeferredTestResult() + : suiteName("") + , testName("") + , failureFile("") + , timeElapsed(0.0f) + , failed(false) +{ +} + +DeferredTestResult::DeferredTestResult(char const* suite, char const* test) + : suiteName(suite) + , testName(test) + , failureFile("") + , timeElapsed(0.0f) + , failed(false) +{ +} + +DeferredTestResult::~DeferredTestResult() +{ +} + +} diff --git a/src/TestRunner.cpp b/src/TestRunner.cpp index 466265d..b7fcb62 100644 --- a/src/TestRunner.cpp +++ b/src/TestRunner.cpp @@ -1,76 +1,76 @@ -#include "TestRunner.h" -#include "TestResults.h" -#include "TestReporter.h" -#include "TestReporterStdout.h" -#include "TimeHelpers.h" -#include "MemoryOutStream.h" - -#include - - -namespace UnitTest { - -int RunAllTests() -{ - TestReporterStdout reporter; - TestRunner runner(reporter); - return runner.RunTestsIf(Test::GetTestList(), NULL, True(), 0); -} - - -TestRunner::TestRunner(TestReporter& reporter) - : m_reporter(&reporter) - , m_result(new TestResults(&reporter)) - , m_timer(new Timer) -{ - m_timer->Start(); -} - -TestRunner::~TestRunner() -{ - delete m_result; - delete m_timer; -} - -int TestRunner::Finish() const -{ - float const secondsElapsed = m_timer->GetTimeInMs() / 1000.0f; - m_reporter->ReportSummary(m_result->GetTotalTestCount(), - m_result->GetFailedTestCount(), - m_result->GetFailureCount(), - secondsElapsed); - - return m_result->GetFailureCount(); -} - -bool TestRunner::IsTestInSuite(const Test* const curTest, char const* suiteName) const -{ - using namespace std; - return (suiteName == NULL) || !strcmp(curTest->m_details.suiteName, suiteName); -} - -void TestRunner::RunTest(TestResults* const result, Test* const curTest, int const maxTestTimeInMs) const -{ - CurrentTest::Results() = result; - - Timer testTimer; - testTimer.Start(); - - result->OnTestStart(curTest->m_details); - - curTest->Run(); - - 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); -} - -} +#include "TestRunner.h" +#include "TestResults.h" +#include "TestReporter.h" +#include "TestReporterStdout.h" +#include "TimeHelpers.h" +#include "MemoryOutStream.h" + +#include + + +namespace UnitTest { + +int RunAllTests() +{ + TestReporterStdout reporter; + TestRunner runner(reporter); + return runner.RunTestsIf(Test::GetTestList(), NULL, True(), 0); +} + + +TestRunner::TestRunner(TestReporter& reporter) + : m_reporter(&reporter) + , m_result(new TestResults(&reporter)) + , m_timer(new Timer) +{ + m_timer->Start(); +} + +TestRunner::~TestRunner() +{ + delete m_result; + delete m_timer; +} + +int TestRunner::Finish() const +{ + float const secondsElapsed = static_cast(m_timer->GetTimeInMs() / 1000.0); + m_reporter->ReportSummary(m_result->GetTotalTestCount(), + m_result->GetFailedTestCount(), + m_result->GetFailureCount(), + secondsElapsed); + + return m_result->GetFailureCount(); +} + +bool TestRunner::IsTestInSuite(const Test* const curTest, char const* suiteName) const +{ + using namespace std; + return (suiteName == NULL) || !strcmp(curTest->m_details.suiteName, suiteName); +} + +void TestRunner::RunTest(TestResults* const result, Test* const curTest, int const maxTestTimeInMs) const +{ + CurrentTest::Results() = result; + + Timer testTimer; + testTimer.Start(); + + result->OnTestStart(curTest->m_details); + + curTest->Run(); + + double 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, static_cast(testTimeInMs/1000.0)); +} + +} diff --git a/src/TestRunner.h b/src/TestRunner.h index 672355d..2ad6e5c 100644 --- a/src/TestRunner.h +++ b/src/TestRunner.h @@ -1,59 +1,59 @@ -#ifndef UNITTEST_TESTRUNNER_H -#define UNITTEST_TESTRUNNER_H - -#include "Test.h" -#include "TestList.h" -#include "CurrentTest.h" - -namespace UnitTest { - -class TestReporter; -class TestResults; -class Timer; - -int RunAllTests(); - -struct True -{ - bool operator()(const Test* const) const - { - return true; - } -}; - -class TestRunner -{ -public: - explicit TestRunner(TestReporter& reporter); - ~TestRunner(); - - template - int RunTestsIf(TestList const& list, char const* suiteName, - const Predicate& predicate, int maxTestTimeInMs) const - { - Test* curTest = list.GetHead(); - - while (curTest != 0) - { - if (IsTestInSuite(curTest, suiteName) && predicate(curTest)) - RunTest(m_result, curTest, maxTestTimeInMs); - - curTest = curTest->next; - } - - return Finish(); - } - -private: - TestReporter* m_reporter; - TestResults* m_result; - Timer* m_timer; - - int Finish() const; - bool IsTestInSuite(const Test* const curTest, char const* suiteName) const; - void RunTest(TestResults* const result, Test* const curTest, int const maxTestTimeInMs) const; -}; - -} - -#endif +#ifndef UNITTEST_TESTRUNNER_H +#define UNITTEST_TESTRUNNER_H + +#include "Test.h" +#include "TestList.h" +#include "CurrentTest.h" + +namespace UnitTest { + +class TestReporter; +class TestResults; +class Timer; + +int RunAllTests(); + +struct True +{ + bool operator()(const Test* const) const + { + return true; + } +}; + +class TestRunner +{ +public: + explicit TestRunner(TestReporter& reporter); + ~TestRunner(); + + template + int RunTestsIf(TestList const& list, char const* suiteName, + const Predicate& predicate, int maxTestTimeInMs) const + { + Test* curTest = list.GetHead(); + + while (curTest != 0) + { + if (IsTestInSuite(curTest, suiteName) && predicate(curTest)) + RunTest(m_result, curTest, maxTestTimeInMs); + + curTest = curTest->next; + } + + return Finish(); + } + +private: + TestReporter* m_reporter; + TestResults* m_result; + Timer* m_timer; + + int Finish() const; + bool IsTestInSuite(const Test* const curTest, char const* suiteName) const; + void RunTest(TestResults* const result, Test* const curTest, int const maxTestTimeInMs) const; +}; + +} + +#endif diff --git a/src/TestSuite.h b/src/TestSuite.h index dd3717e..02067fd 100644 --- a/src/TestSuite.h +++ b/src/TestSuite.h @@ -1,14 +1,12 @@ -#ifndef UNITTEST_TESTSUITE_H -#define UNITTEST_TESTSUITE_H - -namespace UnitTestSuite { - - inline char const* GetSuiteName () - { - return "DefaultSuite"; - } - -} - -#endif - +#ifndef UNITTEST_TESTSUITE_H +#define UNITTEST_TESTSUITE_H + +namespace UnitTestSuite +{ + inline char const* GetSuiteName () + { + return "DefaultSuite"; + } +} + +#endif diff --git a/src/TimeConstraint.cpp b/src/TimeConstraint.cpp index b313be7..4adb260 100644 --- a/src/TimeConstraint.cpp +++ b/src/TimeConstraint.cpp @@ -1,29 +1,29 @@ -#include "TimeConstraint.h" -#include "TestResults.h" -#include "MemoryOutStream.h" -#include "CurrentTest.h" - -namespace UnitTest { - - -TimeConstraint::TimeConstraint(int ms, TestDetails const& details) - : m_details(details) - , m_maxMs(ms) -{ - m_timer.Start(); -} - -TimeConstraint::~TimeConstraint() -{ - int const totalTimeInMs = m_timer.GetTimeInMs(); - if (totalTimeInMs > m_maxMs) - { - MemoryOutStream stream; - stream << "Time constraint failed. Expected to run test under " << m_maxMs << - "ms but took " << totalTimeInMs << "ms."; - - UnitTest::CurrentTest::Results()->OnTestFailure(m_details, stream.GetText()); - } -} - -} +#include "TimeConstraint.h" +#include "TestResults.h" +#include "MemoryOutStream.h" +#include "CurrentTest.h" + +namespace UnitTest { + + +TimeConstraint::TimeConstraint(int ms, TestDetails const& details) + : m_details(details) + , m_maxMs(ms) +{ + m_timer.Start(); +} + +TimeConstraint::~TimeConstraint() +{ + double const totalTimeInMs = m_timer.GetTimeInMs(); + if (totalTimeInMs > m_maxMs) + { + MemoryOutStream stream; + stream << "Time constraint failed. Expected to run test under " << m_maxMs << + "ms but took " << totalTimeInMs << "ms."; + + UnitTest::CurrentTest::Results()->OnTestFailure(m_details, stream.GetText()); + } +} + +} diff --git a/src/Win32/TimeHelpers.cpp b/src/Win32/TimeHelpers.cpp index 69d0d88..4bb5bcf 100644 --- a/src/Win32/TimeHelpers.cpp +++ b/src/Win32/TimeHelpers.cpp @@ -1,47 +1,47 @@ -#include "TimeHelpers.h" -#include - -namespace UnitTest { - -Timer::Timer() - : m_threadHandle(::GetCurrentThread()) - , m_startTime(0) -{ -#if defined(_MSC_VER) && (_MSC_VER == 1200) // VC6 doesn't have DWORD_PTR? - typedef unsigned long DWORD_PTR; -#endif - - DWORD_PTR systemMask; - ::GetProcessAffinityMask(GetCurrentProcess(), &m_processAffinityMask, &systemMask); - ::SetThreadAffinityMask(m_threadHandle, 1); - ::QueryPerformanceFrequency(reinterpret_cast< LARGE_INTEGER* >(&m_frequency)); - ::SetThreadAffinityMask(m_threadHandle, m_processAffinityMask); -} - -void Timer::Start() -{ - m_startTime = GetTime(); -} - -double Timer::GetTimeInMs() const -{ - __int64 const elapsedTime = GetTime() - m_startTime; - double const seconds = double(elapsedTime) / double(m_frequency); - return seconds * 1000.0; -} - -__int64 Timer::GetTime() const -{ - LARGE_INTEGER curTime; - ::SetThreadAffinityMask(m_threadHandle, 1); - ::QueryPerformanceCounter(&curTime); - ::SetThreadAffinityMask(m_threadHandle, m_processAffinityMask); - return curTime.QuadPart; -} - -void TimeHelpers::SleepMs(int const ms) -{ - ::Sleep(ms); -} - -} +#include "TimeHelpers.h" +#include + +namespace UnitTest { + +Timer::Timer() + : m_threadHandle(::GetCurrentThread()) + , m_startTime(0) +{ +#if defined(_MSC_VER) && (_MSC_VER == 1200) // VC6 doesn't have DWORD_PTR + typedef unsigned long DWORD_PTR; +#endif + + DWORD_PTR systemMask; + ::GetProcessAffinityMask(GetCurrentProcess(), &m_processAffinityMask, &systemMask); + ::SetThreadAffinityMask(m_threadHandle, 1); + ::QueryPerformanceFrequency(reinterpret_cast< LARGE_INTEGER* >(&m_frequency)); + ::SetThreadAffinityMask(m_threadHandle, m_processAffinityMask); +} + +void Timer::Start() +{ + m_startTime = GetTime(); +} + +double Timer::GetTimeInMs() const +{ + __int64 const elapsedTime = GetTime() - m_startTime; + double const seconds = double(elapsedTime) / double(m_frequency); + return seconds * 1000.0; +} + +__int64 Timer::GetTime() const +{ + LARGE_INTEGER curTime; + ::SetThreadAffinityMask(m_threadHandle, 1); + ::QueryPerformanceCounter(&curTime); + ::SetThreadAffinityMask(m_threadHandle, m_processAffinityMask); + return curTime.QuadPart; +} + +void TimeHelpers::SleepMs(int const ms) +{ + ::Sleep(ms); +} + +} diff --git a/src/tests/Main.cpp b/src/tests/Main.cpp index b4fae78..3eb37da 100644 --- a/src/tests/Main.cpp +++ b/src/tests/Main.cpp @@ -1,4 +1,4 @@ -#include "../UnitTest++.h" +#include "../unittestpp.h" #include "../TestReporterStdout.h" diff --git a/src/tests/TestAssertHandler.cpp b/src/tests/TestAssertHandler.cpp index 0c594cd..bd7cbea 100644 --- a/src/tests/TestAssertHandler.cpp +++ b/src/tests/TestAssertHandler.cpp @@ -1,4 +1,4 @@ -#include "../UnitTest++.h" +#include "../unittestpp.h" #include "../AssertException.h" #include "../ReportAssert.h" diff --git a/src/tests/TestCheckMacros.cpp b/src/tests/TestCheckMacros.cpp index 6ea1105..8a38099 100644 --- a/src/tests/TestCheckMacros.cpp +++ b/src/tests/TestCheckMacros.cpp @@ -1,4 +1,4 @@ -#include "../UnitTest++.h" +#include "../unittestpp.h" #include "../CurrentTest.h" #include "RecordingReporter.h" #include "ScopedCurrentTest.h" diff --git a/src/tests/TestChecks.cpp b/src/tests/TestChecks.cpp index cee9a3f..ae34792 100644 --- a/src/tests/TestChecks.cpp +++ b/src/tests/TestChecks.cpp @@ -1,4 +1,4 @@ -#include "../UnitTest++.h" +#include "../unittestpp.h" #include "RecordingReporter.h" using namespace UnitTest; diff --git a/src/tests/TestCurrentTest.cpp b/src/tests/TestCurrentTest.cpp index 882b3e4..dd129c3 100644 --- a/src/tests/TestCurrentTest.cpp +++ b/src/tests/TestCurrentTest.cpp @@ -1,4 +1,4 @@ -#include "../UnitTest++.h" +#include "../unittestpp.h" #include "../CurrentTest.h" #include "ScopedCurrentTest.h" diff --git a/src/tests/TestDeferredTestReporter.cpp b/src/tests/TestDeferredTestReporter.cpp index 5560692..0b08919 100644 --- a/src/tests/TestDeferredTestReporter.cpp +++ b/src/tests/TestDeferredTestReporter.cpp @@ -1,4 +1,4 @@ -#include "../UnitTest++.h" +#include "../unittestpp.h" #include "../DeferredTestReporter.h" #include "../Config.h" #include diff --git a/src/tests/TestMemoryOutStream.cpp b/src/tests/TestMemoryOutStream.cpp index c5a4227..41a7843 100644 --- a/src/tests/TestMemoryOutStream.cpp +++ b/src/tests/TestMemoryOutStream.cpp @@ -1,4 +1,4 @@ -#include "../UnitTest++.h" +#include "../unittestpp.h" #include "../MemoryOutStream.h" #include diff --git a/src/tests/TestTest.cpp b/src/tests/TestTest.cpp index d3c3d4c..92e4f0a 100644 --- a/src/tests/TestTest.cpp +++ b/src/tests/TestTest.cpp @@ -1,4 +1,4 @@ -#include "../UnitTest++.h" +#include "../unittestpp.h" #include "../TestReporter.h" #include "../TimeHelpers.h" #include "ScopedCurrentTest.h" diff --git a/src/tests/TestTestList.cpp b/src/tests/TestTestList.cpp index 6c1fba1..b37bff2 100644 --- a/src/tests/TestTestList.cpp +++ b/src/tests/TestTestList.cpp @@ -1,4 +1,4 @@ -#include "../UnitTest++.h" +#include "../unittestpp.h" #include "../TestList.h" using namespace UnitTest; diff --git a/src/tests/TestTestMacros.cpp b/src/tests/TestTestMacros.cpp index 8bed9dc..1149b0c 100644 --- a/src/tests/TestTestMacros.cpp +++ b/src/tests/TestTestMacros.cpp @@ -1,4 +1,4 @@ -#include "../UnitTest++.h" +#include "../unittestpp.h" #include "../TestMacros.h" #include "../TestList.h" #include "../TestResults.h" diff --git a/src/tests/TestTestResults.cpp b/src/tests/TestTestResults.cpp index 5bdea72..a8a0325 100644 --- a/src/tests/TestTestResults.cpp +++ b/src/tests/TestTestResults.cpp @@ -1,4 +1,4 @@ -#include "../UnitTest++.h" +#include "../unittestpp.h" #include "../TestResults.h" #include "RecordingReporter.h" diff --git a/src/tests/TestTestRunner.cpp b/src/tests/TestTestRunner.cpp index fc89b00..9acdaa5 100644 --- a/src/tests/TestTestRunner.cpp +++ b/src/tests/TestTestRunner.cpp @@ -1,4 +1,4 @@ -#include "../UnitTest++.h" +#include "../unittestpp.h" #include "RecordingReporter.h" #include "../ReportAssert.h" #include "../TestList.h" diff --git a/src/tests/TestTestSuite.cpp b/src/tests/TestTestSuite.cpp index 8353e83..1abbf49 100644 --- a/src/tests/TestTestSuite.cpp +++ b/src/tests/TestTestSuite.cpp @@ -1,4 +1,4 @@ -#include "../UnitTest++.h" +#include "../unittestpp.h" // We're really testing if it's possible to use the same suite in two files // to compile and link successfuly (TestTestSuite.cpp has suite with the same name) diff --git a/src/tests/TestTimeConstraint.cpp b/src/tests/TestTimeConstraint.cpp index 10adb36..6f2021d 100644 --- a/src/tests/TestTimeConstraint.cpp +++ b/src/tests/TestTimeConstraint.cpp @@ -1,4 +1,4 @@ -#include "../UnitTest++.h" +#include "../unittestpp.h" #include "../TestResults.h" #include "../TimeHelpers.h" #include "RecordingReporter.h" diff --git a/src/tests/TestTimeConstraintMacro.cpp b/src/tests/TestTimeConstraintMacro.cpp index 785c6ce..056d89d 100644 --- a/src/tests/TestTimeConstraintMacro.cpp +++ b/src/tests/TestTimeConstraintMacro.cpp @@ -1,4 +1,4 @@ -#include "../UnitTest++.h" +#include "../unittestpp.h" #include "../TimeHelpers.h" #include "RecordingReporter.h" diff --git a/src/tests/TestUnitTest++.cpp b/src/tests/TestUnitTestPP.cpp similarity index 93% rename from src/tests/TestUnitTest++.cpp rename to src/tests/TestUnitTestPP.cpp index 62c0033..b62d1c9 100644 --- a/src/tests/TestUnitTest++.cpp +++ b/src/tests/TestUnitTestPP.cpp @@ -1,4 +1,4 @@ -#include "../UnitTest++.h" +#include "../unittestpp.h" #include "../ReportAssert.h" #include "ScopedCurrentTest.h" diff --git a/src/tests/TestXmlTestReporter.cpp b/src/tests/TestXmlTestReporter.cpp index 959a83a..2419668 100644 --- a/src/tests/TestXmlTestReporter.cpp +++ b/src/tests/TestXmlTestReporter.cpp @@ -1,4 +1,4 @@ -#include "../UnitTest++.h" +#include "../unittestpp.h" #include "../XmlTestReporter.h" #include diff --git a/src/UnitTest++.h b/src/unittestpp.h similarity index 100% rename from src/UnitTest++.h rename to src/unittestpp.h From 67d4ecb5c5d3ba379d76b867a8b2c80e77c3b0bc Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Wed, 9 Jan 2013 23:42:14 -0600 Subject: [PATCH 02/30] r3 | charles.nicholson | 2010-03-08 22:58:59 -0600 (Mon, 08 Mar 2010) | 1 line first pass at adding exception macros --- src/CheckMacros.h | 77 +++++---- src/Config.h | 2 + src/ExceptionMacros.h | 18 ++ src/tests/TestCheckMacros.cpp | 262 ----------------------------- src/tests/TestExceptions.cpp | 302 ++++++++++++++++++++++++++++++++++ src/tests/TestUnitTestPP.cpp | 4 + 6 files changed, 373 insertions(+), 292 deletions(-) create mode 100644 src/ExceptionMacros.h create mode 100644 src/tests/TestExceptions.cpp diff --git a/src/CheckMacros.h b/src/CheckMacros.h index 1eaa792..89384c3 100644 --- a/src/CheckMacros.h +++ b/src/CheckMacros.h @@ -1,6 +1,7 @@ #ifndef UNITTEST_CHECKMACROS_H #define UNITTEST_CHECKMACROS_H +#include "ExceptionMacros.h" #include "Checks.h" #include "AssertException.h" #include "MemoryOutStream.h" @@ -34,87 +35,103 @@ #define CHECK(value) \ do \ { \ - try { \ - if (!UnitTest::Check(value)) \ - UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), #value); \ - } \ - catch (...) { \ - UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \ - "Unhandled exception in CHECK(" #value ")"); \ - } \ + UT_TRY \ + ({ \ + if (!UnitTest::Check(value)) \ + UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), #value); \ + }) \ + UT_CATCH_ALL \ + ({ \ + UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \ + "Unhandled exception in CHECK(" #value ")"); \ + }) \ } while (0) #define CHECK_EQUAL(expected, actual) \ do \ { \ - try { \ + UT_TRY \ + ({ \ UnitTest::CheckEqual(*UnitTest::CurrentTest::Results(), expected, actual, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \ - } \ - catch (...) { \ + }) \ + UT_CATCH_ALL \ + ({ \ UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \ "Unhandled exception in CHECK_EQUAL(" #expected ", " #actual ")"); \ - } \ + }) \ } while (0) #define CHECK_CLOSE(expected, actual, tolerance) \ do \ { \ - try { \ + UT_TRY \ + ({ \ UnitTest::CheckClose(*UnitTest::CurrentTest::Results(), expected, actual, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \ - } \ - catch (...) { \ + }) \ + UT_CATCH_ALL \ + ({ \ UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \ "Unhandled exception in CHECK_CLOSE(" #expected ", " #actual ")"); \ - } \ + }) \ } while (0) #define CHECK_ARRAY_EQUAL(expected, actual, count) \ do \ { \ - try { \ + UT_TRY \ + ({ \ UnitTest::CheckArrayEqual(*UnitTest::CurrentTest::Results(), expected, actual, count, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \ - } \ - catch (...) { \ + }) \ + UT_CATCH_ALL \ + ({ \ UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \ "Unhandled exception in CHECK_ARRAY_EQUAL(" #expected ", " #actual ")"); \ - } \ + }) \ } while (0) #define CHECK_ARRAY_CLOSE(expected, actual, count, tolerance) \ do \ { \ - try { \ + UT_TRY \ + ({ \ UnitTest::CheckArrayClose(*UnitTest::CurrentTest::Results(), expected, actual, count, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \ - } \ - catch (...) { \ + }) \ + UT_CATCH_ALL \ + ({ \ UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \ "Unhandled exception in CHECK_ARRAY_CLOSE(" #expected ", " #actual ")"); \ - } \ + }) \ } while (0) #define CHECK_ARRAY2D_CLOSE(expected, actual, rows, columns, tolerance) \ do \ { \ - try { \ + UT_TRY \ + ({ \ UnitTest::CheckArray2DClose(*UnitTest::CurrentTest::Results(), expected, actual, rows, columns, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \ - } \ - catch (...) { \ + }) \ + UT_CATCH_ALL \ + ({ \ UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \ "Unhandled exception in CHECK_ARRAY_CLOSE(" #expected ", " #actual ")"); \ - } \ + }) \ } while (0) +// CHECK_THROW only exists when UNITTEST_USE_EXCEPTIONS is defined (see Config.h) +#ifdef UNITTEST_USE_EXCEPTIONS #define CHECK_THROW(expression, ExpectedExceptionType) \ do \ { \ bool caught_ = false; \ try { expression; } \ catch (ExpectedExceptionType const&) { caught_ = true; } \ - catch (...) {} \ + catch (...) {} \ if (!caught_) \ - UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), "Expected exception: \"" #ExpectedExceptionType "\" not thrown"); \ + UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), "Expected exception: \"" #ExpectedExceptionType "\" not thrown"); \ } while(0) +#endif + #define CHECK_ASSERT(expression) \ CHECK_THROW(expression, UnitTest::AssertException); diff --git a/src/Config.h b/src/Config.h index cb43d91..7cdaa5c 100644 --- a/src/Config.h +++ b/src/Config.h @@ -28,4 +28,6 @@ //#define UNITTEST_USE_CUSTOM_STREAMS +#define UNITTEST_USE_EXCEPTIONS + #endif diff --git a/src/ExceptionMacros.h b/src/ExceptionMacros.h new file mode 100644 index 0000000..f10e780 --- /dev/null +++ b/src/ExceptionMacros.h @@ -0,0 +1,18 @@ +#ifndef UNITTEST_EXCEPTIONMACROS_H +#define UNITTEST_EXCEPTIONMACROS_H + +#include "Config.h" + +#ifdef UNITTEST_USE_EXCEPTIONS + #define UT_TRY(x) try x + #define UT_THROW(x) throw x + #define UT_CATCH(ExceptionType, ExceptionName, CatchBody) catch(ExceptionType& ExceptionName) CatchBody + #define UT_CATCH_ALL(CatchBody) catch(...) CatchBody +#else + #define UT_TRY(x) x + #define UT_THROW(x) + #define UT_CATCH(ExceptionType, ExceptionName, CatchBody) + #define UT_CATCH_ALL(CatchBody) +#endif + +#endif diff --git a/src/tests/TestCheckMacros.cpp b/src/tests/TestCheckMacros.cpp index 8a38099..a30d86a 100644 --- a/src/tests/TestCheckMacros.cpp +++ b/src/tests/TestCheckMacros.cpp @@ -62,37 +62,6 @@ TEST(CheckFailureIncludesCheckContents) CHECK(strstr(reporter.lastFailedMessage, "yaddayadda")); } -int ThrowingFunction() -{ - throw "Doh"; -} - -TEST(CheckFailsOnException) -{ - bool failure = false; - { - RecordingReporter reporter; - UnitTest::TestResults testResults(&reporter); - ScopedCurrentTest scopedResults(testResults); - CHECK(ThrowingFunction() == 1); - failure = (testResults.GetFailureCount() > 0); - } - - CHECK(failure); -} - -TEST(CheckFailureBecauseOfExceptionIncludesCheckContents) -{ - RecordingReporter reporter; - { - UnitTest::TestResults testResults(&reporter); - ScopedCurrentTest scopedResults(testResults); - CHECK(ThrowingFunction() == 1); - } - - CHECK(strstr(reporter.lastFailedMessage, "ThrowingFunction() == 1")); -} - TEST(CheckEqualSucceedsOnEqual) { bool failure = true; @@ -121,20 +90,6 @@ TEST(CheckEqualFailsOnNotEqual) CHECK(failure); } -TEST(CheckEqualFailsOnException) -{ - bool failure = false; - { - RecordingReporter reporter; - UnitTest::TestResults testResults(&reporter); - ScopedCurrentTest scopedResults(testResults); - CHECK_EQUAL(ThrowingFunction(), 1); - failure = (testResults.GetFailureCount() > 0); - } - - CHECK(failure); -} - TEST(CheckEqualFailureContainsCorrectDetails) { int line = 0; @@ -153,37 +108,6 @@ TEST(CheckEqualFailureContainsCorrectDetails) CHECK_EQUAL(line, reporter.lastFailedLine); } -TEST(CheckEqualFailureBecauseOfExceptionContainsCorrectDetails) -{ - int line = 0; - RecordingReporter reporter; - { - UnitTest::TestResults testResults(&reporter); - UnitTest::TestDetails const testDetails("testName", "suiteName", "filename", -1); - ScopedCurrentTest scopedResults(testResults, &testDetails); - - CHECK_EQUAL(ThrowingFunction(), 123); line = __LINE__; - } - - CHECK_EQUAL("testName", reporter.lastFailedTest); - CHECK_EQUAL("suiteName", reporter.lastFailedSuite); - CHECK_EQUAL("filename", reporter.lastFailedFile); - CHECK_EQUAL(line, reporter.lastFailedLine); -} - -TEST(CheckEqualFailureBecauseOfExceptionIncludesCheckContents) -{ - RecordingReporter reporter; - { - UnitTest::TestResults testResults(&reporter); - ScopedCurrentTest scopedResults(testResults); - CHECK_EQUAL(ThrowingFunction(), 123); - } - - CHECK(strstr(reporter.lastFailedMessage, "ThrowingFunction()")); - CHECK(strstr(reporter.lastFailedMessage, "123")); -} - int g_sideEffect = 0; int FunctionWithSideEffects() { @@ -242,20 +166,6 @@ TEST(CheckCloseFailsOnNotEqual) CHECK(failure); } -TEST(CheckCloseFailsOnException) -{ - bool failure = false; - { - RecordingReporter reporter; - UnitTest::TestResults testResults(&reporter); - ScopedCurrentTest scopedResults(testResults); - CHECK_CLOSE ((float)ThrowingFunction(), 1.0001f, 0.1f); - failure = (testResults.GetFailureCount() > 0); - } - - CHECK(failure); -} - TEST(CheckCloseFailureContainsCorrectDetails) { int line = 0; @@ -274,36 +184,6 @@ TEST(CheckCloseFailureContainsCorrectDetails) CHECK_EQUAL(line, reporter.lastFailedLine); } -TEST(CheckCloseFailureBecauseOfExceptionContainsCorrectDetails) -{ - int line = 0; - RecordingReporter reporter; - { - UnitTest::TestResults testResults(&reporter); - UnitTest::TestDetails testDetails("closeTest", "closeSuite", "filename", -1); - ScopedCurrentTest scopedResults(testResults, &testDetails); - CHECK_CLOSE ((float)ThrowingFunction(), 1.0001f, 0.1f); line = __LINE__; - } - - CHECK_EQUAL("closeTest", reporter.lastFailedTest); - CHECK_EQUAL("closeSuite", reporter.lastFailedSuite); - CHECK_EQUAL("filename", reporter.lastFailedFile); - CHECK_EQUAL(line, reporter.lastFailedLine); -} - -TEST(CheckCloseFailureBecauseOfExceptionIncludesCheckContents) -{ - RecordingReporter reporter; - { - UnitTest::TestResults testResults(&reporter); - ScopedCurrentTest scopedResults(testResults); - CHECK_CLOSE ((float)ThrowingFunction(), 1.0001f, 0.1f); - } - - CHECK(strstr(reporter.lastFailedMessage, "(float)ThrowingFunction()")); - CHECK(strstr(reporter.lastFailedMessage, "1.0001f")); -} - TEST(CheckCloseDoesNotHaveSideEffectsWhenPassing) { g_sideEffect = 0; @@ -406,25 +286,6 @@ TEST(CheckArrayCloseFailureContainsCorrectDetails) CHECK_EQUAL(line, reporter.lastFailedLine); } -TEST(CheckArrayCloseFailureBecauseOfExceptionContainsCorrectDetails) -{ - int line = 0; - RecordingReporter reporter; - { - UnitTest::TestResults testResults(&reporter); - UnitTest::TestDetails testDetails("arrayCloseTest", "arrayCloseSuite", "filename", -1); - ScopedCurrentTest scopedResults(testResults, &testDetails); - - int const data[4] = { 0, 1, 2, 3 }; - CHECK_ARRAY_CLOSE (data, ThrowingObject(), 4, 0.01f); line = __LINE__; - } - - CHECK_EQUAL("arrayCloseTest", reporter.lastFailedTest); - CHECK_EQUAL("arrayCloseSuite", reporter.lastFailedSuite); - CHECK_EQUAL("filename", reporter.lastFailedFile); - CHECK_EQUAL(line, reporter.lastFailedLine); -} - TEST(CheckArrayCloseFailureIncludesTolerance) { RecordingReporter reporter; @@ -440,42 +301,6 @@ TEST(CheckArrayCloseFailureIncludesTolerance) CHECK(strstr(reporter.lastFailedMessage, "0.01")); } - -TEST(CheckArrayCloseFailsOnException) -{ - bool failure = false; - { - RecordingReporter reporter; - UnitTest::TestResults testResults(&reporter); - ScopedCurrentTest scopedResults(testResults); - - const float data[4] = { 0, 1, 2, 3 }; - ThrowingObject obj; - CHECK_ARRAY_CLOSE (data, obj, 3, 0.01f); - - failure = (testResults.GetFailureCount() > 0); - } - - CHECK(failure); -} - -TEST(CheckArrayCloseFailureOnExceptionIncludesCheckContents) -{ - RecordingReporter reporter; - { - UnitTest::TestResults testResults(&reporter); - ScopedCurrentTest scopedResults(testResults); - - const float data[4] = { 0, 1, 2, 3 }; - ThrowingObject obj; - CHECK_ARRAY_CLOSE (data, obj, 3, 0.01f); - } - - CHECK(strstr(reporter.lastFailedMessage, "data")); - CHECK(strstr(reporter.lastFailedMessage, "obj")); -} - - TEST(CheckArrayEqualSuceedsOnEqual) { bool failure = true; @@ -545,40 +370,6 @@ TEST(CheckArrayEqualFailureContainsCorrectInfo) CHECK_EQUAL(line, reporter.lastFailedLine); } -TEST(CheckArrayEqualFailsOnException) -{ - bool failure = false; - { - RecordingReporter reporter; - UnitTest::TestResults testResults(&reporter); - ScopedCurrentTest scopedResults(testResults); - - const float data[4] = { 0, 1, 2, 3 }; - ThrowingObject obj; - CHECK_ARRAY_EQUAL (data, obj, 3); - - failure = (testResults.GetFailureCount() > 0); - } - - CHECK(failure); -} - -TEST(CheckArrayEqualFailureOnExceptionIncludesCheckContents) -{ - RecordingReporter reporter; - { - UnitTest::TestResults testResults(&reporter); - ScopedCurrentTest scopedResults(testResults); - - const float data[4] = { 0, 1, 2, 3 }; - ThrowingObject obj; - CHECK_ARRAY_EQUAL (data, obj, 3); - } - - CHECK(strstr(reporter.lastFailedMessage, "data")); - CHECK(strstr(reporter.lastFailedMessage, "obj")); -} - float const* FunctionWithSideEffects2() { ++g_sideEffect; @@ -695,25 +486,6 @@ TEST(CheckArray2DCloseFailureContainsCorrectDetails) CHECK_EQUAL(line, reporter.lastFailedLine); } -TEST(CheckArray2DCloseFailureBecauseOfExceptionContainsCorrectDetails) -{ - int line = 0; - RecordingReporter reporter; - { - UnitTest::TestResults testResults(&reporter); - UnitTest::TestDetails testDetails("array2DCloseTest", "array2DCloseSuite", "filename", -1); - ScopedCurrentTest scopedResults(testResults, &testDetails); - - const float data[2][2] = { {0, 1}, {2, 3} }; - CHECK_ARRAY2D_CLOSE (data, ThrowingObject2D(), 2, 2, 0.01f); line = __LINE__; - } - - CHECK_EQUAL("array2DCloseTest", reporter.lastFailedTest); - CHECK_EQUAL("array2DCloseSuite", reporter.lastFailedSuite); - CHECK_EQUAL("filename", reporter.lastFailedFile); - CHECK_EQUAL(line, reporter.lastFailedLine); -} - TEST(CheckArray2DCloseFailureIncludesTolerance) { RecordingReporter reporter; @@ -729,40 +501,6 @@ TEST(CheckArray2DCloseFailureIncludesTolerance) CHECK(strstr(reporter.lastFailedMessage, "0.01")); } -TEST(CheckArray2DCloseFailsOnException) -{ - bool failure = false; - { - RecordingReporter reporter; - UnitTest::TestResults testResults(&reporter); - ScopedCurrentTest scopedResults(testResults); - - const float data[2][2] = { {0, 1}, {2, 3} }; - ThrowingObject2D obj; - CHECK_ARRAY2D_CLOSE (data, obj, 2, 2, 0.01f); - - failure = (testResults.GetFailureCount() > 0); - } - - CHECK(failure); -} - -TEST(CheckArray2DCloseFailureOnExceptionIncludesCheckContents) -{ - RecordingReporter reporter; - { - UnitTest::TestResults testResults(&reporter); - ScopedCurrentTest scopedResults(testResults); - - const float data[2][2] = { {0, 1}, {2, 3} }; - ThrowingObject2D obj; - CHECK_ARRAY2D_CLOSE (data, obj, 2, 2, 0.01f); - } - - CHECK(strstr(reporter.lastFailedMessage, "data")); - CHECK(strstr(reporter.lastFailedMessage, "obj")); -} - float const* const* FunctionWithSideEffects3() { ++g_sideEffect; diff --git a/src/tests/TestExceptions.cpp b/src/tests/TestExceptions.cpp new file mode 100644 index 0000000..1c4349a --- /dev/null +++ b/src/tests/TestExceptions.cpp @@ -0,0 +1,302 @@ +#include "../Config.h" + +#ifdef UNITTEST_USE_EXCEPTIONS + +#include "../unittestpp.h" +#include "../CurrentTest.h" +#include "RecordingReporter.h" +#include "ScopedCurrentTest.h" + +using namespace std; + +namespace { + +int ThrowingFunction() +{ + throw "Doh"; +} + +TEST(CheckFailsOnException) +{ + bool failure = false; + { + RecordingReporter reporter; + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + CHECK(ThrowingFunction() == 1); + failure = (testResults.GetFailureCount() > 0); + } + + CHECK(failure); +} + +TEST(CheckFailureBecauseOfExceptionIncludesCheckContents) +{ + RecordingReporter reporter; + { + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + CHECK(ThrowingFunction() == 1); + } + + CHECK(strstr(reporter.lastFailedMessage, "ThrowingFunction() == 1")); +} + +TEST(CheckEqualFailsOnException) +{ + bool failure = false; + { + RecordingReporter reporter; + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + CHECK_EQUAL(ThrowingFunction(), 1); + failure = (testResults.GetFailureCount() > 0); + } + + CHECK(failure); +} + +TEST(CheckEqualFailureBecauseOfExceptionContainsCorrectDetails) +{ + int line = 0; + RecordingReporter reporter; + { + UnitTest::TestResults testResults(&reporter); + UnitTest::TestDetails const testDetails("testName", "suiteName", "filename", -1); + ScopedCurrentTest scopedResults(testResults, &testDetails); + + CHECK_EQUAL(ThrowingFunction(), 123); line = __LINE__; + } + + CHECK_EQUAL("testName", reporter.lastFailedTest); + CHECK_EQUAL("suiteName", reporter.lastFailedSuite); + CHECK_EQUAL("filename", reporter.lastFailedFile); + CHECK_EQUAL(line, reporter.lastFailedLine); +} + +TEST(CheckEqualFailureBecauseOfExceptionIncludesCheckContents) +{ + RecordingReporter reporter; + { + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + CHECK_EQUAL(ThrowingFunction(), 123); + } + + CHECK(strstr(reporter.lastFailedMessage, "ThrowingFunction()")); + CHECK(strstr(reporter.lastFailedMessage, "123")); +} + +TEST(CheckCloseFailsOnException) +{ + bool failure = false; + { + RecordingReporter reporter; + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + CHECK_CLOSE ((float)ThrowingFunction(), 1.0001f, 0.1f); + failure = (testResults.GetFailureCount() > 0); + } + + CHECK(failure); +} + +TEST(CheckCloseFailureBecauseOfExceptionContainsCorrectDetails) +{ + int line = 0; + RecordingReporter reporter; + { + UnitTest::TestResults testResults(&reporter); + UnitTest::TestDetails testDetails("closeTest", "closeSuite", "filename", -1); + ScopedCurrentTest scopedResults(testResults, &testDetails); + CHECK_CLOSE ((float)ThrowingFunction(), 1.0001f, 0.1f); line = __LINE__; + } + + CHECK_EQUAL("closeTest", reporter.lastFailedTest); + CHECK_EQUAL("closeSuite", reporter.lastFailedSuite); + CHECK_EQUAL("filename", reporter.lastFailedFile); + CHECK_EQUAL(line, reporter.lastFailedLine); +} + +TEST(CheckCloseFailureBecauseOfExceptionIncludesCheckContents) +{ + RecordingReporter reporter; + { + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + CHECK_CLOSE ((float)ThrowingFunction(), 1.0001f, 0.1f); + } + + CHECK(strstr(reporter.lastFailedMessage, "(float)ThrowingFunction()")); + CHECK(strstr(reporter.lastFailedMessage, "1.0001f")); +} + +class ThrowingObject +{ +public: + float operator[](int) const + { + throw "Test throw"; + } +}; + +TEST(CheckArrayCloseFailureBecauseOfExceptionContainsCorrectDetails) +{ + int line = 0; + RecordingReporter reporter; + { + UnitTest::TestResults testResults(&reporter); + UnitTest::TestDetails testDetails("arrayCloseTest", "arrayCloseSuite", "filename", -1); + ScopedCurrentTest scopedResults(testResults, &testDetails); + + int const data[4] = { 0, 1, 2, 3 }; + CHECK_ARRAY_CLOSE (data, ThrowingObject(), 4, 0.01f); line = __LINE__; + } + + CHECK_EQUAL("arrayCloseTest", reporter.lastFailedTest); + CHECK_EQUAL("arrayCloseSuite", reporter.lastFailedSuite); + CHECK_EQUAL("filename", reporter.lastFailedFile); + CHECK_EQUAL(line, reporter.lastFailedLine); +} + +TEST(CheckArrayCloseFailsOnException) +{ + bool failure = false; + { + RecordingReporter reporter; + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + const float data[4] = { 0, 1, 2, 3 }; + ThrowingObject obj; + CHECK_ARRAY_CLOSE (data, obj, 3, 0.01f); + + failure = (testResults.GetFailureCount() > 0); + } + + CHECK(failure); +} + +TEST(CheckArrayCloseFailureOnExceptionIncludesCheckContents) +{ + RecordingReporter reporter; + { + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + const float data[4] = { 0, 1, 2, 3 }; + ThrowingObject obj; + CHECK_ARRAY_CLOSE (data, obj, 3, 0.01f); + } + + CHECK(strstr(reporter.lastFailedMessage, "data")); + CHECK(strstr(reporter.lastFailedMessage, "obj")); +} + +TEST(CheckArrayEqualFailsOnException) +{ + bool failure = false; + { + RecordingReporter reporter; + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + const float data[4] = { 0, 1, 2, 3 }; + ThrowingObject obj; + CHECK_ARRAY_EQUAL (data, obj, 3); + + failure = (testResults.GetFailureCount() > 0); + } + + CHECK(failure); +} + +TEST(CheckArrayEqualFailureOnExceptionIncludesCheckContents) +{ + RecordingReporter reporter; + { + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + const float data[4] = { 0, 1, 2, 3 }; + ThrowingObject obj; + CHECK_ARRAY_EQUAL (data, obj, 3); + } + + CHECK(strstr(reporter.lastFailedMessage, "data")); + CHECK(strstr(reporter.lastFailedMessage, "obj")); +} + +int g_sideEffect = 0; +float const* FunctionWithSideEffects2() +{ + ++g_sideEffect; + static float const data[] = {1,2,3,4}; + return data; +} + +class ThrowingObject2D +{ +public: + float* operator[](int) const + { + throw "Test throw"; + } +}; + +TEST(CheckArray2DCloseFailureBecauseOfExceptionContainsCorrectDetails) +{ + int line = 0; + RecordingReporter reporter; + { + UnitTest::TestResults testResults(&reporter); + UnitTest::TestDetails testDetails("array2DCloseTest", "array2DCloseSuite", "filename", -1); + ScopedCurrentTest scopedResults(testResults, &testDetails); + + const float data[2][2] = { {0, 1}, {2, 3} }; + CHECK_ARRAY2D_CLOSE (data, ThrowingObject2D(), 2, 2, 0.01f); line = __LINE__; + } + + CHECK_EQUAL("array2DCloseTest", reporter.lastFailedTest); + CHECK_EQUAL("array2DCloseSuite", reporter.lastFailedSuite); + CHECK_EQUAL("filename", reporter.lastFailedFile); + CHECK_EQUAL(line, reporter.lastFailedLine); +} + +TEST(CheckArray2DCloseFailsOnException) +{ + bool failure = false; + { + RecordingReporter reporter; + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + const float data[2][2] = { {0, 1}, {2, 3} }; + ThrowingObject2D obj; + CHECK_ARRAY2D_CLOSE (data, obj, 2, 2, 0.01f); + + failure = (testResults.GetFailureCount() > 0); + } + + CHECK(failure); +} + +TEST(CheckArray2DCloseFailureOnExceptionIncludesCheckContents) +{ + RecordingReporter reporter; + { + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + const float data[2][2] = { {0, 1}, {2, 3} }; + ThrowingObject2D obj; + CHECK_ARRAY2D_CLOSE (data, obj, 2, 2, 0.01f); + } + + CHECK(strstr(reporter.lastFailedMessage, "data")); + CHECK(strstr(reporter.lastFailedMessage, "obj")); +} + +} + +#endif diff --git a/src/tests/TestUnitTestPP.cpp b/src/tests/TestUnitTestPP.cpp index b62d1c9..b8e325b 100644 --- a/src/tests/TestUnitTestPP.cpp +++ b/src/tests/TestUnitTestPP.cpp @@ -56,6 +56,8 @@ TEST (CheckArrayCloseWorksWithVectors) CHECK_ARRAY_CLOSE(a, a, (int)a.size(), 0.0001f); } +#ifdef UNITTEST_USE_EXCEPTIONS + TEST(CheckThrowMacroSucceedsOnCorrectException) { struct TestException {}; @@ -117,6 +119,8 @@ TEST(CheckThrowMacroFailsOnWrongException) CHECK_EQUAL(1, results.GetFailureCount()); } +#endif + struct SimpleFixture { SimpleFixture() From 4f556d65391f440cbc606c439d677f62d7975525 Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Wed, 9 Jan 2013 23:42:29 -0600 Subject: [PATCH 03/30] r4 | charles.nicholson | 2010-03-08 23:23:36 -0600 (Mon, 08 Mar 2010) | 1 line all try/catch calls are either #ifdefd out or replaced with UT_TRY/UT_CATCH macro madness --- src/Config.h | 3 +-- src/ExecuteTest.h | 33 ++++++++++++++++++++------------- src/Posix/SignalTranslator.h | 2 +- src/TestMacros.h | 27 +++++++++++++++------------ src/tests/TestAssertHandler.cpp | 7 ++++++- src/tests/TestTest.cpp | 4 ++-- src/tests/TestTestMacros.cpp | 8 ++++++++ src/tests/TestUnitTestPP.cpp | 11 ----------- 8 files changed, 53 insertions(+), 42 deletions(-) diff --git a/src/Config.h b/src/Config.h index 7cdaa5c..f223558 100644 --- a/src/Config.h +++ b/src/Config.h @@ -26,8 +26,7 @@ // by default, MemoryOutStream is implemented in terms of std::ostringstream, which can be expensive. // uncomment this line to use the custom MemoryOutStream (no deps on std::ostringstream). -//#define UNITTEST_USE_CUSTOM_STREAMS - +#define UNITTEST_USE_CUSTOM_STREAMS #define UNITTEST_USE_EXCEPTIONS #endif diff --git a/src/ExecuteTest.h b/src/ExecuteTest.h index 3ccd426..c09eca2 100644 --- a/src/ExecuteTest.h +++ b/src/ExecuteTest.h @@ -1,6 +1,7 @@ #ifndef UNITTEST_EXECUTE_TEST_H #define UNITTEST_EXECUTE_TEST_H +#include "ExceptionMacros.h" #include "TestDetails.h" #include "MemoryOutStream.h" #include "AssertException.h" @@ -17,28 +18,34 @@ void ExecuteTest(T& testObject, TestDetails const& details) { CurrentTest::Details() = &details; - try - { -#ifdef UNITTEST_POSIX - UNITTEST_THROW_SIGNALS -#endif +#ifndef UNITTEST_POSIX + UT_TRY + ({ + testObject.RunImpl(); + }) +#else + UT_TRY + ({ + UNITTEST_THROW_SIGNALS_POSIX_ONLY testObject.RunImpl(); - } - catch (AssertException const& e) + }) +#endif + + UT_CATCH(AssertException, e, { CurrentTest::Results()->OnTestFailure( TestDetails(details.testName, details.suiteName, e.Filename(), e.LineNumber()), e.what()); - } - catch (std::exception const& e) + }) + UT_CATCH(std::exception, e, { MemoryOutStream stream; stream << "Unhandled exception: " << e.what(); CurrentTest::Results()->OnTestFailure(details, stream.GetText()); - } - catch (...) - { + }) + UT_CATCH_ALL + ({ CurrentTest::Results()->OnTestFailure(details, "Unhandled exception: Crash!"); - } + }) } } diff --git a/src/Posix/SignalTranslator.h b/src/Posix/SignalTranslator.h index f3c3563..2152b9c 100644 --- a/src/Posix/SignalTranslator.h +++ b/src/Posix/SignalTranslator.h @@ -32,7 +32,7 @@ class SignalTranslator #define UNITTEST_EXTENSION __extension__ #endif -#define UNITTEST_THROW_SIGNALS \ +#define UNITTEST_THROW_SIGNALS_POSIX_ONLY \ UnitTest::SignalTranslator sig; \ if (UNITTEST_EXTENSION sigsetjmp(*UnitTest::SignalTranslator::s_jumpTarget, 1) != 0) \ throw ("Unhandled system exception"); diff --git a/src/TestMacros.h b/src/TestMacros.h index 8d29f04..16520e8 100644 --- a/src/TestMacros.h +++ b/src/TestMacros.h @@ -2,13 +2,14 @@ #define UNITTEST_TESTMACROS_H #include "Config.h" +#include "ExceptionMacros.h" #include "ExecuteTest.h" #include "AssertException.h" #include "TestDetails.h" #include "MemoryOutStream.h" #ifndef UNITTEST_POSIX - #define UNITTEST_THROW_SIGNALS + #define UNITTEST_THROW_SIGNALS_POSIX_ONLY #else #include "Posix/SignalTranslator.h" #endif @@ -77,22 +78,24 @@ void Test##Fixture##Name::RunImpl() const \ { \ bool ctorOk = false; \ - try { \ + UT_TRY \ + ({ \ Fixture##Name##Helper fixtureHelper(m_details); \ ctorOk = true; \ - UnitTest::ExecuteTest(fixtureHelper, m_details); \ - } \ - catch (UnitTest::AssertException const& e) \ - { \ + UnitTest::ExecuteTest(fixtureHelper, m_details); \ + }) \ + UT_CATCH (UnitTest::AssertException, e, \ + { \ UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(m_details.testName, m_details.suiteName, e.Filename(), e.LineNumber()), e.what()); \ - } \ - catch (std::exception const& e) \ - { \ + }) \ + UT_CATCH (std::exception, e, \ + { \ UnitTest::MemoryOutStream stream; \ stream << "Unhandled exception: " << e.what(); \ UnitTest::CurrentTest::Results()->OnTestFailure(m_details, stream.GetText()); \ - } \ - catch (...) { \ + }) \ + UT_CATCH_ALL \ + ({ \ if (ctorOk) \ { \ UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(m_details, __LINE__), \ @@ -103,7 +106,7 @@ UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(m_details, __LINE__), \ "Unhandled exception while constructing fixture " #Fixture); \ } \ - } \ + }) \ } \ void Fixture##Name##Helper::RunImpl() diff --git a/src/tests/TestAssertHandler.cpp b/src/tests/TestAssertHandler.cpp index bd7cbea..664a670 100644 --- a/src/tests/TestAssertHandler.cpp +++ b/src/tests/TestAssertHandler.cpp @@ -1,3 +1,7 @@ +#include "../Config.h" + +#ifdef UNITTEST_USE_EXCEPTIONS + #include "../unittestpp.h" #include "../AssertException.h" #include "../ReportAssert.h" @@ -40,5 +44,6 @@ TEST(ReportAssertSetsCorrectInfoInException) } } - } + +#endif diff --git a/src/tests/TestTest.cpp b/src/tests/TestTest.cpp index 92e4f0a..cc48884 100644 --- a/src/tests/TestTest.cpp +++ b/src/tests/TestTest.cpp @@ -50,7 +50,7 @@ TEST(FailingTestHasFailures) CHECK_EQUAL(1, results.GetFailureCount()); } - +#ifdef UNITTEST_USE_EXCEPTIONS TEST(ThrowingTestsAreReportedAsFailures) { class CrashingTest : public Test @@ -72,7 +72,6 @@ TEST(ThrowingTestsAreReportedAsFailures) CHECK_EQUAL(1, results.GetFailureCount()); } - #ifndef UNITTEST_MINGW TEST(CrashingTestsAreReportedAsFailures) { @@ -95,6 +94,7 @@ TEST(CrashingTestsAreReportedAsFailures) CHECK_EQUAL(1, results.GetFailureCount()); } #endif +#endif TEST(TestWithUnspecifiedSuiteGetsDefaultSuite) { diff --git a/src/tests/TestTestMacros.cpp b/src/tests/TestTestMacros.cpp index 1149b0c..a1506e5 100644 --- a/src/tests/TestTestMacros.cpp +++ b/src/tests/TestTestMacros.cpp @@ -22,6 +22,8 @@ TEST (TestsAreAddedToTheListThroughMacro) CHECK(list1.GetHead()->next == 0); } +#ifdef UNITTEST_USE_EXCEPTIONS + struct ThrowingThingie { ThrowingThingie() : dummy(false) @@ -52,6 +54,8 @@ TEST (ExceptionsInFixtureAreReportedAsHappeningInTheFixture) CHECK(strstr(reporter.lastFailedMessage, "ThrowingThingie")); } +#endif + struct DummyFixture { int x; @@ -104,6 +108,8 @@ TEST(TestAddedWithTEST_FIXTURE_EXMacroGetsDefaultSuite) CHECK_EQUAL ("DefaultSuite", macroTestList2.GetHead()->m_details.suiteName); } +#ifdef UNITTEST_USE_EXCEPTIONS + struct FixtureCtorThrows { FixtureCtorThrows() { throw "exception"; } @@ -185,6 +191,8 @@ TEST(CorrectlyReportsFixturesWithCtorsThatAssert) CHECK(strstr(reporter.lastFailedMessage, "assert failure")); } +#endif + } // We're really testing if it's possible to use the same suite in two files diff --git a/src/tests/TestUnitTestPP.cpp b/src/tests/TestUnitTestPP.cpp index b8e325b..9237aa9 100644 --- a/src/tests/TestUnitTestPP.cpp +++ b/src/tests/TestUnitTestPP.cpp @@ -2,8 +2,6 @@ #include "../ReportAssert.h" #include "ScopedCurrentTest.h" -#include - // These are sample tests that show the different features of the framework namespace { @@ -47,15 +45,6 @@ TEST(ArrayCloseSucceeds) CHECK_ARRAY_CLOSE(a1, a2, 3, 0.1f); } -TEST (CheckArrayCloseWorksWithVectors) -{ - std::vector< float > a(4); - for (int i = 0; i < 4; ++i) - a[i] = (float)i; - - CHECK_ARRAY_CLOSE(a, a, (int)a.size(), 0.0001f); -} - #ifdef UNITTEST_USE_EXCEPTIONS TEST(CheckThrowMacroSucceedsOnCorrectException) From 23c7368d9288d911b58f595f7e747a881b74b786 Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Wed, 9 Jan 2013 23:42:35 -0600 Subject: [PATCH 04/30] r5 | charles.nicholson | 2010-03-15 17:46:01 -0500 (Mon, 15 Mar 2010) | 1 line remove leftover exception test structures, fix ReportAssert for no-exceptions build --- src/AssertException.cpp | 9 +++++++-- src/AssertException.h | 11 ++++++++--- src/Config.h | 2 +- src/ReportAssert.cpp | 28 +++++++++++++++++----------- src/tests/TestCheckMacros.cpp | 21 --------------------- 5 files changed, 33 insertions(+), 38 deletions(-) diff --git a/src/AssertException.cpp b/src/AssertException.cpp index cd3c51c..0ac4484 100644 --- a/src/AssertException.cpp +++ b/src/AssertException.cpp @@ -1,4 +1,7 @@ #include "AssertException.h" + +#ifdef UNITTEST_USE_EXCEPTIONS + #include namespace UnitTest { @@ -12,11 +15,11 @@ AssertException::AssertException(char const* description, char const* filename, strcpy(m_filename, filename); } -AssertException::~AssertException() throw() +AssertException::~AssertException() { } -char const* AssertException::what() const throw() +char const* AssertException::what() const { return m_description; } @@ -32,3 +35,5 @@ int AssertException::LineNumber() const } } + +#endif diff --git a/src/AssertException.h b/src/AssertException.h index 9c268fc..72200c8 100644 --- a/src/AssertException.h +++ b/src/AssertException.h @@ -1,8 +1,11 @@ #ifndef UNITTEST_ASSERTEXCEPTION_H #define UNITTEST_ASSERTEXCEPTION_H -#include +#include "Config.h" + +#ifdef UNITTEST_USE_EXCEPTIONS +#include namespace UnitTest { @@ -10,9 +13,9 @@ class AssertException : public std::exception { public: AssertException(char const* description, char const* filename, int lineNumber); - virtual ~AssertException() throw(); + virtual ~AssertException(); - virtual char const* what() const throw(); + virtual char const* what() const; char const* Filename() const; int LineNumber() const; @@ -26,3 +29,5 @@ class AssertException : public std::exception } #endif + +#endif diff --git a/src/Config.h b/src/Config.h index f223558..a1f12ba 100644 --- a/src/Config.h +++ b/src/Config.h @@ -27,6 +27,6 @@ // uncomment this line to use the custom MemoryOutStream (no deps on std::ostringstream). #define UNITTEST_USE_CUSTOM_STREAMS -#define UNITTEST_USE_EXCEPTIONS +//#define UNITTEST_USE_EXCEPTIONS #endif diff --git a/src/ReportAssert.cpp b/src/ReportAssert.cpp index c91f4f6..0386b62 100644 --- a/src/ReportAssert.cpp +++ b/src/ReportAssert.cpp @@ -1,11 +1,17 @@ -#include "ReportAssert.h" -#include "AssertException.h" - -namespace UnitTest { - -void ReportAssert(char const* description, char const* filename, int lineNumber) -{ - throw AssertException(description, filename, lineNumber); -} - -} +#include "ReportAssert.h" +#include "AssertException.h" + +namespace UnitTest { + +void ReportAssert(char const* description, char const* filename, int lineNumber) +{ + (void)description; + (void)filename; + (void)lineNumber; + +#ifdef UNITTEST_USE_EXCEPTIONS + throw AssertException(description, filename, lineNumber); +#endif +} + +} diff --git a/src/tests/TestCheckMacros.cpp b/src/tests/TestCheckMacros.cpp index a30d86a..33fdc44 100644 --- a/src/tests/TestCheckMacros.cpp +++ b/src/tests/TestCheckMacros.cpp @@ -206,17 +206,6 @@ TEST(CheckCloseDoesNotHaveSideEffectsWhenFailing) CHECK_EQUAL(1, g_sideEffect); } - -class ThrowingObject -{ -public: - float operator[](int) const - { - throw "Test throw"; - } -}; - - TEST(CheckArrayCloseSucceedsOnEqual) { bool failure = true; @@ -404,16 +393,6 @@ TEST(CheckArrayCloseDoesNotHaveSideEffectsWhenFailing) CHECK_EQUAL(1, g_sideEffect); } -class ThrowingObject2D -{ -public: - float* operator[](int) const - { - throw "Test throw"; - } -}; - - TEST(CheckArray2DCloseSucceedsOnEqual) { bool failure = true; From 6712ae184ad1c15f7e0a0ddfb52479131d20e200 Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Wed, 9 Jan 2013 23:42:44 -0600 Subject: [PATCH 05/30] r6 | charles.nicholson | 2010-03-15 19:03:04 -0500 (Mon, 15 Mar 2010) | 1 line pull in less win32 stuff in timehelpers, strip down top-level unittestpp.h --- src/TestMacros.h | 1 + src/Win32/TimeHelpers.cpp | 2 ++ src/unittestpp.h | 12 ++---------- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/TestMacros.h b/src/TestMacros.h index 16520e8..8aad30e 100644 --- a/src/TestMacros.h +++ b/src/TestMacros.h @@ -2,6 +2,7 @@ #define UNITTEST_TESTMACROS_H #include "Config.h" +#include "TestSuite.h" #include "ExceptionMacros.h" #include "ExecuteTest.h" #include "AssertException.h" diff --git a/src/Win32/TimeHelpers.cpp b/src/Win32/TimeHelpers.cpp index 4bb5bcf..2f6f5f7 100644 --- a/src/Win32/TimeHelpers.cpp +++ b/src/Win32/TimeHelpers.cpp @@ -1,4 +1,6 @@ #include "TimeHelpers.h" + +#define WIN32_LEAN_AND_MEAN #include namespace UnitTest { diff --git a/src/unittestpp.h b/src/unittestpp.h index bacc4cf..7e0d893 100644 --- a/src/unittestpp.h +++ b/src/unittestpp.h @@ -1,16 +1,8 @@ -#ifndef UNITTESTCPP_H -#define UNITTESTCPP_H - -//lint -esym(1509,*Fixture) +#ifndef UNITTESTPP_H +#define UNITTESTPP_H #include "Config.h" -#include "Test.h" -#include "TestList.h" -#include "TestSuite.h" -#include "TestResults.h" - #include "TestMacros.h" - #include "CheckMacros.h" #include "TestRunner.h" #include "TimeConstraint.h" From ab8b81859141a47c396171a51b8b91a3cdf07b34 Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Wed, 9 Jan 2013 23:42:51 -0600 Subject: [PATCH 06/30] r7 | charles.nicholson | 2010-03-16 16:18:18 -0500 (Tue, 16 Mar 2010) | 1 line add DeferredTestReporter and DeferredTestResult back in, conditional on UNITTEST_USE_DEFERRED_REPORTER --- src/Config.h | 3 +- src/DeferredTestReporter.cpp | 5 ++ src/DeferredTestReporter.h | 62 +++++++++++++----------- src/DeferredTestResult.cpp | 6 ++- src/DeferredTestResult.h | 67 ++++++++++++++------------ src/tests/TestDeferredTestReporter.cpp | 7 ++- 6 files changed, 86 insertions(+), 64 deletions(-) diff --git a/src/Config.h b/src/Config.h index a1f12ba..147f05f 100644 --- a/src/Config.h +++ b/src/Config.h @@ -27,6 +27,7 @@ // uncomment this line to use the custom MemoryOutStream (no deps on std::ostringstream). #define UNITTEST_USE_CUSTOM_STREAMS -//#define UNITTEST_USE_EXCEPTIONS +#define UNITTEST_USE_DEFERRED_REPORTER +#define UNITTEST_USE_EXCEPTIONS #endif diff --git a/src/DeferredTestReporter.cpp b/src/DeferredTestReporter.cpp index fbd08db..8b7a29c 100644 --- a/src/DeferredTestReporter.cpp +++ b/src/DeferredTestReporter.cpp @@ -1,3 +1,6 @@ +#include "Config.h" +#ifdef UNITTEST_USE_DEFERRED_REPORTER + #include "DeferredTestReporter.h" #include "TestDetails.h" @@ -26,3 +29,5 @@ DeferredTestReporter::DeferredTestResultList& DeferredTestReporter::GetResults() { return m_results; } + +#endif diff --git a/src/DeferredTestReporter.h b/src/DeferredTestReporter.h index 615a24e..c037af3 100644 --- a/src/DeferredTestReporter.h +++ b/src/DeferredTestReporter.h @@ -1,29 +1,33 @@ -#ifndef UNITTEST_DEFERREDTESTREPORTER_H -#define UNITTEST_DEFERREDTESTREPORTER_H - -#include "TestReporter.h" -#include "DeferredTestResult.h" -#include "Config.h" - -#include - -namespace UnitTest -{ - -class DeferredTestReporter : public TestReporter -{ -public: - virtual void ReportTestStart(TestDetails const& details); - virtual void ReportFailure(TestDetails const& details, char const* failure); - virtual void ReportTestFinish(TestDetails const& details, float secondsElapsed); - - typedef std::vector< DeferredTestResult > DeferredTestResultList; - DeferredTestResultList& GetResults(); - -private: - DeferredTestResultList m_results; -}; - -} - -#endif +#ifndef UNITTEST_DEFERREDTESTREPORTER_H +#define UNITTEST_DEFERREDTESTREPORTER_H + +#include "Config.h" + +#ifdef UNITTEST_USE_DEFERRED_REPORTER + +#include "TestReporter.h" +#include "DeferredTestResult.h" + +#include + +namespace UnitTest +{ + +class DeferredTestReporter : public TestReporter +{ +public: + virtual void ReportTestStart(TestDetails const& details); + virtual void ReportFailure(TestDetails const& details, char const* failure); + virtual void ReportTestFinish(TestDetails const& details, float secondsElapsed); + + typedef std::vector< DeferredTestResult > DeferredTestResultList; + DeferredTestResultList& GetResults(); + +private: + DeferredTestResultList m_results; +}; + +} + +#endif +#endif diff --git a/src/DeferredTestResult.cpp b/src/DeferredTestResult.cpp index 944f894..33fc145 100644 --- a/src/DeferredTestResult.cpp +++ b/src/DeferredTestResult.cpp @@ -1,5 +1,7 @@ -#include "DeferredTestResult.h" #include "Config.h" +#ifdef UNITTEST_USE_DEFERRED_REPORTER + +#include "DeferredTestResult.h" namespace UnitTest { @@ -27,3 +29,5 @@ DeferredTestResult::~DeferredTestResult() } } + +#endif diff --git a/src/DeferredTestResult.h b/src/DeferredTestResult.h index d0a1dab..db3ffaa 100644 --- a/src/DeferredTestResult.h +++ b/src/DeferredTestResult.h @@ -1,32 +1,35 @@ -#ifndef UNITTEST_DEFERREDTESTRESULT_H -#define UNITTEST_DEFERREDTESTRESULT_H - -#include "Config.h" - -#include -#include - -namespace UnitTest -{ - -struct DeferredTestResult -{ - DeferredTestResult(); - DeferredTestResult(char const* suite, char const* test); - ~DeferredTestResult(); - - std::string suiteName; - std::string testName; - std::string failureFile; - - typedef std::pair< int, std::string > Failure; - typedef std::vector< Failure > FailureVec; - FailureVec failures; - - float timeElapsed; - bool failed; -}; - -} - -#endif //UNITTEST_DEFERREDTESTRESULT_H +#ifndef UNITTEST_DEFERREDTESTRESULT_H +#define UNITTEST_DEFERREDTESTRESULT_H + +#include "Config.h" + +#ifdef UNITTEST_USE_DEFERRED_REPORTER + +#include +#include + +namespace UnitTest +{ + +struct DeferredTestResult +{ + DeferredTestResult(); + DeferredTestResult(char const* suite, char const* test); + ~DeferredTestResult(); + + std::string suiteName; + std::string testName; + std::string failureFile; + + typedef std::pair< int, std::string > Failure; + typedef std::vector< Failure > FailureVec; + FailureVec failures; + + float timeElapsed; + bool failed; +}; + +} + +#endif +#endif diff --git a/src/tests/TestDeferredTestReporter.cpp b/src/tests/TestDeferredTestReporter.cpp index 0b08919..fcdbd0f 100644 --- a/src/tests/TestDeferredTestReporter.cpp +++ b/src/tests/TestDeferredTestReporter.cpp @@ -1,6 +1,9 @@ +#include "../Config.h" + +#ifdef UNITTEST_USE_DEFERRED_REPORTER + #include "../unittestpp.h" #include "../DeferredTestReporter.h" -#include "../Config.h" #include namespace UnitTest @@ -115,3 +118,5 @@ TEST_FIXTURE(DeferredTestReporterFixture, DeferredTestReporterTakesCopyOfFailure } }} + +#endif From 3a40aa80a1c8f97c9b456f47ad4542b5fb000cc3 Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Wed, 9 Jan 2013 23:43:07 -0600 Subject: [PATCH 07/30] r8 | charles.nicholson | 2010-03-16 21:27:33 -0500 (Tue, 16 Mar 2010) | 1 line fixed bug where tests weren't correctly executing while testing the TestRunner (accessing the Details and Results singletons was redirecting failures to bogus RecordingReporters, instead of the real UT++ test engine). Hoisted assert failure reporting into ReportAssert, in preparation for setjmp/longjmp assert handling in the absence of exceptions. Slight renamings and cosmetic fixups --- src/AssertException.cpp | 24 +--------- src/AssertException.h | 12 +---- src/CheckMacros.h | 9 +++- src/ExecuteTest.h | 10 ++-- src/ReportAssert.cpp | 43 +++++++++++++++-- src/ReportAssert.h | 14 +++++- src/Test.cpp | 5 +- src/Test.h | 3 +- src/TestList.cpp | 2 +- src/TestMacros.h | 4 +- src/TestRunner.cpp | 10 +++- src/TestRunner.h | 6 ++- src/tests/TestAssertHandler.cpp | 84 ++++++++++++++++++++++++++++----- src/tests/TestTestList.cpp | 24 +++++----- src/tests/TestTestMacros.cpp | 2 +- src/tests/TestTestRunner.cpp | 42 ++++++++++------- 16 files changed, 196 insertions(+), 98 deletions(-) diff --git a/src/AssertException.cpp b/src/AssertException.cpp index 0ac4484..cc2c7e1 100644 --- a/src/AssertException.cpp +++ b/src/AssertException.cpp @@ -2,38 +2,16 @@ #ifdef UNITTEST_USE_EXCEPTIONS -#include - namespace UnitTest { -AssertException::AssertException(char const* description, char const* filename, int lineNumber) - : m_lineNumber(lineNumber) +AssertException::AssertException() { - using namespace std; - - strcpy(m_description, description); - strcpy(m_filename, filename); } AssertException::~AssertException() { } -char const* AssertException::what() const -{ - return m_description; -} - -char const* AssertException::Filename() const -{ - return m_filename; -} - -int AssertException::LineNumber() const -{ - return m_lineNumber; -} - } #endif diff --git a/src/AssertException.h b/src/AssertException.h index 72200c8..4603827 100644 --- a/src/AssertException.h +++ b/src/AssertException.h @@ -12,18 +12,8 @@ namespace UnitTest { class AssertException : public std::exception { public: - AssertException(char const* description, char const* filename, int lineNumber); + AssertException(); virtual ~AssertException(); - - virtual char const* what() const; - - char const* Filename() const; - int LineNumber() const; - -private: - char m_description[512]; - char m_filename[256]; - int m_lineNumber; }; } diff --git a/src/CheckMacros.h b/src/CheckMacros.h index 89384c3..5523b3c 100644 --- a/src/CheckMacros.h +++ b/src/CheckMacros.h @@ -130,10 +130,15 @@ if (!caught_) \ UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), "Expected exception: \"" #ExpectedExceptionType "\" not thrown"); \ } while(0) -#endif #define CHECK_ASSERT(expression) \ - CHECK_THROW(expression, UnitTest::AssertException); + do \ + { \ + UnitTest::ExpectAssert(true); \ + CHECK_THROW(expression, UnitTest::AssertException); \ + UnitTest::ExpectAssert(false); \ + } while(0) #endif +#endif diff --git a/src/ExecuteTest.h b/src/ExecuteTest.h index c09eca2..0c37eb3 100644 --- a/src/ExecuteTest.h +++ b/src/ExecuteTest.h @@ -14,9 +14,10 @@ namespace UnitTest { template< typename T > -void ExecuteTest(T& testObject, TestDetails const& details) +void ExecuteTest(T& testObject, TestDetails const& details, bool isMockTest) { - CurrentTest::Details() = &details; + if (isMockTest == false) + CurrentTest::Details() = &details; #ifndef UNITTEST_POSIX UT_TRY @@ -33,8 +34,7 @@ void ExecuteTest(T& testObject, TestDetails const& details) UT_CATCH(AssertException, e, { - CurrentTest::Results()->OnTestFailure( - TestDetails(details.testName, details.suiteName, e.Filename(), e.LineNumber()), e.what()); + (void)e; }) UT_CATCH(std::exception, e, { @@ -44,7 +44,7 @@ void ExecuteTest(T& testObject, TestDetails const& details) }) UT_CATCH_ALL ({ - CurrentTest::Results()->OnTestFailure(details, "Unhandled exception: Crash!"); + CurrentTest::Results()->OnTestFailure(details, "Unhandled exception: test crashed"); }) } diff --git a/src/ReportAssert.cpp b/src/ReportAssert.cpp index 0386b62..fb4d043 100644 --- a/src/ReportAssert.cpp +++ b/src/ReportAssert.cpp @@ -1,17 +1,52 @@ #include "ReportAssert.h" #include "AssertException.h" +#include "CurrentTest.h" +#include "TestResults.h" +#include "TestDetails.h" namespace UnitTest { +namespace +{ + bool& AssertExpectedFlag() + { + static bool s_assertExpected = false; + return s_assertExpected; + } +} + void ReportAssert(char const* description, char const* filename, int lineNumber) { - (void)description; - (void)filename; - (void)lineNumber; + ReportAssertEx(CurrentTest::Results(), CurrentTest::Details(), description, filename, lineNumber); +} + +void ReportAssertEx(TestResults* testResults, + const TestDetails* testDetails, + char const* description, + char const* filename, + int lineNumber) +{ + if (AssertExpectedFlag() == false) + { + TestDetails assertDetails(testDetails->testName, testDetails->suiteName, filename, lineNumber); + testResults->OnTestFailure(assertDetails, description); + } + + ExpectAssert(false); #ifdef UNITTEST_USE_EXCEPTIONS - throw AssertException(description, filename, lineNumber); + throw AssertException(); #endif } +void ExpectAssert(bool expected) +{ + AssertExpectedFlag() = expected; +} + +bool AssertExpected() +{ + return AssertExpectedFlag(); +} + } diff --git a/src/ReportAssert.h b/src/ReportAssert.h index a000e15..253229a 100644 --- a/src/ReportAssert.h +++ b/src/ReportAssert.h @@ -3,8 +3,20 @@ namespace UnitTest { +class TestResults; +class TestDetails; + void ReportAssert(char const* description, char const* filename, int lineNumber); - + +void ReportAssertEx(TestResults* testResults, + const TestDetails* testDetails, + char const* description, + char const* filename, + int lineNumber); + +void ExpectAssert(bool expected); +bool AssertExpected(); + } #endif diff --git a/src/Test.cpp b/src/Test.cpp index 6b63041..d00749c 100644 --- a/src/Test.cpp +++ b/src/Test.cpp @@ -20,8 +20,9 @@ TestList& Test::GetTestList() Test::Test(char const* testName, char const* suiteName, char const* filename, int lineNumber) : m_details(testName, suiteName, filename, lineNumber) - , next(0) + , m_nextTest(0) , m_timeConstraintExempt(false) + , m_isMockTest(false) { } @@ -31,7 +32,7 @@ Test::~Test() void Test::Run() { - ExecuteTest(*this, m_details); + ExecuteTest(*this, m_details, m_isMockTest); } void Test::RunImpl() const diff --git a/src/Test.h b/src/Test.h index 436dbc1..7c2f175 100644 --- a/src/Test.h +++ b/src/Test.h @@ -16,8 +16,9 @@ class Test void Run(); TestDetails const m_details; - Test* next; + Test* m_nextTest; mutable bool m_timeConstraintExempt; + mutable bool m_isMockTest; static TestList& GetTestList(); diff --git a/src/TestList.cpp b/src/TestList.cpp index 4f58034..38fbfec 100644 --- a/src/TestList.cpp +++ b/src/TestList.cpp @@ -21,7 +21,7 @@ void TestList::Add(Test* test) } else { - m_tail->next = test; + m_tail->m_nextTest = test; m_tail = test; } } diff --git a/src/TestMacros.h b/src/TestMacros.h index 8aad30e..912f8ca 100644 --- a/src/TestMacros.h +++ b/src/TestMacros.h @@ -83,11 +83,11 @@ ({ \ Fixture##Name##Helper fixtureHelper(m_details); \ ctorOk = true; \ - UnitTest::ExecuteTest(fixtureHelper, m_details); \ + UnitTest::ExecuteTest(fixtureHelper, m_details, false); \ }) \ UT_CATCH (UnitTest::AssertException, e, \ { \ - UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(m_details.testName, m_details.suiteName, e.Filename(), e.LineNumber()), e.what()); \ + (void)e; \ }) \ UT_CATCH (std::exception, e, \ { \ diff --git a/src/TestRunner.cpp b/src/TestRunner.cpp index b7fcb62..108348e 100644 --- a/src/TestRunner.cpp +++ b/src/TestRunner.cpp @@ -32,6 +32,11 @@ TestRunner::~TestRunner() delete m_timer; } +TestResults* TestRunner::GetTestResults() +{ + return m_result; +} + int TestRunner::Finish() const { float const secondsElapsed = static_cast(m_timer->GetTimeInMs() / 1000.0); @@ -51,7 +56,8 @@ bool TestRunner::IsTestInSuite(const Test* const curTest, char const* suiteName) void TestRunner::RunTest(TestResults* const result, Test* const curTest, int const maxTestTimeInMs) const { - CurrentTest::Results() = result; + if (curTest->m_isMockTest == false) + CurrentTest::Results() = result; Timer testTimer; testTimer.Start(); @@ -70,7 +76,7 @@ void TestRunner::RunTest(TestResults* const result, Test* const curTest, int con result->OnTestFailure(curTest->m_details, stream.GetText()); } - result->OnTestFinish(curTest->m_details, static_cast(testTimeInMs/1000.0)); + result->OnTestFinish(curTest->m_details, static_cast< float >(testTimeInMs / 1000.0)); } } diff --git a/src/TestRunner.h b/src/TestRunner.h index 2ad6e5c..27ec9c6 100644 --- a/src/TestRunner.h +++ b/src/TestRunner.h @@ -27,7 +27,7 @@ class TestRunner explicit TestRunner(TestReporter& reporter); ~TestRunner(); - template + template< class Predicate > int RunTestsIf(TestList const& list, char const* suiteName, const Predicate& predicate, int maxTestTimeInMs) const { @@ -38,12 +38,14 @@ class TestRunner if (IsTestInSuite(curTest, suiteName) && predicate(curTest)) RunTest(m_result, curTest, maxTestTimeInMs); - curTest = curTest->next; + curTest = curTest->m_nextTest; } return Finish(); } + TestResults* GetTestResults(); + private: TestReporter* m_reporter; TestResults* m_result; diff --git a/src/tests/TestAssertHandler.cpp b/src/tests/TestAssertHandler.cpp index 664a670..6116b19 100644 --- a/src/tests/TestAssertHandler.cpp +++ b/src/tests/TestAssertHandler.cpp @@ -1,49 +1,111 @@ #include "../Config.h" -#ifdef UNITTEST_USE_EXCEPTIONS - #include "../unittestpp.h" -#include "../AssertException.h" #include "../ReportAssert.h" +#include "../AssertException.h" + +#include "RecordingReporter.h" using namespace UnitTest; namespace { +TEST(CanSetAssertExpected) +{ + ExpectAssert(true); + CHECK(AssertExpected()); + + ExpectAssert(false); + CHECK(!AssertExpected()); +} + +#ifdef UNITTEST_USE_EXCEPTIONS + TEST(ReportAssertThrowsAssertException) { bool caught = false; try { - ReportAssert("", "", 0); + TestResults testResults; + TestDetails testDetails("", "", "", 0); + ReportAssertEx(&testResults, &testDetails, "", "", 0); } catch(AssertException const&) { caught = true; } - CHECK (true == caught); + CHECK(true == caught); +} + +TEST(ReportAssertClearsExpectAssertFlag) +{ + RecordingReporter reporter; + TestResults testResults(&reporter); + TestDetails testDetails("", "", "", 0); + + try + { + ExpectAssert(true); + ReportAssertEx(&testResults, &testDetails, "", "", 0); + } + catch(AssertException const&) + { + } + + CHECK(AssertExpected() == false); + CHECK_EQUAL(0, reporter.testFailedCount); } -TEST(ReportAssertSetsCorrectInfoInException) +TEST(ReportAssertWritesFailureToResultsAndDetailsWhenAssertIsNotExpected) { const int lineNumber = 12345; const char* description = "description"; const char* filename = "filename"; + RecordingReporter reporter; + TestResults testResults(&reporter); + TestDetails testDetails("", "", "", 0); + try { - ReportAssert(description, filename, lineNumber); + ReportAssertEx(&testResults, &testDetails, description, filename, lineNumber); } - catch(AssertException const& e) + catch(AssertException const&) { - CHECK_EQUAL(description, e.what()); - CHECK_EQUAL(filename, e.Filename()); - CHECK_EQUAL(lineNumber, e.LineNumber()); } + + CHECK_EQUAL(description, reporter.lastFailedMessage); + CHECK_EQUAL(filename, reporter.lastFailedFile); + CHECK_EQUAL(lineNumber, reporter.lastFailedLine); } +TEST(ReportAssertReportsNoErrorsWhenAssertIsExpected) +{ + ExpectAssert(true); + + RecordingReporter reporter; + TestResults testResults(&reporter); + TestDetails testDetails("", "", "", 0); + + try + { + ReportAssertEx(&testResults, &testDetails, "", "", 0); + } + catch(AssertException const&) + { + } + + CHECK_EQUAL(0, reporter.testFailedCount); } #endif + +TEST(CheckAssertMacroSetsAssertExpectationToFalseAfterRunning) +{ + CHECK_ASSERT(ReportAssert("", "", 0)); + CHECK(!AssertExpected()); +} + +} diff --git a/src/tests/TestTestList.cpp b/src/tests/TestTestList.cpp index b37bff2..6b88ed4 100644 --- a/src/tests/TestTestList.cpp +++ b/src/tests/TestTestList.cpp @@ -6,23 +6,23 @@ using namespace UnitTest; namespace { -TEST (TestListIsEmptyByDefault) +TEST(TestListIsEmptyByDefault) { TestList list; - CHECK (list.GetHead() == 0); + CHECK(list.GetHead() == 0); } -TEST (AddingTestSetsHeadToTest) +TEST(AddingTestSetsHeadToTest) { Test test("test"); TestList list; list.Add(&test); - CHECK (list.GetHead() == &test); - CHECK (test.next == 0); + CHECK(list.GetHead() == &test); + CHECK(test.m_nextTest == 0); } -TEST (AddingSecondTestAddsItToEndOfList) +TEST(AddingSecondTestAddsItToEndOfList) { Test test1("test1"); Test test2("test2"); @@ -31,20 +31,20 @@ TEST (AddingSecondTestAddsItToEndOfList) list.Add(&test1); list.Add(&test2); - CHECK (list.GetHead() == &test1); - CHECK (test1.next == &test2); - CHECK (test2.next == 0); + CHECK(list.GetHead() == &test1); + CHECK(test1.m_nextTest == &test2); + CHECK(test2.m_nextTest == 0); } -TEST (ListAdderAddsTestToList) +TEST(ListAdderAddsTestToList) { TestList list; Test test(""); ListAdder adder(list, &test); - CHECK (list.GetHead() == &test); - CHECK (test.next == 0); + CHECK(list.GetHead() == &test); + CHECK(test.m_nextTest == 0); } } diff --git a/src/tests/TestTestMacros.cpp b/src/tests/TestTestMacros.cpp index a1506e5..d613580 100644 --- a/src/tests/TestTestMacros.cpp +++ b/src/tests/TestTestMacros.cpp @@ -19,7 +19,7 @@ TEST_EX(DummyTest, list1) TEST (TestsAreAddedToTheListThroughMacro) { CHECK(list1.GetHead() != 0); - CHECK(list1.GetHead()->next == 0); + CHECK(list1.GetHead()->m_nextTest == 0); } #ifdef UNITTEST_USE_EXCEPTIONS diff --git a/src/tests/TestTestRunner.cpp b/src/tests/TestTestRunner.cpp index 9acdaa5..bda88ae 100644 --- a/src/tests/TestTestRunner.cpp +++ b/src/tests/TestTestRunner.cpp @@ -10,6 +10,23 @@ using namespace UnitTest; namespace { +struct TestRunnerFixture +{ + TestRunnerFixture() + : runner(reporter) + { + s_testRunnerFixtureTestResults = runner.GetTestResults(); + } + + static TestResults* s_testRunnerFixtureTestResults; + + RecordingReporter reporter; + TestList list; + TestRunner runner; +}; + +TestResults* TestRunnerFixture::s_testRunnerFixtureTestResults = NULL; + struct MockTest : public Test { MockTest(char const* testName, bool const success_, bool const assert_, int const count_ = 1) @@ -18,16 +35,19 @@ struct MockTest : public Test , asserted(assert_) , count(count_) { + m_isMockTest = true; } - virtual void RunImpl(TestResults& testResults_) const + virtual void RunImpl() const { + TestResults* testResults = TestRunnerFixture::s_testRunnerFixtureTestResults; + for (int i=0; i < count; ++i) { if (asserted) - ReportAssert("desc", "file", 0); + ReportAssertEx(testResults, &m_details, "desc", "file", 0); else if (!success) - testResults_.OnTestFailure(m_details, "message"); + testResults->OnTestFailure(m_details, "message"); } } @@ -36,19 +56,6 @@ struct MockTest : public Test int const count; }; - -struct TestRunnerFixture -{ - TestRunnerFixture() - : runner(reporter) - { - } - - RecordingReporter reporter; - TestList list; - TestRunner runner; -}; - TEST_FIXTURE(TestRunnerFixture, TestStartIsReportedCorrectly) { MockTest test("goodtest", true, false); @@ -104,7 +111,7 @@ TEST_FIXTURE(TestRunnerFixture, CallsReportFailureOncePerFailingTest) MockTest test3("test", false, false); list.Add(&test3); - CHECK_EQUAL(2, runner.RunTestsIf(list, NULL, True(), 0)); + CHECK_EQUAL(2, runner.RunTestsIf(list, NULL, True(), 0)); CHECK_EQUAL(2, reporter.testFailedCount); } @@ -117,7 +124,6 @@ TEST_FIXTURE(TestRunnerFixture, TestsThatAssertAreReportedAsFailing) CHECK_EQUAL(1, reporter.testFailedCount); } - TEST_FIXTURE(TestRunnerFixture, ReporterNotifiedOfTestCount) { MockTest test1("test", true, false); From c8f551a5021ffc249e6d1caa0277b6dc97ef8a88 Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Wed, 9 Jan 2013 23:43:13 -0600 Subject: [PATCH 08/30] r9 | charles.nicholson | 2010-03-17 17:13:51 -0500 (Wed, 17 Mar 2010) | 1 line setjmp/longjmp in place for assert handling when UNITTEST_USE_EXCEPTIONS is not defined --- src/CheckMacros.h | 10 +++---- src/ExecuteTest.h | 53 ++++++++++++++++++--------------- src/ReportAssert.cpp | 22 ++++++++++++-- src/ReportAssert.h | 12 -------- src/ReportAssertImpl.h | 45 ++++++++++++++++++++++++++++ src/TimeConstraint.cpp | 2 +- src/tests/TestAssertHandler.cpp | 53 ++++++++++++++++++++++++--------- src/tests/TestTestRunner.cpp | 11 ++++++- src/tests/TestUnitTestPP.cpp | 1 - src/unittestpp.h | 1 + 10 files changed, 150 insertions(+), 60 deletions(-) create mode 100644 src/ReportAssertImpl.h diff --git a/src/CheckMacros.h b/src/CheckMacros.h index 5523b3c..c29d78e 100644 --- a/src/CheckMacros.h +++ b/src/CheckMacros.h @@ -7,6 +7,7 @@ #include "MemoryOutStream.h" #include "TestDetails.h" #include "CurrentTest.h" +#include "ReportAssertImpl.h" #ifdef CHECK #error UnitTest++ redefines CHECK @@ -118,7 +119,7 @@ } while (0) -// CHECK_THROW only exists when UNITTEST_USE_EXCEPTIONS is defined (see Config.h) +// CHECK_THROW and CHECK_ASSERT only exist when UNITTEST_USE_EXCEPTIONS is defined (see Config.h) #ifdef UNITTEST_USE_EXCEPTIONS #define CHECK_THROW(expression, ExpectedExceptionType) \ do \ @@ -135,10 +136,9 @@ #define CHECK_ASSERT(expression) \ do \ { \ - UnitTest::ExpectAssert(true); \ + UnitTest::Detail::ExpectAssert(true); \ CHECK_THROW(expression, UnitTest::AssertException); \ - UnitTest::ExpectAssert(false); \ + UnitTest::Detail::ExpectAssert(false); \ } while(0) - -#endif #endif +#endif \ No newline at end of file diff --git a/src/ExecuteTest.h b/src/ExecuteTest.h index 0c37eb3..fdf9462 100644 --- a/src/ExecuteTest.h +++ b/src/ExecuteTest.h @@ -1,12 +1,17 @@ #ifndef UNITTEST_EXECUTE_TEST_H #define UNITTEST_EXECUTE_TEST_H +#include "Config.h" #include "ExceptionMacros.h" #include "TestDetails.h" #include "MemoryOutStream.h" #include "AssertException.h" #include "CurrentTest.h" +#ifndef UNITTEST_USE_EXCEPTIONS + #include "ReportAssertImpl.h" +#endif + #ifdef UNITTEST_POSIX #include "Posix/SignalTranslator.h" #endif @@ -19,33 +24,33 @@ void ExecuteTest(T& testObject, TestDetails const& details, bool isMockTest) if (isMockTest == false) CurrentTest::Details() = &details; +#ifndef UNITTEST_USE_EXCEPTIONS + if (UNITTEST_SET_ASSERT_JUMP_TARGET() == 0) + { +#endif #ifndef UNITTEST_POSIX - UT_TRY - ({ - testObject.RunImpl(); - }) + UT_TRY({ testObject.RunImpl(); }) #else - UT_TRY - ({ - UNITTEST_THROW_SIGNALS_POSIX_ONLY - testObject.RunImpl(); - }) + UT_TRY + ({ + UNITTEST_THROW_SIGNALS_POSIX_ONLY + testObject.RunImpl(); + }) +#endif + UT_CATCH(AssertException, e, { (void)e; }) + UT_CATCH(std::exception, e, + { + MemoryOutStream stream; + stream << "Unhandled exception: " << e.what(); + CurrentTest::Results()->OnTestFailure(details, stream.GetText()); + }) + UT_CATCH_ALL + ({ + CurrentTest::Results()->OnTestFailure(details, "Unhandled exception: test crashed"); + }) +#ifndef UNITTEST_USE_EXCEPTIONS + } #endif - - UT_CATCH(AssertException, e, - { - (void)e; - }) - UT_CATCH(std::exception, e, - { - MemoryOutStream stream; - stream << "Unhandled exception: " << e.what(); - CurrentTest::Results()->OnTestFailure(details, stream.GetText()); - }) - UT_CATCH_ALL - ({ - CurrentTest::Results()->OnTestFailure(details, "Unhandled exception: test crashed"); - }) } } diff --git a/src/ReportAssert.cpp b/src/ReportAssert.cpp index fb4d043..6e712fd 100644 --- a/src/ReportAssert.cpp +++ b/src/ReportAssert.cpp @@ -1,9 +1,14 @@ #include "ReportAssert.h" +#include "ReportAssertImpl.h" #include "AssertException.h" #include "CurrentTest.h" #include "TestResults.h" #include "TestDetails.h" +#ifndef UNITTEST_USE_EXCEPTIONS + #include "ReportAssertImpl.h" +#endif + namespace UnitTest { namespace @@ -17,9 +22,20 @@ namespace void ReportAssert(char const* description, char const* filename, int lineNumber) { - ReportAssertEx(CurrentTest::Results(), CurrentTest::Details(), description, filename, lineNumber); + Detail::ReportAssertEx(CurrentTest::Results(), CurrentTest::Details(), + description, filename, lineNumber); } +namespace Detail { + +#ifndef UNITTEST_USE_EXCEPTIONS +jmp_buf* GetAssertJmpBuf() +{ + static jmp_buf s_jmpBuf; + return &s_jmpBuf; +} +#endif + void ReportAssertEx(TestResults* testResults, const TestDetails* testDetails, char const* description, @@ -36,6 +52,8 @@ void ReportAssertEx(TestResults* testResults, #ifdef UNITTEST_USE_EXCEPTIONS throw AssertException(); +#else + UNITTEST_JUMP_TO_ASSERT_JUMP_TARGET(); #endif } @@ -49,4 +67,4 @@ bool AssertExpected() return AssertExpectedFlag(); } -} +}} diff --git a/src/ReportAssert.h b/src/ReportAssert.h index 253229a..893cd3c 100644 --- a/src/ReportAssert.h +++ b/src/ReportAssert.h @@ -3,20 +3,8 @@ namespace UnitTest { -class TestResults; -class TestDetails; - void ReportAssert(char const* description, char const* filename, int lineNumber); -void ReportAssertEx(TestResults* testResults, - const TestDetails* testDetails, - char const* description, - char const* filename, - int lineNumber); - -void ExpectAssert(bool expected); -bool AssertExpected(); - } #endif diff --git a/src/ReportAssertImpl.h b/src/ReportAssertImpl.h new file mode 100644 index 0000000..f53bade --- /dev/null +++ b/src/ReportAssertImpl.h @@ -0,0 +1,45 @@ +#ifndef UNITTEST_REPORTASSERTIMPL_H +#define UNITTEST_REPORTASSERTIMPL_H + +#include "Config.h" + +#ifndef UNITTEST_USE_EXCEPTIONS + #include +#endif + +namespace UnitTest { + +class TestResults; +class TestDetails; + +namespace Detail { + +void ExpectAssert(bool expected); + +void ReportAssertEx(TestResults* testResults, + const TestDetails* testDetails, + char const* description, + char const* filename, + int lineNumber); + +bool AssertExpected(); + +#ifndef UNITTEST_USE_EXCEPTIONS + jmp_buf* GetAssertJmpBuf(); + + #ifdef _MSC_VER + #define UNITTEST_SET_ASSERT_JUMP_TARGET() \ + __pragma(warning(push)) __pragma(warning(disable:4611)) \ + setjmp(*UnitTest::Detail::GetAssertJmpBuf()) \ + __pragma(warning(pop)) + #else + #define UNITTEST_SET_ASSERT_JUMP_TARGET() setjmp(*UnitTest::Detail::GetAssertJmpBuf()) + #endif + + #define UNITTEST_JUMP_TO_ASSERT_JUMP_TARGET() longjmp(*UnitTest::Detail::GetAssertJmpBuf(), 1) +#endif + +} +} + +#endif diff --git a/src/TimeConstraint.cpp b/src/TimeConstraint.cpp index 4adb260..89f1b87 100644 --- a/src/TimeConstraint.cpp +++ b/src/TimeConstraint.cpp @@ -22,7 +22,7 @@ TimeConstraint::~TimeConstraint() stream << "Time constraint failed. Expected to run test under " << m_maxMs << "ms but took " << totalTimeInMs << "ms."; - UnitTest::CurrentTest::Results()->OnTestFailure(m_details, stream.GetText()); + CurrentTest::Results()->OnTestFailure(m_details, stream.GetText()); } } diff --git a/src/tests/TestAssertHandler.cpp b/src/tests/TestAssertHandler.cpp index 6116b19..7cbce10 100644 --- a/src/tests/TestAssertHandler.cpp +++ b/src/tests/TestAssertHandler.cpp @@ -2,9 +2,11 @@ #include "../unittestpp.h" #include "../ReportAssert.h" +#include "../ReportAssertImpl.h" #include "../AssertException.h" #include "RecordingReporter.h" +#include using namespace UnitTest; @@ -12,11 +14,11 @@ namespace { TEST(CanSetAssertExpected) { - ExpectAssert(true); - CHECK(AssertExpected()); + Detail::ExpectAssert(true); + CHECK(Detail::AssertExpected()); - ExpectAssert(false); - CHECK(!AssertExpected()); + Detail::ExpectAssert(false); + CHECK(!Detail::AssertExpected()); } #ifdef UNITTEST_USE_EXCEPTIONS @@ -29,7 +31,7 @@ TEST(ReportAssertThrowsAssertException) { TestResults testResults; TestDetails testDetails("", "", "", 0); - ReportAssertEx(&testResults, &testDetails, "", "", 0); + Detail::ReportAssertEx(&testResults, &testDetails, "", "", 0); } catch(AssertException const&) { @@ -47,14 +49,14 @@ TEST(ReportAssertClearsExpectAssertFlag) try { - ExpectAssert(true); - ReportAssertEx(&testResults, &testDetails, "", "", 0); + Detail::ExpectAssert(true); + Detail::ReportAssertEx(&testResults, &testDetails, "", "", 0); } catch(AssertException const&) { } - CHECK(AssertExpected() == false); + CHECK(Detail::AssertExpected() == false); CHECK_EQUAL(0, reporter.testFailedCount); } @@ -70,7 +72,7 @@ TEST(ReportAssertWritesFailureToResultsAndDetailsWhenAssertIsNotExpected) try { - ReportAssertEx(&testResults, &testDetails, description, filename, lineNumber); + Detail::ReportAssertEx(&testResults, &testDetails, description, filename, lineNumber); } catch(AssertException const&) { @@ -83,7 +85,7 @@ TEST(ReportAssertWritesFailureToResultsAndDetailsWhenAssertIsNotExpected) TEST(ReportAssertReportsNoErrorsWhenAssertIsExpected) { - ExpectAssert(true); + Detail::ExpectAssert(true); RecordingReporter reporter; TestResults testResults(&reporter); @@ -91,7 +93,7 @@ TEST(ReportAssertReportsNoErrorsWhenAssertIsExpected) try { - ReportAssertEx(&testResults, &testDetails, "", "", 0); + Detail::ReportAssertEx(&testResults, &testDetails, "", "", 0); } catch(AssertException const&) { @@ -100,12 +102,35 @@ TEST(ReportAssertReportsNoErrorsWhenAssertIsExpected) CHECK_EQUAL(0, reporter.testFailedCount); } -#endif - TEST(CheckAssertMacroSetsAssertExpectationToFalseAfterRunning) { + Detail::ExpectAssert(true); CHECK_ASSERT(ReportAssert("", "", 0)); - CHECK(!AssertExpected()); + CHECK(!Detail::AssertExpected()); + Detail::ExpectAssert(false); +} + +#else + +TEST(SetAssertJumpTargetReturnsFalseWhenSettingJumpTarget) +{ + CHECK(UNITTEST_SET_ASSERT_JUMP_TARGET() == false); } +TEST(JumpToAssertJumpTarget_JumpsToSetPoint_ReturnsTrue) +{ + const volatile bool taken = !!UNITTEST_SET_ASSERT_JUMP_TARGET(); + + volatile bool set = false; + if (taken == false) + { + UNITTEST_JUMP_TO_ASSERT_JUMP_TARGET(); + set = true; + } + + CHECK(set == false); +} + +#endif + } diff --git a/src/tests/TestTestRunner.cpp b/src/tests/TestTestRunner.cpp index bda88ae..d0de516 100644 --- a/src/tests/TestTestRunner.cpp +++ b/src/tests/TestTestRunner.cpp @@ -4,6 +4,7 @@ #include "../TestList.h" #include "../TimeHelpers.h" #include "../TimeConstraint.h" +#include "../ReportAssertImpl.h" using namespace UnitTest; @@ -45,7 +46,7 @@ struct MockTest : public Test for (int i=0; i < count; ++i) { if (asserted) - ReportAssertEx(testResults, &m_details, "desc", "file", 0); + Detail::ReportAssertEx(testResults, &m_details, "desc", "file", 0); else if (!success) testResults->OnTestFailure(m_details, "message"); } @@ -124,6 +125,14 @@ TEST_FIXTURE(TestRunnerFixture, TestsThatAssertAreReportedAsFailing) CHECK_EQUAL(1, reporter.testFailedCount); } +TEST_FIXTURE(TestRunnerFixture, AssertingTestAbortsAsSoonAsAssertIsHit) +{ + MockTest test("test", false, true, 3); + list.Add(&test); + runner.RunTestsIf(list, NULL, True(), 0); + CHECK_EQUAL(1, reporter.summaryFailureCount); +} + TEST_FIXTURE(TestRunnerFixture, ReporterNotifiedOfTestCount) { MockTest test1("test", true, false); diff --git a/src/tests/TestUnitTestPP.cpp b/src/tests/TestUnitTestPP.cpp index 9237aa9..3fdf7a8 100644 --- a/src/tests/TestUnitTestPP.cpp +++ b/src/tests/TestUnitTestPP.cpp @@ -1,5 +1,4 @@ #include "../unittestpp.h" -#include "../ReportAssert.h" #include "ScopedCurrentTest.h" // These are sample tests that show the different features of the framework diff --git a/src/unittestpp.h b/src/unittestpp.h index 7e0d893..db0dfb9 100644 --- a/src/unittestpp.h +++ b/src/unittestpp.h @@ -6,5 +6,6 @@ #include "CheckMacros.h" #include "TestRunner.h" #include "TimeConstraint.h" +#include "ReportAssert.h" #endif From bcde677ff0f74bb52eaf3790c95bfcabd027276d Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Wed, 9 Jan 2013 23:43:23 -0600 Subject: [PATCH 09/30] r10 | charles.nicholson | 2010-03-17 18:04:53 -0500 (Wed, 17 Mar 2010) | 1 line rename unittestpp folder to src, fix bin/lib/obj folders in vcproj files --- src/MemoryOutStream.h | 136 +++++------ src/Posix/TimeHelpers.cpp | 66 +++--- src/Posix/TimeHelpers.h | 56 ++--- src/TestReporterStdout.cpp | 92 ++++---- src/Win32/TimeHelpers.h | 96 ++++---- src/tests/TestTimeConstraintMacro.cpp | 130 +++++------ src/tests/test-unittestpp.vcproj | 256 +++++++++++++++++++++ src/unittestpp.vcproj | 318 ++++++++++++++++++++++++++ 8 files changed, 862 insertions(+), 288 deletions(-) create mode 100644 src/tests/test-unittestpp.vcproj create mode 100644 src/unittestpp.vcproj diff --git a/src/MemoryOutStream.h b/src/MemoryOutStream.h index 37a4afd..754c1e5 100644 --- a/src/MemoryOutStream.h +++ b/src/MemoryOutStream.h @@ -1,68 +1,68 @@ -#ifndef UNITTEST_MEMORYOUTSTREAM_H -#define UNITTEST_MEMORYOUTSTREAM_H - -#include "Config.h" - -#ifndef UNITTEST_USE_CUSTOM_STREAMS - -#include - -namespace UnitTest -{ - -class MemoryOutStream : public std::ostringstream -{ -public: - MemoryOutStream() {} - ~MemoryOutStream() {} - char const* GetText() const; - -private: - MemoryOutStream(MemoryOutStream const&); - void operator =(MemoryOutStream const&); - - mutable std::string m_text; -}; - -} - -#else - -#include - -namespace UnitTest -{ - -class MemoryOutStream -{ -public: - explicit MemoryOutStream(int const size = 256); - ~MemoryOutStream(); - - char const* GetText() const; - - MemoryOutStream& operator << (char const* txt); - MemoryOutStream& operator << (int n); - MemoryOutStream& operator << (long n); - MemoryOutStream& operator << (unsigned long n); - MemoryOutStream& operator << (float f); - MemoryOutStream& operator << (double d); - MemoryOutStream& operator << (void const* p); - MemoryOutStream& operator << (unsigned int s); - - enum { GROW_CHUNK_SIZE = 32 }; - int GetCapacity() const; - -private: - void operator= (MemoryOutStream const&); - void GrowBuffer(int capacity); - - int m_capacity; - char* m_buffer; -}; - -} - -#endif - -#endif +#ifndef UNITTEST_MEMORYOUTSTREAM_H +#define UNITTEST_MEMORYOUTSTREAM_H + +#include "Config.h" + +#ifndef UNITTEST_USE_CUSTOM_STREAMS + +#include + +namespace UnitTest +{ + +class MemoryOutStream : public std::ostringstream +{ +public: + MemoryOutStream() {} + ~MemoryOutStream() {} + char const* GetText() const; + +private: + MemoryOutStream(MemoryOutStream const&); + void operator =(MemoryOutStream const&); + + mutable std::string m_text; +}; + +} + +#else + +#include + +namespace UnitTest +{ + +class MemoryOutStream +{ +public: + explicit MemoryOutStream(int const size = 256); + ~MemoryOutStream(); + + char const* GetText() const; + + MemoryOutStream& operator << (char const* txt); + MemoryOutStream& operator << (int n); + MemoryOutStream& operator << (long n); + MemoryOutStream& operator << (unsigned long n); + MemoryOutStream& operator << (float f); + MemoryOutStream& operator << (double d); + MemoryOutStream& operator << (void const* p); + MemoryOutStream& operator << (unsigned int s); + + enum { GROW_CHUNK_SIZE = 32 }; + int GetCapacity() const; + +private: + void operator= (MemoryOutStream const&); + void GrowBuffer(int capacity); + + int m_capacity; + char* m_buffer; +}; + +} + +#endif + +#endif diff --git a/src/Posix/TimeHelpers.cpp b/src/Posix/TimeHelpers.cpp index 65c6393..35e8136 100644 --- a/src/Posix/TimeHelpers.cpp +++ b/src/Posix/TimeHelpers.cpp @@ -1,33 +1,33 @@ -#include "TimeHelpers.h" -#include - -namespace UnitTest { - -Timer::Timer() -{ - m_startTime.tv_sec = 0; - m_startTime.tv_usec = 0; -} - -void Timer::Start() -{ - gettimeofday(&m_startTime, 0); -} - -double Timer::GetTimeInMs() const -{ - struct timeval currentTime; - gettimeofday(¤tTime, 0); - - double const dsecs = currentTime.tv_sec - m_startTime.tv_sec; - double const dus = currentTime.tv_usec - m_startTime.tv_usec; - - return (dsecs * 1000.0) + (dus / 1000.0); -} - -void TimeHelpers::SleepMs(int ms) -{ - usleep(ms * 1000); -} - -} +#include "TimeHelpers.h" +#include + +namespace UnitTest { + +Timer::Timer() +{ + m_startTime.tv_sec = 0; + m_startTime.tv_usec = 0; +} + +void Timer::Start() +{ + gettimeofday(&m_startTime, 0); +} + +double Timer::GetTimeInMs() const +{ + struct timeval currentTime; + gettimeofday(¤tTime, 0); + + double const dsecs = currentTime.tv_sec - m_startTime.tv_sec; + double const dus = currentTime.tv_usec - m_startTime.tv_usec; + + return (dsecs * 1000.0) + (dus / 1000.0); +} + +void TimeHelpers::SleepMs(int ms) +{ + usleep(ms * 1000); +} + +} diff --git a/src/Posix/TimeHelpers.h b/src/Posix/TimeHelpers.h index 528e62e..f6c500b 100644 --- a/src/Posix/TimeHelpers.h +++ b/src/Posix/TimeHelpers.h @@ -1,28 +1,28 @@ -#ifndef UNITTEST_TIMEHELPERS_H -#define UNITTEST_TIMEHELPERS_H - -#include - -namespace UnitTest { - -class Timer -{ -public: - Timer(); - void Start(); - double GetTimeInMs() const; - -private: - struct timeval m_startTime; -}; - - -namespace TimeHelpers -{ -void SleepMs (int ms); -} - - -} - -#endif +#ifndef UNITTEST_TIMEHELPERS_H +#define UNITTEST_TIMEHELPERS_H + +#include + +namespace UnitTest { + +class Timer +{ +public: + Timer(); + void Start(); + double GetTimeInMs() const; + +private: + struct timeval m_startTime; +}; + + +namespace TimeHelpers +{ +void SleepMs (int ms); +} + + +} + +#endif diff --git a/src/TestReporterStdout.cpp b/src/TestReporterStdout.cpp index 563113c..3a29db4 100644 --- a/src/TestReporterStdout.cpp +++ b/src/TestReporterStdout.cpp @@ -1,46 +1,46 @@ -#include "TestReporterStdout.h" -#include - -#include "TestDetails.h" - -// cstdio doesn't pull in namespace std on VC6, so we do it here. -#if defined(_MSC_VER) && (_MSC_VER == 1200) - namespace std {} -#endif - -namespace UnitTest { - -void TestReporterStdout::ReportFailure(TestDetails const& details, char const* failure) -{ -#if defined(__APPLE__) || defined(__GNUG__) - char const* const errorFormat = "%s:%d: error: Failure in %s: %s\n"; -#else - char const* const errorFormat = "%s(%d): error: Failure in %s: %s\n"; -#endif - - using namespace std; - printf(errorFormat, details.filename, details.lineNumber, details.testName, failure); -} - -void TestReporterStdout::ReportTestStart(TestDetails const& /*test*/) -{ -} - -void TestReporterStdout::ReportTestFinish(TestDetails const& /*test*/, float) -{ -} - -void TestReporterStdout::ReportSummary(int const totalTestCount, int const failedTestCount, - int const failureCount, float secondsElapsed) -{ - using namespace std; - - if (failureCount > 0) - printf("FAILURE: %d out of %d tests failed (%d failures).\n", failedTestCount, totalTestCount, failureCount); - else - printf("Success: %d tests passed.\n", totalTestCount); - - printf("Test time: %.2f seconds.\n", secondsElapsed); -} - -} +#include "TestReporterStdout.h" +#include + +#include "TestDetails.h" + +// cstdio doesn't pull in namespace std on VC6, so we do it here. +#if defined(_MSC_VER) && (_MSC_VER == 1200) + namespace std {} +#endif + +namespace UnitTest { + +void TestReporterStdout::ReportFailure(TestDetails const& details, char const* failure) +{ +#if defined(__APPLE__) || defined(__GNUG__) + char const* const errorFormat = "%s:%d: error: Failure in %s: %s\n"; +#else + char const* const errorFormat = "%s(%d): error: Failure in %s: %s\n"; +#endif + + using namespace std; + printf(errorFormat, details.filename, details.lineNumber, details.testName, failure); +} + +void TestReporterStdout::ReportTestStart(TestDetails const& /*test*/) +{ +} + +void TestReporterStdout::ReportTestFinish(TestDetails const& /*test*/, float) +{ +} + +void TestReporterStdout::ReportSummary(int const totalTestCount, int const failedTestCount, + int const failureCount, float secondsElapsed) +{ + using namespace std; + + if (failureCount > 0) + printf("FAILURE: %d out of %d tests failed (%d failures).\n", failedTestCount, totalTestCount, failureCount); + else + printf("Success: %d tests passed.\n", totalTestCount); + + printf("Test time: %.2f seconds.\n", secondsElapsed); +} + +} diff --git a/src/Win32/TimeHelpers.h b/src/Win32/TimeHelpers.h index 088de24..9bbf12b 100644 --- a/src/Win32/TimeHelpers.h +++ b/src/Win32/TimeHelpers.h @@ -1,48 +1,48 @@ -#ifndef UNITTEST_TIMEHELPERS_H -#define UNITTEST_TIMEHELPERS_H - -#include "../Config.h" - - -#ifdef UNITTEST_MINGW - #ifndef __int64 - #define __int64 long long - #endif -#endif - -namespace UnitTest { - -class Timer -{ -public: - Timer(); - void Start(); - double GetTimeInMs() const; - -private: - __int64 GetTime() const; - - void* m_threadHandle; - -#if defined(_WIN64) - unsigned __int64 m_processAffinityMask; -#else - unsigned long m_processAffinityMask; -#endif - - __int64 m_startTime; - __int64 m_frequency; -}; - - -namespace TimeHelpers -{ -void SleepMs (int ms); -} - - -} - - - -#endif +#ifndef UNITTEST_TIMEHELPERS_H +#define UNITTEST_TIMEHELPERS_H + +#include "../Config.h" + + +#ifdef UNITTEST_MINGW + #ifndef __int64 + #define __int64 long long + #endif +#endif + +namespace UnitTest { + +class Timer +{ +public: + Timer(); + void Start(); + double GetTimeInMs() const; + +private: + __int64 GetTime() const; + + void* m_threadHandle; + +#if defined(_WIN64) + unsigned __int64 m_processAffinityMask; +#else + unsigned long m_processAffinityMask; +#endif + + __int64 m_startTime; + __int64 m_frequency; +}; + + +namespace TimeHelpers +{ +void SleepMs (int ms); +} + + +} + + + +#endif diff --git a/src/tests/TestTimeConstraintMacro.cpp b/src/tests/TestTimeConstraintMacro.cpp index 056d89d..6939cff 100644 --- a/src/tests/TestTimeConstraintMacro.cpp +++ b/src/tests/TestTimeConstraintMacro.cpp @@ -1,65 +1,65 @@ -#include "../unittestpp.h" -#include "../TimeHelpers.h" - -#include "RecordingReporter.h" -#include "ScopedCurrentTest.h" - -namespace { - -TEST(TimeConstraintMacroQualifiesNamespace) -{ - // If this compiles without a "using namespace UnitTest;", all is well. - UNITTEST_TIME_CONSTRAINT(1); -} - -TEST(TimeConstraintMacroUsesCorrectInfo) -{ - int testLine = 0; - RecordingReporter reporter; - - { - UnitTest::TestResults testResults(&reporter); - ScopedCurrentTest scopedResults(testResults); - - UNITTEST_TIME_CONSTRAINT(10); testLine = __LINE__; - UnitTest::TimeHelpers::SleepMs(20); - } - - using namespace std; - - CHECK_EQUAL(1, reporter.testFailedCount); - CHECK(strstr(reporter.lastFailedFile, __FILE__)); - CHECK_EQUAL(testLine, reporter.lastFailedLine); - CHECK(strstr(reporter.lastFailedTest, "TimeConstraintMacroUsesCorrectInfo")); -} - -TEST(TimeConstraintMacroComparesAgainstPreciseActual) -{ - int testLine = 0; - RecordingReporter reporter; - - { - UnitTest::TestResults testResults(&reporter); - ScopedCurrentTest scopedResults(testResults); - - UNITTEST_TIME_CONSTRAINT(1); testLine = __LINE__; - - // start a new timer and run until we're as little over the 1 msec - // threshold as we can achieve; this should guarantee that the "test" - // runs in some very small amount of time > 1 msec - UnitTest::Timer myTimer; - myTimer.Start(); - - while (myTimer.GetTimeInMs() < 1.001) - UnitTest::TimeHelpers::SleepMs(0); - } - - using namespace std; - - CHECK_EQUAL(1, reporter.testFailedCount); - CHECK(strstr(reporter.lastFailedFile, __FILE__)); - CHECK_EQUAL(testLine, reporter.lastFailedLine); - CHECK(strstr(reporter.lastFailedTest, "TimeConstraintMacroComparesAgainstPreciseActual")); -} - -} +#include "../unittestpp.h" +#include "../TimeHelpers.h" + +#include "RecordingReporter.h" +#include "ScopedCurrentTest.h" + +namespace { + +TEST(TimeConstraintMacroQualifiesNamespace) +{ + // If this compiles without a "using namespace UnitTest;", all is well. + UNITTEST_TIME_CONSTRAINT(1); +} + +TEST(TimeConstraintMacroUsesCorrectInfo) +{ + int testLine = 0; + RecordingReporter reporter; + + { + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + UNITTEST_TIME_CONSTRAINT(10); testLine = __LINE__; + UnitTest::TimeHelpers::SleepMs(20); + } + + using namespace std; + + CHECK_EQUAL(1, reporter.testFailedCount); + CHECK(strstr(reporter.lastFailedFile, __FILE__)); + CHECK_EQUAL(testLine, reporter.lastFailedLine); + CHECK(strstr(reporter.lastFailedTest, "TimeConstraintMacroUsesCorrectInfo")); +} + +TEST(TimeConstraintMacroComparesAgainstPreciseActual) +{ + int testLine = 0; + RecordingReporter reporter; + + { + UnitTest::TestResults testResults(&reporter); + ScopedCurrentTest scopedResults(testResults); + + UNITTEST_TIME_CONSTRAINT(1); testLine = __LINE__; + + // start a new timer and run until we're as little over the 1 msec + // threshold as we can achieve; this should guarantee that the "test" + // runs in some very small amount of time > 1 msec + UnitTest::Timer myTimer; + myTimer.Start(); + + while (myTimer.GetTimeInMs() < 1.001) + UnitTest::TimeHelpers::SleepMs(0); + } + + using namespace std; + + CHECK_EQUAL(1, reporter.testFailedCount); + CHECK(strstr(reporter.lastFailedFile, __FILE__)); + CHECK_EQUAL(testLine, reporter.lastFailedLine); + CHECK(strstr(reporter.lastFailedTest, "TimeConstraintMacroComparesAgainstPreciseActual")); +} + +} diff --git a/src/tests/test-unittestpp.vcproj b/src/tests/test-unittestpp.vcproj new file mode 100644 index 0000000..0352507 --- /dev/null +++ b/src/tests/test-unittestpp.vcproj @@ -0,0 +1,256 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/unittestpp.vcproj b/src/unittestpp.vcproj new file mode 100644 index 0000000..e66dff8 --- /dev/null +++ b/src/unittestpp.vcproj @@ -0,0 +1,318 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From eebfcb4103c2d1f86c7cb31c069c75ca7ace5971 Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Wed, 9 Jan 2013 23:43:32 -0600 Subject: [PATCH 10/30] r11 | charles.nicholson | 2010-03-17 18:49:54 -0500 (Wed, 17 Mar 2010) | 1 line fix makefile, gcc 4.3 compiles cleanly, fix obj/bin/lib dirs --- src/AssertException.cpp | 2 +- src/AssertException.h | 2 +- src/ExecuteTest.h | 1 + src/XmlTestReporter.cpp | 6 +++++- src/XmlTestReporter.h | 4 ++++ src/tests/TestXmlTestReporter.cpp | 5 +++++ src/tests/test-unittestpp.vcproj | 8 ++++++-- src/unittestpp.vcproj | 16 ++++++++++++---- unittestpp_vs2005.sln | 29 +++++++++++++++++++++++++++++ 9 files changed, 64 insertions(+), 9 deletions(-) create mode 100644 unittestpp_vs2005.sln diff --git a/src/AssertException.cpp b/src/AssertException.cpp index cc2c7e1..3615b82 100644 --- a/src/AssertException.cpp +++ b/src/AssertException.cpp @@ -8,7 +8,7 @@ AssertException::AssertException() { } -AssertException::~AssertException() +AssertException::~AssertException() throw() { } diff --git a/src/AssertException.h b/src/AssertException.h index 4603827..07f3400 100644 --- a/src/AssertException.h +++ b/src/AssertException.h @@ -13,7 +13,7 @@ class AssertException : public std::exception { public: AssertException(); - virtual ~AssertException(); + virtual ~AssertException() throw(); }; } diff --git a/src/ExecuteTest.h b/src/ExecuteTest.h index fdf9462..423a6b7 100644 --- a/src/ExecuteTest.h +++ b/src/ExecuteTest.h @@ -4,6 +4,7 @@ #include "Config.h" #include "ExceptionMacros.h" #include "TestDetails.h" +#include "TestResults.h" #include "MemoryOutStream.h" #include "AssertException.h" #include "CurrentTest.h" diff --git a/src/XmlTestReporter.cpp b/src/XmlTestReporter.cpp index 436ceeb..24aa85d 100644 --- a/src/XmlTestReporter.cpp +++ b/src/XmlTestReporter.cpp @@ -1,5 +1,7 @@ -#include "XmlTestReporter.h" #include "Config.h" +#ifdef UNITTEST_USE_DEFERRED_REPORTER + +#include "XmlTestReporter.h" #include #include @@ -125,3 +127,5 @@ void XmlTestReporter::AddFailure(std::ostream& os, DeferredTestResult const& res } } + +#endif diff --git a/src/XmlTestReporter.h b/src/XmlTestReporter.h index c775b5a..a50aefc 100644 --- a/src/XmlTestReporter.h +++ b/src/XmlTestReporter.h @@ -1,6 +1,9 @@ #ifndef UNITTEST_XMLTESTREPORTER_H #define UNITTEST_XMLTESTREPORTER_H +#include "Config.h" +#ifdef UNITTEST_USE_DEFERRED_REPORTER + #include "DeferredTestReporter.h" #include @@ -32,3 +35,4 @@ class XmlTestReporter : public DeferredTestReporter } #endif +#endif diff --git a/src/tests/TestXmlTestReporter.cpp b/src/tests/TestXmlTestReporter.cpp index 2419668..cf2e1f2 100644 --- a/src/tests/TestXmlTestReporter.cpp +++ b/src/tests/TestXmlTestReporter.cpp @@ -1,3 +1,6 @@ +#include "../Config.h" +#ifdef UNITTEST_USE_DEFERRED_REPORTER + #include "../unittestpp.h" #include "../XmlTestReporter.h" @@ -181,3 +184,5 @@ TEST_FIXTURE(XmlTestReporterFixture, MultipleFailures) } } + +#endif diff --git a/src/tests/test-unittestpp.vcproj b/src/tests/test-unittestpp.vcproj index 0352507..f35bed4 100644 --- a/src/tests/test-unittestpp.vcproj +++ b/src/tests/test-unittestpp.vcproj @@ -17,7 +17,7 @@
+ + diff --git a/src/unittestpp.vcproj b/src/unittestpp.vcproj index e66dff8..7e48179 100644 --- a/src/unittestpp.vcproj +++ b/src/unittestpp.vcproj @@ -17,8 +17,8 @@ @@ -80,8 +80,8 @@ + + + + diff --git a/unittestpp_vs2005.sln b/unittestpp_vs2005.sln new file mode 100644 index 0000000..88ef7df --- /dev/null +++ b/unittestpp_vs2005.sln @@ -0,0 +1,29 @@ + +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "unittestpp", "src\unittestpp.vcproj", "{64A4FEFE-0461-4E95-8CC1-91EF5F57DBC6}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test-unittestpp", "src\tests\test-unittestpp.vcproj", "{9CCC3439-309E-4E85-B3B8-CE704D385D48}" + ProjectSection(ProjectDependencies) = postProject + {64A4FEFE-0461-4E95-8CC1-91EF5F57DBC6} = {64A4FEFE-0461-4E95-8CC1-91EF5F57DBC6} + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {64A4FEFE-0461-4E95-8CC1-91EF5F57DBC6}.Debug|Win32.ActiveCfg = Debug|Win32 + {64A4FEFE-0461-4E95-8CC1-91EF5F57DBC6}.Debug|Win32.Build.0 = Debug|Win32 + {64A4FEFE-0461-4E95-8CC1-91EF5F57DBC6}.Release|Win32.ActiveCfg = Release|Win32 + {64A4FEFE-0461-4E95-8CC1-91EF5F57DBC6}.Release|Win32.Build.0 = Release|Win32 + {9CCC3439-309E-4E85-B3B8-CE704D385D48}.Debug|Win32.ActiveCfg = Debug|Win32 + {9CCC3439-309E-4E85-B3B8-CE704D385D48}.Debug|Win32.Build.0 = Debug|Win32 + {9CCC3439-309E-4E85-B3B8-CE704D385D48}.Release|Win32.ActiveCfg = Release|Win32 + {9CCC3439-309E-4E85-B3B8-CE704D385D48}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal From b2e2959c7650d06b91ea48e601b15406d7860c18 Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Wed, 9 Jan 2013 23:43:37 -0600 Subject: [PATCH 11/30] r12 | charles.nicholson | 2010-03-17 18:59:25 -0500 (Wed, 17 Mar 2010) | 1 line move unittestpp.h and config.h to top-level folder, to allow 'include unittestpp/unittestpp.h' directives in client code --- src/Config.h => config.h | 0 src/AssertException.h | 3 +-- src/Checks.h | 2 +- src/DeferredTestReporter.cpp | 2 +- src/DeferredTestReporter.h | 2 +- src/DeferredTestResult.cpp | 2 +- src/DeferredTestResult.h | 3 +-- src/ExceptionMacros.h | 2 +- src/ExecuteTest.h | 2 +- src/MemoryOutStream.h | 3 +-- src/ReportAssertImpl.h | 2 +- src/Test.cpp | 2 +- src/TestMacros.h | 2 +- src/TimeHelpers.h | 2 +- src/Win32/TimeHelpers.h | 3 +-- src/XmlTestReporter.cpp | 2 +- src/XmlTestReporter.h | 2 +- src/tests/Main.cpp | 4 +--- src/tests/TestAssertHandler.cpp | 4 ++-- src/tests/TestCheckMacros.cpp | 2 +- src/tests/TestChecks.cpp | 2 +- src/tests/TestCurrentTest.cpp | 2 +- src/tests/TestDeferredTestReporter.cpp | 4 ++-- src/tests/TestExceptions.cpp | 5 ++--- src/tests/TestMemoryOutStream.cpp | 2 +- src/tests/TestTest.cpp | 2 +- src/tests/TestTestList.cpp | 2 +- src/tests/TestTestMacros.cpp | 2 +- src/tests/TestTestResults.cpp | 2 +- src/tests/TestTestRunner.cpp | 2 +- src/tests/TestTestSuite.cpp | 2 +- src/tests/TestTimeConstraint.cpp | 2 +- src/tests/TestTimeConstraintMacro.cpp | 2 +- src/tests/TestUnitTestPP.cpp | 2 +- src/tests/TestXmlTestReporter.cpp | 4 ++-- src/unittestpp.h | 11 ----------- src/unittestpp.vcproj | 4 ++-- unittestpp.h | 11 +++++++++++ 38 files changed, 51 insertions(+), 58 deletions(-) rename src/Config.h => config.h (100%) delete mode 100644 src/unittestpp.h create mode 100644 unittestpp.h diff --git a/src/Config.h b/config.h similarity index 100% rename from src/Config.h rename to config.h diff --git a/src/AssertException.h b/src/AssertException.h index 07f3400..5d27556 100644 --- a/src/AssertException.h +++ b/src/AssertException.h @@ -1,8 +1,7 @@ #ifndef UNITTEST_ASSERTEXCEPTION_H #define UNITTEST_ASSERTEXCEPTION_H -#include "Config.h" - +#include "../config.h" #ifdef UNITTEST_USE_EXCEPTIONS #include diff --git a/src/Checks.h b/src/Checks.h index e3ec7b2..b6bbdb8 100644 --- a/src/Checks.h +++ b/src/Checks.h @@ -1,7 +1,7 @@ #ifndef UNITTEST_CHECKS_H #define UNITTEST_CHECKS_H -#include "Config.h" +#include "../config.h" #include "TestResults.h" #include "MemoryOutStream.h" diff --git a/src/DeferredTestReporter.cpp b/src/DeferredTestReporter.cpp index 8b7a29c..2d8c550 100644 --- a/src/DeferredTestReporter.cpp +++ b/src/DeferredTestReporter.cpp @@ -1,4 +1,4 @@ -#include "Config.h" +#include "../config.h" #ifdef UNITTEST_USE_DEFERRED_REPORTER #include "DeferredTestReporter.h" diff --git a/src/DeferredTestReporter.h b/src/DeferredTestReporter.h index c037af3..3fcc9f5 100644 --- a/src/DeferredTestReporter.h +++ b/src/DeferredTestReporter.h @@ -1,7 +1,7 @@ #ifndef UNITTEST_DEFERREDTESTREPORTER_H #define UNITTEST_DEFERREDTESTREPORTER_H -#include "Config.h" +#include "../config.h" #ifdef UNITTEST_USE_DEFERRED_REPORTER diff --git a/src/DeferredTestResult.cpp b/src/DeferredTestResult.cpp index 33fc145..bd8b36e 100644 --- a/src/DeferredTestResult.cpp +++ b/src/DeferredTestResult.cpp @@ -1,4 +1,4 @@ -#include "Config.h" +#include "../config.h" #ifdef UNITTEST_USE_DEFERRED_REPORTER #include "DeferredTestResult.h" diff --git a/src/DeferredTestResult.h b/src/DeferredTestResult.h index db3ffaa..ad139c0 100644 --- a/src/DeferredTestResult.h +++ b/src/DeferredTestResult.h @@ -1,8 +1,7 @@ #ifndef UNITTEST_DEFERREDTESTRESULT_H #define UNITTEST_DEFERREDTESTRESULT_H -#include "Config.h" - +#include "../config.h" #ifdef UNITTEST_USE_DEFERRED_REPORTER #include diff --git a/src/ExceptionMacros.h b/src/ExceptionMacros.h index f10e780..311d7e5 100644 --- a/src/ExceptionMacros.h +++ b/src/ExceptionMacros.h @@ -1,7 +1,7 @@ #ifndef UNITTEST_EXCEPTIONMACROS_H #define UNITTEST_EXCEPTIONMACROS_H -#include "Config.h" +#include "../config.h" #ifdef UNITTEST_USE_EXCEPTIONS #define UT_TRY(x) try x diff --git a/src/ExecuteTest.h b/src/ExecuteTest.h index 423a6b7..f90aa7f 100644 --- a/src/ExecuteTest.h +++ b/src/ExecuteTest.h @@ -1,7 +1,7 @@ #ifndef UNITTEST_EXECUTE_TEST_H #define UNITTEST_EXECUTE_TEST_H -#include "Config.h" +#include "../config.h" #include "ExceptionMacros.h" #include "TestDetails.h" #include "TestResults.h" diff --git a/src/MemoryOutStream.h b/src/MemoryOutStream.h index 754c1e5..2727b17 100644 --- a/src/MemoryOutStream.h +++ b/src/MemoryOutStream.h @@ -1,8 +1,7 @@ #ifndef UNITTEST_MEMORYOUTSTREAM_H #define UNITTEST_MEMORYOUTSTREAM_H -#include "Config.h" - +#include "../config.h" #ifndef UNITTEST_USE_CUSTOM_STREAMS #include diff --git a/src/ReportAssertImpl.h b/src/ReportAssertImpl.h index f53bade..43cc569 100644 --- a/src/ReportAssertImpl.h +++ b/src/ReportAssertImpl.h @@ -1,7 +1,7 @@ #ifndef UNITTEST_REPORTASSERTIMPL_H #define UNITTEST_REPORTASSERTIMPL_H -#include "Config.h" +#include "../config.h" #ifndef UNITTEST_USE_EXCEPTIONS #include diff --git a/src/Test.cpp b/src/Test.cpp index d00749c..eaab9aa 100644 --- a/src/Test.cpp +++ b/src/Test.cpp @@ -1,4 +1,4 @@ -#include "Config.h" +#include "../config.h" #include "Test.h" #include "TestList.h" #include "TestResults.h" diff --git a/src/TestMacros.h b/src/TestMacros.h index 912f8ca..c111604 100644 --- a/src/TestMacros.h +++ b/src/TestMacros.h @@ -1,7 +1,7 @@ #ifndef UNITTEST_TESTMACROS_H #define UNITTEST_TESTMACROS_H -#include "Config.h" +#include "../config.h" #include "TestSuite.h" #include "ExceptionMacros.h" #include "ExecuteTest.h" diff --git a/src/TimeHelpers.h b/src/TimeHelpers.h index cbc3ff4..24f0efd 100644 --- a/src/TimeHelpers.h +++ b/src/TimeHelpers.h @@ -1,4 +1,4 @@ -#include "Config.h" +#include "../config.h" #if defined UNITTEST_POSIX #include "Posix/TimeHelpers.h" diff --git a/src/Win32/TimeHelpers.h b/src/Win32/TimeHelpers.h index 9bbf12b..0d9ed7f 100644 --- a/src/Win32/TimeHelpers.h +++ b/src/Win32/TimeHelpers.h @@ -1,8 +1,7 @@ #ifndef UNITTEST_TIMEHELPERS_H #define UNITTEST_TIMEHELPERS_H -#include "../Config.h" - +#include "../../config.h" #ifdef UNITTEST_MINGW #ifndef __int64 diff --git a/src/XmlTestReporter.cpp b/src/XmlTestReporter.cpp index 24aa85d..9d938c1 100644 --- a/src/XmlTestReporter.cpp +++ b/src/XmlTestReporter.cpp @@ -1,4 +1,4 @@ -#include "Config.h" +#include "../config.h" #ifdef UNITTEST_USE_DEFERRED_REPORTER #include "XmlTestReporter.h" diff --git a/src/XmlTestReporter.h b/src/XmlTestReporter.h index a50aefc..abd9fce 100644 --- a/src/XmlTestReporter.h +++ b/src/XmlTestReporter.h @@ -1,7 +1,7 @@ #ifndef UNITTEST_XMLTESTREPORTER_H #define UNITTEST_XMLTESTREPORTER_H -#include "Config.h" +#include "../config.h" #ifdef UNITTEST_USE_DEFERRED_REPORTER #include "DeferredTestReporter.h" diff --git a/src/tests/Main.cpp b/src/tests/Main.cpp index 3eb37da..963ad7b 100644 --- a/src/tests/Main.cpp +++ b/src/tests/Main.cpp @@ -1,6 +1,4 @@ -#include "../unittestpp.h" -#include "../TestReporterStdout.h" - +#include "../../unittestpp.h" int main(int, char const *[]) { diff --git a/src/tests/TestAssertHandler.cpp b/src/tests/TestAssertHandler.cpp index 7cbce10..99e707a 100644 --- a/src/tests/TestAssertHandler.cpp +++ b/src/tests/TestAssertHandler.cpp @@ -1,6 +1,6 @@ -#include "../Config.h" +#include "../../config.h" +#include "../../unittestpp.h" -#include "../unittestpp.h" #include "../ReportAssert.h" #include "../ReportAssertImpl.h" #include "../AssertException.h" diff --git a/src/tests/TestCheckMacros.cpp b/src/tests/TestCheckMacros.cpp index 33fdc44..6b9fb66 100644 --- a/src/tests/TestCheckMacros.cpp +++ b/src/tests/TestCheckMacros.cpp @@ -1,4 +1,4 @@ -#include "../unittestpp.h" +#include "../../unittestpp.h" #include "../CurrentTest.h" #include "RecordingReporter.h" #include "ScopedCurrentTest.h" diff --git a/src/tests/TestChecks.cpp b/src/tests/TestChecks.cpp index ae34792..f32d2e7 100644 --- a/src/tests/TestChecks.cpp +++ b/src/tests/TestChecks.cpp @@ -1,4 +1,4 @@ -#include "../unittestpp.h" +#include "../../unittestpp.h" #include "RecordingReporter.h" using namespace UnitTest; diff --git a/src/tests/TestCurrentTest.cpp b/src/tests/TestCurrentTest.cpp index dd129c3..766539f 100644 --- a/src/tests/TestCurrentTest.cpp +++ b/src/tests/TestCurrentTest.cpp @@ -1,4 +1,4 @@ -#include "../unittestpp.h" +#include "../../unittestpp.h" #include "../CurrentTest.h" #include "ScopedCurrentTest.h" diff --git a/src/tests/TestDeferredTestReporter.cpp b/src/tests/TestDeferredTestReporter.cpp index fcdbd0f..3dcb2af 100644 --- a/src/tests/TestDeferredTestReporter.cpp +++ b/src/tests/TestDeferredTestReporter.cpp @@ -1,8 +1,8 @@ -#include "../Config.h" +#include "../../config.h" #ifdef UNITTEST_USE_DEFERRED_REPORTER -#include "../unittestpp.h" +#include "../../unittestpp.h" #include "../DeferredTestReporter.h" #include diff --git a/src/tests/TestExceptions.cpp b/src/tests/TestExceptions.cpp index 1c4349a..88f9c70 100644 --- a/src/tests/TestExceptions.cpp +++ b/src/tests/TestExceptions.cpp @@ -1,8 +1,7 @@ -#include "../Config.h" - +#include "../../config.h" #ifdef UNITTEST_USE_EXCEPTIONS -#include "../unittestpp.h" +#include "../../unittestpp.h" #include "../CurrentTest.h" #include "RecordingReporter.h" #include "ScopedCurrentTest.h" diff --git a/src/tests/TestMemoryOutStream.cpp b/src/tests/TestMemoryOutStream.cpp index 41a7843..7a3bc64 100644 --- a/src/tests/TestMemoryOutStream.cpp +++ b/src/tests/TestMemoryOutStream.cpp @@ -1,4 +1,4 @@ -#include "../unittestpp.h" +#include "../../unittestpp.h" #include "../MemoryOutStream.h" #include diff --git a/src/tests/TestTest.cpp b/src/tests/TestTest.cpp index cc48884..59eb759 100644 --- a/src/tests/TestTest.cpp +++ b/src/tests/TestTest.cpp @@ -1,4 +1,4 @@ -#include "../unittestpp.h" +#include "../../unittestpp.h" #include "../TestReporter.h" #include "../TimeHelpers.h" #include "ScopedCurrentTest.h" diff --git a/src/tests/TestTestList.cpp b/src/tests/TestTestList.cpp index 6b88ed4..fdeba34 100644 --- a/src/tests/TestTestList.cpp +++ b/src/tests/TestTestList.cpp @@ -1,4 +1,4 @@ -#include "../unittestpp.h" +#include "../../unittestpp.h" #include "../TestList.h" using namespace UnitTest; diff --git a/src/tests/TestTestMacros.cpp b/src/tests/TestTestMacros.cpp index d613580..f8028d8 100644 --- a/src/tests/TestTestMacros.cpp +++ b/src/tests/TestTestMacros.cpp @@ -1,4 +1,4 @@ -#include "../unittestpp.h" +#include "../../unittestpp.h" #include "../TestMacros.h" #include "../TestList.h" #include "../TestResults.h" diff --git a/src/tests/TestTestResults.cpp b/src/tests/TestTestResults.cpp index a8a0325..15fff1e 100644 --- a/src/tests/TestTestResults.cpp +++ b/src/tests/TestTestResults.cpp @@ -1,4 +1,4 @@ -#include "../unittestpp.h" +#include "../../unittestpp.h" #include "../TestResults.h" #include "RecordingReporter.h" diff --git a/src/tests/TestTestRunner.cpp b/src/tests/TestTestRunner.cpp index d0de516..3dc3edc 100644 --- a/src/tests/TestTestRunner.cpp +++ b/src/tests/TestTestRunner.cpp @@ -1,4 +1,4 @@ -#include "../unittestpp.h" +#include "../../unittestpp.h" #include "RecordingReporter.h" #include "../ReportAssert.h" #include "../TestList.h" diff --git a/src/tests/TestTestSuite.cpp b/src/tests/TestTestSuite.cpp index 1abbf49..07e51cd 100644 --- a/src/tests/TestTestSuite.cpp +++ b/src/tests/TestTestSuite.cpp @@ -1,4 +1,4 @@ -#include "../unittestpp.h" +#include "../../unittestpp.h" // We're really testing if it's possible to use the same suite in two files // to compile and link successfuly (TestTestSuite.cpp has suite with the same name) diff --git a/src/tests/TestTimeConstraint.cpp b/src/tests/TestTimeConstraint.cpp index 6f2021d..96f880c 100644 --- a/src/tests/TestTimeConstraint.cpp +++ b/src/tests/TestTimeConstraint.cpp @@ -1,4 +1,4 @@ -#include "../unittestpp.h" +#include "../../unittestpp.h" #include "../TestResults.h" #include "../TimeHelpers.h" #include "RecordingReporter.h" diff --git a/src/tests/TestTimeConstraintMacro.cpp b/src/tests/TestTimeConstraintMacro.cpp index 6939cff..76f15c3 100644 --- a/src/tests/TestTimeConstraintMacro.cpp +++ b/src/tests/TestTimeConstraintMacro.cpp @@ -1,4 +1,4 @@ -#include "../unittestpp.h" +#include "../../unittestpp.h" #include "../TimeHelpers.h" #include "RecordingReporter.h" diff --git a/src/tests/TestUnitTestPP.cpp b/src/tests/TestUnitTestPP.cpp index 3fdf7a8..a9da7a4 100644 --- a/src/tests/TestUnitTestPP.cpp +++ b/src/tests/TestUnitTestPP.cpp @@ -1,4 +1,4 @@ -#include "../unittestpp.h" +#include "../../unittestpp.h" #include "ScopedCurrentTest.h" // These are sample tests that show the different features of the framework diff --git a/src/tests/TestXmlTestReporter.cpp b/src/tests/TestXmlTestReporter.cpp index cf2e1f2..4c17b6c 100644 --- a/src/tests/TestXmlTestReporter.cpp +++ b/src/tests/TestXmlTestReporter.cpp @@ -1,7 +1,7 @@ -#include "../Config.h" +#include "../../config.h" #ifdef UNITTEST_USE_DEFERRED_REPORTER -#include "../unittestpp.h" +#include "../../unittestpp.h" #include "../XmlTestReporter.h" #include diff --git a/src/unittestpp.h b/src/unittestpp.h deleted file mode 100644 index db0dfb9..0000000 --- a/src/unittestpp.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef UNITTESTPP_H -#define UNITTESTPP_H - -#include "Config.h" -#include "TestMacros.h" -#include "CheckMacros.h" -#include "TestRunner.h" -#include "TimeConstraint.h" -#include "ReportAssert.h" - -#endif diff --git a/src/unittestpp.vcproj b/src/unittestpp.vcproj index 7e48179..0ff7274 100644 --- a/src/unittestpp.vcproj +++ b/src/unittestpp.vcproj @@ -177,7 +177,7 @@ > Date: Wed, 9 Jan 2013 23:43:48 -0600 Subject: [PATCH 12/30] r13 | charles.nicholson | 2010-03-17 19:05:19 -0500 (Wed, 17 Mar 2010) | 1 line rename sln/vcproj to '_vs2005', fix up targets to still be named unittestpp and test-unittestpp --- .../{test-unittestpp.vcproj => test-unittestpp_vs2005.vcproj} | 4 +++- src/{unittestpp.vcproj => unittestpp_vs2005.vcproj} | 4 +++- unittestpp_vs2005.sln | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) rename src/tests/{test-unittestpp.vcproj => test-unittestpp_vs2005.vcproj} (92%) rename src/{unittestpp.vcproj => unittestpp_vs2005.vcproj} (92%) diff --git a/src/tests/test-unittestpp.vcproj b/src/tests/test-unittestpp_vs2005.vcproj similarity index 92% rename from src/tests/test-unittestpp.vcproj rename to src/tests/test-unittestpp_vs2005.vcproj index f35bed4..6aaeec2 100644 --- a/src/tests/test-unittestpp.vcproj +++ b/src/tests/test-unittestpp_vs2005.vcproj @@ -2,7 +2,7 @@ Date: Wed, 9 Jan 2013 23:43:54 -0600 Subject: [PATCH 13/30] r14 | charles.nicholson | 2010-03-17 19:39:17 -0500 (Wed, 17 Mar 2010) | 1 line better configuration names --- src/tests/test-unittestpp_vs2005.vcproj | 4 ++-- src/unittestpp_vs2005.vcproj | 4 ++-- unittestpp_vs2005.sln | 20 ++++++++++---------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/tests/test-unittestpp_vs2005.vcproj b/src/tests/test-unittestpp_vs2005.vcproj index 6aaeec2..41526af 100644 --- a/src/tests/test-unittestpp_vs2005.vcproj +++ b/src/tests/test-unittestpp_vs2005.vcproj @@ -16,7 +16,7 @@ Date: Wed, 9 Jan 2013 23:43:59 -0600 Subject: [PATCH 14/30] r15 | charles.nicholson | 2010-03-17 20:08:52 -0500 (Wed, 17 Mar 2010) | 1 line simple changes from sony --- src/Posix/TimeHelpers.h | 2 +- src/TestMacros.h | 2 +- src/Win32/TimeHelpers.cpp | 2 +- src/Win32/TimeHelpers.h | 5 +---- 4 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/Posix/TimeHelpers.h b/src/Posix/TimeHelpers.h index f6c500b..5a5bd79 100644 --- a/src/Posix/TimeHelpers.h +++ b/src/Posix/TimeHelpers.h @@ -19,7 +19,7 @@ class Timer namespace TimeHelpers { -void SleepMs (int ms); + void SleepMs(int ms); } diff --git a/src/TestMacros.h b/src/TestMacros.h index c111604..931d8e7 100644 --- a/src/TestMacros.h +++ b/src/TestMacros.h @@ -78,7 +78,7 @@ \ void Test##Fixture##Name::RunImpl() const \ { \ - bool ctorOk = false; \ + volatile bool ctorOk = false; \ UT_TRY \ ({ \ Fixture##Name##Helper fixtureHelper(m_details); \ diff --git a/src/Win32/TimeHelpers.cpp b/src/Win32/TimeHelpers.cpp index 2f6f5f7..f7568be 100644 --- a/src/Win32/TimeHelpers.cpp +++ b/src/Win32/TimeHelpers.cpp @@ -41,7 +41,7 @@ __int64 Timer::GetTime() const return curTime.QuadPart; } -void TimeHelpers::SleepMs(int const ms) +void TimeHelpers::SleepMs(int ms) { ::Sleep(ms); } diff --git a/src/Win32/TimeHelpers.h b/src/Win32/TimeHelpers.h index 0d9ed7f..f31409b 100644 --- a/src/Win32/TimeHelpers.h +++ b/src/Win32/TimeHelpers.h @@ -36,12 +36,9 @@ class Timer namespace TimeHelpers { -void SleepMs (int ms); + void SleepMs(int ms); } - } - - #endif From 637f00a8a6994264f311f7832e3783d2880c32d0 Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Wed, 9 Jan 2013 23:44:07 -0600 Subject: [PATCH 15/30] r16 | charles.nicholson | 2010-03-18 15:01:25 -0500 (Thu, 18 Mar 2010) | 1 line DLL builds for win32, more bin/lib/obj location and configuration name changing in vs2005 --- Makefile | 194 ++++++++++++------------ config.h | 4 + src/AssertException.h | 3 +- src/Checks.h | 8 +- src/CurrentTest.cpp | 4 +- src/CurrentTest.h | 6 +- src/DeferredTestReporter.cpp | 2 +- src/DeferredTestReporter.h | 4 +- src/DeferredTestResult.cpp | 13 ++ src/DeferredTestResult.h | 24 ++- src/MemoryOutStream.h | 6 +- src/ReportAssert.cpp | 18 +-- src/ReportAssert.h | 4 +- src/ReportAssertImpl.h | 16 +- src/Test.h | 2 +- src/TestDetails.h | 4 +- src/TestList.h | 5 +- src/TestReporter.h | 4 +- src/TestReporterStdout.h | 2 +- src/TestResults.h | 4 +- src/TestRunner.h | 4 +- src/TimeConstraint.h | 3 +- src/Win32/TimeHelpers.h | 5 +- src/XmlTestReporter.cpp | 4 +- src/XmlTestReporter.h | 2 +- src/tests/TestDeferredTestReporter.cpp | 8 +- src/tests/test-unittestpp_vs2005.vcproj | 167 +++++++++++++++++++- src/unittestpp_vs2005.vcproj | 165 +++++++++++++++++++- unittestpp_vs2005.sln | 30 ++-- 29 files changed, 544 insertions(+), 171 deletions(-) diff --git a/Makefile b/Makefile index 0ce613b..b590a3f 100644 --- a/Makefile +++ b/Makefile @@ -1,96 +1,98 @@ -CXX = g++ -CXXFLAGS ?= -g -Wall -W -Winline -ansi -LDFLAGS ?= -SED = sed -MV = mv -RM = rm - -.SUFFIXES: .o .cpp - -lib = libUnitTest++.a -test = TestUnitTest++ - -src = src/AssertException.cpp \ - src/Test.cpp \ - src/Checks.cpp \ - src/TestRunner.cpp \ - src/TestResults.cpp \ - src/TestReporter.cpp \ - src/TestReporterStdout.cpp \ - src/ReportAssert.cpp \ - src/TestList.cpp \ - src/TimeConstraint.cpp \ - src/TestDetails.cpp \ - src/MemoryOutStream.cpp \ - src/DeferredTestReporter.cpp \ - src/DeferredTestResult.cpp \ - src/XmlTestReporter.cpp \ - src/CurrentTest.cpp - -ifeq ($(MSYSTEM), MINGW32) - src += src/Win32/TimeHelpers.cpp -else - src += src/Posix/SignalTranslator.cpp \ - src/Posix/TimeHelpers.cpp -endif - -test_src = src/tests/Main.cpp \ - src/tests/TestAssertHandler.cpp \ - src/tests/TestChecks.cpp \ - src/tests/TestUnitTestPP.cpp \ - src/tests/TestTest.cpp \ - src/tests/TestTestResults.cpp \ - src/tests/TestTestRunner.cpp \ - src/tests/TestCheckMacros.cpp \ - src/tests/TestTestList.cpp \ - src/tests/TestTestMacros.cpp \ - src/tests/TestTimeConstraint.cpp \ - src/tests/TestTimeConstraintMacro.cpp \ - src/tests/TestMemoryOutStream.cpp \ - src/tests/TestDeferredTestReporter.cpp \ - src/tests/TestXmlTestReporter.cpp \ - src/tests/TestCurrentTest.cpp - -objects = $(patsubst %.cpp, %.o, $(src)) -test_objects = $(patsubst %.cpp, %.o, $(test_src)) -dependencies = $(subst .o,.d,$(objects)) -test_dependencies = $(subst .o,.d,$(test_objects)) - -define make-depend - $(CXX) $(CXXFLAGS) -M $1 | \ - $(SED) -e 's,\($(notdir $2)\) *:,$(dir $2)\1: ,' > $3.tmp - $(SED) -e 's/#.*//' \ - -e 's/^[^:]*: *//' \ - -e 's/ *\\$$//' \ - -e '/^$$/ d' \ - -e 's/$$/ :/' $3.tmp >> $3.tmp - $(MV) $3.tmp $3 -endef - - -all: $(test) - - -$(lib): $(objects) - @echo Creating $(lib) library... - @ar cr $(lib) $(objects) - -$(test): $(lib) $(test_objects) - @echo Linking $(test)... - @$(CXX) $(LDFLAGS) -o $(test) $(test_objects) $(lib) - @echo Running unit tests... - @./$(test) - -clean: - -@$(RM) $(objects) $(test_objects) $(dependencies) $(test_dependencies) $(test) $(lib) 2> /dev/null - -%.o : %.cpp - @echo $< - @$(call make-depend,$<,$@,$(subst .o,.d,$@)) - @$(CXX) $(CXXFLAGS) -c $< -o $(patsubst %.cpp, %.o, $<) - - -ifneq "$(MAKECMDGOALS)" "clean" --include $(dependencies) --include $(test_dependencies) -endif +CXX = g++ +CXXFLAGS ?= -g -Wall -W -Winline -ansi +LDFLAGS ?= +SED = sed +MV = mv +RM = rm + +.SUFFIXES: .o .cpp + +lib = libunittestpp.a +test = test-unittestpp + +src = src/AssertException.cpp \ + src/Test.cpp \ + src/Checks.cpp \ + src/TestRunner.cpp \ + src/TestResults.cpp \ + src/TestReporter.cpp \ + src/TestReporterStdout.cpp \ + src/ReportAssert.cpp \ + src/TestList.cpp \ + src/TimeConstraint.cpp \ + src/TestDetails.cpp \ + src/MemoryOutStream.cpp \ + src/DeferredTestReporter.cpp \ + src/DeferredTestResult.cpp \ + src/XmlTestReporter.cpp \ + src/CurrentTest.cpp + +ifeq ($(MSYSTEM), MINGW32) + src += src/Win32/TimeHelpers.cpp +else + src += src/Posix/SignalTranslator.cpp \ + src/Posix/TimeHelpers.cpp +endif + +test_src = src/tests/Main.cpp \ + src/tests/TestAssertHandler.cpp \ + src/tests/TestChecks.cpp \ + src/tests/TestUnitTestPP.cpp \ + src/tests/TestTest.cpp \ + src/tests/TestTestResults.cpp \ + src/tests/TestTestRunner.cpp \ + src/tests/TestCheckMacros.cpp \ + src/tests/TestTestList.cpp \ + src/tests/TestTestMacros.cpp \ + src/tests/TestTimeConstraint.cpp \ + src/tests/TestTimeConstraintMacro.cpp \ + src/tests/TestMemoryOutStream.cpp \ + src/tests/TestDeferredTestReporter.cpp \ + src/tests/TestXmlTestReporter.cpp \ + src/tests/TestCurrentTest.cpp + +objects = $(patsubst %.cpp, %.o, $(src)) +test_objects = $(patsubst %.cpp, %.o, $(test_src)) +dependencies = $(subst .o,.d,$(objects)) +test_dependencies = $(subst .o,.d,$(test_objects)) + +define make-depend + $(CXX) $(CXXFLAGS) -M $1 | \ + $(SED) -e 's,\($(notdir $2)\) *:,$(dir $2)\1: ,' > $3.tmp + $(SED) -e 's/#.*//' \ + -e 's/^[^:]*: *//' \ + -e 's/ *\\$$//' \ + -e '/^$$/ d' \ + -e 's/$$/ :/' $3.tmp >> $3.tmp + $(MV) $3.tmp $3 +endef + + +all: $(test) + + +$(lib): $(objects) + @mkdir -p lib/win32_gcc_debug + @echo Creating $(lib) library... + @ar cr lib/win32_gcc_debug/$(lib) $(objects) + +$(test): $(lib) $(test_objects) + @mkdir -p bin/win32_gcc_static_debug + @echo Linking $(test)... + @$(CXX) $(LDFLAGS) -o bin/win32_gcc_static_debug/$(test) $(test_objects) lib/win32_gcc_debug/$(lib) + @echo Running unit tests... + @bin/win32_gcc_static_debug/$(test) + +clean: + -@$(RM) $(objects) $(test_objects) $(dependencies) $(test_dependencies) $(test) $(lib) 2> /dev/null + +%.o : %.cpp + @echo $< + @$(call make-depend,$<,$@,$(subst .o,.d,$@)) + @$(CXX) $(CXXFLAGS) -c $< -o $(patsubst %.cpp, %.o, $<) + + +ifneq "$(MAKECMDGOALS)" "clean" +-include $(dependencies) +-include $(test_dependencies) +endif diff --git a/config.h b/config.h index 147f05f..52e7e28 100644 --- a/config.h +++ b/config.h @@ -12,6 +12,10 @@ #pragma warning(disable:4786) #pragma warning(disable:4290) #endif + + #ifdef _USRDLL + #define UNITTEST_WIN32_DLL + #endif #endif #if defined(unix) || defined(__unix__) || defined(__unix) || defined(linux) || \ diff --git a/src/AssertException.h b/src/AssertException.h index 5d27556..cd40bfd 100644 --- a/src/AssertException.h +++ b/src/AssertException.h @@ -4,11 +4,12 @@ #include "../config.h" #ifdef UNITTEST_USE_EXCEPTIONS +#include "DllMacros.h" #include namespace UnitTest { -class AssertException : public std::exception +class UNITTEST_LINKAGE AssertException : public std::exception { public: AssertException(); diff --git a/src/Checks.h b/src/Checks.h index b6bbdb8..c323244 100644 --- a/src/Checks.h +++ b/src/Checks.h @@ -27,13 +27,13 @@ void CheckEqual(TestResults& results, Expected const& expected, Actual const& ac } } -void CheckEqual(TestResults& results, char const* expected, char const* actual, TestDetails const& details); +UNITTEST_LINKAGE void CheckEqual(TestResults& results, char const* expected, char const* actual, TestDetails const& details); -void CheckEqual(TestResults& results, char* expected, char* actual, TestDetails const& details); +UNITTEST_LINKAGE void CheckEqual(TestResults& results, char* expected, char* actual, TestDetails const& details); -void CheckEqual(TestResults& results, char* expected, char const* actual, TestDetails const& details); +UNITTEST_LINKAGE void CheckEqual(TestResults& results, char* expected, char const* actual, TestDetails const& details); -void CheckEqual(TestResults& results, char const* expected, char* actual, TestDetails const& details); +UNITTEST_LINKAGE void CheckEqual(TestResults& results, char const* expected, char* actual, TestDetails const& details); template< typename Expected, typename Actual, typename Tolerance > bool AreClose(Expected const& expected, Actual const& actual, Tolerance const& tolerance) diff --git a/src/CurrentTest.cpp b/src/CurrentTest.cpp index 941fb9b..19eb9bf 100644 --- a/src/CurrentTest.cpp +++ b/src/CurrentTest.cpp @@ -3,13 +3,13 @@ namespace UnitTest { -TestResults*& CurrentTest::Results() +UNITTEST_LINKAGE TestResults*& CurrentTest::Results() { static TestResults* testResults = NULL; return testResults; } -const TestDetails*& CurrentTest::Details() +UNITTEST_LINKAGE const TestDetails*& CurrentTest::Details() { static const TestDetails* testDetails = NULL; return testDetails; diff --git a/src/CurrentTest.h b/src/CurrentTest.h index 3b77ca5..190c99b 100644 --- a/src/CurrentTest.h +++ b/src/CurrentTest.h @@ -1,6 +1,8 @@ #ifndef UNITTEST_CURRENTTESTRESULTS_H #define UNITTEST_CURRENTTESTRESULTS_H +#include "DllMacros.h" + namespace UnitTest { class TestResults; @@ -8,8 +10,8 @@ class TestDetails; namespace CurrentTest { - TestResults*& Results(); - const TestDetails*& Details(); + UNITTEST_LINKAGE TestResults*& Results(); + UNITTEST_LINKAGE const TestDetails*& Details(); } } diff --git a/src/DeferredTestReporter.cpp b/src/DeferredTestReporter.cpp index 2d8c550..ce59827 100644 --- a/src/DeferredTestReporter.cpp +++ b/src/DeferredTestReporter.cpp @@ -15,7 +15,7 @@ void DeferredTestReporter::ReportFailure(TestDetails const& details, char const* { DeferredTestResult& r = m_results.back(); r.failed = true; - r.failures.push_back(DeferredTestResult::Failure(details.lineNumber, failure)); + r.failures.push_back(DeferredTestFailure(details.lineNumber, failure)); r.failureFile = details.filename; } diff --git a/src/DeferredTestReporter.h b/src/DeferredTestReporter.h index 3fcc9f5..7c2a4c8 100644 --- a/src/DeferredTestReporter.h +++ b/src/DeferredTestReporter.h @@ -10,10 +10,12 @@ #include +UNITTEST_STDVECTOR_LINKAGE(UnitTest::DeferredTestResult); + namespace UnitTest { -class DeferredTestReporter : public TestReporter +class UNITTEST_LINKAGE DeferredTestReporter : public TestReporter { public: virtual void ReportTestStart(TestDetails const& details); diff --git a/src/DeferredTestResult.cpp b/src/DeferredTestResult.cpp index bd8b36e..f176243 100644 --- a/src/DeferredTestResult.cpp +++ b/src/DeferredTestResult.cpp @@ -2,10 +2,23 @@ #ifdef UNITTEST_USE_DEFERRED_REPORTER #include "DeferredTestResult.h" +#include namespace UnitTest { +DeferredTestFailure::DeferredTestFailure() + : lineNumber(-1) +{ + failureStr[0] = '\0'; +} + +DeferredTestFailure::DeferredTestFailure(int lineNumber_, const char* failureStr_) + : lineNumber(lineNumber_) +{ + std::strcpy(failureStr, failureStr_); +} + DeferredTestResult::DeferredTestResult() : suiteName("") , testName("") diff --git a/src/DeferredTestResult.h b/src/DeferredTestResult.h index ad139c0..5729434 100644 --- a/src/DeferredTestResult.h +++ b/src/DeferredTestResult.h @@ -4,14 +4,33 @@ #include "../config.h" #ifdef UNITTEST_USE_DEFERRED_REPORTER +#include "DllMacros.h" #include #include namespace UnitTest { -struct DeferredTestResult +class UNITTEST_LINKAGE DeferredTestFailure { +public: + DeferredTestFailure(); + DeferredTestFailure(int lineNumber_, const char* failureStr_); + + int lineNumber; + char failureStr[1024]; +}; + +} + +UNITTEST_STDVECTOR_LINKAGE(UnitTest::DeferredTestFailure); + +namespace UnitTest +{ + +class UNITTEST_LINKAGE DeferredTestResult +{ +public: DeferredTestResult(); DeferredTestResult(char const* suite, char const* test); ~DeferredTestResult(); @@ -20,8 +39,7 @@ struct DeferredTestResult std::string testName; std::string failureFile; - typedef std::pair< int, std::string > Failure; - typedef std::vector< Failure > FailureVec; + typedef std::vector< DeferredTestFailure > FailureVec; FailureVec failures; float timeElapsed; diff --git a/src/MemoryOutStream.h b/src/MemoryOutStream.h index 2727b17..06c1adb 100644 --- a/src/MemoryOutStream.h +++ b/src/MemoryOutStream.h @@ -2,6 +2,8 @@ #define UNITTEST_MEMORYOUTSTREAM_H #include "../config.h" +#include "DllMacros.h" + #ifndef UNITTEST_USE_CUSTOM_STREAMS #include @@ -9,7 +11,7 @@ namespace UnitTest { -class MemoryOutStream : public std::ostringstream +class UNITTEST_LINKAGE MemoryOutStream : public std::ostringstream { public: MemoryOutStream() {} @@ -32,7 +34,7 @@ class MemoryOutStream : public std::ostringstream namespace UnitTest { -class MemoryOutStream +class UNITTEST_LINKAGE MemoryOutStream { public: explicit MemoryOutStream(int const size = 256); diff --git a/src/ReportAssert.cpp b/src/ReportAssert.cpp index 6e712fd..e256641 100644 --- a/src/ReportAssert.cpp +++ b/src/ReportAssert.cpp @@ -20,7 +20,7 @@ namespace } } -void ReportAssert(char const* description, char const* filename, int lineNumber) +UNITTEST_LINKAGE void ReportAssert(char const* description, char const* filename, int lineNumber) { Detail::ReportAssertEx(CurrentTest::Results(), CurrentTest::Details(), description, filename, lineNumber); @@ -35,12 +35,12 @@ jmp_buf* GetAssertJmpBuf() return &s_jmpBuf; } #endif - -void ReportAssertEx(TestResults* testResults, - const TestDetails* testDetails, - char const* description, - char const* filename, - int lineNumber) + +UNITTEST_LINKAGE void ReportAssertEx(TestResults* testResults, + const TestDetails* testDetails, + char const* description, + char const* filename, + int lineNumber) { if (AssertExpectedFlag() == false) { @@ -57,12 +57,12 @@ void ReportAssertEx(TestResults* testResults, #endif } -void ExpectAssert(bool expected) +UNITTEST_LINKAGE void ExpectAssert(bool expected) { AssertExpectedFlag() = expected; } -bool AssertExpected() +UNITTEST_LINKAGE bool AssertExpected() { return AssertExpectedFlag(); } diff --git a/src/ReportAssert.h b/src/ReportAssert.h index 893cd3c..0ca0b6e 100644 --- a/src/ReportAssert.h +++ b/src/ReportAssert.h @@ -1,9 +1,11 @@ #ifndef UNITTEST_ASSERT_H #define UNITTEST_ASSERT_H +#include "DllMacros.h" + namespace UnitTest { -void ReportAssert(char const* description, char const* filename, int lineNumber); +UNITTEST_LINKAGE void ReportAssert(char const* description, char const* filename, int lineNumber); } diff --git a/src/ReportAssertImpl.h b/src/ReportAssertImpl.h index 43cc569..659ad9e 100644 --- a/src/ReportAssertImpl.h +++ b/src/ReportAssertImpl.h @@ -14,18 +14,18 @@ class TestDetails; namespace Detail { -void ExpectAssert(bool expected); +UNITTEST_LINKAGE void ExpectAssert(bool expected); -void ReportAssertEx(TestResults* testResults, - const TestDetails* testDetails, - char const* description, - char const* filename, - int lineNumber); +UNITTEST_LINKAGE void ReportAssertEx(TestResults* testResults, + const TestDetails* testDetails, + char const* description, + char const* filename, + int lineNumber); -bool AssertExpected(); +UNITTEST_LINKAGE bool AssertExpected(); #ifndef UNITTEST_USE_EXCEPTIONS - jmp_buf* GetAssertJmpBuf(); + UNITTEST_LINKAGE jmp_buf* GetAssertJmpBuf(); #ifdef _MSC_VER #define UNITTEST_SET_ASSERT_JUMP_TARGET() \ diff --git a/src/Test.h b/src/Test.h index 7c2f175..1e1dbb2 100644 --- a/src/Test.h +++ b/src/Test.h @@ -8,7 +8,7 @@ namespace UnitTest { class TestResults; class TestList; -class Test +class UNITTEST_LINKAGE Test { public: explicit Test(char const* testName, char const* suiteName = "DefaultSuite", char const* filename = "", int lineNumber = 0); diff --git a/src/TestDetails.h b/src/TestDetails.h index c3f5e46..909179b 100644 --- a/src/TestDetails.h +++ b/src/TestDetails.h @@ -1,9 +1,11 @@ #ifndef UNITTEST_TESTDETAILS_H #define UNITTEST_TESTDETAILS_H +#include "DllMacros.h" + namespace UnitTest { -class TestDetails +class UNITTEST_LINKAGE TestDetails { public: TestDetails(char const* testName, char const* suiteName, char const* filename, int lineNumber); diff --git a/src/TestList.h b/src/TestList.h index ff560bc..32a7280 100644 --- a/src/TestList.h +++ b/src/TestList.h @@ -1,12 +1,13 @@ #ifndef UNITTEST_TESTLIST_H #define UNITTEST_TESTLIST_H +#include "DllMacros.h" namespace UnitTest { class Test; -class TestList +class UNITTEST_LINKAGE TestList { public: TestList(); @@ -20,7 +21,7 @@ class TestList }; -class ListAdder +class UNITTEST_LINKAGE ListAdder { public: ListAdder(TestList& list, Test* test); diff --git a/src/TestReporter.h b/src/TestReporter.h index e0aa76f..2ee9130 100644 --- a/src/TestReporter.h +++ b/src/TestReporter.h @@ -1,11 +1,13 @@ #ifndef UNITTEST_TESTREPORTER_H #define UNITTEST_TESTREPORTER_H +#include "DllMacros.h" + namespace UnitTest { class TestDetails; -class TestReporter +class UNITTEST_LINKAGE TestReporter { public: virtual ~TestReporter(); diff --git a/src/TestReporterStdout.h b/src/TestReporterStdout.h index c722947..4f52f8a 100644 --- a/src/TestReporterStdout.h +++ b/src/TestReporterStdout.h @@ -5,7 +5,7 @@ namespace UnitTest { -class TestReporterStdout : public TestReporter +class UNITTEST_LINKAGE TestReporterStdout : public TestReporter { private: virtual void ReportTestStart(TestDetails const& test); diff --git a/src/TestResults.h b/src/TestResults.h index c9dc146..a856c0d 100644 --- a/src/TestResults.h +++ b/src/TestResults.h @@ -1,12 +1,14 @@ #ifndef UNITTEST_TESTRESULTS_H #define UNITTEST_TESTRESULTS_H +#include "DllMacros.h" + namespace UnitTest { class TestReporter; class TestDetails; -class TestResults +class UNITTEST_LINKAGE TestResults { public: explicit TestResults(TestReporter* reporter = 0); diff --git a/src/TestRunner.h b/src/TestRunner.h index 27ec9c6..0253ae2 100644 --- a/src/TestRunner.h +++ b/src/TestRunner.h @@ -11,7 +11,7 @@ class TestReporter; class TestResults; class Timer; -int RunAllTests(); +UNITTEST_LINKAGE int RunAllTests(); struct True { @@ -21,7 +21,7 @@ struct True } }; -class TestRunner +class UNITTEST_LINKAGE TestRunner { public: explicit TestRunner(TestReporter& reporter); diff --git a/src/TimeConstraint.h b/src/TimeConstraint.h index 2034837..6989726 100644 --- a/src/TimeConstraint.h +++ b/src/TimeConstraint.h @@ -2,13 +2,14 @@ #define UNITTEST_TIMECONSTRAINT_H #include "TimeHelpers.h" +#include "DllMacros.h" namespace UnitTest { class TestResults; class TestDetails; -class TimeConstraint +class UNITTEST_LINKAGE TimeConstraint { public: TimeConstraint(int ms, TestDetails const& details); diff --git a/src/Win32/TimeHelpers.h b/src/Win32/TimeHelpers.h index f31409b..fd19ef4 100644 --- a/src/Win32/TimeHelpers.h +++ b/src/Win32/TimeHelpers.h @@ -2,6 +2,7 @@ #define UNITTEST_TIMEHELPERS_H #include "../../config.h" +#include "../DllMacros.h" #ifdef UNITTEST_MINGW #ifndef __int64 @@ -11,7 +12,7 @@ namespace UnitTest { -class Timer +class UNITTEST_LINKAGE Timer { public: Timer(); @@ -36,7 +37,7 @@ class Timer namespace TimeHelpers { - void SleepMs(int ms); + UNITTEST_LINKAGE void SleepMs(int ms); } } diff --git a/src/XmlTestReporter.cpp b/src/XmlTestReporter.cpp index 9d938c1..deb27ca 100644 --- a/src/XmlTestReporter.cpp +++ b/src/XmlTestReporter.cpp @@ -119,8 +119,8 @@ void XmlTestReporter::AddFailure(std::ostream& os, DeferredTestResult const& res it != result.failures.end(); ++it) { - string const escapedMessage = XmlEscape(it->second); - string const message = BuildFailureMessage(result.failureFile, it->first, escapedMessage); + string const escapedMessage = XmlEscape(std::string(it->failureStr)); + string const message = BuildFailureMessage(result.failureFile, it->lineNumber, escapedMessage); os << ""; } diff --git a/src/XmlTestReporter.h b/src/XmlTestReporter.h index abd9fce..14d69a6 100644 --- a/src/XmlTestReporter.h +++ b/src/XmlTestReporter.h @@ -11,7 +11,7 @@ namespace UnitTest { -class XmlTestReporter : public DeferredTestReporter +class UNITTEST_LINKAGE XmlTestReporter : public DeferredTestReporter { public: explicit XmlTestReporter(std::ostream& ostream); diff --git a/src/tests/TestDeferredTestReporter.cpp b/src/tests/TestDeferredTestReporter.cpp index 3dcb2af..ad049d1 100644 --- a/src/tests/TestDeferredTestReporter.cpp +++ b/src/tests/TestDeferredTestReporter.cpp @@ -94,8 +94,8 @@ TEST_FIXTURE(DeferredTestReporterFixture, ReportFailureSavesFailureDetailsForMul DeferredTestResult const& result = reporter.GetResults().at(0); CHECK_EQUAL(2, (int)result.failures.size()); - CHECK_EQUAL(failure1, result.failures[0].second); - CHECK_EQUAL(failure2, result.failures[1].second); + CHECK_EQUAL(failure1, result.failures[0].failureStr); + CHECK_EQUAL(failure2, result.failures[1].failureStr); } TEST_FIXTURE(DeferredTestReporterFixture, DeferredTestReporterTakesCopyOfFailureMessage) @@ -113,8 +113,8 @@ TEST_FIXTURE(DeferredTestReporterFixture, DeferredTestReporterTakesCopyOfFailure strcpy(failureMessage, badStr); DeferredTestResult const& result = reporter.GetResults().at(0); - DeferredTestResult::Failure const& failure = result.failures.at(0); - CHECK_EQUAL(goodStr, failure.second); + DeferredTestFailure const& failure = result.failures.at(0); + CHECK_EQUAL(goodStr, failure.failureStr); } }} diff --git a/src/tests/test-unittestpp_vs2005.vcproj b/src/tests/test-unittestpp_vs2005.vcproj index 41526af..8747e87 100644 --- a/src/tests/test-unittestpp_vs2005.vcproj +++ b/src/tests/test-unittestpp_vs2005.vcproj @@ -17,8 +17,8 @@ @@ -62,7 +62,7 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -48,7 +48,7 @@ UsePrecompiledHeader="0" WarningLevel="4" Detect64BitPortabilityProblems="true" - DebugInformationFormat="4" + DebugInformationFormat="3" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -206,6 +353,10 @@ RelativePath=".\DeferredTestResult.h" > + + diff --git a/unittestpp_vs2005.sln b/unittestpp_vs2005.sln index ffdc58d..2f9a3cd 100644 --- a/unittestpp_vs2005.sln +++ b/unittestpp_vs2005.sln @@ -10,18 +10,28 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test-unittestpp_vs2005", "s EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution - win32_debug|Win32 = win32_debug|Win32 - win32_release|Win32 = win32_release|Win32 + win32_dll_debug|Win32 = win32_dll_debug|Win32 + win32_dll_release|Win32 = win32_dll_release|Win32 + win32_lib_debug|Win32 = win32_lib_debug|Win32 + win32_lib_release|Win32 = win32_lib_release|Win32 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {64A4FEFE-0461-4E95-8CC1-91EF5F57DBC6}.win32_debug|Win32.ActiveCfg = win32_debug|Win32 - {64A4FEFE-0461-4E95-8CC1-91EF5F57DBC6}.win32_debug|Win32.Build.0 = win32_debug|Win32 - {64A4FEFE-0461-4E95-8CC1-91EF5F57DBC6}.win32_release|Win32.ActiveCfg = win32_release|Win32 - {64A4FEFE-0461-4E95-8CC1-91EF5F57DBC6}.win32_release|Win32.Build.0 = win32_release|Win32 - {9CCC3439-309E-4E85-B3B8-CE704D385D48}.win32_debug|Win32.ActiveCfg = win32_static_debug|Win32 - {9CCC3439-309E-4E85-B3B8-CE704D385D48}.win32_debug|Win32.Build.0 = win32_static_debug|Win32 - {9CCC3439-309E-4E85-B3B8-CE704D385D48}.win32_release|Win32.ActiveCfg = win32_static_release|Win32 - {9CCC3439-309E-4E85-B3B8-CE704D385D48}.win32_release|Win32.Build.0 = win32_static_release|Win32 + {64A4FEFE-0461-4E95-8CC1-91EF5F57DBC6}.win32_dll_debug|Win32.ActiveCfg = win32_dll_debug|Win32 + {64A4FEFE-0461-4E95-8CC1-91EF5F57DBC6}.win32_dll_debug|Win32.Build.0 = win32_dll_debug|Win32 + {64A4FEFE-0461-4E95-8CC1-91EF5F57DBC6}.win32_dll_release|Win32.ActiveCfg = win32_dll_release|Win32 + {64A4FEFE-0461-4E95-8CC1-91EF5F57DBC6}.win32_dll_release|Win32.Build.0 = win32_dll_release|Win32 + {64A4FEFE-0461-4E95-8CC1-91EF5F57DBC6}.win32_lib_debug|Win32.ActiveCfg = win32_lib_debug|Win32 + {64A4FEFE-0461-4E95-8CC1-91EF5F57DBC6}.win32_lib_debug|Win32.Build.0 = win32_lib_debug|Win32 + {64A4FEFE-0461-4E95-8CC1-91EF5F57DBC6}.win32_lib_release|Win32.ActiveCfg = win32_lib_release|Win32 + {64A4FEFE-0461-4E95-8CC1-91EF5F57DBC6}.win32_lib_release|Win32.Build.0 = win32_lib_release|Win32 + {9CCC3439-309E-4E85-B3B8-CE704D385D48}.win32_dll_debug|Win32.ActiveCfg = win32_dll_debug|Win32 + {9CCC3439-309E-4E85-B3B8-CE704D385D48}.win32_dll_debug|Win32.Build.0 = win32_dll_debug|Win32 + {9CCC3439-309E-4E85-B3B8-CE704D385D48}.win32_dll_release|Win32.ActiveCfg = win32_dll_release|Win32 + {9CCC3439-309E-4E85-B3B8-CE704D385D48}.win32_dll_release|Win32.Build.0 = win32_dll_release|Win32 + {9CCC3439-309E-4E85-B3B8-CE704D385D48}.win32_lib_debug|Win32.ActiveCfg = win32_static_debug|Win32 + {9CCC3439-309E-4E85-B3B8-CE704D385D48}.win32_lib_debug|Win32.Build.0 = win32_static_debug|Win32 + {9CCC3439-309E-4E85-B3B8-CE704D385D48}.win32_lib_release|Win32.ActiveCfg = win32_static_release|Win32 + {9CCC3439-309E-4E85-B3B8-CE704D385D48}.win32_lib_release|Win32.Build.0 = win32_static_release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From 32288a53b9818f218fae482aa3612f271e1600d9 Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Wed, 9 Jan 2013 23:44:16 -0600 Subject: [PATCH 16/30] r17 | charles.nicholson | 2010-03-18 15:01:48 -0500 (Thu, 18 Mar 2010) | 1 line forgot to add file --- src/DllMacros.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/DllMacros.h diff --git a/src/DllMacros.h b/src/DllMacros.h new file mode 100644 index 0000000..c88818d --- /dev/null +++ b/src/DllMacros.h @@ -0,0 +1,32 @@ +#ifndef UNITTEST_DLLMACROS_H +#define UNITTEST_DLLMACROS_H + +#include "../config.h" + +#ifdef UNITTEST_WIN32_DLL + #define UNITTEST_IMPORT __declspec(dllimport) + #define UNITTEST_EXPORT __declspec(dllexport) + + #ifdef UNITTEST_DLL_EXPORT + #define UNITTEST_LINKAGE UNITTEST_EXPORT + #define UNITTEST_IMPEXP_TEMPLATE + #else + #define UNITTEST_LINKAGE UNITTEST_IMPORT + #define UNITTEST_IMPEXP_TEMPLATE extern + #endif + + #define UNITTEST_STDVECTOR_LINKAGE(T) \ + __pragma(warning(push)) \ + __pragma(warning(disable:4231)) \ + UNITTEST_IMPEXP_TEMPLATE template class UNITTEST_LINKAGE std::allocator < T >; \ + UNITTEST_IMPEXP_TEMPLATE template class UNITTEST_LINKAGE std::vector< T >; \ + __pragma(warning(pop)) +#else + #define UNITTEST_IMPORT + #define UNITTEST_EXPORT + #define UNITTEST_LINKAGE + #define UNITTEST_IMPEXP_TEMPLATE + #define UNITTEST_STDVECTOR_LINKAGE(T) +#endif + +#endif From 88b09d46e81303d65d7098da226ccc67a6dedb3c Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Wed, 9 Jan 2013 23:44:22 -0600 Subject: [PATCH 17/30] r18 | charles.nicholson | 2010-03-18 15:42:23 -0500 (Thu, 18 Mar 2010) | 1 line add scea 'TestReporterMulti' as 'CompositeTestReporter', add tests --- Makefile | 6 +- src/CompositeTestReporter.cpp | 67 +++++++++ src/CompositeTestReporter.h | 34 +++++ src/TestReporter.cpp | 1 - src/tests/TestCompositeTestReporter.cpp | 176 ++++++++++++++++++++++++ src/tests/test-unittestpp_vs2005.vcproj | 4 + src/unittestpp_vs2005.vcproj | 8 ++ 7 files changed, 293 insertions(+), 3 deletions(-) create mode 100644 src/CompositeTestReporter.cpp create mode 100644 src/CompositeTestReporter.h create mode 100644 src/tests/TestCompositeTestReporter.cpp diff --git a/Makefile b/Makefile index b590a3f..205dedc 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,8 @@ src = src/AssertException.cpp \ src/DeferredTestReporter.cpp \ src/DeferredTestResult.cpp \ src/XmlTestReporter.cpp \ - src/CurrentTest.cpp + src/CurrentTest.cpp \ + src/CompositeTestReporter.cpp ifeq ($(MSYSTEM), MINGW32) src += src/Win32/TimeHelpers.cpp @@ -49,7 +50,8 @@ test_src = src/tests/Main.cpp \ src/tests/TestMemoryOutStream.cpp \ src/tests/TestDeferredTestReporter.cpp \ src/tests/TestXmlTestReporter.cpp \ - src/tests/TestCurrentTest.cpp + src/tests/TestCurrentTest.cpp \ + src/tests/TestCompositeTestReporter.cpp objects = $(patsubst %.cpp, %.o, $(src)) test_objects = $(patsubst %.cpp, %.o, $(test_src)) diff --git a/src/CompositeTestReporter.cpp b/src/CompositeTestReporter.cpp new file mode 100644 index 0000000..2a3d22e --- /dev/null +++ b/src/CompositeTestReporter.cpp @@ -0,0 +1,67 @@ +#include "CompositeTestReporter.h" +#include + +namespace UnitTest { + +CompositeTestReporter::CompositeTestReporter() + : m_reporterCount(0) +{ +} + +int CompositeTestReporter::GetReporterCount() const +{ + return m_reporterCount; +} + +bool CompositeTestReporter::AddReporter(TestReporter* reporter) +{ + if (m_reporterCount == kMaxReporters) + return false; + + m_reporters[m_reporterCount++] = reporter; + return true; +} + +bool CompositeTestReporter::RemoveReporter(TestReporter* reporter) +{ + for (int index = 0; index < m_reporterCount; ++index) + { + if (m_reporters[index] == reporter) + { + m_reporters[index] = m_reporters[m_reporterCount - 1]; + --m_reporterCount; + return true; + } + } + + return false; +} + +void CompositeTestReporter::ReportFailure(TestDetails const& details, char const* failure) +{ + for (int index = 0; index < m_reporterCount; ++index) + m_reporters[index]->ReportFailure(details, failure); +} + +void CompositeTestReporter::ReportTestStart(TestDetails const& test) +{ + for (int index = 0; index < m_reporterCount; ++index) + m_reporters[index]->ReportTestStart(test); +} + +void CompositeTestReporter::ReportTestFinish(TestDetails const& test, float secondsElapsed) +{ + for (int index = 0; index < m_reporterCount; ++index) + m_reporters[index]->ReportTestFinish(test, secondsElapsed); +} + +void CompositeTestReporter::ReportSummary(int totalTestCount, + int failedTestCount, + int failureCount, + float secondsElapsed) +{ + for (int index = 0; index < m_reporterCount; ++index) + m_reporters[index]->ReportSummary(totalTestCount, failedTestCount, failureCount, secondsElapsed); +} + +} diff --git a/src/CompositeTestReporter.h b/src/CompositeTestReporter.h new file mode 100644 index 0000000..a4806f4 --- /dev/null +++ b/src/CompositeTestReporter.h @@ -0,0 +1,34 @@ +#ifndef UNITTEST_COMPOSITETESTREPORTER_H +#define UNITTEST_COMPOSITETESTREPORTER_H + +#include "TestReporter.h" + +namespace UnitTest { + +class UNITTEST_LINKAGE CompositeTestReporter : public TestReporter +{ +public: + CompositeTestReporter(); + + int GetReporterCount() const; + bool AddReporter(TestReporter* reporter); + bool RemoveReporter(TestReporter* reporter); + + virtual void ReportTestStart(TestDetails const& test); + virtual void ReportFailure(TestDetails const& test, char const* failure); + virtual void ReportTestFinish(TestDetails const& test, float secondsElapsed); + virtual void ReportSummary(int totalTestCount, int failedTestCount, int failureCount, float secondsElapsed); + +private: + enum { kMaxReporters = 16 }; + TestReporter* m_reporters[kMaxReporters]; + int m_reporterCount; + + // revoked + CompositeTestReporter(const CompositeTestReporter&); + CompositeTestReporter& operator =(const CompositeTestReporter&); +}; + +} + +#endif diff --git a/src/TestReporter.cpp b/src/TestReporter.cpp index c783af1..78c765f 100644 --- a/src/TestReporter.cpp +++ b/src/TestReporter.cpp @@ -2,7 +2,6 @@ namespace UnitTest { - TestReporter::~TestReporter() { } diff --git a/src/tests/TestCompositeTestReporter.cpp b/src/tests/TestCompositeTestReporter.cpp new file mode 100644 index 0000000..d302577 --- /dev/null +++ b/src/tests/TestCompositeTestReporter.cpp @@ -0,0 +1,176 @@ +#include "../../unittestpp.h" +#include "../CompositeTestReporter.h" + +using namespace UnitTest; + +namespace { + +TEST(ZeroReportersByDefault) +{ + CHECK_EQUAL(0, CompositeTestReporter().GetReporterCount()); +} + +struct MockReporter : TestReporter +{ + MockReporter() + : testStartCalled(false) + , testStartDetails(NULL) + , failureCalled(false) + , failureDetails(NULL) + , failureStr(NULL) + , testFinishCalled(false) + , testFinishDetails(NULL) + , testFinishSecondsElapsed(-1.0f) + , summaryCalled(false) + , summaryTotalTestCount(-1) + , summaryFailureCount(-1) + , summarySecondsElapsed(-1.0f) + { + } + + virtual void ReportTestStart(TestDetails const& test) + { + testStartCalled = true; + testStartDetails = &test; + } + + virtual void ReportFailure(TestDetails const& test, char const* failure) + { + failureCalled = true; + failureDetails = &test; + failureStr = failure; + } + + virtual void ReportTestFinish(TestDetails const& test, float secondsElapsed) + { + testFinishCalled = true; + testFinishDetails = &test; + testFinishSecondsElapsed = secondsElapsed; + } + + virtual void ReportSummary(int totalTestCount, + int failedTestCount, + int failureCount, + float secondsElapsed) + { + summaryCalled = true; + summaryTotalTestCount = totalTestCount; + summaryFailedTestCount = failedTestCount; + summaryFailureCount = failureCount; + summarySecondsElapsed = secondsElapsed; + } + + bool testStartCalled; + TestDetails const* testStartDetails; + + bool failureCalled; + TestDetails const* failureDetails; + const char* failureStr; + + bool testFinishCalled; + TestDetails const* testFinishDetails; + float testFinishSecondsElapsed; + + bool summaryCalled; + int summaryTotalTestCount; + int summaryFailedTestCount; + int summaryFailureCount; + float summarySecondsElapsed; +}; + +TEST(AddReporter) +{ + MockReporter r; + CompositeTestReporter c; + + CHECK(c.AddReporter(&r)); + CHECK_EQUAL(1, c.GetReporterCount()); +} + +TEST(RemoveReporter) +{ + MockReporter r; + CompositeTestReporter c; + + c.AddReporter(&r); + CHECK(c.RemoveReporter(&r)); + CHECK_EQUAL(0, c.GetReporterCount()); +} + +struct Fixture +{ + Fixture() + { + c.AddReporter(&r0); + c.AddReporter(&r1); + } + + MockReporter r0, r1; + CompositeTestReporter c; +}; + +TEST_FIXTURE(Fixture, ReportTestStartCallsReportTestStartOnAllAggregates) +{ + TestDetails t("", "", "", 0); + c.ReportTestStart(t); + + CHECK(r0.testStartCalled); + CHECK_EQUAL(&t, r0.testStartDetails); + CHECK(r1.testStartCalled); + CHECK_EQUAL(&t, r1.testStartDetails); +} + +TEST_FIXTURE(Fixture, ReportFailureCallsReportFailureOnAllAggregates) +{ + TestDetails t("", "", "", 0); + const char* failStr = "fail"; + c.ReportFailure(t, failStr); + + CHECK(r0.failureCalled); + CHECK_EQUAL(&t, r0.failureDetails); + CHECK_EQUAL(failStr, r0.failureStr); + + CHECK(r1.failureCalled); + CHECK_EQUAL(&t, r1.failureDetails); + CHECK_EQUAL(failStr, r1.failureStr); +} + +TEST_FIXTURE(Fixture, ReportTestFinishCallsReportTestFinishOnAllAggregates) +{ + TestDetails t("", "", "", 0); + const float s = 1.2345f; + c.ReportTestFinish(t, s); + + CHECK(r0.testFinishCalled); + CHECK_EQUAL(&t, r0.testFinishDetails); + CHECK_CLOSE(s, r0.testFinishSecondsElapsed, 0.00001f); + + CHECK(r1.testFinishCalled); + CHECK_EQUAL(&t, r1.testFinishDetails); + CHECK_CLOSE(s, r1.testFinishSecondsElapsed, 0.00001f); +} + +TEST_FIXTURE(Fixture, ReportSummaryCallsReportSummaryOnAllAggregates) +{ + TestDetails t("", "", "", 0); + const int testCount = 3; + const int failedTestCount = 4; + const int failureCount = 5; + const float secondsElapsed = 3.14159f; + + c.ReportSummary(testCount, failedTestCount, failureCount, secondsElapsed); + + CHECK(r0.summaryCalled); + CHECK_EQUAL(testCount, r0.summaryTotalTestCount); + CHECK_EQUAL(failedTestCount, r0.summaryFailedTestCount); + CHECK_EQUAL(failureCount, r0.summaryFailureCount); + CHECK_CLOSE(secondsElapsed, r0.summarySecondsElapsed, 0.00001f); + + CHECK(r1.summaryCalled); + CHECK_EQUAL(testCount, r1.summaryTotalTestCount); + CHECK_EQUAL(failedTestCount, r1.summaryFailedTestCount); + CHECK_EQUAL(failureCount, r1.summaryFailureCount); + CHECK_CLOSE(secondsElapsed, r1.summarySecondsElapsed, 0.00001f); +} + +} diff --git a/src/tests/test-unittestpp_vs2005.vcproj b/src/tests/test-unittestpp_vs2005.vcproj index 8747e87..b11a266 100644 --- a/src/tests/test-unittestpp_vs2005.vcproj +++ b/src/tests/test-unittestpp_vs2005.vcproj @@ -357,6 +357,10 @@ RelativePath=".\TestChecks.cpp" > + + diff --git a/src/unittestpp_vs2005.vcproj b/src/unittestpp_vs2005.vcproj index 8b1b042..b9d0e16 100644 --- a/src/unittestpp_vs2005.vcproj +++ b/src/unittestpp_vs2005.vcproj @@ -325,6 +325,14 @@ RelativePath=".\Checks.h" > + + + + From a0501f6b713132270f4c018c91050f0e7df142d8 Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Wed, 9 Jan 2013 23:44:30 -0600 Subject: [PATCH 18/30] r19 | charles.nicholson | 2010-03-18 16:22:06 -0500 (Thu, 18 Mar 2010) | 1 line add mt and md build configurations for vs2005, for CRT selection convenience --- src/tests/test-unittestpp_vs2005.vcproj | 169 +++++++++++++++++++++++- src/unittestpp_vs2005.vcproj | 139 ++++++++++++++++++- unittestpp_vs2005.sln | 30 +++-- 3 files changed, 316 insertions(+), 22 deletions(-) diff --git a/src/tests/test-unittestpp_vs2005.vcproj b/src/tests/test-unittestpp_vs2005.vcproj index b11a266..e13fba8 100644 --- a/src/tests/test-unittestpp_vs2005.vcproj +++ b/src/tests/test-unittestpp_vs2005.vcproj @@ -16,9 +16,9 @@ @@ -94,9 +94,9 @@ /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/unittestpp_vs2005.vcproj b/src/unittestpp_vs2005.vcproj index b9d0e16..67c8c28 100644 --- a/src/unittestpp_vs2005.vcproj +++ b/src/unittestpp_vs2005.vcproj @@ -16,9 +16,9 @@ @@ -80,9 +80,9 @@ /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/unittestpp_vs2005.sln b/unittestpp_vs2005.sln index 2f9a3cd..69074e8 100644 --- a/unittestpp_vs2005.sln +++ b/unittestpp_vs2005.sln @@ -12,26 +12,36 @@ Global GlobalSection(SolutionConfigurationPlatforms) = preSolution win32_dll_debug|Win32 = win32_dll_debug|Win32 win32_dll_release|Win32 = win32_dll_release|Win32 - win32_lib_debug|Win32 = win32_lib_debug|Win32 - win32_lib_release|Win32 = win32_lib_release|Win32 + win32_lib_md_debug|Win32 = win32_lib_md_debug|Win32 + win32_lib_md_release|Win32 = win32_lib_md_release|Win32 + win32_lib_mt_debug|Win32 = win32_lib_mt_debug|Win32 + win32_lib_mt_release|Win32 = win32_lib_mt_release|Win32 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {64A4FEFE-0461-4E95-8CC1-91EF5F57DBC6}.win32_dll_debug|Win32.ActiveCfg = win32_dll_debug|Win32 {64A4FEFE-0461-4E95-8CC1-91EF5F57DBC6}.win32_dll_debug|Win32.Build.0 = win32_dll_debug|Win32 {64A4FEFE-0461-4E95-8CC1-91EF5F57DBC6}.win32_dll_release|Win32.ActiveCfg = win32_dll_release|Win32 {64A4FEFE-0461-4E95-8CC1-91EF5F57DBC6}.win32_dll_release|Win32.Build.0 = win32_dll_release|Win32 - {64A4FEFE-0461-4E95-8CC1-91EF5F57DBC6}.win32_lib_debug|Win32.ActiveCfg = win32_lib_debug|Win32 - {64A4FEFE-0461-4E95-8CC1-91EF5F57DBC6}.win32_lib_debug|Win32.Build.0 = win32_lib_debug|Win32 - {64A4FEFE-0461-4E95-8CC1-91EF5F57DBC6}.win32_lib_release|Win32.ActiveCfg = win32_lib_release|Win32 - {64A4FEFE-0461-4E95-8CC1-91EF5F57DBC6}.win32_lib_release|Win32.Build.0 = win32_lib_release|Win32 + {64A4FEFE-0461-4E95-8CC1-91EF5F57DBC6}.win32_lib_md_debug|Win32.ActiveCfg = win32_lib_md_debug|Win32 + {64A4FEFE-0461-4E95-8CC1-91EF5F57DBC6}.win32_lib_md_debug|Win32.Build.0 = win32_lib_md_debug|Win32 + {64A4FEFE-0461-4E95-8CC1-91EF5F57DBC6}.win32_lib_md_release|Win32.ActiveCfg = win32_lib_md_release|Win32 + {64A4FEFE-0461-4E95-8CC1-91EF5F57DBC6}.win32_lib_md_release|Win32.Build.0 = win32_lib_md_release|Win32 + {64A4FEFE-0461-4E95-8CC1-91EF5F57DBC6}.win32_lib_mt_debug|Win32.ActiveCfg = win32_lib_mt_debug|Win32 + {64A4FEFE-0461-4E95-8CC1-91EF5F57DBC6}.win32_lib_mt_debug|Win32.Build.0 = win32_lib_mt_debug|Win32 + {64A4FEFE-0461-4E95-8CC1-91EF5F57DBC6}.win32_lib_mt_release|Win32.ActiveCfg = win32_lib_mt_release|Win32 + {64A4FEFE-0461-4E95-8CC1-91EF5F57DBC6}.win32_lib_mt_release|Win32.Build.0 = win32_lib_mt_release|Win32 {9CCC3439-309E-4E85-B3B8-CE704D385D48}.win32_dll_debug|Win32.ActiveCfg = win32_dll_debug|Win32 {9CCC3439-309E-4E85-B3B8-CE704D385D48}.win32_dll_debug|Win32.Build.0 = win32_dll_debug|Win32 {9CCC3439-309E-4E85-B3B8-CE704D385D48}.win32_dll_release|Win32.ActiveCfg = win32_dll_release|Win32 {9CCC3439-309E-4E85-B3B8-CE704D385D48}.win32_dll_release|Win32.Build.0 = win32_dll_release|Win32 - {9CCC3439-309E-4E85-B3B8-CE704D385D48}.win32_lib_debug|Win32.ActiveCfg = win32_static_debug|Win32 - {9CCC3439-309E-4E85-B3B8-CE704D385D48}.win32_lib_debug|Win32.Build.0 = win32_static_debug|Win32 - {9CCC3439-309E-4E85-B3B8-CE704D385D48}.win32_lib_release|Win32.ActiveCfg = win32_static_release|Win32 - {9CCC3439-309E-4E85-B3B8-CE704D385D48}.win32_lib_release|Win32.Build.0 = win32_static_release|Win32 + {9CCC3439-309E-4E85-B3B8-CE704D385D48}.win32_lib_md_debug|Win32.ActiveCfg = win32_static_md_debug|Win32 + {9CCC3439-309E-4E85-B3B8-CE704D385D48}.win32_lib_md_debug|Win32.Build.0 = win32_static_md_debug|Win32 + {9CCC3439-309E-4E85-B3B8-CE704D385D48}.win32_lib_md_release|Win32.ActiveCfg = win32_static_md_release|Win32 + {9CCC3439-309E-4E85-B3B8-CE704D385D48}.win32_lib_md_release|Win32.Build.0 = win32_static_md_release|Win32 + {9CCC3439-309E-4E85-B3B8-CE704D385D48}.win32_lib_mt_debug|Win32.ActiveCfg = win32_static_mt_debug|Win32 + {9CCC3439-309E-4E85-B3B8-CE704D385D48}.win32_lib_mt_debug|Win32.Build.0 = win32_static_mt_debug|Win32 + {9CCC3439-309E-4E85-B3B8-CE704D385D48}.win32_lib_mt_release|Win32.ActiveCfg = win32_static_mt_release|Win32 + {9CCC3439-309E-4E85-B3B8-CE704D385D48}.win32_lib_mt_release|Win32.Build.0 = win32_static_mt_release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From 534aca32360329a25853e000c62b187062ddab3e Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Wed, 9 Jan 2013 23:44:37 -0600 Subject: [PATCH 19/30] r20 | charles.nicholson | 2010-03-18 16:49:54 -0500 (Thu, 18 Mar 2010) | 1 line add UNITTEST_WIN32 macro, turn dllmacros.h into helpermacros.h, wrap do/while(0) in __pragma to avoid VS 'conditional expression is constant' warning --- config.h | 6 ++-- src/AssertException.h | 2 +- src/CheckMacros.h | 43 ++++++++++++----------------- src/CurrentTest.h | 2 +- src/DeferredTestResult.h | 2 +- src/{DllMacros.h => HelperMacros.h} | 14 ++++++++-- src/MemoryOutStream.h | 2 +- src/ReportAssert.h | 2 +- src/ReportAssertImpl.h | 2 +- src/TestDetails.h | 2 +- src/TestList.h | 2 +- src/TestReporter.h | 2 +- src/TestReporterStdout.cpp | 2 +- src/TestResults.h | 2 +- src/TimeConstraint.h | 7 +++-- src/Win32/TimeHelpers.cpp | 2 +- src/Win32/TimeHelpers.h | 2 +- src/tests/TestExceptions.cpp | 18 ++++++------ src/unittestpp_vs2005.vcproj | 6 ++-- 19 files changed, 63 insertions(+), 57 deletions(-) rename src/{DllMacros.h => HelperMacros.h} (68%) diff --git a/config.h b/config.h index 52e7e28..03b0bd9 100644 --- a/config.h +++ b/config.h @@ -4,7 +4,6 @@ // Standard defines documented here: http://predef.sourceforge.net #if defined(_MSC_VER) - #pragma warning(disable:4127) // conditional expression is constant #pragma warning(disable:4702) // unreachable code #pragma warning(disable:4722) // destructor never returns, potential memory leak @@ -16,6 +15,7 @@ #ifdef _USRDLL #define UNITTEST_WIN32_DLL #endif + #define UNITTEST_WIN32 #endif #if defined(unix) || defined(__unix__) || defined(__unix) || defined(linux) || \ @@ -30,8 +30,8 @@ // by default, MemoryOutStream is implemented in terms of std::ostringstream, which can be expensive. // uncomment this line to use the custom MemoryOutStream (no deps on std::ostringstream). -#define UNITTEST_USE_CUSTOM_STREAMS +//#define UNITTEST_USE_CUSTOM_STREAMS #define UNITTEST_USE_DEFERRED_REPORTER -#define UNITTEST_USE_EXCEPTIONS +//#define UNITTEST_USE_EXCEPTIONS #endif diff --git a/src/AssertException.h b/src/AssertException.h index cd40bfd..4a98ed0 100644 --- a/src/AssertException.h +++ b/src/AssertException.h @@ -4,7 +4,7 @@ #include "../config.h" #ifdef UNITTEST_USE_EXCEPTIONS -#include "DllMacros.h" +#include "HelperMacros.h" #include namespace UnitTest { diff --git a/src/CheckMacros.h b/src/CheckMacros.h index c29d78e..671688e 100644 --- a/src/CheckMacros.h +++ b/src/CheckMacros.h @@ -1,6 +1,7 @@ #ifndef UNITTEST_CHECKMACROS_H #define UNITTEST_CHECKMACROS_H +#include "HelperMacros.h" #include "ExceptionMacros.h" #include "Checks.h" #include "AssertException.h" @@ -34,9 +35,8 @@ #endif #define CHECK(value) \ - do \ - { \ - UT_TRY \ + UNITTEST_MULTILINE_MACRO_BEGIN \ + UT_TRY \ ({ \ if (!UnitTest::Check(value)) \ UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), #value); \ @@ -46,11 +46,10 @@ UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \ "Unhandled exception in CHECK(" #value ")"); \ }) \ - } while (0) + UNITTEST_MULTILINE_MACRO_END #define CHECK_EQUAL(expected, actual) \ - do \ - { \ + UNITTEST_MULTILINE_MACRO_BEGIN \ UT_TRY \ ({ \ UnitTest::CheckEqual(*UnitTest::CurrentTest::Results(), expected, actual, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \ @@ -60,11 +59,10 @@ UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \ "Unhandled exception in CHECK_EQUAL(" #expected ", " #actual ")"); \ }) \ - } while (0) + UNITTEST_MULTILINE_MACRO_END #define CHECK_CLOSE(expected, actual, tolerance) \ - do \ - { \ + UNITTEST_MULTILINE_MACRO_BEGIN \ UT_TRY \ ({ \ UnitTest::CheckClose(*UnitTest::CurrentTest::Results(), expected, actual, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \ @@ -74,11 +72,10 @@ UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \ "Unhandled exception in CHECK_CLOSE(" #expected ", " #actual ")"); \ }) \ - } while (0) + UNITTEST_MULTILINE_MACRO_END #define CHECK_ARRAY_EQUAL(expected, actual, count) \ - do \ - { \ + UNITTEST_MULTILINE_MACRO_BEGIN \ UT_TRY \ ({ \ UnitTest::CheckArrayEqual(*UnitTest::CurrentTest::Results(), expected, actual, count, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \ @@ -88,11 +85,10 @@ UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \ "Unhandled exception in CHECK_ARRAY_EQUAL(" #expected ", " #actual ")"); \ }) \ - } while (0) + UNITTEST_MULTILINE_MACRO_END #define CHECK_ARRAY_CLOSE(expected, actual, count, tolerance) \ - do \ - { \ + UNITTEST_MULTILINE_MACRO_BEGIN \ UT_TRY \ ({ \ UnitTest::CheckArrayClose(*UnitTest::CurrentTest::Results(), expected, actual, count, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \ @@ -102,11 +98,10 @@ UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \ "Unhandled exception in CHECK_ARRAY_CLOSE(" #expected ", " #actual ")"); \ }) \ - } while (0) + UNITTEST_MULTILINE_MACRO_END #define CHECK_ARRAY2D_CLOSE(expected, actual, rows, columns, tolerance) \ - do \ - { \ + UNITTEST_MULTILINE_MACRO_BEGIN \ UT_TRY \ ({ \ UnitTest::CheckArray2DClose(*UnitTest::CurrentTest::Results(), expected, actual, rows, columns, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \ @@ -116,29 +111,27 @@ UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \ "Unhandled exception in CHECK_ARRAY_CLOSE(" #expected ", " #actual ")"); \ }) \ - } while (0) + UNITTEST_MULTILINE_MACRO_END // CHECK_THROW and CHECK_ASSERT only exist when UNITTEST_USE_EXCEPTIONS is defined (see Config.h) #ifdef UNITTEST_USE_EXCEPTIONS #define CHECK_THROW(expression, ExpectedExceptionType) \ - do \ - { \ + UNITTEST_MULTILINE_MACRO_BEGIN \ bool caught_ = false; \ try { expression; } \ catch (ExpectedExceptionType const&) { caught_ = true; } \ catch (...) {} \ if (!caught_) \ UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), "Expected exception: \"" #ExpectedExceptionType "\" not thrown"); \ - } while(0) + UNITTEST_MULTILINE_MACRO_END #define CHECK_ASSERT(expression) \ - do \ - { \ + UNITTEST_MULTILINE_MACRO_BEGIN \ UnitTest::Detail::ExpectAssert(true); \ CHECK_THROW(expression, UnitTest::AssertException); \ UnitTest::Detail::ExpectAssert(false); \ - } while(0) + UNITTEST_MULTILINE_MACRO_END #endif #endif \ No newline at end of file diff --git a/src/CurrentTest.h b/src/CurrentTest.h index 190c99b..0d62fdc 100644 --- a/src/CurrentTest.h +++ b/src/CurrentTest.h @@ -1,7 +1,7 @@ #ifndef UNITTEST_CURRENTTESTRESULTS_H #define UNITTEST_CURRENTTESTRESULTS_H -#include "DllMacros.h" +#include "HelperMacros.h" namespace UnitTest { diff --git a/src/DeferredTestResult.h b/src/DeferredTestResult.h index 5729434..fde3b21 100644 --- a/src/DeferredTestResult.h +++ b/src/DeferredTestResult.h @@ -4,7 +4,7 @@ #include "../config.h" #ifdef UNITTEST_USE_DEFERRED_REPORTER -#include "DllMacros.h" +#include "HelperMacros.h" #include #include diff --git a/src/DllMacros.h b/src/HelperMacros.h similarity index 68% rename from src/DllMacros.h rename to src/HelperMacros.h index c88818d..9560d13 100644 --- a/src/DllMacros.h +++ b/src/HelperMacros.h @@ -1,8 +1,18 @@ -#ifndef UNITTEST_DLLMACROS_H -#define UNITTEST_DLLMACROS_H +#ifndef UNITTEST_HELPERMACROS_H +#define UNITTEST_HELPERMACROS_H #include "../config.h" +#define UNITTEST_MULTILINE_MACRO_BEGIN do { + +#ifdef UNITTEST_WIN32 + #define UNITTEST_MULTILINE_MACRO_END \ + } __pragma(warning(push)) __pragma(warning(disable:4127)) while (0) __pragma(warning(pop)) +#else + #define UNITTEST_MULTILINE_MACRO_END } while(0) +#endif + + #ifdef UNITTEST_WIN32_DLL #define UNITTEST_IMPORT __declspec(dllimport) #define UNITTEST_EXPORT __declspec(dllexport) diff --git a/src/MemoryOutStream.h b/src/MemoryOutStream.h index 06c1adb..1ba51e0 100644 --- a/src/MemoryOutStream.h +++ b/src/MemoryOutStream.h @@ -2,7 +2,7 @@ #define UNITTEST_MEMORYOUTSTREAM_H #include "../config.h" -#include "DllMacros.h" +#include "HelperMacros.h" #ifndef UNITTEST_USE_CUSTOM_STREAMS diff --git a/src/ReportAssert.h b/src/ReportAssert.h index 0ca0b6e..7bdf7bb 100644 --- a/src/ReportAssert.h +++ b/src/ReportAssert.h @@ -1,7 +1,7 @@ #ifndef UNITTEST_ASSERT_H #define UNITTEST_ASSERT_H -#include "DllMacros.h" +#include "HelperMacros.h" namespace UnitTest { diff --git a/src/ReportAssertImpl.h b/src/ReportAssertImpl.h index 659ad9e..1560725 100644 --- a/src/ReportAssertImpl.h +++ b/src/ReportAssertImpl.h @@ -27,7 +27,7 @@ UNITTEST_LINKAGE bool AssertExpected(); #ifndef UNITTEST_USE_EXCEPTIONS UNITTEST_LINKAGE jmp_buf* GetAssertJmpBuf(); - #ifdef _MSC_VER + #ifdef UNITTEST_WIN32 #define UNITTEST_SET_ASSERT_JUMP_TARGET() \ __pragma(warning(push)) __pragma(warning(disable:4611)) \ setjmp(*UnitTest::Detail::GetAssertJmpBuf()) \ diff --git a/src/TestDetails.h b/src/TestDetails.h index 909179b..898f7f3 100644 --- a/src/TestDetails.h +++ b/src/TestDetails.h @@ -1,7 +1,7 @@ #ifndef UNITTEST_TESTDETAILS_H #define UNITTEST_TESTDETAILS_H -#include "DllMacros.h" +#include "HelperMacros.h" namespace UnitTest { diff --git a/src/TestList.h b/src/TestList.h index 32a7280..ed190c2 100644 --- a/src/TestList.h +++ b/src/TestList.h @@ -1,7 +1,7 @@ #ifndef UNITTEST_TESTLIST_H #define UNITTEST_TESTLIST_H -#include "DllMacros.h" +#include "HelperMacros.h" namespace UnitTest { diff --git a/src/TestReporter.h b/src/TestReporter.h index 2ee9130..99bfaa6 100644 --- a/src/TestReporter.h +++ b/src/TestReporter.h @@ -1,7 +1,7 @@ #ifndef UNITTEST_TESTREPORTER_H #define UNITTEST_TESTREPORTER_H -#include "DllMacros.h" +#include "HelperMacros.h" namespace UnitTest { diff --git a/src/TestReporterStdout.cpp b/src/TestReporterStdout.cpp index 3a29db4..cd2c131 100644 --- a/src/TestReporterStdout.cpp +++ b/src/TestReporterStdout.cpp @@ -4,7 +4,7 @@ #include "TestDetails.h" // cstdio doesn't pull in namespace std on VC6, so we do it here. -#if defined(_MSC_VER) && (_MSC_VER == 1200) +#if defined(UNITTEST_WIN32) && (_MSC_VER == 1200) namespace std {} #endif diff --git a/src/TestResults.h b/src/TestResults.h index a856c0d..d4006a0 100644 --- a/src/TestResults.h +++ b/src/TestResults.h @@ -1,7 +1,7 @@ #ifndef UNITTEST_TESTRESULTS_H #define UNITTEST_TESTRESULTS_H -#include "DllMacros.h" +#include "HelperMacros.h" namespace UnitTest { diff --git a/src/TimeConstraint.h b/src/TimeConstraint.h index 6989726..fe14461 100644 --- a/src/TimeConstraint.h +++ b/src/TimeConstraint.h @@ -2,7 +2,7 @@ #define UNITTEST_TIMECONSTRAINT_H #include "TimeHelpers.h" -#include "DllMacros.h" +#include "HelperMacros.h" namespace UnitTest { @@ -27,7 +27,10 @@ class UNITTEST_LINKAGE TimeConstraint #define UNITTEST_TIME_CONSTRAINT(ms) \ UnitTest::TimeConstraint unitTest__timeConstraint__(ms, UnitTest::TestDetails(m_details, __LINE__)) -#define UNITTEST_TIME_CONSTRAINT_EXEMPT() do { m_timeConstraintExempt = true; } while (0) +#define UNITTEST_TIME_CONSTRAINT_EXEMPT() \ + UNITTEST_MULTILINE_MACRO_BEGIN \ + m_timeConstraintExempt = true; \ + UNITTEST_MULTILINE_MACRO_END } diff --git a/src/Win32/TimeHelpers.cpp b/src/Win32/TimeHelpers.cpp index f7568be..1b39cab 100644 --- a/src/Win32/TimeHelpers.cpp +++ b/src/Win32/TimeHelpers.cpp @@ -9,7 +9,7 @@ Timer::Timer() : m_threadHandle(::GetCurrentThread()) , m_startTime(0) { -#if defined(_MSC_VER) && (_MSC_VER == 1200) // VC6 doesn't have DWORD_PTR +#if defined(UNITTEST_WIN32) && (_MSC_VER == 1200) // VC6 doesn't have DWORD_PTR typedef unsigned long DWORD_PTR; #endif diff --git a/src/Win32/TimeHelpers.h b/src/Win32/TimeHelpers.h index fd19ef4..80c9118 100644 --- a/src/Win32/TimeHelpers.h +++ b/src/Win32/TimeHelpers.h @@ -2,7 +2,7 @@ #define UNITTEST_TIMEHELPERS_H #include "../../config.h" -#include "../DllMacros.h" +#include "../HelperMacros.h" #ifdef UNITTEST_MINGW #ifndef __int64 diff --git a/src/tests/TestExceptions.cpp b/src/tests/TestExceptions.cpp index 88f9c70..5894e2c 100644 --- a/src/tests/TestExceptions.cpp +++ b/src/tests/TestExceptions.cpp @@ -93,7 +93,7 @@ TEST(CheckCloseFailsOnException) RecordingReporter reporter; UnitTest::TestResults testResults(&reporter); ScopedCurrentTest scopedResults(testResults); - CHECK_CLOSE ((float)ThrowingFunction(), 1.0001f, 0.1f); + CHECK_CLOSE((float)ThrowingFunction(), 1.0001f, 0.1f); failure = (testResults.GetFailureCount() > 0); } @@ -108,7 +108,7 @@ TEST(CheckCloseFailureBecauseOfExceptionContainsCorrectDetails) UnitTest::TestResults testResults(&reporter); UnitTest::TestDetails testDetails("closeTest", "closeSuite", "filename", -1); ScopedCurrentTest scopedResults(testResults, &testDetails); - CHECK_CLOSE ((float)ThrowingFunction(), 1.0001f, 0.1f); line = __LINE__; + CHECK_CLOSE((float)ThrowingFunction(), 1.0001f, 0.1f); line = __LINE__; } CHECK_EQUAL("closeTest", reporter.lastFailedTest); @@ -123,7 +123,7 @@ TEST(CheckCloseFailureBecauseOfExceptionIncludesCheckContents) { UnitTest::TestResults testResults(&reporter); ScopedCurrentTest scopedResults(testResults); - CHECK_CLOSE ((float)ThrowingFunction(), 1.0001f, 0.1f); + CHECK_CLOSE((float)ThrowingFunction(), 1.0001f, 0.1f); } CHECK(strstr(reporter.lastFailedMessage, "(float)ThrowingFunction()")); @@ -149,7 +149,7 @@ TEST(CheckArrayCloseFailureBecauseOfExceptionContainsCorrectDetails) ScopedCurrentTest scopedResults(testResults, &testDetails); int const data[4] = { 0, 1, 2, 3 }; - CHECK_ARRAY_CLOSE (data, ThrowingObject(), 4, 0.01f); line = __LINE__; + CHECK_ARRAY_CLOSE(data, ThrowingObject(), 4, 0.01f); line = __LINE__; } CHECK_EQUAL("arrayCloseTest", reporter.lastFailedTest); @@ -168,7 +168,7 @@ TEST(CheckArrayCloseFailsOnException) const float data[4] = { 0, 1, 2, 3 }; ThrowingObject obj; - CHECK_ARRAY_CLOSE (data, obj, 3, 0.01f); + CHECK_ARRAY_CLOSE(data, obj, 3, 0.01f); failure = (testResults.GetFailureCount() > 0); } @@ -185,7 +185,7 @@ TEST(CheckArrayCloseFailureOnExceptionIncludesCheckContents) const float data[4] = { 0, 1, 2, 3 }; ThrowingObject obj; - CHECK_ARRAY_CLOSE (data, obj, 3, 0.01f); + CHECK_ARRAY_CLOSE(data, obj, 3, 0.01f); } CHECK(strstr(reporter.lastFailedMessage, "data")); @@ -253,7 +253,7 @@ TEST(CheckArray2DCloseFailureBecauseOfExceptionContainsCorrectDetails) ScopedCurrentTest scopedResults(testResults, &testDetails); const float data[2][2] = { {0, 1}, {2, 3} }; - CHECK_ARRAY2D_CLOSE (data, ThrowingObject2D(), 2, 2, 0.01f); line = __LINE__; + CHECK_ARRAY2D_CLOSE(data, ThrowingObject2D(), 2, 2, 0.01f); line = __LINE__; } CHECK_EQUAL("array2DCloseTest", reporter.lastFailedTest); @@ -272,7 +272,7 @@ TEST(CheckArray2DCloseFailsOnException) const float data[2][2] = { {0, 1}, {2, 3} }; ThrowingObject2D obj; - CHECK_ARRAY2D_CLOSE (data, obj, 2, 2, 0.01f); + CHECK_ARRAY2D_CLOSE(data, obj, 2, 2, 0.01f); failure = (testResults.GetFailureCount() > 0); } @@ -289,7 +289,7 @@ TEST(CheckArray2DCloseFailureOnExceptionIncludesCheckContents) const float data[2][2] = { {0, 1}, {2, 3} }; ThrowingObject2D obj; - CHECK_ARRAY2D_CLOSE (data, obj, 2, 2, 0.01f); + CHECK_ARRAY2D_CLOSE(data, obj, 2, 2, 0.01f); } CHECK(strstr(reporter.lastFailedMessage, "data")); diff --git a/src/unittestpp_vs2005.vcproj b/src/unittestpp_vs2005.vcproj index 67c8c28..67aeb6a 100644 --- a/src/unittestpp_vs2005.vcproj +++ b/src/unittestpp_vs2005.vcproj @@ -489,15 +489,15 @@ > Date: Wed, 9 Jan 2013 23:44:42 -0600 Subject: [PATCH 20/30] r21 | charles.nicholson | 2010-03-18 16:52:29 -0500 (Thu, 18 Mar 2010) | 1 line reset config.h macros --- config.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config.h b/config.h index 03b0bd9..18ae8c3 100644 --- a/config.h +++ b/config.h @@ -30,8 +30,8 @@ // by default, MemoryOutStream is implemented in terms of std::ostringstream, which can be expensive. // uncomment this line to use the custom MemoryOutStream (no deps on std::ostringstream). -//#define UNITTEST_USE_CUSTOM_STREAMS +#define UNITTEST_USE_CUSTOM_STREAMS #define UNITTEST_USE_DEFERRED_REPORTER -//#define UNITTEST_USE_EXCEPTIONS +#define UNITTEST_USE_EXCEPTIONS #endif From 7b9e3a17f8b5891032437f455ca27780da7730ad Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Wed, 9 Jan 2013 23:44:50 -0600 Subject: [PATCH 21/30] r22 | charles.nicholson | 2010-03-18 18:39:32 -0500 (Thu, 18 Mar 2010) | 1 line negate config flags and comment them out by default; this allows command-line preprocessor symbol injection to control flags. Useful for having a master copy of utpp that build with different flags for different compilers/platforms --- config.h | 28 +++++++++++++++++++++----- src/AssertException.cpp | 2 +- src/AssertException.h | 2 +- src/CheckMacros.h | 6 +++--- src/DeferredTestReporter.cpp | 2 +- src/DeferredTestReporter.h | 2 +- src/DeferredTestResult.cpp | 2 +- src/DeferredTestResult.h | 2 +- src/ExceptionMacros.h | 2 +- src/ExecuteTest.h | 6 +++--- src/MemoryOutStream.cpp | 10 +++------ src/MemoryOutStream.h | 2 +- src/ReportAssert.cpp | 6 +++--- src/ReportAssertImpl.h | 4 ++-- src/XmlTestReporter.cpp | 2 +- src/XmlTestReporter.h | 2 +- src/tests/TestAssertHandler.cpp | 2 +- src/tests/TestDeferredTestReporter.cpp | 4 ++-- src/tests/TestExceptions.cpp | 2 +- src/tests/TestMemoryOutStream.cpp | 2 +- src/tests/TestTest.cpp | 2 +- src/tests/TestTestMacros.cpp | 4 ++-- src/tests/TestUnitTestPP.cpp | 2 +- src/tests/TestXmlTestReporter.cpp | 18 ++++++++--------- 24 files changed, 65 insertions(+), 51 deletions(-) diff --git a/config.h b/config.h index 18ae8c3..6036173 100644 --- a/config.h +++ b/config.h @@ -27,11 +27,29 @@ #define UNITTEST_MINGW #endif -// by default, MemoryOutStream is implemented in terms of std::ostringstream, which can be expensive. -// uncomment this line to use the custom MemoryOutStream (no deps on std::ostringstream). -#define UNITTEST_USE_CUSTOM_STREAMS -#define UNITTEST_USE_DEFERRED_REPORTER -#define UNITTEST_USE_EXCEPTIONS +// MemoryOutStream is a custom reimplementation of parts of std::ostringstream. +// Uncomment this line to have MemoryOutStream implemented in terms of std::ostringstream. +// This is useful if you are using the CHECK macros on objects that have something like this defined: +// std::ostringstream& operator<<(std::ostringstream& s, const YourObject& value) + +//#define UNITTEST_MEMORYOUTSTREAM_IS_STD_OSTRINGSTREAM + + +// DeferredTestReporter uses the STL to collect test results for subsequent export by reporters like +// XmlTestReporter. If you don't want to use this functionality, uncomment this line and no STL +// headers or code will be compiled into UnitTest++ + +//#define UNITTEST_NO_DEFERRED_REPORTER + + +// By default, asserts that you report via UnitTest::ReportAssert() abort the current test and +// continue to the next one by throwing an exception, which unwinds the stack naturally, destroying +// all auto variables on its way back down. If you don't want to (or can't) use exceptions for your +// platform/compiler, uncomment this line. All exception code will be removed from UnitTest++, +// assert recovery will be done via setjmp/longjmp, and NO correct stack unwinding will happen! + +//#define UNITTEST_NO_EXCEPTIONS + #endif diff --git a/src/AssertException.cpp b/src/AssertException.cpp index 3615b82..634eb07 100644 --- a/src/AssertException.cpp +++ b/src/AssertException.cpp @@ -1,6 +1,6 @@ #include "AssertException.h" -#ifdef UNITTEST_USE_EXCEPTIONS +#ifndef UNITTEST_NO_EXCEPTIONS namespace UnitTest { diff --git a/src/AssertException.h b/src/AssertException.h index 4a98ed0..74291db 100644 --- a/src/AssertException.h +++ b/src/AssertException.h @@ -2,7 +2,7 @@ #define UNITTEST_ASSERTEXCEPTION_H #include "../config.h" -#ifdef UNITTEST_USE_EXCEPTIONS +#ifndef UNITTEST_NO_EXCEPTIONS #include "HelperMacros.h" #include diff --git a/src/CheckMacros.h b/src/CheckMacros.h index 671688e..1e73699 100644 --- a/src/CheckMacros.h +++ b/src/CheckMacros.h @@ -114,8 +114,8 @@ UNITTEST_MULTILINE_MACRO_END -// CHECK_THROW and CHECK_ASSERT only exist when UNITTEST_USE_EXCEPTIONS is defined (see Config.h) -#ifdef UNITTEST_USE_EXCEPTIONS +// CHECK_THROW and CHECK_ASSERT only exist when UNITTEST_NO_EXCEPTIONS isn't defined (see config.h) +#ifndef UNITTEST_NO_EXCEPTIONS #define CHECK_THROW(expression, ExpectedExceptionType) \ UNITTEST_MULTILINE_MACRO_BEGIN \ bool caught_ = false; \ @@ -134,4 +134,4 @@ UnitTest::Detail::ExpectAssert(false); \ UNITTEST_MULTILINE_MACRO_END #endif -#endif \ No newline at end of file +#endif diff --git a/src/DeferredTestReporter.cpp b/src/DeferredTestReporter.cpp index ce59827..83dee1a 100644 --- a/src/DeferredTestReporter.cpp +++ b/src/DeferredTestReporter.cpp @@ -1,5 +1,5 @@ #include "../config.h" -#ifdef UNITTEST_USE_DEFERRED_REPORTER +#ifndef UNITTEST_NO_DEFERRED_REPORTER #include "DeferredTestReporter.h" #include "TestDetails.h" diff --git a/src/DeferredTestReporter.h b/src/DeferredTestReporter.h index 7c2a4c8..d4947f4 100644 --- a/src/DeferredTestReporter.h +++ b/src/DeferredTestReporter.h @@ -3,7 +3,7 @@ #include "../config.h" -#ifdef UNITTEST_USE_DEFERRED_REPORTER +#ifndef UNITTEST_NO_DEFERRED_REPORTER #include "TestReporter.h" #include "DeferredTestResult.h" diff --git a/src/DeferredTestResult.cpp b/src/DeferredTestResult.cpp index f176243..cbf0a8a 100644 --- a/src/DeferredTestResult.cpp +++ b/src/DeferredTestResult.cpp @@ -1,5 +1,5 @@ #include "../config.h" -#ifdef UNITTEST_USE_DEFERRED_REPORTER +#ifndef UNITTEST_NO_DEFERRED_REPORTER #include "DeferredTestResult.h" #include diff --git a/src/DeferredTestResult.h b/src/DeferredTestResult.h index fde3b21..e580d0c 100644 --- a/src/DeferredTestResult.h +++ b/src/DeferredTestResult.h @@ -2,7 +2,7 @@ #define UNITTEST_DEFERREDTESTRESULT_H #include "../config.h" -#ifdef UNITTEST_USE_DEFERRED_REPORTER +#ifndef UNITTEST_NO_DEFERRED_REPORTER #include "HelperMacros.h" #include diff --git a/src/ExceptionMacros.h b/src/ExceptionMacros.h index 311d7e5..4ddf5ec 100644 --- a/src/ExceptionMacros.h +++ b/src/ExceptionMacros.h @@ -3,7 +3,7 @@ #include "../config.h" -#ifdef UNITTEST_USE_EXCEPTIONS +#ifndef UNITTEST_NO_EXCEPTIONS #define UT_TRY(x) try x #define UT_THROW(x) throw x #define UT_CATCH(ExceptionType, ExceptionName, CatchBody) catch(ExceptionType& ExceptionName) CatchBody diff --git a/src/ExecuteTest.h b/src/ExecuteTest.h index f90aa7f..2f47013 100644 --- a/src/ExecuteTest.h +++ b/src/ExecuteTest.h @@ -9,7 +9,7 @@ #include "AssertException.h" #include "CurrentTest.h" -#ifndef UNITTEST_USE_EXCEPTIONS +#ifdef UNITTEST_NO_EXCEPTIONS #include "ReportAssertImpl.h" #endif @@ -25,7 +25,7 @@ void ExecuteTest(T& testObject, TestDetails const& details, bool isMockTest) if (isMockTest == false) CurrentTest::Details() = &details; -#ifndef UNITTEST_USE_EXCEPTIONS +#ifdef UNITTEST_NO_EXCEPTIONS if (UNITTEST_SET_ASSERT_JUMP_TARGET() == 0) { #endif @@ -49,7 +49,7 @@ void ExecuteTest(T& testObject, TestDetails const& details, bool isMockTest) ({ CurrentTest::Results()->OnTestFailure(details, "Unhandled exception: test crashed"); }) -#ifndef UNITTEST_USE_EXCEPTIONS +#ifdef UNITTEST_NO_EXCEPTIONS } #endif } diff --git a/src/MemoryOutStream.cpp b/src/MemoryOutStream.cpp index c82740d..160849a 100644 --- a/src/MemoryOutStream.cpp +++ b/src/MemoryOutStream.cpp @@ -1,23 +1,19 @@ #include "MemoryOutStream.h" -#ifndef UNITTEST_USE_CUSTOM_STREAMS - +#ifdef UNITTEST_MEMORYOUTSTREAM_IS_STD_OSTRINGSTREAM namespace UnitTest { char const* MemoryOutStream::GetText() const { - m_text = this->str(); - return m_text.c_str(); + m_text = this->str(); + return m_text.c_str(); } - } - #else - #include #include diff --git a/src/MemoryOutStream.h b/src/MemoryOutStream.h index 1ba51e0..c92f17c 100644 --- a/src/MemoryOutStream.h +++ b/src/MemoryOutStream.h @@ -4,7 +4,7 @@ #include "../config.h" #include "HelperMacros.h" -#ifndef UNITTEST_USE_CUSTOM_STREAMS +#ifdef UNITTEST_MEMORYOUTSTREAM_IS_STD_OSTRINGSTREAM #include diff --git a/src/ReportAssert.cpp b/src/ReportAssert.cpp index e256641..5ba1d30 100644 --- a/src/ReportAssert.cpp +++ b/src/ReportAssert.cpp @@ -5,7 +5,7 @@ #include "TestResults.h" #include "TestDetails.h" -#ifndef UNITTEST_USE_EXCEPTIONS +#ifdef UNITTEST_NO_EXCEPTIONS #include "ReportAssertImpl.h" #endif @@ -28,7 +28,7 @@ UNITTEST_LINKAGE void ReportAssert(char const* description, char const* filename namespace Detail { -#ifndef UNITTEST_USE_EXCEPTIONS +#ifdef UNITTEST_NO_EXCEPTIONS jmp_buf* GetAssertJmpBuf() { static jmp_buf s_jmpBuf; @@ -50,7 +50,7 @@ UNITTEST_LINKAGE void ReportAssertEx(TestResults* testResults, ExpectAssert(false); -#ifdef UNITTEST_USE_EXCEPTIONS +#ifndef UNITTEST_NO_EXCEPTIONS throw AssertException(); #else UNITTEST_JUMP_TO_ASSERT_JUMP_TARGET(); diff --git a/src/ReportAssertImpl.h b/src/ReportAssertImpl.h index 1560725..f6ecfde 100644 --- a/src/ReportAssertImpl.h +++ b/src/ReportAssertImpl.h @@ -3,7 +3,7 @@ #include "../config.h" -#ifndef UNITTEST_USE_EXCEPTIONS +#ifdef UNITTEST_NO_EXCEPTIONS #include #endif @@ -24,7 +24,7 @@ UNITTEST_LINKAGE void ReportAssertEx(TestResults* testResults, UNITTEST_LINKAGE bool AssertExpected(); -#ifndef UNITTEST_USE_EXCEPTIONS +#ifdef UNITTEST_NO_EXCEPTIONS UNITTEST_LINKAGE jmp_buf* GetAssertJmpBuf(); #ifdef UNITTEST_WIN32 diff --git a/src/XmlTestReporter.cpp b/src/XmlTestReporter.cpp index deb27ca..09f0f24 100644 --- a/src/XmlTestReporter.cpp +++ b/src/XmlTestReporter.cpp @@ -1,5 +1,5 @@ #include "../config.h" -#ifdef UNITTEST_USE_DEFERRED_REPORTER +#ifndef UNITTEST_NO_DEFERRED_REPORTER #include "XmlTestReporter.h" diff --git a/src/XmlTestReporter.h b/src/XmlTestReporter.h index 14d69a6..2adf298 100644 --- a/src/XmlTestReporter.h +++ b/src/XmlTestReporter.h @@ -2,7 +2,7 @@ #define UNITTEST_XMLTESTREPORTER_H #include "../config.h" -#ifdef UNITTEST_USE_DEFERRED_REPORTER +#ifndef UNITTEST_NO_DEFERRED_REPORTER #include "DeferredTestReporter.h" diff --git a/src/tests/TestAssertHandler.cpp b/src/tests/TestAssertHandler.cpp index 99e707a..3b28c5f 100644 --- a/src/tests/TestAssertHandler.cpp +++ b/src/tests/TestAssertHandler.cpp @@ -21,7 +21,7 @@ TEST(CanSetAssertExpected) CHECK(!Detail::AssertExpected()); } -#ifdef UNITTEST_USE_EXCEPTIONS +#ifndef UNITTEST_NO_EXCEPTIONS TEST(ReportAssertThrowsAssertException) { diff --git a/src/tests/TestDeferredTestReporter.cpp b/src/tests/TestDeferredTestReporter.cpp index ad049d1..7550ab4 100644 --- a/src/tests/TestDeferredTestReporter.cpp +++ b/src/tests/TestDeferredTestReporter.cpp @@ -1,6 +1,6 @@ #include "../../config.h" -#ifdef UNITTEST_USE_DEFERRED_REPORTER +#ifndef UNITTEST_NO_DEFERRED_REPORTER #include "../../unittestpp.h" #include "../DeferredTestReporter.h" @@ -12,7 +12,7 @@ namespace UnitTest namespace { -#ifdef UNITTEST_USE_CUSTOM_STREAMS +#ifndef UNITTEST_MEMORYOUTSTREAM_IS_STD_OSTRINGSTREAM MemoryOutStream& operator <<(MemoryOutStream& lhs, const std::string& rhs) { lhs << rhs.c_str(); diff --git a/src/tests/TestExceptions.cpp b/src/tests/TestExceptions.cpp index 5894e2c..f8089b4 100644 --- a/src/tests/TestExceptions.cpp +++ b/src/tests/TestExceptions.cpp @@ -1,5 +1,5 @@ #include "../../config.h" -#ifdef UNITTEST_USE_EXCEPTIONS +#ifndef UNITTEST_NO_EXCEPTIONS #include "../../unittestpp.h" #include "../CurrentTest.h" diff --git a/src/tests/TestMemoryOutStream.cpp b/src/tests/TestMemoryOutStream.cpp index 7a3bc64..5feaf98 100644 --- a/src/tests/TestMemoryOutStream.cpp +++ b/src/tests/TestMemoryOutStream.cpp @@ -87,7 +87,7 @@ TEST(StreamingSizeTWritesCorrectCharacters) CHECK_EQUAL("53124", stream.GetText()); } -#ifdef UNITTEST_USE_CUSTOM_STREAMS +#ifndef UNITTEST_MEMORYOUTSTREAM_IS_STD_OSTRINGSTREAM TEST(StreamInitialCapacityIsCorrect) { diff --git a/src/tests/TestTest.cpp b/src/tests/TestTest.cpp index 59eb759..2ae2192 100644 --- a/src/tests/TestTest.cpp +++ b/src/tests/TestTest.cpp @@ -50,7 +50,7 @@ TEST(FailingTestHasFailures) CHECK_EQUAL(1, results.GetFailureCount()); } -#ifdef UNITTEST_USE_EXCEPTIONS +#ifndef UNITTEST_NO_EXCEPTIONS TEST(ThrowingTestsAreReportedAsFailures) { class CrashingTest : public Test diff --git a/src/tests/TestTestMacros.cpp b/src/tests/TestTestMacros.cpp index f8028d8..87cfef7 100644 --- a/src/tests/TestTestMacros.cpp +++ b/src/tests/TestTestMacros.cpp @@ -22,7 +22,7 @@ TEST (TestsAreAddedToTheListThroughMacro) CHECK(list1.GetHead()->m_nextTest == 0); } -#ifdef UNITTEST_USE_EXCEPTIONS +#ifndef UNITTEST_NO_EXCEPTIONS struct ThrowingThingie { @@ -108,7 +108,7 @@ TEST(TestAddedWithTEST_FIXTURE_EXMacroGetsDefaultSuite) CHECK_EQUAL ("DefaultSuite", macroTestList2.GetHead()->m_details.suiteName); } -#ifdef UNITTEST_USE_EXCEPTIONS +#ifndef UNITTEST_NO_EXCEPTIONS struct FixtureCtorThrows { diff --git a/src/tests/TestUnitTestPP.cpp b/src/tests/TestUnitTestPP.cpp index a9da7a4..e6a00bf 100644 --- a/src/tests/TestUnitTestPP.cpp +++ b/src/tests/TestUnitTestPP.cpp @@ -44,7 +44,7 @@ TEST(ArrayCloseSucceeds) CHECK_ARRAY_CLOSE(a1, a2, 3, 0.1f); } -#ifdef UNITTEST_USE_EXCEPTIONS +#ifndef UNITTEST_NO_EXCEPTIONS TEST(CheckThrowMacroSucceedsOnCorrectException) { diff --git a/src/tests/TestXmlTestReporter.cpp b/src/tests/TestXmlTestReporter.cpp index 4c17b6c..dde5759 100644 --- a/src/tests/TestXmlTestReporter.cpp +++ b/src/tests/TestXmlTestReporter.cpp @@ -1,5 +1,5 @@ #include "../../config.h" -#ifdef UNITTEST_USE_DEFERRED_REPORTER +#ifndef UNITTEST_NO_DEFERRED_REPORTER #include "../../unittestpp.h" #include "../XmlTestReporter.h" @@ -12,7 +12,7 @@ using std::ostringstream; namespace { -#ifdef UNITTEST_USE_CUSTOM_STREAMS +#ifndef UNITTEST_MEMORYOUTSTREAM_IS_STD_OSTRINGSTREAM // Overload to let MemoryOutStream accept std::string MemoryOutStream& operator<<(MemoryOutStream& s, const std::string& value) @@ -73,9 +73,9 @@ TEST_FIXTURE(XmlTestReporterFixture, EmptyReportSummaryFormat) reporter.ReportSummary(0, 0, 0, 0.1f); const char *expected = -"" -"" -""; + "" + "" + ""; CHECK_EQUAL(expected, output.str()); } @@ -88,10 +88,10 @@ TEST_FIXTURE(XmlTestReporterFixture, SingleSuccessfulTestReportSummaryFormat) reporter.ReportSummary(1, 0, 0, 0.1f); const char *expected = -"" -"" -"" -""; + "" + "" + "" + ""; CHECK_EQUAL(expected, output.str()); } From 7510e7f42be4493099d175deb12df6a73c94d856 Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Wed, 9 Jan 2013 23:44:56 -0600 Subject: [PATCH 22/30] r23 | charles.nicholson | 2010-03-18 19:14:06 -0500 (Thu, 18 Mar 2010) | 1 line long long streaming for MemoryOutStream, from sony --- src/MemoryOutStream.cpp | 36 +++++++++++++++++++++++++------ src/MemoryOutStream.h | 18 +++++++++------- src/tests/TestMemoryOutStream.cpp | 16 ++++++++++++++ 3 files changed, 55 insertions(+), 15 deletions(-) diff --git a/src/MemoryOutStream.cpp b/src/MemoryOutStream.cpp index 160849a..757ed63 100644 --- a/src/MemoryOutStream.cpp +++ b/src/MemoryOutStream.cpp @@ -57,7 +57,7 @@ char const* MemoryOutStream::GetText() const return m_buffer; } -MemoryOutStream& MemoryOutStream::operator << (char const* txt) +MemoryOutStream& MemoryOutStream::operator <<(char const* txt) { using namespace std; @@ -74,37 +74,59 @@ MemoryOutStream& MemoryOutStream::operator << (char const* txt) return *this; } -MemoryOutStream& MemoryOutStream::operator << (int const n) +MemoryOutStream& MemoryOutStream::operator <<(int const n) { FormatToStream(*this, "%i", n); return *this; } -MemoryOutStream& MemoryOutStream::operator << (long const n) +MemoryOutStream& MemoryOutStream::operator <<(long const n) { FormatToStream(*this, "%li", n); return *this; } -MemoryOutStream& MemoryOutStream::operator << (unsigned long const n) +MemoryOutStream& MemoryOutStream::operator <<(unsigned long const n) { FormatToStream(*this, "%lu", n); return *this; } -MemoryOutStream& MemoryOutStream::operator << (float const f) +MemoryOutStream& MemoryOutStream::operator <<(long long const n) +{ +#ifdef UNITTEST_WIN32 + FormatToStream(*this, "%I64d", n); +#else + FormatToStream(*this, "%lld", n); +#endif + + return *this; +} + +MemoryOutStream& MemoryOutStream::operator <<(unsigned long long const n) +{ +#ifdef UNITTEST_WIN32 + FormatToStream(*this, "%I64u", n); +#else + FormatToStream(*this, "%llu", n); +#endif + + return *this; +} + +MemoryOutStream& MemoryOutStream::operator <<(float const f) { FormatToStream(*this, "%ff", f); return *this; } -MemoryOutStream& MemoryOutStream::operator << (void const* p) +MemoryOutStream& MemoryOutStream::operator <<(void const* p) { FormatToStream(*this, "%p", p); return *this; } -MemoryOutStream& MemoryOutStream::operator << (unsigned int const s) +MemoryOutStream& MemoryOutStream::operator <<(unsigned int const s) { FormatToStream(*this, "%u", s); return *this; diff --git a/src/MemoryOutStream.h b/src/MemoryOutStream.h index c92f17c..aaedba0 100644 --- a/src/MemoryOutStream.h +++ b/src/MemoryOutStream.h @@ -42,14 +42,16 @@ class UNITTEST_LINKAGE MemoryOutStream char const* GetText() const; - MemoryOutStream& operator << (char const* txt); - MemoryOutStream& operator << (int n); - MemoryOutStream& operator << (long n); - MemoryOutStream& operator << (unsigned long n); - MemoryOutStream& operator << (float f); - MemoryOutStream& operator << (double d); - MemoryOutStream& operator << (void const* p); - MemoryOutStream& operator << (unsigned int s); + MemoryOutStream& operator <<(char const* txt); + MemoryOutStream& operator <<(int n); + MemoryOutStream& operator <<(long n); + MemoryOutStream& operator <<(long long n); + MemoryOutStream& operator <<(unsigned long n); + MemoryOutStream& operator <<(unsigned long long n); + MemoryOutStream& operator <<(float f); + MemoryOutStream& operator <<(double d); + MemoryOutStream& operator <<(void const* p); + MemoryOutStream& operator <<(unsigned int s); enum { GROW_CHUNK_SIZE = 32 }; int GetCapacity() const; diff --git a/src/tests/TestMemoryOutStream.cpp b/src/tests/TestMemoryOutStream.cpp index 5feaf98..4845ec9 100644 --- a/src/tests/TestMemoryOutStream.cpp +++ b/src/tests/TestMemoryOutStream.cpp @@ -2,6 +2,8 @@ #include "../MemoryOutStream.h" #include +#include +#include using namespace UnitTest; using namespace std; @@ -57,6 +59,20 @@ TEST(StreamingUnsignedLongWritesCorrectCharacters) CHECK_EQUAL("123", stream.GetText()); } +TEST(StreamingLongLongWritesCorrectCharacters) +{ + MemoryOutStream stream; + stream << (long long)(ULONG_MAX) * 2; + CHECK_EQUAL("8589934590", stream.GetText()); +} + +TEST(StreamingUnsignedLongLongWritesCorrectCharacters) +{ + MemoryOutStream stream; + stream << (unsigned long long)(ULONG_MAX) * 2; + CHECK_EQUAL("8589934590", stream.GetText()); +} + TEST(StreamingFloatWritesCorrectCharacters) { MemoryOutStream stream; From e4272010e682c40d3d553836668f6e7d636ff398 Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Wed, 9 Jan 2013 23:45:02 -0600 Subject: [PATCH 23/30] r24 | charles.nicholson | 2010-03-19 18:34:42 -0500 (Fri, 19 Mar 2010) | 1 line inject 'using namespace std' into TestTestMacros.cpp --- src/tests/TestTestMacros.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tests/TestTestMacros.cpp b/src/tests/TestTestMacros.cpp index 87cfef7..b057e4f 100644 --- a/src/tests/TestTestMacros.cpp +++ b/src/tests/TestTestMacros.cpp @@ -8,6 +8,7 @@ #include "ScopedCurrentTest.h" using namespace UnitTest; +using namespace std; namespace { From e92de84bc2a769353196adac7084b323e9bbd1b6 Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Wed, 9 Jan 2013 23:45:10 -0600 Subject: [PATCH 24/30] r25 | charles.nicholson | 2010-03-22 14:01:16 -0500 (Mon, 22 Mar 2010) | 1 line add vs2008 solution + vcproj files --- src/HelperMacros.h | 2 +- src/tests/test-unittestpp_vs2008.vcproj | 569 ++++++++++++++++++++++ src/unittestpp_vs2008.vcproj | 607 ++++++++++++++++++++++++ unittestpp_vs2008.sln | 49 ++ 4 files changed, 1226 insertions(+), 1 deletion(-) create mode 100644 src/tests/test-unittestpp_vs2008.vcproj create mode 100644 src/unittestpp_vs2008.vcproj create mode 100644 unittestpp_vs2008.sln diff --git a/src/HelperMacros.h b/src/HelperMacros.h index 9560d13..97d6b2c 100644 --- a/src/HelperMacros.h +++ b/src/HelperMacros.h @@ -28,7 +28,7 @@ #define UNITTEST_STDVECTOR_LINKAGE(T) \ __pragma(warning(push)) \ __pragma(warning(disable:4231)) \ - UNITTEST_IMPEXP_TEMPLATE template class UNITTEST_LINKAGE std::allocator < T >; \ + UNITTEST_IMPEXP_TEMPLATE template class UNITTEST_LINKAGE std::allocator< T >; \ UNITTEST_IMPEXP_TEMPLATE template class UNITTEST_LINKAGE std::vector< T >; \ __pragma(warning(pop)) #else diff --git a/src/tests/test-unittestpp_vs2008.vcproj b/src/tests/test-unittestpp_vs2008.vcproj new file mode 100644 index 0000000..19762d1 --- /dev/null +++ b/src/tests/test-unittestpp_vs2008.vcproj @@ -0,0 +1,569 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/unittestpp_vs2008.vcproj b/src/unittestpp_vs2008.vcproj new file mode 100644 index 0000000..fee20c0 --- /dev/null +++ b/src/unittestpp_vs2008.vcproj @@ -0,0 +1,607 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/unittestpp_vs2008.sln b/unittestpp_vs2008.sln new file mode 100644 index 0000000..087941c --- /dev/null +++ b/unittestpp_vs2008.sln @@ -0,0 +1,49 @@ + +Microsoft Visual Studio Solution File, Format Version 10.00 +# Visual Studio 2008 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "unittestpp_vs2008", "src\unittestpp_vs2008.vcproj", "{64A4FEFE-0461-4E95-8CC1-91EF5F57DBC6}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test-unittestpp_vs2008", "src\tests\test-unittestpp_vs2008.vcproj", "{9CCC3439-309E-4E85-B3B8-CE704D385D48}" + ProjectSection(ProjectDependencies) = postProject + {64A4FEFE-0461-4E95-8CC1-91EF5F57DBC6} = {64A4FEFE-0461-4E95-8CC1-91EF5F57DBC6} + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + win32_dll_debug|Win32 = win32_dll_debug|Win32 + win32_dll_release|Win32 = win32_dll_release|Win32 + win32_lib_md_debug|Win32 = win32_lib_md_debug|Win32 + win32_lib_md_release|Win32 = win32_lib_md_release|Win32 + win32_lib_mt_debug|Win32 = win32_lib_mt_debug|Win32 + win32_lib_mt_release|Win32 = win32_lib_mt_release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {64A4FEFE-0461-4E95-8CC1-91EF5F57DBC6}.win32_dll_debug|Win32.ActiveCfg = win32_dll_debug|Win32 + {64A4FEFE-0461-4E95-8CC1-91EF5F57DBC6}.win32_dll_debug|Win32.Build.0 = win32_dll_debug|Win32 + {64A4FEFE-0461-4E95-8CC1-91EF5F57DBC6}.win32_dll_release|Win32.ActiveCfg = win32_dll_release|Win32 + {64A4FEFE-0461-4E95-8CC1-91EF5F57DBC6}.win32_dll_release|Win32.Build.0 = win32_dll_release|Win32 + {64A4FEFE-0461-4E95-8CC1-91EF5F57DBC6}.win32_lib_md_debug|Win32.ActiveCfg = win32_lib_md_debug|Win32 + {64A4FEFE-0461-4E95-8CC1-91EF5F57DBC6}.win32_lib_md_debug|Win32.Build.0 = win32_lib_md_debug|Win32 + {64A4FEFE-0461-4E95-8CC1-91EF5F57DBC6}.win32_lib_md_release|Win32.ActiveCfg = win32_lib_md_release|Win32 + {64A4FEFE-0461-4E95-8CC1-91EF5F57DBC6}.win32_lib_md_release|Win32.Build.0 = win32_lib_md_release|Win32 + {64A4FEFE-0461-4E95-8CC1-91EF5F57DBC6}.win32_lib_mt_debug|Win32.ActiveCfg = win32_lib_mt_debug|Win32 + {64A4FEFE-0461-4E95-8CC1-91EF5F57DBC6}.win32_lib_mt_debug|Win32.Build.0 = win32_lib_mt_debug|Win32 + {64A4FEFE-0461-4E95-8CC1-91EF5F57DBC6}.win32_lib_mt_release|Win32.ActiveCfg = win32_lib_mt_release|Win32 + {64A4FEFE-0461-4E95-8CC1-91EF5F57DBC6}.win32_lib_mt_release|Win32.Build.0 = win32_lib_mt_release|Win32 + {9CCC3439-309E-4E85-B3B8-CE704D385D48}.win32_dll_debug|Win32.ActiveCfg = win32_dll_debug|Win32 + {9CCC3439-309E-4E85-B3B8-CE704D385D48}.win32_dll_debug|Win32.Build.0 = win32_dll_debug|Win32 + {9CCC3439-309E-4E85-B3B8-CE704D385D48}.win32_dll_release|Win32.ActiveCfg = win32_dll_release|Win32 + {9CCC3439-309E-4E85-B3B8-CE704D385D48}.win32_dll_release|Win32.Build.0 = win32_dll_release|Win32 + {9CCC3439-309E-4E85-B3B8-CE704D385D48}.win32_lib_md_debug|Win32.ActiveCfg = win32_static_md_debug|Win32 + {9CCC3439-309E-4E85-B3B8-CE704D385D48}.win32_lib_md_debug|Win32.Build.0 = win32_static_md_debug|Win32 + {9CCC3439-309E-4E85-B3B8-CE704D385D48}.win32_lib_md_release|Win32.ActiveCfg = win32_static_md_release|Win32 + {9CCC3439-309E-4E85-B3B8-CE704D385D48}.win32_lib_md_release|Win32.Build.0 = win32_static_md_release|Win32 + {9CCC3439-309E-4E85-B3B8-CE704D385D48}.win32_lib_mt_debug|Win32.ActiveCfg = win32_static_mt_debug|Win32 + {9CCC3439-309E-4E85-B3B8-CE704D385D48}.win32_lib_mt_debug|Win32.Build.0 = win32_static_mt_debug|Win32 + {9CCC3439-309E-4E85-B3B8-CE704D385D48}.win32_lib_mt_release|Win32.ActiveCfg = win32_static_mt_release|Win32 + {9CCC3439-309E-4E85-B3B8-CE704D385D48}.win32_lib_mt_release|Win32.Build.0 = win32_static_mt_release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal From 3fe7f2f5bdf8f11fc31c3aecabe637851ca28f87 Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Wed, 9 Jan 2013 23:45:16 -0600 Subject: [PATCH 25/30] r26 | charles.nicholson | 2010-03-22 14:16:24 -0500 (Mon, 22 Mar 2010) | 1 line platform macros for jmp_buf, setjmp, longjmp. Remove unused code, fix shadowed virtual functions (yikes!) --- config.h | 1 - src/HelperMacros.h | 10 ++++++++++ src/ReportAssert.cpp | 4 ++-- src/ReportAssertImpl.h | 9 +++++---- src/tests/TestExceptions.cpp | 8 -------- src/tests/TestTestRunner.cpp | 4 ++-- 6 files changed, 19 insertions(+), 17 deletions(-) diff --git a/config.h b/config.h index 6036173..bb95a45 100644 --- a/config.h +++ b/config.h @@ -51,5 +51,4 @@ //#define UNITTEST_NO_EXCEPTIONS - #endif diff --git a/src/HelperMacros.h b/src/HelperMacros.h index 97d6b2c..68792da 100644 --- a/src/HelperMacros.h +++ b/src/HelperMacros.h @@ -39,4 +39,14 @@ #define UNITTEST_STDVECTOR_LINKAGE(T) #endif +#ifdef UNITTEST_WIN32 + #define UNITTEST_JMPBUF jmp_buf + #define UNITTEST_SETJMP setjmp + #define UNITTEST_LONGJMP longjmp +#elif defined UNITTEST_POSIX + #define UNITTEST_JMPBUF std::jmp_buf + #define UNITTEST_SETJMP setjmp + #define UNITTEST_LONGJMP std::longjmp +#endif + #endif diff --git a/src/ReportAssert.cpp b/src/ReportAssert.cpp index 5ba1d30..c38a518 100644 --- a/src/ReportAssert.cpp +++ b/src/ReportAssert.cpp @@ -29,9 +29,9 @@ UNITTEST_LINKAGE void ReportAssert(char const* description, char const* filename namespace Detail { #ifdef UNITTEST_NO_EXCEPTIONS -jmp_buf* GetAssertJmpBuf() +UNITTEST_JMPBUF* GetAssertJmpBuf() { - static jmp_buf s_jmpBuf; + static UNITTEST_JMPBUF s_jmpBuf; return &s_jmpBuf; } #endif diff --git a/src/ReportAssertImpl.h b/src/ReportAssertImpl.h index f6ecfde..aefc78d 100644 --- a/src/ReportAssertImpl.h +++ b/src/ReportAssertImpl.h @@ -2,6 +2,7 @@ #define UNITTEST_REPORTASSERTIMPL_H #include "../config.h" +#include "HelperMacros.h" #ifdef UNITTEST_NO_EXCEPTIONS #include @@ -25,18 +26,18 @@ UNITTEST_LINKAGE void ReportAssertEx(TestResults* testResults, UNITTEST_LINKAGE bool AssertExpected(); #ifdef UNITTEST_NO_EXCEPTIONS - UNITTEST_LINKAGE jmp_buf* GetAssertJmpBuf(); + UNITTEST_LINKAGE UNITTEST_JMPBUF* GetAssertJmpBuf(); #ifdef UNITTEST_WIN32 #define UNITTEST_SET_ASSERT_JUMP_TARGET() \ __pragma(warning(push)) __pragma(warning(disable:4611)) \ - setjmp(*UnitTest::Detail::GetAssertJmpBuf()) \ + UNITTEST_SETJMP(*UnitTest::Detail::GetAssertJmpBuf()) \ __pragma(warning(pop)) #else - #define UNITTEST_SET_ASSERT_JUMP_TARGET() setjmp(*UnitTest::Detail::GetAssertJmpBuf()) + #define UNITTEST_SET_ASSERT_JUMP_TARGET() UNITTEST_SETJMP(*UnitTest::Detail::GetAssertJmpBuf()) #endif - #define UNITTEST_JUMP_TO_ASSERT_JUMP_TARGET() longjmp(*UnitTest::Detail::GetAssertJmpBuf(), 1) + #define UNITTEST_JUMP_TO_ASSERT_JUMP_TARGET() UNITTEST_LONGJMP(*UnitTest::Detail::GetAssertJmpBuf(), 1) #endif } diff --git a/src/tests/TestExceptions.cpp b/src/tests/TestExceptions.cpp index f8089b4..6f55c9a 100644 --- a/src/tests/TestExceptions.cpp +++ b/src/tests/TestExceptions.cpp @@ -226,14 +226,6 @@ TEST(CheckArrayEqualFailureOnExceptionIncludesCheckContents) CHECK(strstr(reporter.lastFailedMessage, "obj")); } -int g_sideEffect = 0; -float const* FunctionWithSideEffects2() -{ - ++g_sideEffect; - static float const data[] = {1,2,3,4}; - return data; -} - class ThrowingObject2D { public: diff --git a/src/tests/TestTestRunner.cpp b/src/tests/TestTestRunner.cpp index 3dc3edc..0aeec11 100644 --- a/src/tests/TestTestRunner.cpp +++ b/src/tests/TestTestRunner.cpp @@ -81,7 +81,7 @@ class SlowTest : public Test { public: SlowTest() : Test("slow", "somesuite", "filename", 123) {} - virtual void RunImpl(TestResults&) const + virtual void RunImpl() const { TimeHelpers::SleepMs(20); } @@ -213,7 +213,7 @@ TEST_FIXTURE(TestRunnerFixture, SlowTestWithTimeExemptionPasses) { public: SlowExemptedTest() : Test("slowexempted", "", 0) {} - virtual void RunImpl(TestResults&) const + virtual void RunImpl() const { UNITTEST_TIME_CONSTRAINT_EXEMPT(); TimeHelpers::SleepMs(20); From f5ba40579569242ab668c723393e7106b48857b9 Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Wed, 9 Jan 2013 23:45:20 -0600 Subject: [PATCH 26/30] r27 | charles.nicholson | 2010-03-25 15:45:52 -0500 (Thu, 25 Mar 2010) | 1 line add Clear() to MemoryOutStream() --- src/MemoryOutStream.cpp | 11 +++++++++++ src/MemoryOutStream.h | 4 +++- src/tests/TestMemoryOutStream.cpp | 8 ++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/MemoryOutStream.cpp b/src/MemoryOutStream.cpp index 757ed63..1e1e97d 100644 --- a/src/MemoryOutStream.cpp +++ b/src/MemoryOutStream.cpp @@ -10,6 +10,12 @@ char const* MemoryOutStream::GetText() const return m_text.c_str(); } +void MemoryOutStream::Clear() +{ + this->str(std::string()); + m_text = this->str(); +} + } #else @@ -52,6 +58,11 @@ MemoryOutStream::~MemoryOutStream() delete [] m_buffer; } +void MemoryOutStream::Clear() +{ + m_buffer[0] = '\0'; +} + char const* MemoryOutStream::GetText() const { return m_buffer; diff --git a/src/MemoryOutStream.h b/src/MemoryOutStream.h index aaedba0..380826a 100644 --- a/src/MemoryOutStream.h +++ b/src/MemoryOutStream.h @@ -16,7 +16,8 @@ class UNITTEST_LINKAGE MemoryOutStream : public std::ostringstream public: MemoryOutStream() {} ~MemoryOutStream() {} - char const* GetText() const; + void Clear(); + char const* GetText() const; private: MemoryOutStream(MemoryOutStream const&); @@ -40,6 +41,7 @@ class UNITTEST_LINKAGE MemoryOutStream explicit MemoryOutStream(int const size = 256); ~MemoryOutStream(); + void Clear(); char const* GetText() const; MemoryOutStream& operator <<(char const* txt); diff --git a/src/tests/TestMemoryOutStream.cpp b/src/tests/TestMemoryOutStream.cpp index 4845ec9..3ecf947 100644 --- a/src/tests/TestMemoryOutStream.cpp +++ b/src/tests/TestMemoryOutStream.cpp @@ -103,6 +103,14 @@ TEST(StreamingSizeTWritesCorrectCharacters) CHECK_EQUAL("53124", stream.GetText()); } +TEST(ClearEmptiesMemoryOutStreamContents) +{ + MemoryOutStream stream; + stream << "Hello world"; + stream.Clear(); + CHECK_EQUAL("", stream.GetText()); +} + #ifndef UNITTEST_MEMORYOUTSTREAM_IS_STD_OSTRINGSTREAM TEST(StreamInitialCapacityIsCorrect) From 57bf80682e174479fd32e65f9ebd4c765a86a658 Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Wed, 9 Jan 2013 23:45:25 -0600 Subject: [PATCH 27/30] r28 | charles.nicholson | 2010-07-29 17:43:45 -0500 (Thu, 29 Jul 2010) | 1 line fix strict aliasing violation, was causing gcc failures. use std::memcpy instead of union-cast --- src/tests/TestChecks.cpp | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/tests/TestChecks.cpp b/src/tests/TestChecks.cpp index f32d2e7..10b3071 100644 --- a/src/tests/TestChecks.cpp +++ b/src/tests/TestChecks.cpp @@ -1,6 +1,8 @@ #include "../../unittestpp.h" #include "RecordingReporter.h" +#include + using namespace UnitTest; @@ -119,25 +121,21 @@ TEST(CheckCloseWithZeroEpsilonWorksForSameNumber) TEST(CheckCloseWithNaNFails) { - union - { - unsigned int bitpattern; - float nan; - }; - bitpattern = 0xFFFFFFFF; - TestResults results; + const unsigned int bitpattern = 0xFFFFFFFF; + float nan; + std::memcpy(&nan, &bitpattern, sizeof(bitpattern)); + + TestResults results; CheckClose(results, 3.0f, nan, 0.1f, TestDetails("", "", "", 0)); CHECK_EQUAL(1, results.GetFailureCount()); } TEST(CheckCloseWithNaNAgainstItselfFails) { - union - { - unsigned int bitpattern; - float nan; - }; - bitpattern = 0xFFFFFFFF; + const unsigned int bitpattern = 0xFFFFFFFF; + float nan; + std::memcpy(&nan, &bitpattern, sizeof(bitpattern)); + TestResults results; CheckClose(results, nan, nan, 0.1f, TestDetails("", "", "", 0)); CHECK_EQUAL(1, results.GetFailureCount()); From d286f58ead97a02b75a6fee30e8ff6a6984589ab Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Wed, 9 Jan 2013 23:45:30 -0600 Subject: [PATCH 28/30] r29 | charles.nicholson | 2010-07-30 12:44:06 -0500 (Fri, 30 Jul 2010) | 1 line normalize configurations, output paths --- src/tests/test-unittestpp_vs2005.vcproj | 12 ++--- src/tests/test-unittestpp_vs2008.vcproj | 36 +++++++-------- src/unittestpp_vs2005.vcproj | 36 +++++++-------- src/unittestpp_vs2008.vcproj | 36 +++++++-------- unittestpp_vs2005.sln | 60 ++++++++++++------------- unittestpp_vs2008.sln | 60 ++++++++++++------------- 6 files changed, 120 insertions(+), 120 deletions(-) diff --git a/src/tests/test-unittestpp_vs2005.vcproj b/src/tests/test-unittestpp_vs2005.vcproj index e13fba8..50d9fa3 100644 --- a/src/tests/test-unittestpp_vs2005.vcproj +++ b/src/tests/test-unittestpp_vs2005.vcproj @@ -16,7 +16,7 @@ @@ -93,9 +93,9 @@ /> @@ -246,9 +246,9 @@ /> @@ -399,9 +399,9 @@ /> @@ -80,9 +80,9 @@ /> @@ -217,9 +217,9 @@ /> @@ -354,9 +354,9 @@ /> @@ -80,9 +80,9 @@ /> @@ -214,9 +214,9 @@ /> @@ -348,9 +348,9 @@ /> Date: Wed, 9 Jan 2013 23:45:36 -0600 Subject: [PATCH 29/30] r30 | charles.nicholson@gmail.com | 2010-07-30 16:09:20 -0500 (Fri, 30 Jul 2010) | 1 line dummy change to test committing --- README | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README b/README index 187e69b..1389cc6 100644 --- a/README +++ b/README @@ -7,7 +7,7 @@ the terms of the License contained in the file COPYING distributed with this package. This license is the same as the MIT/X Consortium license. -See src/tests/TestUnitTestPP.cpp for usage. +See src/tests/TestUnitTest++.cpp for usage. Authors: Noel Llopis (llopis@convexhull.com) @@ -52,7 +52,7 @@ Version 1.2 (2006-10-29) - Added named test suites - Added CHECK_ARRAY2D_CLOSE - Posix library name is libUnitTest++.a now -- Floating point numbers are postfixed with f in the failure reports +- Floating point numbers are postfixed with 'f' in the failure reports Version 1.1 (2006-04-18) - CHECK macros do not have side effects even if one of the parameters changes state From 443b35690a4cc1cc07d05370c0071b17e8b87ddf Mon Sep 17 00:00:00 2001 From: Patrick Johnmeyer Date: Thu, 10 Jan 2013 00:05:00 -0600 Subject: [PATCH 30/30] Fixed test failures in Streaming[Unsigned]LongLongWritesCorrectCharacters --- src/tests/TestMemoryOutStream.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tests/TestMemoryOutStream.cpp b/src/tests/TestMemoryOutStream.cpp index 3ecf947..f83b10c 100644 --- a/src/tests/TestMemoryOutStream.cpp +++ b/src/tests/TestMemoryOutStream.cpp @@ -62,14 +62,14 @@ TEST(StreamingUnsignedLongWritesCorrectCharacters) TEST(StreamingLongLongWritesCorrectCharacters) { MemoryOutStream stream; - stream << (long long)(ULONG_MAX) * 2; + stream << (long long)8589934590ll; CHECK_EQUAL("8589934590", stream.GetText()); } TEST(StreamingUnsignedLongLongWritesCorrectCharacters) { MemoryOutStream stream; - stream << (unsigned long long)(ULONG_MAX) * 2; + stream << (unsigned long long)8589934590ull; CHECK_EQUAL("8589934590", stream.GetText()); }