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