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.

151 lines
3.6KB

  1. // ---
  2. //
  3. // $Id: cpptest-output.h,v 1.7 2008/07/15 21:20:26 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. /** \file */
  27. #ifndef CPPTEST_OUTPUT_H
  28. #define CPPTEST_OUTPUT_H
  29. #ifdef _MSC_VER
  30. # define CPPTEST_UNUSED(x)
  31. #else
  32. # define CPPTEST_UNUSED(x) (void)x
  33. #endif
  34. namespace Test
  35. {
  36. class Source;
  37. class Time;
  38. /// \brief %Test suite output handler.
  39. ///
  40. /// Abstract base class for all suite output handlers. Derive from this
  41. /// class to create real output handlers that creates arbitrary complex
  42. /// output handlers.
  43. ///
  44. /// All parts of testing is reported (test start/stop, suite start/stop,
  45. /// individual test start/stop, and assertments), thus giving maximum
  46. /// flexibility for derived classes.
  47. ///
  48. class Output
  49. {
  50. public:
  51. /// Empty destructor.
  52. ///
  53. virtual ~Output() {}
  54. /// Called when testing is started.
  55. ///
  56. /// \param tests Total number of tests in all suites.
  57. ///
  58. virtual void initialize(int tests)
  59. {
  60. CPPTEST_UNUSED(tests);
  61. }
  62. /// Called when testing is finished.
  63. ///
  64. /// \param tests Total number of tests in all suites.
  65. /// \param time Total elapsed time for all tests.
  66. ///
  67. virtual void finished(int tests, const Time& time)
  68. {
  69. CPPTEST_UNUSED(tests);
  70. CPPTEST_UNUSED(time);
  71. }
  72. /// Called when a suite is entered.
  73. ///
  74. /// \param tests Number of tests in this suite.
  75. /// \param name Name of the suite.
  76. ///
  77. virtual void suite_start(int tests, const std::string& name)
  78. {
  79. CPPTEST_UNUSED(tests);
  80. CPPTEST_UNUSED(name);
  81. }
  82. /// Called when a suite is finished.
  83. ///
  84. /// \param tests Number of tests in this suite.
  85. /// \param name Name of the suite.
  86. /// \param time Total elapsed time for all tests in this suite.
  87. ///
  88. virtual void suite_end(int tests, const std::string& name,
  89. const Time& time)
  90. {
  91. CPPTEST_UNUSED(tests);
  92. CPPTEST_UNUSED(name);
  93. CPPTEST_UNUSED(time);
  94. }
  95. /// Called when a tests is executed.
  96. ///
  97. /// \param name Name of the test function.
  98. ///
  99. virtual void test_start(const std::string& name)
  100. {
  101. CPPTEST_UNUSED(name);
  102. }
  103. /// Called when a test if finished, regardless if an assertment was
  104. /// issued.
  105. ///
  106. /// \param name Name of the test function.
  107. /// \param ok True if the test was successful; false otherwise.
  108. /// \param time Execution time.
  109. ///
  110. virtual void test_end(const std::string& name, bool ok,
  111. const Time& time)
  112. {
  113. CPPTEST_UNUSED(name);
  114. CPPTEST_UNUSED(ok);
  115. CPPTEST_UNUSED(time);
  116. }
  117. /// Called when an assertment is issued.
  118. ///
  119. /// \param s Assert point information.
  120. ///
  121. virtual void assertment(const Source& s)
  122. {
  123. CPPTEST_UNUSED(s);
  124. }
  125. protected:
  126. /// Empty constructor.
  127. ///
  128. Output() {}
  129. private:
  130. Output(const Output&);
  131. Output& operator=(const Output&);
  132. };
  133. } // namespace Test
  134. #endif // #ifndef CPPTEST_OUTPUT_H