framework.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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/signal.h>
  38. /**
  39. Framework is the structure which is passed to the test implementation to be filled.
  40. This must be implemented in order for the test framework to load the tests. We call
  41. get_world() in order to fill this structure.
  42. */
  43. #include <vector>
  44. namespace { class Collection; }
  45. typedef std::vector<libtest::Collection*> Suites;
  46. namespace libtest {
  47. class Framework {
  48. public:
  49. public:
  50. test_return_t create();
  51. const std::string& name() const
  52. {
  53. return _name;
  54. }
  55. void create(test_callback_create_fn* arg)
  56. {
  57. _create= arg;
  58. }
  59. void destroy(test_callback_destroy_fn* arg)
  60. {
  61. _destroy= arg;
  62. }
  63. void collections(collection_st* arg);
  64. void set_on_error(test_callback_error_fn *arg)
  65. {
  66. _on_error= arg;
  67. }
  68. test_return_t on_error(const enum test_return_t, void *);
  69. void set_socket()
  70. {
  71. _servers.set_socket();
  72. }
  73. void set_sasl(const std::string& username_arg, const std::string& password_arg)
  74. {
  75. _servers.set_sasl(username_arg, password_arg);
  76. }
  77. libtest::server_startup_st& servers()
  78. {
  79. return _servers;
  80. }
  81. void set_runner(libtest::Runner *arg)
  82. {
  83. _runner= arg;
  84. }
  85. libtest::Runner *runner();
  86. void exec();
  87. libtest::Collection& collection();
  88. virtual ~Framework();
  89. Framework(libtest::SignalThread&,
  90. const std::string&,
  91. const std::string&,
  92. const std::string&);
  93. bool match(const char* arg);
  94. void *creators_ptr()
  95. {
  96. return _creators_ptr;
  97. }
  98. libtest::SignalThread& signal()
  99. {
  100. return _signal;
  101. }
  102. uint32_t sum_total();
  103. uint32_t sum_success();
  104. uint32_t sum_skipped();
  105. uint32_t sum_failed();
  106. size_t size()
  107. {
  108. return _collection.size();
  109. }
  110. uint32_t total() const
  111. {
  112. return _total;
  113. }
  114. uint32_t success() const
  115. {
  116. return _success;
  117. }
  118. uint32_t skipped() const
  119. {
  120. return _skipped;
  121. }
  122. uint32_t failed() const
  123. {
  124. return _failed;
  125. }
  126. Suites& suites()
  127. {
  128. return _collection;
  129. }
  130. private:
  131. Framework& operator=(const Framework&);
  132. uint32_t _total;
  133. uint32_t _success;
  134. uint32_t _skipped;
  135. uint32_t _failed;
  136. /* These methods are called outside of any collection call. */
  137. test_callback_create_fn *_create;
  138. test_callback_destroy_fn *_destroy;
  139. /**
  140. If an error occurs during the test, this is called.
  141. */
  142. test_callback_error_fn *_on_error;
  143. /**
  144. Runner represents the callers for the tests. If not implemented we will use
  145. a set of default implementations.
  146. */
  147. libtest::Runner *_runner;
  148. libtest::server_startup_st _servers;
  149. bool _socket;
  150. void *_creators_ptr;
  151. unsigned long int _servers_to_run;
  152. Suites _collection;
  153. libtest::SignalThread& _signal;
  154. std::string _only_run;
  155. std::string _wildcard;
  156. std::string _name;
  157. };
  158. } // namespace libtest