sigslot_tester.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. // This file was GENERATED by command:
  2. // pump.py sigslottester.h.pump
  3. // DO NOT EDIT BY HAND!!!
  4. /*
  5. * Copyright 2014 The WebRTC Project Authors. All rights reserved.
  6. *
  7. * Use of this source code is governed by a BSD-style license
  8. * that can be found in the LICENSE file in the root of the source
  9. * tree. An additional intellectual property rights grant can be found
  10. * in the file PATENTS. All contributing project authors may
  11. * be found in the AUTHORS file in the root of the source tree.
  12. */
  13. #ifndef RTC_BASE_SIGSLOT_TESTER_H_
  14. #define RTC_BASE_SIGSLOT_TESTER_H_
  15. // To generate sigslottester.h from sigslottester.h.pump, execute:
  16. // /home/build/google3/third_party/gtest/scripts/pump.py sigslottester.h.pump
  17. // SigslotTester(s) are utility classes to check if signals owned by an
  18. // object are being invoked at the right time and with the right arguments.
  19. // They are meant to be used in tests. Tests must provide "capture" pointers
  20. // (i.e. address of variables) where the arguments from the signal callback
  21. // can be stored.
  22. //
  23. // Example:
  24. // /* Some signal */
  25. // sigslot::signal1<const std::string&> foo;
  26. //
  27. // /* We want to monitor foo in some test. Note how signal argument is
  28. // const std::string&, but capture-type is std::string. Capture type
  29. // must be type that can be assigned to. */
  30. // std::string capture;
  31. // SigslotTester1<const std::string&, std::string> slot(&foo, &capture);
  32. // foo.emit("hello");
  33. // EXPECT_EQ(1, slot.callback_count());
  34. // EXPECT_EQ("hello", capture);
  35. // /* See unit-tests for more examples */
  36. #include "rtc_base/constructor_magic.h"
  37. #include "rtc_base/third_party/sigslot/sigslot.h"
  38. namespace rtc {
  39. // Base version for testing signals that passes no arguments.
  40. class SigslotTester0 : public sigslot::has_slots<> {
  41. public:
  42. explicit SigslotTester0(sigslot::signal0<>* signal) : callback_count_(0) {
  43. signal->connect(this, &SigslotTester0::OnSignalCallback);
  44. }
  45. int callback_count() const { return callback_count_; }
  46. private:
  47. void OnSignalCallback() { callback_count_++; }
  48. int callback_count_;
  49. RTC_DISALLOW_COPY_AND_ASSIGN(SigslotTester0);
  50. };
  51. // Versions below are for testing signals that pass arguments. For all the
  52. // templates below:
  53. // - A1-A5 is the type of the argument i in the callback. Signals may and often
  54. // do use const-references here for efficiency.
  55. // - C1-C5 is the type of the variable to capture argument i. These should be
  56. // non-const value types suitable for use as lvalues.
  57. template <class A1, class C1>
  58. class SigslotTester1 : public sigslot::has_slots<> {
  59. public:
  60. SigslotTester1(sigslot::signal1<A1>* signal, C1* capture1)
  61. : callback_count_(0), capture1_(capture1) {
  62. signal->connect(this, &SigslotTester1::OnSignalCallback);
  63. }
  64. int callback_count() const { return callback_count_; }
  65. private:
  66. void OnSignalCallback(A1 arg1) {
  67. callback_count_++;
  68. *capture1_ = arg1;
  69. }
  70. int callback_count_;
  71. C1* capture1_;
  72. RTC_DISALLOW_COPY_AND_ASSIGN(SigslotTester1);
  73. };
  74. template <class A1, class A2, class C1, class C2>
  75. class SigslotTester2 : public sigslot::has_slots<> {
  76. public:
  77. SigslotTester2(sigslot::signal2<A1, A2>* signal, C1* capture1, C2* capture2)
  78. : callback_count_(0), capture1_(capture1), capture2_(capture2) {
  79. signal->connect(this, &SigslotTester2::OnSignalCallback);
  80. }
  81. int callback_count() const { return callback_count_; }
  82. private:
  83. void OnSignalCallback(A1 arg1, A2 arg2) {
  84. callback_count_++;
  85. *capture1_ = arg1;
  86. *capture2_ = arg2;
  87. }
  88. int callback_count_;
  89. C1* capture1_;
  90. C2* capture2_;
  91. RTC_DISALLOW_COPY_AND_ASSIGN(SigslotTester2);
  92. };
  93. template <class A1, class A2, class A3, class C1, class C2, class C3>
  94. class SigslotTester3 : public sigslot::has_slots<> {
  95. public:
  96. SigslotTester3(sigslot::signal3<A1, A2, A3>* signal,
  97. C1* capture1,
  98. C2* capture2,
  99. C3* capture3)
  100. : callback_count_(0),
  101. capture1_(capture1),
  102. capture2_(capture2),
  103. capture3_(capture3) {
  104. signal->connect(this, &SigslotTester3::OnSignalCallback);
  105. }
  106. int callback_count() const { return callback_count_; }
  107. private:
  108. void OnSignalCallback(A1 arg1, A2 arg2, A3 arg3) {
  109. callback_count_++;
  110. *capture1_ = arg1;
  111. *capture2_ = arg2;
  112. *capture3_ = arg3;
  113. }
  114. int callback_count_;
  115. C1* capture1_;
  116. C2* capture2_;
  117. C3* capture3_;
  118. RTC_DISALLOW_COPY_AND_ASSIGN(SigslotTester3);
  119. };
  120. template <class A1,
  121. class A2,
  122. class A3,
  123. class A4,
  124. class C1,
  125. class C2,
  126. class C3,
  127. class C4>
  128. class SigslotTester4 : public sigslot::has_slots<> {
  129. public:
  130. SigslotTester4(sigslot::signal4<A1, A2, A3, A4>* signal,
  131. C1* capture1,
  132. C2* capture2,
  133. C3* capture3,
  134. C4* capture4)
  135. : callback_count_(0),
  136. capture1_(capture1),
  137. capture2_(capture2),
  138. capture3_(capture3),
  139. capture4_(capture4) {
  140. signal->connect(this, &SigslotTester4::OnSignalCallback);
  141. }
  142. int callback_count() const { return callback_count_; }
  143. private:
  144. void OnSignalCallback(A1 arg1, A2 arg2, A3 arg3, A4 arg4) {
  145. callback_count_++;
  146. *capture1_ = arg1;
  147. *capture2_ = arg2;
  148. *capture3_ = arg3;
  149. *capture4_ = arg4;
  150. }
  151. int callback_count_;
  152. C1* capture1_;
  153. C2* capture2_;
  154. C3* capture3_;
  155. C4* capture4_;
  156. RTC_DISALLOW_COPY_AND_ASSIGN(SigslotTester4);
  157. };
  158. template <class A1,
  159. class A2,
  160. class A3,
  161. class A4,
  162. class A5,
  163. class C1,
  164. class C2,
  165. class C3,
  166. class C4,
  167. class C5>
  168. class SigslotTester5 : public sigslot::has_slots<> {
  169. public:
  170. SigslotTester5(sigslot::signal5<A1, A2, A3, A4, A5>* signal,
  171. C1* capture1,
  172. C2* capture2,
  173. C3* capture3,
  174. C4* capture4,
  175. C5* capture5)
  176. : callback_count_(0),
  177. capture1_(capture1),
  178. capture2_(capture2),
  179. capture3_(capture3),
  180. capture4_(capture4),
  181. capture5_(capture5) {
  182. signal->connect(this, &SigslotTester5::OnSignalCallback);
  183. }
  184. int callback_count() const { return callback_count_; }
  185. private:
  186. void OnSignalCallback(A1 arg1, A2 arg2, A3 arg3, A4 arg4, A5 arg5) {
  187. callback_count_++;
  188. *capture1_ = arg1;
  189. *capture2_ = arg2;
  190. *capture3_ = arg3;
  191. *capture4_ = arg4;
  192. *capture5_ = arg5;
  193. }
  194. int callback_count_;
  195. C1* capture1_;
  196. C2* capture2_;
  197. C3* capture3_;
  198. C4* capture4_;
  199. C5* capture5_;
  200. RTC_DISALLOW_COPY_AND_ASSIGN(SigslotTester5);
  201. };
  202. } // namespace rtc
  203. #endif // RTC_BASE_SIGSLOT_TESTER_H_