?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download

  1. #include "UnitTest++/UnitTestPP.h"
  2. #include "UnitTest++/CompositeTestReporter.h"
  3.  
  4. using namespace UnitTest;
  5.  
  6. namespace {
  7.  
  8.    TEST(ZeroReportersByDefault)
  9.    {
  10.       CHECK_EQUAL(0, CompositeTestReporter().GetReporterCount());
  11.    }
  12.  
  13.    struct MockReporter : TestReporter
  14.    {
  15.       MockReporter()
  16.          : testStartCalled(false)
  17.          , testStartDetails(NULL)
  18.          , failureCalled(false)
  19.          , failureDetails(NULL)
  20.          , failureStr(NULL)
  21.          , testFinishCalled(false)
  22.          , testFinishDetails(NULL)
  23.          , testFinishSecondsElapsed(-1.0f)
  24.          , summaryCalled(false)
  25.          , summaryTotalTestCount(-1)
  26.          , summaryFailureCount(-1)
  27.          , summarySecondsElapsed(-1.0f)
  28.       {}
  29.  
  30.       virtual void ReportTestStart(TestDetails const& test)
  31.       {
  32.          testStartCalled = true;
  33.          testStartDetails = &test;
  34.       }
  35.  
  36.       virtual void ReportFailure(TestDetails const& test, char const* failure)
  37.       {
  38.          failureCalled = true;
  39.          failureDetails = &test;
  40.          failureStr = failure;
  41.       }
  42.  
  43.       virtual void ReportTestFinish(TestDetails const& test, float secondsElapsed)
  44.       {
  45.          testFinishCalled = true;
  46.          testFinishDetails = &test;
  47.          testFinishSecondsElapsed = secondsElapsed;
  48.       }
  49.  
  50.       virtual void ReportSummary(int totalTestCount,
  51.                                  int failedTestCount,
  52.                                  int failureCount,
  53.                                  float secondsElapsed)
  54.       {
  55.          summaryCalled = true;
  56.          summaryTotalTestCount = totalTestCount;
  57.          summaryFailedTestCount = failedTestCount;
  58.          summaryFailureCount = failureCount;
  59.          summarySecondsElapsed = secondsElapsed;
  60.       }
  61.  
  62.       bool testStartCalled;
  63.       TestDetails const* testStartDetails;
  64.  
  65.       bool failureCalled;
  66.       TestDetails const* failureDetails;
  67.       const char* failureStr;
  68.  
  69.       bool testFinishCalled;
  70.       TestDetails const* testFinishDetails;
  71.       float testFinishSecondsElapsed;
  72.  
  73.       bool summaryCalled;
  74.       int summaryTotalTestCount;
  75.       int summaryFailedTestCount;
  76.       int summaryFailureCount;
  77.       float summarySecondsElapsed;
  78.    };
  79.  
  80.    TEST(AddReporter)
  81.    {
  82.       MockReporter r;
  83.       CompositeTestReporter c;
  84.  
  85.       CHECK(c.AddReporter(&r));
  86.       CHECK_EQUAL(1, c.GetReporterCount());
  87.    }
  88.  
  89.    TEST(RemoveReporter)
  90.    {
  91.       MockReporter r;
  92.       CompositeTestReporter c;
  93.  
  94.       c.AddReporter(&r);
  95.       CHECK(c.RemoveReporter(&r));
  96.       CHECK_EQUAL(0, c.GetReporterCount());
  97.    }
  98.  
  99.    struct Fixture
  100.    {
  101.       Fixture()
  102.       {
  103.          c.AddReporter(&r0);
  104.          c.AddReporter(&r1);
  105.       }
  106.  
  107.       MockReporter r0, r1;
  108.       CompositeTestReporter c;
  109.    };
  110.  
  111.    TEST_FIXTURE(Fixture, ReportTestStartCallsReportTestStartOnAllAggregates)
  112.    {
  113.       TestDetails t("", "", "", 0);
  114.       c.ReportTestStart(t);
  115.  
  116.       CHECK(r0.testStartCalled);
  117.       CHECK_EQUAL(&t, r0.testStartDetails);
  118.       CHECK(r1.testStartCalled);
  119.       CHECK_EQUAL(&t, r1.testStartDetails);
  120.    }
  121.  
  122.    TEST_FIXTURE(Fixture, ReportFailureCallsReportFailureOnAllAggregates)
  123.    {
  124.       TestDetails t("", "", "", 0);
  125.       const char* failStr = "fail";
  126.       c.ReportFailure(t, failStr);
  127.  
  128.       CHECK(r0.failureCalled);
  129.       CHECK_EQUAL(&t, r0.failureDetails);
  130.       CHECK_EQUAL(failStr, r0.failureStr);
  131.  
  132.       CHECK(r1.failureCalled);
  133.       CHECK_EQUAL(&t, r1.failureDetails);
  134.       CHECK_EQUAL(failStr, r1.failureStr);
  135.    }
  136.  
  137.    TEST_FIXTURE(Fixture, ReportTestFinishCallsReportTestFinishOnAllAggregates)
  138.    {
  139.       TestDetails t("", "", "", 0);
  140.       const float s = 1.2345f;
  141.       c.ReportTestFinish(t, s);
  142.  
  143.       CHECK(r0.testFinishCalled);
  144.       CHECK_EQUAL(&t, r0.testFinishDetails);
  145.       CHECK_CLOSE(s, r0.testFinishSecondsElapsed, 0.00001f);
  146.  
  147.       CHECK(r1.testFinishCalled);
  148.       CHECK_EQUAL(&t, r1.testFinishDetails);
  149.       CHECK_CLOSE(s, r1.testFinishSecondsElapsed, 0.00001f);
  150.    }
  151.  
  152.    TEST_FIXTURE(Fixture, ReportSummaryCallsReportSummaryOnAllAggregates)
  153.    {
  154.       TestDetails t("", "", "", 0);
  155.       const int testCount = 3;
  156.       const int failedTestCount = 4;
  157.       const int failureCount = 5;
  158.       const float secondsElapsed = 3.14159f;
  159.  
  160.       c.ReportSummary(testCount, failedTestCount, failureCount, secondsElapsed);
  161.  
  162.       CHECK(r0.summaryCalled);
  163.       CHECK_EQUAL(testCount, r0.summaryTotalTestCount);
  164.       CHECK_EQUAL(failedTestCount, r0.summaryFailedTestCount);
  165.       CHECK_EQUAL(failureCount, r0.summaryFailureCount);
  166.       CHECK_CLOSE(secondsElapsed, r0.summarySecondsElapsed, 0.00001f);
  167.  
  168.       CHECK(r1.summaryCalled);
  169.       CHECK_EQUAL(testCount, r1.summaryTotalTestCount);
  170.       CHECK_EQUAL(failedTestCount, r1.summaryFailedTestCount);
  171.       CHECK_EQUAL(failureCount, r1.summaryFailureCount);
  172.       CHECK_CLOSE(secondsElapsed, r1.summarySecondsElapsed, 0.00001f);
  173.    }
  174.  
  175. }
  176.