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.

99 lines
2.2KB

  1. // ---
  2. //
  3. // $Id: collectoroutput.cpp,v 1.4 2008/07/15 20:33:31 hartwork Exp $
  4. //
  5. // CppTest - A C++ Unit Testing Framework
  6. // Copyright (c) 2003 Niklas Lundell
  7. //
  8. // ---
  9. //
  10. // This library is free software; you can redistribute it and/or
  11. // modify it under the terms of the GNU Lesser General Public
  12. // License as published by the Free Software Foundation; either
  13. // version 2 of the License, or (at your option) any later version.
  14. //
  15. // This library is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. // Lesser General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU Lesser General Public
  21. // License along with this library; if not, write to the
  22. // Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  23. // Boston, MA 02111-1307, USA.
  24. //
  25. // ---
  26. #include "cpptest-collectoroutput.h"
  27. namespace Test
  28. {
  29. CollectorOutput::TestInfo::TestInfo(const std::string name)
  30. : _name(name)
  31. {}
  32. CollectorOutput::SuiteInfo::SuiteInfo(const std::string& name, int tests)
  33. : _name(name),
  34. _errors(0)
  35. {
  36. _tests.reserve(tests);
  37. }
  38. /// Constructs a collector object.
  39. ///
  40. CollectorOutput::CollectorOutput()
  41. : Output(),
  42. _total_errors(0)
  43. {}
  44. void
  45. CollectorOutput::finished(int tests, const Time& time)
  46. {
  47. _total_tests = tests;
  48. _total_time = time;
  49. }
  50. void
  51. CollectorOutput::suite_start(int tests, const std::string& name)
  52. {
  53. if (tests > 0)
  54. {
  55. _suites.push_back(SuiteInfo(name, tests));
  56. _cur_suite = &_suites.back();
  57. }
  58. }
  59. void
  60. CollectorOutput::suite_end(int tests, const std::string&, const Time& time)
  61. {
  62. if (tests > 0)
  63. {
  64. _cur_suite->_time = time;
  65. _total_errors += _cur_suite->_errors;
  66. }
  67. }
  68. void
  69. CollectorOutput::test_start(const std::string& name)
  70. {
  71. _cur_suite->_tests.push_back(TestInfo(name));
  72. _cur_test = &_cur_suite->_tests.back();
  73. }
  74. void
  75. CollectorOutput::test_end(const std::string&, bool ok, const Time& time)
  76. {
  77. if (!(_cur_test->_success = ok))
  78. ++_cur_suite->_errors;
  79. _cur_test->_time = time;
  80. }
  81. void
  82. CollectorOutput::assertment(const Source& s)
  83. {
  84. _cur_test->_sources.push_back(s);
  85. }
  86. } // namespace Test