Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

118 lines
2.7 KiB

  1. #ifndef CPPUNIT_TESTTEST_H
  2. #define CPPUNIT_TESTTEST_H
  3. #ifndef CPPUNIT_TESTCASE_H
  4. #include "TestCase.h"
  5. #endif
  6. #ifndef CPPUNIT_TESTSUITE_H
  7. #include "TestSuite.h"
  8. #endif
  9. #ifndef CPPUNIT_TESTRESULT_H
  10. #include "TestResult.h"
  11. #endif
  12. #ifndef CPPUNIT_TESTCALLER_H
  13. #include "TestCaller.h"
  14. #endif
  15. class TestTest : public TestCase
  16. {
  17. protected:
  18. TestCase *m_failure;
  19. TestCase *m_error;
  20. TestCase *m_success;
  21. public:
  22. TestTest (std::string name) : TestCase (name) {}
  23. void testFailure ();
  24. void testError ();
  25. void testSuccess ();
  26. static Test *suite ();
  27. void setUp ();
  28. void tearDown ();
  29. private:
  30. class FailureTestCase : public TestCase
  31. { public: FailureTestCase (std::string name) : TestCase (name) {}
  32. protected: void runTest () { assert (false); }; };
  33. class ErrorTestCase : public TestCase
  34. { public: ErrorTestCase (std::string name) : TestCase (name) {}
  35. protected: void runTest () { int zero = 0; int result = 8 / zero; }; };
  36. class SuccessTestCase : public TestCase
  37. { public: SuccessTestCase (std::string name) : TestCase (name) {}
  38. protected: void runTest () { assert (true); }; };
  39. };
  40. inline void TestTest::setUp ()
  41. {
  42. m_failure = new FailureTestCase ("failure");
  43. m_error = new ErrorTestCase ("error");
  44. m_success = new SuccessTestCase ("success");
  45. }
  46. inline void TestTest::tearDown ()
  47. {
  48. delete m_failure;
  49. delete m_error;
  50. delete m_success;
  51. }
  52. inline void TestTest::testFailure ()
  53. {
  54. std::auto_ptr<TestResult> result (m_failure->run ());
  55. assert (result->runTests () == 1);
  56. assert (result->testFailures () == 1);
  57. assert (result->testErrors () == 0);
  58. assert (!result->wasSuccessful ());
  59. }
  60. inline void TestTest::testError ()
  61. {
  62. std::auto_ptr<TestResult> result (m_error->run ());
  63. assert (result->runTests () == 1);
  64. assert (result->testFailures () == 0);
  65. assert (result->testErrors () == 1);
  66. assert (!result->wasSuccessful ());
  67. }
  68. inline void TestTest::testSuccess ()
  69. {
  70. std::auto_ptr<TestResult> result (m_success->run ());
  71. assert (result->runTests () == 1);
  72. assert (result->testFailures () == 0);
  73. assert (result->testErrors () == 0);
  74. assert (result->wasSuccessful ());
  75. }
  76. inline Test *TestTest::suite ()
  77. {
  78. TestSuite *suite = new TestSuite ("TestTest");
  79. suite->addTest (new TestCaller<TestTest> ("testFailure", testFailure));
  80. suite->addTest (new TestCaller<TestTest> ("testError", testError));
  81. suite->addTest (new TestCaller<TestTest> ("testSuccess", testSuccess));
  82. return suite;
  83. }
  84. #endif