collection.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
  2. *
  3. * Data Differential YATL (i.e. libtest) library
  4. *
  5. * Copyright (C) 2012 Data Differential, http://datadifferential.com/
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are
  9. * met:
  10. *
  11. * * Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. *
  14. * * Redistributions in binary form must reproduce the above
  15. * copyright notice, this list of conditions and the following disclaimer
  16. * in the documentation and/or other materials provided with the
  17. * distribution.
  18. *
  19. * * The names of its contributors may not be used to endorse or
  20. * promote products derived from this software without specific prior
  21. * written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  24. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  25. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  26. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  27. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  28. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  29. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  30. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  31. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  32. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  33. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. */
  36. #pragma once
  37. #include <libtest/formatter.hpp>
  38. #include <libtest/timer.hpp>
  39. namespace { class Framework; }
  40. /**
  41. A structure which describes a collection of test cases.
  42. */
  43. struct collection_st {
  44. const char *name;
  45. test_callback_fn *pre;
  46. test_callback_fn *post;
  47. struct test_st *tests;
  48. };
  49. namespace libtest {
  50. class Collection {
  51. public:
  52. Collection(libtest::Framework*, collection_st*);
  53. ~Collection();
  54. test_return_t exec();
  55. const char* name() const
  56. {
  57. return _name.c_str();
  58. }
  59. TestCases& tests()
  60. {
  61. return _testcases;
  62. }
  63. void succeess();
  64. void skip();
  65. void fail();
  66. uint32_t succeeded() const
  67. {
  68. return _success;
  69. }
  70. uint32_t skipped() const
  71. {
  72. return _skipped;
  73. }
  74. uint32_t failed() const
  75. {
  76. return _failed;
  77. }
  78. void format();
  79. size_t total() const
  80. {
  81. return _testcases.size();
  82. }
  83. void plan();
  84. void complete();
  85. private:
  86. void push_testcase(const test_st* test_);
  87. private:
  88. std::string _name;
  89. test_return_t _ret;
  90. test_callback_fn *_pre;
  91. test_callback_fn *_post;
  92. struct test_st *_tests;
  93. libtest::Framework* _frame;
  94. uint32_t _success;
  95. uint32_t _skipped;
  96. uint32_t _failed;
  97. libtest::Timer _timer;
  98. libtest::Formatters& _formatter;
  99. TestCases _testcases;
  100. TestCases::iterator case_iter;
  101. private:
  102. Collection( const Collection& );
  103. const Collection& operator=( const Collection& );
  104. };
  105. } // namespace libtest