TestTest.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #include "../UnitTest++.h"
  2. #include "../TestReporter.h"
  3. #include "../TimeHelpers.h"
  4. #include "ScopedCurrentTest.h"
  5. using namespace UnitTest;
  6. namespace {
  7. TEST(PassingTestHasNoFailures)
  8. {
  9. class PassingTest : public Test
  10. {
  11. public:
  12. PassingTest() : Test("passing") {}
  13. virtual void RunImpl() const
  14. {
  15. CHECK(true);
  16. }
  17. };
  18. TestResults results;
  19. {
  20. ScopedCurrentTest scopedResults(results);
  21. PassingTest().Run();
  22. }
  23. CHECK_EQUAL(0, results.GetFailureCount());
  24. }
  25. TEST(FailingTestHasFailures)
  26. {
  27. class FailingTest : public Test
  28. {
  29. public:
  30. FailingTest() : Test("failing") {}
  31. virtual void RunImpl() const
  32. {
  33. CHECK(false);
  34. }
  35. };
  36. TestResults results;
  37. {
  38. ScopedCurrentTest scopedResults(results);
  39. FailingTest().Run();
  40. }
  41. CHECK_EQUAL(1, results.GetFailureCount());
  42. }
  43. TEST(ThrowingTestsAreReportedAsFailures)
  44. {
  45. class CrashingTest : public Test
  46. {
  47. public:
  48. CrashingTest() : Test("throwing") {}
  49. virtual void RunImpl() const
  50. {
  51. throw "Blah";
  52. }
  53. };
  54. TestResults results;
  55. {
  56. ScopedCurrentTest scopedResult(results);
  57. CrashingTest().Run();
  58. }
  59. CHECK_EQUAL(1, results.GetFailureCount());
  60. }
  61. #ifndef UNITTEST_MINGW
  62. TEST(CrashingTestsAreReportedAsFailures)
  63. {
  64. class CrashingTest : public Test
  65. {
  66. public:
  67. CrashingTest() : Test("crashing") {}
  68. virtual void RunImpl() const
  69. {
  70. reinterpret_cast< void (*)() >(0)();
  71. }
  72. };
  73. TestResults results;
  74. {
  75. ScopedCurrentTest scopedResult(results);
  76. CrashingTest().Run();
  77. }
  78. CHECK_EQUAL(1, results.GetFailureCount());
  79. }
  80. #endif
  81. TEST(TestWithUnspecifiedSuiteGetsDefaultSuite)
  82. {
  83. Test test("test");
  84. CHECK(test.m_details.suiteName != NULL);
  85. CHECK_EQUAL("DefaultSuite", test.m_details.suiteName);
  86. }
  87. TEST(TestReflectsSpecifiedSuiteName)
  88. {
  89. Test test("test", "testSuite");
  90. CHECK(test.m_details.suiteName != NULL);
  91. CHECK_EQUAL("testSuite", test.m_details.suiteName);
  92. }
  93. void Fail()
  94. {
  95. CHECK(false);
  96. }
  97. TEST(OutOfCoreCHECKMacrosCanFailTests)
  98. {
  99. TestResults results;
  100. {
  101. ScopedCurrentTest scopedResult(results);
  102. Fail();
  103. }
  104. CHECK_EQUAL(1, results.GetFailureCount());
  105. }
  106. }