From ee4adf600bdd3aa60cc0e92a39f2111be0a90bc6 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Wed, 27 May 2015 15:00:06 +0200 Subject: Added library for supporting unit tests (nw) --- .../unittest-cpp/tests/TestXmlTestReporter.cpp | 188 +++++++++++++++++++++ 1 file changed, 188 insertions(+) create mode 100644 3rdparty/unittest-cpp/tests/TestXmlTestReporter.cpp (limited to '3rdparty/unittest-cpp/tests/TestXmlTestReporter.cpp') diff --git a/3rdparty/unittest-cpp/tests/TestXmlTestReporter.cpp b/3rdparty/unittest-cpp/tests/TestXmlTestReporter.cpp new file mode 100644 index 00000000000..154ada82c79 --- /dev/null +++ b/3rdparty/unittest-cpp/tests/TestXmlTestReporter.cpp @@ -0,0 +1,188 @@ +#include "UnitTest++/Config.h" +#ifndef UNITTEST_NO_DEFERRED_REPORTER + +#include "UnitTest++/UnitTestPP.h" +#include "UnitTest++/XmlTestReporter.h" + +#include + +using namespace UnitTest; +using std::ostringstream; + +namespace +{ + +#ifndef UNITTEST_MEMORYOUTSTREAM_IS_STD_OSTRINGSTREAM + +// Overload to let MemoryOutStream accept std::string +MemoryOutStream& operator<<(MemoryOutStream& s, const std::string& value) +{ + s << value.c_str(); + return s; +} + +#endif + +struct XmlTestReporterFixture +{ + XmlTestReporterFixture() + : reporter(output) + { + } + + ostringstream output; + XmlTestReporter reporter; +}; + +TEST_FIXTURE(XmlTestReporterFixture, MultipleCharactersAreEscaped) +{ + TestDetails const details("TestName", "suite", "filename.h", 4321); + + reporter.ReportTestStart(details); + reporter.ReportFailure(details, "\"\"\'\'&&<<>>"); + reporter.ReportTestFinish(details, 0.1f); + reporter.ReportSummary(1, 2, 3, 0.1f); + + char const* expected = + "" + "" + "" + "" + "" + ""; + + CHECK_EQUAL(expected, output.str().c_str()); +} + +TEST_FIXTURE(XmlTestReporterFixture, OutputIsCachedUntilReportSummaryIsCalled) +{ + TestDetails const details("", "", "", 0); + + reporter.ReportTestStart(details); + reporter.ReportFailure(details, "message"); + reporter.ReportTestFinish(details, 1.0F); + CHECK(output.str().empty()); + + reporter.ReportSummary(1, 1, 1, 1.0f); + CHECK(!output.str().empty()); +} + +TEST_FIXTURE(XmlTestReporterFixture, EmptyReportSummaryFormat) +{ + reporter.ReportSummary(0, 0, 0, 0.1f); + + const char *expected = + "" + "" + ""; + + CHECK_EQUAL(expected, output.str().c_str()); +} + +TEST_FIXTURE(XmlTestReporterFixture, SingleSuccessfulTestReportSummaryFormat) +{ + TestDetails const details("TestName", "DefaultSuite", "", 0); + + reporter.ReportTestStart(details); + reporter.ReportSummary(1, 0, 0, 0.1f); + + const char *expected = + "" + "" + "" + ""; + + CHECK_EQUAL(expected, output.str().c_str()); +} + +TEST_FIXTURE(XmlTestReporterFixture, SingleFailedTestReportSummaryFormat) +{ + TestDetails const details("A Test", "suite", "A File", 4321); + + reporter.ReportTestStart(details); + reporter.ReportFailure(details, "A Failure"); + reporter.ReportSummary(1, 1, 1, 0.1f); + + const char *expected = + "" + "" + "" + "" + "" + ""; + + CHECK_EQUAL(expected, output.str().c_str()); +} + +TEST_FIXTURE(XmlTestReporterFixture, FailureMessageIsXMLEscaped) +{ + TestDetails const details("TestName", "suite", "filename.h", 4321); + + reporter.ReportTestStart(details); + reporter.ReportFailure(details, "\"\'&<>"); + reporter.ReportTestFinish(details, 0.1f); + reporter.ReportSummary(1, 1, 1, 0.1f); + + char const* expected = + "" + "" + "" + "" + "" + ""; + + CHECK_EQUAL(expected, output.str().c_str()); +} + +TEST_FIXTURE(XmlTestReporterFixture, OneFailureAndOneSuccess) +{ + TestDetails const failedDetails("FailedTest", "suite", "fail.h", 1); + reporter.ReportTestStart(failedDetails); + reporter.ReportFailure(failedDetails, "expected 1 but was 2"); + reporter.ReportTestFinish(failedDetails, 0.1f); + + TestDetails const succeededDetails("SucceededTest", "suite", "", 0); + reporter.ReportTestStart(succeededDetails); + reporter.ReportTestFinish(succeededDetails, 1.0f); + reporter.ReportSummary(2, 1, 1, 1.1f); + + char const* expected = + "" + "" + "" + "" + "" + "" + ""; + + CHECK_EQUAL(expected, output.str().c_str()); +} + +TEST_FIXTURE(XmlTestReporterFixture, MultipleFailures) +{ + TestDetails const failedDetails1("FailedTest", "suite", "fail.h", 1); + TestDetails const failedDetails2("FailedTest", "suite", "fail.h", 31); + + reporter.ReportTestStart(failedDetails1); + reporter.ReportFailure(failedDetails1, "expected 1 but was 2"); + reporter.ReportFailure(failedDetails2, "expected one but was two"); + reporter.ReportTestFinish(failedDetails1, 0.1f); + + reporter.ReportSummary(1, 1, 2, 1.1f); + + char const* expected = + "" + "" + "" + "" + "" + "" + ""; + + CHECK_EQUAL(expected, output.str().c_str()); +} + +} + +#endif -- cgit v1.2.3-70-g09d2