diff ext/UnitTest++/src/tests/TestDeferredTestReporter.cpp @ 37:0d325e9d5953

added unittest++ files into ext. Not hooked into build scripts yet
author jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
date Sat, 12 Jul 2008 12:00:57 +0000
parents
children 73a9f7addd33
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ext/UnitTest++/src/tests/TestDeferredTestReporter.cpp	Sat Jul 12 12:00:57 2008 +0000
@@ -0,0 +1,104 @@
+#include "../UnitTest++.h"
+#include "../DeferredTestReporter.h"
+
+#include <string>
+
+namespace UnitTest
+{
+
+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);
+    CHECK_EQUAL(testSuite.c_str(), result.suiteName);
+}
+
+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);
+}
+
+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(2u, result.failures.size());
+    CHECK_EQUAL(failure1, result.failures[0].second);
+    CHECK_EQUAL(failure2, result.failures[1].second);
+}
+
+TEST_FIXTURE(DeferredTestReporterFixture, DeferredTestReporterTakesCopyOfFailureMessage)
+{
+    reporter.ReportTestStart(details);
+
+    char failureMessage[128];
+    char const* goodStr = "Real failure message";
+    char const* badStr = "Bogus failure message";
+    
+    std::strcpy(failureMessage, goodStr);
+    reporter.ReportFailure(details, failureMessage);
+    std::strcpy(failureMessage, badStr);
+
+    DeferredTestResult const& result = reporter.GetResults().at(0);
+    DeferredTestResult::Failure const& failure = result.failures.at(0);
+    CHECK_EQUAL(goodStr, failure.second);
+}
+
+}