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