framework.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
  2. *
  3. * Data Differential YATL (i.e. libtest) library
  4. *
  5. * Copyright (C) 2012-2013 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. #include <fstream>
  45. namespace { class Collection; }
  46. typedef std::vector<libtest::Collection*> Suites;
  47. namespace libtest {
  48. class Framework {
  49. public:
  50. public:
  51. test_return_t create();
  52. const std::string& name() const
  53. {
  54. return _name;
  55. }
  56. void create(test_callback_create_fn* arg)
  57. {
  58. _create= arg;
  59. }
  60. void destroy(test_callback_destroy_fn* arg)
  61. {
  62. _destroy= arg;
  63. }
  64. void collections(collection_st arg[]);
  65. void set_on_error(test_callback_error_fn *arg)
  66. {
  67. _on_error= arg;
  68. }
  69. test_return_t on_error(const enum test_return_t, void *);
  70. void set_socket()
  71. {
  72. _servers.set_socket();
  73. }
  74. void set_sasl(const std::string& username_arg, const std::string& password_arg)
  75. {
  76. _servers.set_sasl(username_arg, password_arg);
  77. }
  78. libtest::server_startup_st& servers()
  79. {
  80. return _servers;
  81. }
  82. void set_runner(libtest::Runner *arg)
  83. {
  84. _runner= arg;
  85. }
  86. libtest::Runner *runner();
  87. void exec();
  88. libtest::Collection& collection();
  89. virtual ~Framework();
  90. Framework(libtest::SignalThread&,
  91. const std::string&,
  92. const std::string&,
  93. const std::string&);
  94. bool match(const char* arg);
  95. void *creators_ptr()
  96. {
  97. return _creators_ptr;
  98. }
  99. libtest::SignalThread& signal()
  100. {
  101. return _signal;
  102. }
  103. size_t size()
  104. {
  105. return _collection.size();
  106. }
  107. Suites& suites()
  108. {
  109. return _collection;
  110. }
  111. libtest::Formatters& formatter()
  112. {
  113. return _formatter;
  114. }
  115. size_t total() const
  116. {
  117. return _total;
  118. }
  119. size_t success() const
  120. {
  121. return _success;
  122. }
  123. size_t skipped() const
  124. {
  125. return _skipped;
  126. }
  127. size_t failed() const
  128. {
  129. return _failed;
  130. }
  131. private:
  132. // Sums
  133. size_t _total;
  134. size_t _success;
  135. size_t _skipped;
  136. size_t _failed;
  137. /* These methods are called outside of any collection call. */
  138. test_callback_create_fn *_create;
  139. test_callback_destroy_fn *_destroy;
  140. /**
  141. If an error occurs during the test, this is called.
  142. */
  143. test_callback_error_fn *_on_error;
  144. /**
  145. Runner represents the callers for the tests. If not implemented we will use
  146. a set of default implementations.
  147. */
  148. libtest::Runner *_runner;
  149. libtest::server_startup_st _servers;
  150. bool _socket;
  151. void *_creators_ptr;
  152. unsigned long int _servers_to_run;
  153. Suites _collection;
  154. libtest::SignalThread& _signal;
  155. std::string _only_run;
  156. std::string _wildcard;
  157. std::string _name;
  158. private:
  159. Framework( const Framework& );
  160. const Framework& operator=( const Framework& );
  161. libtest::Formatters _formatter;
  162. std::ofstream xml_file;
  163. std::ofstream tap_file;
  164. };
  165. } // namespace libtest