summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/unittest-cpp/tests/TestCheckMacros.cpp
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/unittest-cpp/tests/TestCheckMacros.cpp')
-rw-r--r--3rdparty/unittest-cpp/tests/TestCheckMacros.cpp518
1 files changed, 518 insertions, 0 deletions
diff --git a/3rdparty/unittest-cpp/tests/TestCheckMacros.cpp b/3rdparty/unittest-cpp/tests/TestCheckMacros.cpp
new file mode 100644
index 00000000000..45ea0e97905
--- /dev/null
+++ b/3rdparty/unittest-cpp/tests/TestCheckMacros.cpp
@@ -0,0 +1,518 @@
+#include "UnitTest++/UnitTestPP.h"
+#include "UnitTest++/CurrentTest.h"
+#include "RecordingReporter.h"
+#include "ScopedCurrentTest.h"
+
+using namespace std;
+
+namespace {
+
+TEST(CheckSucceedsOnTrue)
+{
+ bool failure = true;
+ {
+ RecordingReporter reporter;
+ UnitTest::TestResults testResults(&reporter);
+
+ ScopedCurrentTest scopedResults(testResults);
+ CHECK(true);
+
+ failure = (testResults.GetFailureCount() > 0);
+ }
+
+ CHECK(!failure);
+}
+
+TEST(CheckFailsOnFalse)
+{
+ bool failure = false;
+ {
+ RecordingReporter reporter;
+ UnitTest::TestResults testResults(&reporter);
+ ScopedCurrentTest scopedResults(testResults);
+ CHECK(false);
+ failure = (testResults.GetFailureCount() > 0);
+ }
+
+ CHECK(failure);
+}
+
+TEST(FailureReportsCorrectTestName)
+{
+ RecordingReporter reporter;
+ {
+ UnitTest::TestResults testResults(&reporter);
+ ScopedCurrentTest scopedResults(testResults);
+ CHECK(false);
+ }
+
+ CHECK_EQUAL(m_details.testName, reporter.lastFailedTest);
+}
+
+TEST(CheckFailureIncludesCheckContents)
+{
+ RecordingReporter reporter;
+ {
+ UnitTest::TestResults testResults(&reporter);
+ ScopedCurrentTest scopedResults(testResults);
+ const bool yaddayadda = false;
+ CHECK(yaddayadda);
+ }
+
+ CHECK(strstr(reporter.lastFailedMessage, "yaddayadda"));
+}
+
+TEST(CheckEqualSucceedsOnEqual)
+{
+ bool failure = true;
+ {
+ RecordingReporter reporter;
+ UnitTest::TestResults testResults(&reporter);
+ ScopedCurrentTest scopedResults(testResults);
+ CHECK_EQUAL(1, 1);
+ failure = (testResults.GetFailureCount() > 0);
+ }
+
+ CHECK(!failure);
+}
+
+TEST(CheckEqualFailsOnNotEqual)
+{
+ bool failure = false;
+ {
+ RecordingReporter reporter;
+ UnitTest::TestResults testResults(&reporter);
+ ScopedCurrentTest scopedResults(testResults);
+ CHECK_EQUAL(1, 2);
+ failure = (testResults.GetFailureCount() > 0);
+ }
+
+ CHECK(failure);
+}
+
+TEST(CheckEqualFailureContainsCorrectDetails)
+{
+ int line = 0;
+ RecordingReporter reporter;
+ {
+ UnitTest::TestResults testResults(&reporter);
+ UnitTest::TestDetails const testDetails("testName", "suiteName", "filename", -1);
+ ScopedCurrentTest scopedResults(testResults, &testDetails);
+
+ CHECK_EQUAL(1, 123); line = __LINE__;
+ }
+
+ CHECK_EQUAL("testName", reporter.lastFailedTest);
+ CHECK_EQUAL("suiteName", reporter.lastFailedSuite);
+ CHECK_EQUAL("filename", reporter.lastFailedFile);
+ CHECK_EQUAL(line, reporter.lastFailedLine);
+}
+
+int g_sideEffect = 0;
+int FunctionWithSideEffects()
+{
+ ++g_sideEffect;
+ return 1;
+}
+
+TEST(CheckEqualDoesNotHaveSideEffectsWhenPassing)
+{
+ g_sideEffect = 0;
+ {
+ UnitTest::TestResults testResults;
+ ScopedCurrentTest scopedResults(testResults);
+ CHECK_EQUAL(1, FunctionWithSideEffects());
+ }
+ CHECK_EQUAL(1, g_sideEffect);
+}
+
+TEST(CheckEqualDoesNotHaveSideEffectsWhenFailing)
+{
+ g_sideEffect = 0;
+ {
+ UnitTest::TestResults testResults;
+ ScopedCurrentTest scopedResults(testResults);
+ CHECK_EQUAL(2, FunctionWithSideEffects());
+ }
+ CHECK_EQUAL(1, g_sideEffect);
+}
+
+
+TEST(CheckCloseSucceedsOnEqual)
+{
+ bool failure = true;
+ {
+ RecordingReporter reporter;
+ UnitTest::TestResults testResults(&reporter);
+ ScopedCurrentTest scopedResults(testResults);
+ CHECK_CLOSE (1.0f, 1.001f, 0.01f);
+ failure = (testResults.GetFailureCount() > 0);
+ }
+
+ CHECK(!failure);
+}
+
+TEST(CheckCloseFailsOnNotEqual)
+{
+ bool failure = false;
+ {
+ RecordingReporter reporter;
+ UnitTest::TestResults testResults(&reporter);
+ ScopedCurrentTest scopedResults(testResults);
+ CHECK_CLOSE (1.0f, 1.1f, 0.01f);
+ failure = (testResults.GetFailureCount() > 0);
+ }
+
+ CHECK(failure);
+}
+
+TEST(CheckCloseFailureContainsCorrectDetails)
+{
+ int line = 0;
+ RecordingReporter reporter;
+ {
+ UnitTest::TestResults testResults(&reporter);
+ UnitTest::TestDetails testDetails("test", "suite", "filename", -1);
+ ScopedCurrentTest scopedResults(testResults, &testDetails);
+
+ CHECK_CLOSE (1.0f, 1.1f, 0.01f); line = __LINE__;
+ }
+
+ CHECK_EQUAL("test", reporter.lastFailedTest);
+ CHECK_EQUAL("suite", reporter.lastFailedSuite);
+ CHECK_EQUAL("filename", reporter.lastFailedFile);
+ CHECK_EQUAL(line, reporter.lastFailedLine);
+}
+
+TEST(CheckCloseDoesNotHaveSideEffectsWhenPassing)
+{
+ g_sideEffect = 0;
+ {
+ UnitTest::TestResults testResults;
+ ScopedCurrentTest scopedResults(testResults);
+ CHECK_CLOSE (1, FunctionWithSideEffects(), 0.1f);
+ }
+ CHECK_EQUAL(1, g_sideEffect);
+}
+
+TEST(CheckCloseDoesNotHaveSideEffectsWhenFailing)
+{
+ g_sideEffect = 0;
+ {
+ UnitTest::TestResults testResults;
+ ScopedCurrentTest scopedResults(testResults);
+ CHECK_CLOSE (2, FunctionWithSideEffects(), 0.1f);
+ }
+ CHECK_EQUAL(1, g_sideEffect);
+}
+
+TEST(CheckArrayCloseSucceedsOnEqual)
+{
+ bool failure = true;
+ {
+ RecordingReporter reporter;
+ UnitTest::TestResults testResults(&reporter);
+ ScopedCurrentTest scopedResults(testResults);
+ const float data[4] = { 0, 1, 2, 3 };
+ CHECK_ARRAY_CLOSE (data, data, 4, 0.01f);
+ failure = (testResults.GetFailureCount() > 0);
+ }
+
+ CHECK(!failure);
+}
+
+TEST(CheckArrayCloseFailsOnNotEqual)
+{
+ bool failure = false;
+ {
+ RecordingReporter reporter;
+ UnitTest::TestResults testResults(&reporter);
+ ScopedCurrentTest scopedResults(testResults);
+
+ int const data1[4] = { 0, 1, 2, 3 };
+ int const data2[4] = { 0, 1, 3, 3 };
+ CHECK_ARRAY_CLOSE (data1, data2, 4, 0.01f);
+
+ failure = (testResults.GetFailureCount() > 0);
+ }
+
+ CHECK(failure);
+}
+
+TEST(CheckArrayCloseFailureIncludesCheckExpectedAndActual)
+{
+ RecordingReporter reporter;
+ {
+ UnitTest::TestResults testResults(&reporter);
+ ScopedCurrentTest scopedResults(testResults);
+
+ int const data1[4] = { 0, 1, 2, 3 };
+ int const data2[4] = { 0, 1, 3, 3 };
+ CHECK_ARRAY_CLOSE (data1, data2, 4, 0.01f);
+ }
+
+ CHECK(strstr(reporter.lastFailedMessage, "xpected [ 0 1 2 3 ]"));
+ CHECK(strstr(reporter.lastFailedMessage, "was [ 0 1 3 3 ]"));
+}
+
+TEST(CheckArrayCloseFailureContainsCorrectDetails)
+{
+ int line = 0;
+ RecordingReporter reporter;
+ {
+ UnitTest::TestResults testResults(&reporter);
+ UnitTest::TestDetails testDetails("arrayCloseTest", "arrayCloseSuite", "filename", -1);
+ ScopedCurrentTest scopedResults(testResults, &testDetails);
+
+ int const data1[4] = { 0, 1, 2, 3 };
+ int const data2[4] = { 0, 1, 3, 3 };
+ CHECK_ARRAY_CLOSE (data1, data2, 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;
+ {
+ UnitTest::TestResults testResults(&reporter);
+ ScopedCurrentTest scopedResults(testResults);
+
+ float const data1[4] = { 0, 1, 2, 3 };
+ float const data2[4] = { 0, 1, 3, 3 };
+ CHECK_ARRAY_CLOSE (data1, data2, 4, 0.01f);
+ }
+
+ CHECK(strstr(reporter.lastFailedMessage, "0.01"));
+}
+
+TEST(CheckArrayEqualSuceedsOnEqual)
+{
+ bool failure = true;
+ {
+ RecordingReporter reporter;
+ UnitTest::TestResults testResults(&reporter);
+ ScopedCurrentTest scopedResults(testResults);
+
+ const float data[4] = { 0, 1, 2, 3 };
+ CHECK_ARRAY_EQUAL (data, data, 4);
+
+ failure = (testResults.GetFailureCount() > 0);
+ }
+
+ CHECK(!failure);
+}
+
+TEST(CheckArrayEqualFailsOnNotEqual)
+{
+ bool failure = false;
+ {
+ RecordingReporter reporter;
+ UnitTest::TestResults testResults(&reporter);
+ ScopedCurrentTest scopedResults(testResults);
+
+ int const data1[4] = { 0, 1, 2, 3 };
+ int const data2[4] = { 0, 1, 3, 3 };
+ CHECK_ARRAY_EQUAL (data1, data2, 4);
+
+ failure = (testResults.GetFailureCount() > 0);
+ }
+
+ CHECK(failure);
+}
+
+TEST(CheckArrayEqualFailureIncludesCheckExpectedAndActual)
+{
+ RecordingReporter reporter;
+ {
+ UnitTest::TestResults testResults(&reporter);
+ ScopedCurrentTest scopedResults(testResults);
+
+ int const data1[4] = { 0, 1, 2, 3 };
+ int const data2[4] = { 0, 1, 3, 3 };
+ CHECK_ARRAY_EQUAL (data1, data2, 4);
+ }
+
+ CHECK(strstr(reporter.lastFailedMessage, "xpected [ 0 1 2 3 ]"));
+ CHECK(strstr(reporter.lastFailedMessage, "was [ 0 1 3 3 ]"));
+}
+
+TEST(CheckArrayEqualFailureContainsCorrectInfo)
+{
+ int line = 0;
+ RecordingReporter reporter;
+ {
+ UnitTest::TestResults testResults(&reporter);
+ ScopedCurrentTest scopedResults(testResults);
+
+ int const data1[4] = { 0, 1, 2, 3 };
+ int const data2[4] = { 0, 1, 3, 3 };
+ CHECK_ARRAY_EQUAL (data1, data2, 4); line = __LINE__;
+ }
+
+ CHECK_EQUAL("CheckArrayEqualFailureContainsCorrectInfo", reporter.lastFailedTest);
+ CHECK_EQUAL(__FILE__, reporter.lastFailedFile);
+ CHECK_EQUAL(line, reporter.lastFailedLine);
+}
+
+float const* FunctionWithSideEffects2()
+{
+ ++g_sideEffect;
+ static float const data[] = {1,2,3,4};
+ return data;
+}
+
+TEST(CheckArrayCloseDoesNotHaveSideEffectsWhenPassing)
+{
+ g_sideEffect = 0;
+ {
+ UnitTest::TestResults testResults;
+ ScopedCurrentTest scopedResults(testResults);
+
+ const float data[] = { 0, 1, 2, 3 };
+ CHECK_ARRAY_CLOSE (data, FunctionWithSideEffects2(), 4, 0.01f);
+ }
+ CHECK_EQUAL(1, g_sideEffect);
+}
+
+TEST(CheckArrayCloseDoesNotHaveSideEffectsWhenFailing)
+{
+ g_sideEffect = 0;
+ {
+ UnitTest::TestResults testResults;
+ ScopedCurrentTest scopedResults(testResults);
+
+ const float data[] = { 0, 1, 3, 3 };
+ CHECK_ARRAY_CLOSE (data, FunctionWithSideEffects2(), 4, 0.01f);
+ }
+
+ CHECK_EQUAL(1, g_sideEffect);
+}
+
+TEST(CheckArray2DCloseSucceedsOnEqual)
+{
+ bool failure = true;
+ {
+ RecordingReporter reporter;
+ UnitTest::TestResults testResults(&reporter);
+ ScopedCurrentTest scopedResults(testResults);
+
+ const float data[2][2] = { {0, 1}, {2, 3} };
+ CHECK_ARRAY2D_CLOSE (data, data, 2, 2, 0.01f);
+
+ failure = (testResults.GetFailureCount() > 0);
+ }
+
+ CHECK(!failure);
+}
+
+TEST(CheckArray2DCloseFailsOnNotEqual)
+{
+ bool failure = false;
+ {
+ RecordingReporter reporter;
+ UnitTest::TestResults testResults(&reporter);
+ ScopedCurrentTest scopedResults(testResults);
+
+ int const data1[2][2] = { {0, 1}, {2, 3} };
+ int const data2[2][2] = { {0, 1}, {3, 3} };
+ CHECK_ARRAY2D_CLOSE (data1, data2, 2, 2, 0.01f);
+
+ failure = (testResults.GetFailureCount() > 0);
+ }
+
+ CHECK(failure);
+}
+
+TEST(CheckArray2DCloseFailureIncludesCheckExpectedAndActual)
+{
+ RecordingReporter reporter;
+ {
+ UnitTest::TestResults testResults(&reporter);
+ ScopedCurrentTest scopedResults(testResults);
+
+ int const data1[2][2] = { {0, 1}, {2, 3} };
+ int const data2[2][2] = { {0, 1}, {3, 3} };
+
+ CHECK_ARRAY2D_CLOSE (data1, data2, 2, 2, 0.01f);
+ }
+
+ CHECK(strstr(reporter.lastFailedMessage, "xpected [ [ 0 1 ] [ 2 3 ] ]"));
+ CHECK(strstr(reporter.lastFailedMessage, "was [ [ 0 1 ] [ 3 3 ] ]"));
+}
+
+TEST(CheckArray2DCloseFailureContainsCorrectDetails)
+{
+ int line = 0;
+ RecordingReporter reporter;
+ {
+ UnitTest::TestResults testResults(&reporter);
+ UnitTest::TestDetails testDetails("array2DCloseTest", "array2DCloseSuite", "filename", -1);
+ ScopedCurrentTest scopedResults(testResults, &testDetails);
+
+ int const data1[2][2] = { {0, 1}, {2, 3} };
+ int const data2[2][2] = { {0, 1}, {3, 3} };
+ CHECK_ARRAY2D_CLOSE (data1, data2, 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;
+ {
+ UnitTest::TestResults testResults(&reporter);
+ ScopedCurrentTest scopedResults(testResults);
+
+ float const data1[2][2] = { {0, 1}, {2, 3} };
+ float const data2[2][2] = { {0, 1}, {3, 3} };
+ CHECK_ARRAY2D_CLOSE (data1, data2, 2, 2, 0.01f);
+ }
+
+ CHECK(strstr(reporter.lastFailedMessage, "0.01"));
+}
+
+float const* const* FunctionWithSideEffects3()
+{
+ ++g_sideEffect;
+ static float const data1[] = {0,1};
+ static float const data2[] = {2,3};
+ static const float* const data[] = {data1, data2};
+ return data;
+}
+
+TEST(CheckArray2DCloseDoesNotHaveSideEffectsWhenPassing)
+{
+ g_sideEffect = 0;
+ {
+ UnitTest::TestResults testResults;
+ ScopedCurrentTest scopedResults(testResults);
+
+ const float data[2][2] = { {0, 1}, {2, 3} };
+ CHECK_ARRAY2D_CLOSE (data, FunctionWithSideEffects3(), 2, 2, 0.01f);
+ }
+ CHECK_EQUAL(1, g_sideEffect);
+}
+
+TEST(CheckArray2DCloseDoesNotHaveSideEffectsWhenFailing)
+{
+ g_sideEffect = 0;
+ {
+ UnitTest::TestResults testResults;
+ ScopedCurrentTest scopedResults(testResults);
+
+ const float data[2][2] = { {0, 1}, {3, 3} };
+ CHECK_ARRAY2D_CLOSE (data, FunctionWithSideEffects3(), 2, 2, 0.01f);
+ }
+ CHECK_EQUAL(1, g_sideEffect);
+}
+
+}
o' /> Vas Crabb11 months mame0265commit f8af5cc2cf... Vas Crabb12 months mame0264commit 5b670ad51f... Vas Crabb13 months mame0263commit 93d8318325... Vas Crabb14 months mame0262commit d48a61f921... Vas Crabb15 months mame0261commit ca50094e8d... Vas Crabb17 months mame0260commit 0a7f1fe9cf... Vas Crabb18 months mame0259commit 4ff20056c3... Vas Crabb19 months mame0258commit 2e0aa82350... Vas Crabb20 months mame0257commit f811a66c53... Vas Crabb21 months mame0256commit b41370db02... Vas Crabb22 months mame0255commit c6650dc072... Vas Crabb23 months mame0254commit bfa8d724a0... Vas Crabb2 years mame0253commit b6d9756c5e... Vas Crabb2 years mame0252commit fb98822c34... Vas Crabb2 years mame0251commit 34e6ec1ef8... Vas Crabb2 years mame0250commit b7cbe74c4b... Vas Crabb2 years mame0249commit 91c5b9ecea... Vas Crabb3 years mame0248commit 2d3d0deec8... Vas Crabb3 years mame0247commit fa2d36c634... Vas Crabb3 years mame0246commit 205b03897c... Vas Crabb3 years mame0245commit 5d31f0fc97... Vas Crabb3 years mame0244commit bcf77373a5... Vas Crabb3 years mame0243commit addbb8ab40... Vas Crabb3 years mame0242commit e8166b5274... Vas Crabb3 years mame0241commit 31f001e501... Vas Crabb3 years mame0240commit f0ab44fe1c... Vas Crabb3 years mame0239commit 80bcaea1ed... Vas Crabb3 years mame0238commit fb21b78904... Vas Crabb3 years mame0237commit 34d8357465... Vas Crabb4 years mame0236commit 5e865af540... Vas Crabb4 years mame0235commit ec9ba6fa76... Vas Crabb4 years mame0234commit 2633c19a68... Vas Crabb4 years mame0233commit 05d0cf61e7... Vas Crabb4 years mame0232commit 2b0f01bc3a... Vas Crabb4 years mame0231commit 1f22113661... Vas Crabb4 years mame0230commit 943c06cba0... Vas Crabb4 years mame0229commit 4322eaae9d... Vas Crabb4 years mame0228commit 140f446933... Vas Crabb4 years mame0227commit d85735634c... Vas Crabb4 years mame0226commit 3c56452b07... Vas Crabb5 years mame0225commit 5a1fd0cc17... Vas Crabb5 years mame0224commit 5892c78a15... Vas Crabb5 years mame0223commit c55a261d26... Vas Crabb5 years mame0222commit 6d50d60a43... Vas Crabb5 years mame0221commit e8a0e0469b... Vas Crabb5 years mame0220commit c5c5723b9d... Vas Crabb5 years mame0219commit 221f006442... Vas Crabb5 years mame0218commit 0e2a252d30... Vas Crabb5 years mame0217commit 13997a8f31... Vas Crabb5 years mame0216commit b8b7c7e232... Vas Crabb5 years mame0215commit e9ef4808dd... Vas Crabb6 years mame0214commit 24d07a12d7... Vas Crabb6 years mame0213commit f7172322a2... Vas Crabb6 years mame0212commit 1182bd9325... Vas Crabb6 years mame0211commit 1b969a8acb... Vas Crabb6 years mame0210commit ad45c9c609... Vas Crabb6 years mame0209commit 2b317bf296... Vas Crabb6 years mame0208commit 9483624864...