?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. #include "UnitTest++/Config.h"
  2. #include "UnitTest++/UnitTestPP.h"
  3.  
  4. #include "UnitTest++/ReportAssert.h"
  5. #include "UnitTest++/ReportAssertImpl.h"
  6. #include "UnitTest++/AssertException.h"
  7.  
  8. #include "RecordingReporter.h"
  9. #include <csetjmp>
  10.  
  11. using namespace UnitTest;
  12.  
  13. namespace {
  14.  
  15.    TEST(CanSetAssertExpected)
  16.    {
  17.       Detail::ExpectAssert(true);
  18.       CHECK(Detail::AssertExpected());
  19.  
  20.       Detail::ExpectAssert(false);
  21.       CHECK(!Detail::AssertExpected());
  22.    }
  23.  
  24. #ifndef UNITTEST_NO_EXCEPTIONS
  25.  
  26.    TEST(ReportAssertThrowsAssertException)
  27.    {
  28.       bool caught = false;
  29.  
  30.       try
  31.       {
  32.          TestResults testResults;
  33.          TestDetails testDetails("", "", "", 0);
  34.          Detail::ReportAssertEx(&testResults, &testDetails, "", "", 0);
  35.       }
  36.       catch(AssertException const&)
  37.       {
  38.          caught = true;
  39.       }
  40.  
  41.       CHECK(true == caught);
  42.    }
  43.  
  44.    TEST(ReportAssertClearsExpectAssertFlag)
  45.    {
  46.       RecordingReporter reporter;
  47.       TestResults testResults(&reporter);
  48.       TestDetails testDetails("", "", "", 0);
  49.  
  50.       try
  51.       {
  52.          Detail::ExpectAssert(true);
  53.          Detail::ReportAssertEx(&testResults, &testDetails, "", "", 0);
  54.       }
  55.       catch(AssertException const&)
  56.       {}
  57.  
  58.       CHECK(Detail::AssertExpected() == false);
  59.       CHECK_EQUAL(0, reporter.testFailedCount);
  60.    }
  61.  
  62.    TEST(ReportAssertWritesFailureToResultsAndDetailsWhenAssertIsNotExpected)
  63.    {
  64.       const int lineNumber = 12345;
  65.       const char* description = "description";
  66.       const char* filename = "filename";
  67.  
  68.       RecordingReporter reporter;
  69.       TestResults testResults(&reporter);
  70.       TestDetails testDetails("", "", "", 0);
  71.  
  72.       try
  73.       {
  74.          Detail::ReportAssertEx(&testResults, &testDetails, description, filename, lineNumber);
  75.       }
  76.       catch(AssertException const&)
  77.       {}
  78.  
  79.       CHECK_EQUAL(description, reporter.lastFailedMessage);
  80.       CHECK_EQUAL(filename, reporter.lastFailedFile);
  81.       CHECK_EQUAL(lineNumber, reporter.lastFailedLine);
  82.    }
  83.  
  84.    TEST(ReportAssertReportsNoErrorsWhenAssertIsExpected)
  85.    {
  86.       Detail::ExpectAssert(true);
  87.  
  88.       RecordingReporter reporter;
  89.       TestResults testResults(&reporter);
  90.       TestDetails testDetails("", "", "", 0);
  91.  
  92.       try
  93.       {
  94.          Detail::ReportAssertEx(&testResults, &testDetails, "", "", 0);
  95.       }
  96.       catch(AssertException const&)
  97.       {}
  98.  
  99.       CHECK_EQUAL(0, reporter.testFailedCount);
  100.    }
  101.  
  102.    TEST(CheckAssertMacroSetsAssertExpectationToFalseAfterRunning)
  103.    {
  104.       Detail::ExpectAssert(true);
  105.       CHECK_ASSERT(ReportAssert("", "", 0));
  106.       CHECK(!Detail::AssertExpected());
  107.       Detail::ExpectAssert(false);
  108.    }
  109.  
  110. #else
  111.  
  112.    TEST(SetAssertJumpTargetReturnsFalseWhenSettingJumpTarget)
  113.    {
  114.       CHECK(UNITTEST_SET_ASSERT_JUMP_TARGET() == false);
  115.    }
  116.  
  117.    TEST(JumpToAssertJumpTarget_JumpsToSetPoint_ReturnsTrue)
  118.    {
  119.       const volatile bool taken = !!UNITTEST_SET_ASSERT_JUMP_TARGET();
  120.  
  121.       volatile bool set = false;
  122.       if (taken == false)
  123.       {
  124.          UNITTEST_JUMP_TO_ASSERT_JUMP_TARGET();
  125.          set = true;
  126.       }
  127.  
  128.       CHECK(set == false);
  129.    }
  130.  
  131. #endif
  132.  
  133. }
  134.