?login_element?

Subversion Repositories NedoOS

Rev

Rev 539 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. #include "UnitTest++/UnitTestPP.h"
  2. #include "UnitTest++/TestReporter.h"
  3. #include "UnitTest++/TimeHelpers.h"
  4. #include "ScopedCurrentTest.h"
  5.  
  6. using namespace UnitTest;
  7.  
  8. namespace {
  9.  
  10.    TEST(PassingTestHasNoFailures)
  11.    {
  12.       class PassingTest : public Test
  13.       {
  14.       public:
  15.          PassingTest() : Test("passing") {}
  16.          virtual void RunImpl() const
  17.          {
  18.             CHECK(true);
  19.          }
  20.       };
  21.  
  22.       TestResults results;
  23.       {
  24.          ScopedCurrentTest scopedResults(results);
  25.          PassingTest().Run();
  26.       }
  27.  
  28.       CHECK_EQUAL(0, results.GetFailureCount());
  29.    }
  30.  
  31.  
  32.    TEST(FailingTestHasFailures)
  33.    {
  34.       class FailingTest : public Test
  35.       {
  36.       public:
  37.          FailingTest() : Test("failing") {}
  38.          virtual void RunImpl() const
  39.          {
  40.             CHECK(false);
  41.          }
  42.       };
  43.  
  44.       TestResults results;
  45.       {
  46.          ScopedCurrentTest scopedResults(results);
  47.          FailingTest().Run();
  48.       }
  49.  
  50.       CHECK_EQUAL(1, results.GetFailureCount());
  51.    }
  52.  
  53. #ifndef UNITTEST_NO_EXCEPTIONS
  54.    TEST(ThrowingTestsAreReportedAsFailures)
  55.    {
  56.       class CrashingTest : public Test
  57.       {
  58.       public:
  59.          CrashingTest() : Test("throwing") {}
  60.          virtual void RunImpl() const
  61.          {
  62.             throw "Blah";
  63.          }
  64.       };
  65.  
  66.       TestResults results;
  67.       {
  68.          ScopedCurrentTest scopedResult(results);
  69.          CrashingTest().Run();
  70.       }
  71.  
  72.       CHECK_EQUAL(1, results.GetFailureCount());
  73.    }
  74.  
  75. #if !defined(UNITTEST_MINGW) && !defined(UNITTEST_WIN32) && !defined(__clang__)
  76. // Skip this test in debug because some debuggers don't like it.
  77. #if defined(NDEBUG)
  78.    TEST(CrashingTestsAreReportedAsFailures)
  79.    {
  80.       class CrashingTest : public Test
  81.       {
  82.       public:
  83.          CrashingTest() : Test("crashing") {}
  84.          virtual void RunImpl() const
  85.          {
  86.  
  87.             reinterpret_cast< void (*)() >(0)();
  88.          }
  89.       };
  90.  
  91.       TestResults results;
  92.       {
  93.          ScopedCurrentTest scopedResult(results);
  94.          CrashingTest().Run();
  95.       }
  96.  
  97.       CHECK_EQUAL(1, results.GetFailureCount());
  98.    }
  99. #endif
  100. #endif
  101. #endif
  102.  
  103.    TEST(TestWithUnspecifiedSuiteGetsDefaultSuite)
  104.    {
  105.       Test test("test");
  106.       CHECK(test.m_details.suiteName != NULL);
  107.       CHECK_EQUAL("DefaultSuite", test.m_details.suiteName);
  108.    }
  109.  
  110.    TEST(TestReflectsSpecifiedSuiteName)
  111.    {
  112.       Test test("test", "testSuite");
  113.       CHECK(test.m_details.suiteName != NULL);
  114.       CHECK_EQUAL("testSuite", test.m_details.suiteName);
  115.    }
  116.  
  117.    void Fail()
  118.    {
  119.       CHECK(false);
  120.    }
  121.  
  122.    TEST(OutOfCoreCHECKMacrosCanFailTests)
  123.    {
  124.       TestResults results;
  125.       {
  126.          ScopedCurrentTest scopedResult(results);
  127.          Fail();
  128.       }
  129.  
  130.       CHECK_EQUAL(1, results.GetFailureCount());
  131.    }
  132.  
  133. }
  134.