TextTestResult.cpp
Upload User: dzyhzl
Upload Date: 2019-04-29
Package Size: 56270k
Code Size: 3k
Development Platform:

C/C++

  1. #include "TextTestResult.h"
  2. #include "CppUnitException.h"
  3. #include "estring.h"
  4. using namespace std;
  5. void TextTestResult::addError (Test *test, CppUnitException *e)
  6. {
  7.     TestResult::addError (test, e);
  8.     cerr << "En";
  9. }
  10. void TextTestResult::addFailure (Test *test, CppUnitException *e)
  11. {
  12.     TestResult::addFailure (test, e);
  13.     cerr << "Fn";
  14. }
  15. void TextTestResult::startTest (Test *test)
  16. {
  17.     TestResult::startTest (test);
  18.     cerr << ".";
  19. }
  20. void TextTestResult::printErrors (ostream& stream)
  21. {
  22.     if (testErrors () != 0) {
  23.         if (testErrors () == 1)
  24.             stream << "There was " << testErrors () << " error: " << endl;
  25.         else
  26.             stream << "There were " << testErrors () << " errors: " << endl;
  27.         int i = 1;
  28.         for (vector<TestFailure *>::iterator it = errors ().begin (); it != errors ().end (); ++it) {
  29.             TestFailure             *failure    = *it;
  30.             CppUnitException        *e          = failure->thrownException ();
  31.             stream << i 
  32.                    << ") "
  33.                    << "line: " << (e ? estring (e->lineNumber ()) : "") << " "
  34.                    << (e ? e->fileName () : "") << " "
  35.                    << """ << failure->thrownException ()->what () << """
  36.                    << endl;
  37.             i++;
  38.         }
  39.     }
  40. }
  41. void TextTestResult::printFailures (ostream& stream) 
  42. {
  43.     if (testFailures () != 0) {
  44.         if (testFailures () == 1)
  45.             stream << "There was " << testFailures () << " failure: " << endl;
  46.         else
  47.             stream << "There were " << testFailures () << " failures: " << endl;
  48.         int i = 1;
  49.         for (vector<TestFailure *>::iterator it = failures ().begin (); it != failures ().end (); ++it) {
  50.             TestFailure             *failure    = *it;
  51.             CppUnitException        *e          = failure->thrownException ();
  52.             stream << i 
  53.                    << ") "
  54.                    << "line: " << (e ? estring (e->lineNumber ()) : "") << " "
  55.                    << (e ? e->fileName () : "") << " "
  56.                    << """ << failure->thrownException ()->what () << """
  57.                    << endl;
  58.             i++;
  59.         }
  60.     }
  61. }
  62. void TextTestResult::print (ostream& stream) 
  63. {
  64.     printHeader (stream);
  65.     printErrors (stream);
  66.     printFailures (stream);
  67. }
  68. void TextTestResult::printHeader (ostream& stream)
  69. {
  70.     if (wasSuccessful ())
  71.         cout << endl << "OK (" << runTests () << " tests)" << endl;
  72.     else
  73.         cout << endl
  74.              << "!!!FAILURES!!!" << endl
  75.              << "Test Results:" << endl
  76.              << "Run:  "
  77.              << runTests ()
  78.              << "   Failures: "
  79.              << testFailures ()
  80.              << "   Errors: "
  81.              << testErrors ()
  82.              << endl;
  83. }