summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/unittest-cpp/tests/TestDeferredTestReporter.cpp
diff options
context:
space:
mode:
author Miodrag Milanovic <mmicko@gmail.com>2015-05-27 15:00:06 +0200
committer Miodrag Milanovic <mmicko@gmail.com>2015-05-27 15:00:06 +0200
commitee4adf600bdd3aa60cc0e92a39f2111be0a90bc6 (patch)
tree5ecb86b72eef1c19ad3ab6c7ba8d8b2a964e0cb9 /3rdparty/unittest-cpp/tests/TestDeferredTestReporter.cpp
parent55fa9840f263361efc73126c3f41be606fea7168 (diff)
Added library for supporting unit tests (nw)
Diffstat (limited to '3rdparty/unittest-cpp/tests/TestDeferredTestReporter.cpp')
-rw-r--r--3rdparty/unittest-cpp/tests/TestDeferredTestReporter.cpp122
1 files changed, 122 insertions, 0 deletions
diff --git a/3rdparty/unittest-cpp/tests/TestDeferredTestReporter.cpp b/3rdparty/unittest-cpp/tests/TestDeferredTestReporter.cpp
new file mode 100644
index 00000000000..60c347cbfc1
--- /dev/null
+++ b/3rdparty/unittest-cpp/tests/TestDeferredTestReporter.cpp
@@ -0,0 +1,122 @@
+#include "UnitTest++/Config.h"
+
+#ifndef UNITTEST_NO_DEFERRED_REPORTER
+
+#include "UnitTest++/UnitTestPP.h"
+#include "UnitTest++/DeferredTestReporter.h"
+#include <cstring>
+
+namespace UnitTest
+{
+
+namespace
+{
+
+#ifndef UNITTEST_MEMORYOUTSTREAM_IS_STD_OSTRINGSTREAM
+ MemoryOutStream& operator <<(MemoryOutStream& lhs, const std::string& rhs)
+ {
+ lhs << rhs.c_str();
+ return lhs;
+ }
+#endif
+
+struct MockDeferredTestReporter : public DeferredTestReporter
+{
+ virtual void ReportSummary(int, int, int, float)
+ {
+ }
+};
+
+struct DeferredTestReporterFixture
+{
+ DeferredTestReporterFixture()
+ : testName("UniqueTestName")
+ , testSuite("UniqueTestSuite")
+ , fileName("filename.h")
+ , lineNumber(12)
+ , details(testName.c_str(), testSuite.c_str(), fileName.c_str(), lineNumber)
+ {
+ }
+
+ MockDeferredTestReporter reporter;
+ std::string const testName;
+ std::string const testSuite;
+ std::string const fileName;
+ int const lineNumber;
+ TestDetails const details;
+};
+
+TEST_FIXTURE(DeferredTestReporterFixture, ReportTestStartCreatesANewDeferredTest)
+{
+ reporter.ReportTestStart(details);
+ CHECK_EQUAL(1, (int)reporter.GetResults().size());
+}
+
+TEST_FIXTURE(DeferredTestReporterFixture, ReportTestStartCapturesTestNameAndSuite)
+{
+ reporter.ReportTestStart(details);
+
+ DeferredTestResult const& result = reporter.GetResults().at(0);
+ CHECK_EQUAL(testName.c_str(), result.testName.c_str());
+ CHECK_EQUAL(testSuite.c_str(), result.suiteName.c_str());
+}
+
+TEST_FIXTURE(DeferredTestReporterFixture, ReportTestEndCapturesTestTime)
+{
+ float const elapsed = 123.45f;
+ reporter.ReportTestStart(details);
+ reporter.ReportTestFinish(details, elapsed);
+
+ DeferredTestResult const& result = reporter.GetResults().at(0);
+ CHECK_CLOSE(elapsed, result.timeElapsed, 0.0001f);
+}
+
+TEST_FIXTURE(DeferredTestReporterFixture, ReportFailureSavesFailureDetails)
+{
+ char const* failure = "failure";
+
+ reporter.ReportTestStart(details);
+ reporter.ReportFailure(details, failure);
+
+ DeferredTestResult const& result = reporter.GetResults().at(0);
+ CHECK(result.failed == true);
+ CHECK_EQUAL(fileName.c_str(), result.failureFile.c_str());
+}
+
+TEST_FIXTURE(DeferredTestReporterFixture, ReportFailureSavesFailureDetailsForMultipleFailures)
+{
+ char const* failure1 = "failure 1";
+ char const* failure2 = "failure 2";
+
+ reporter.ReportTestStart(details);
+ reporter.ReportFailure(details, failure1);
+ reporter.ReportFailure(details, failure2);
+
+ DeferredTestResult const& result = reporter.GetResults().at(0);
+ CHECK_EQUAL(2, (int)result.failures.size());
+ CHECK_EQUAL(failure1, result.failures[0].failureStr);
+ CHECK_EQUAL(failure2, result.failures[1].failureStr);
+}
+
+TEST_FIXTURE(DeferredTestReporterFixture, DeferredTestReporterTakesCopyOfFailureMessage)
+{
+ reporter.ReportTestStart(details);
+
+ char failureMessage[128];
+ char const* goodStr = "Real failure message";
+ char const* badStr = "Bogus failure message";
+
+ using namespace std;
+
+ strcpy(failureMessage, goodStr);
+ reporter.ReportFailure(details, failureMessage);
+ strcpy(failureMessage, badStr);
+
+ DeferredTestResult const& result = reporter.GetResults().at(0);
+ DeferredTestFailure const& failure = result.failures.at(0);
+ CHECK_EQUAL(goodStr, failure.failureStr);
+}
+
+}}
+
+#endif