henrike@webrtc.org | 4e5f65a | 2014-06-05 20:40:11 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 15 | #ifndef RTC_BASE_SIGSLOTTESTER_H_ |
| 16 | #define RTC_BASE_SIGSLOTTESTER_H_ |
henrike@webrtc.org | 4e5f65a | 2014-06-05 20:40:11 | [diff] [blame] | 17 | |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 18 | // To generate sigslottester.h from sigslottester.h.pump, execute: |
| 19 | // /home/build/google3/third_party/gtest/scripts/pump.py sigslottester.h.pump |
henrike@webrtc.org | 4e5f65a | 2014-06-05 20:40:11 | [diff] [blame] | 20 | |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 41 | #include "rtc_base/constructormagic.h" |
| 42 | #include "rtc_base/sigslot.h" |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 43 | |
| 44 | namespace rtc { |
| 45 | |
| 46 | // Base version for testing signals that passes no arguments. |
| 47 | class SigslotTester0 : public sigslot::has_slots<> { |
| 48 | public: |
| 49 | explicit SigslotTester0(sigslot::signal0<>* signal) : callback_count_(0) { |
| 50 | signal->connect(this, &SigslotTester0::OnSignalCallback); |
| 51 | } |
| 52 | |
| 53 | int callback_count() const { return callback_count_; } |
| 54 | |
| 55 | private: |
| 56 | void OnSignalCallback() { callback_count_++; } |
| 57 | int callback_count_; |
| 58 | |
| 59 | RTC_DISALLOW_COPY_AND_ASSIGN(SigslotTester0); |
| 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: |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 72 | SigslotTester1(sigslot::signal1<A1>* signal, C1* capture1) |
| 73 | : callback_count_(0), capture1_(capture1) { |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 74 | signal->connect(this, &SigslotTester1::OnSignalCallback); |
| 75 | } |
| 76 | |
| 77 | int callback_count() const { return callback_count_; } |
| 78 | |
| 79 | private: |
| 80 | void OnSignalCallback(A1 arg1) { |
| 81 | callback_count_++; |
| 82 | *capture1_ = arg1; |
| 83 | } |
| 84 | |
| 85 | int callback_count_; |
| 86 | C1* capture1_; |
| 87 | |
| 88 | RTC_DISALLOW_COPY_AND_ASSIGN(SigslotTester1); |
| 89 | }; |
| 90 | |
| 91 | template <class A1, class A2, class C1, class C2> |
| 92 | class SigslotTester2 : public sigslot::has_slots<> { |
| 93 | public: |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 94 | SigslotTester2(sigslot::signal2<A1, A2>* signal, C1* capture1, C2* capture2) |
| 95 | : callback_count_(0), capture1_(capture1), capture2_(capture2) { |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 96 | signal->connect(this, &SigslotTester2::OnSignalCallback); |
| 97 | } |
| 98 | |
| 99 | int callback_count() const { return callback_count_; } |
| 100 | |
| 101 | private: |
| 102 | void OnSignalCallback(A1 arg1, A2 arg2) { |
| 103 | callback_count_++; |
| 104 | *capture1_ = arg1; |
| 105 | *capture2_ = arg2; |
| 106 | } |
| 107 | |
| 108 | int callback_count_; |
| 109 | C1* capture1_; |
| 110 | C2* capture2_; |
| 111 | |
| 112 | RTC_DISALLOW_COPY_AND_ASSIGN(SigslotTester2); |
| 113 | }; |
| 114 | |
| 115 | template <class A1, class A2, class A3, class C1, class C2, class C3> |
| 116 | class SigslotTester3 : public sigslot::has_slots<> { |
| 117 | public: |
| 118 | SigslotTester3(sigslot::signal3<A1, A2, A3>* signal, |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 119 | C1* capture1, |
| 120 | C2* capture2, |
| 121 | C3* capture3) |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 122 | : callback_count_(0), |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 123 | capture1_(capture1), |
| 124 | capture2_(capture2), |
| 125 | capture3_(capture3) { |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 126 | signal->connect(this, &SigslotTester3::OnSignalCallback); |
| 127 | } |
| 128 | |
| 129 | int callback_count() const { return callback_count_; } |
| 130 | |
| 131 | private: |
| 132 | void OnSignalCallback(A1 arg1, A2 arg2, A3 arg3) { |
| 133 | callback_count_++; |
| 134 | *capture1_ = arg1; |
| 135 | *capture2_ = arg2; |
| 136 | *capture3_ = arg3; |
| 137 | } |
| 138 | |
| 139 | int callback_count_; |
| 140 | C1* capture1_; |
| 141 | C2* capture2_; |
| 142 | C3* capture3_; |
| 143 | |
| 144 | RTC_DISALLOW_COPY_AND_ASSIGN(SigslotTester3); |
| 145 | }; |
| 146 | |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 147 | template <class A1, |
| 148 | class A2, |
| 149 | class A3, |
| 150 | class A4, |
| 151 | class C1, |
| 152 | class C2, |
| 153 | class C3, |
| 154 | class C4> |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 155 | class SigslotTester4 : public sigslot::has_slots<> { |
| 156 | public: |
| 157 | SigslotTester4(sigslot::signal4<A1, A2, A3, A4>* signal, |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 158 | C1* capture1, |
| 159 | C2* capture2, |
| 160 | C3* capture3, |
| 161 | C4* capture4) |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 162 | : callback_count_(0), |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 163 | capture1_(capture1), |
| 164 | capture2_(capture2), |
| 165 | capture3_(capture3), |
| 166 | capture4_(capture4) { |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 167 | signal->connect(this, &SigslotTester4::OnSignalCallback); |
| 168 | } |
| 169 | |
| 170 | int callback_count() const { return callback_count_; } |
| 171 | |
| 172 | private: |
| 173 | void OnSignalCallback(A1 arg1, A2 arg2, A3 arg3, A4 arg4) { |
| 174 | callback_count_++; |
| 175 | *capture1_ = arg1; |
| 176 | *capture2_ = arg2; |
| 177 | *capture3_ = arg3; |
| 178 | *capture4_ = arg4; |
| 179 | } |
| 180 | |
| 181 | int callback_count_; |
| 182 | C1* capture1_; |
| 183 | C2* capture2_; |
| 184 | C3* capture3_; |
| 185 | C4* capture4_; |
| 186 | |
| 187 | RTC_DISALLOW_COPY_AND_ASSIGN(SigslotTester4); |
| 188 | }; |
| 189 | |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 190 | template <class A1, |
| 191 | class A2, |
| 192 | class A3, |
| 193 | class A4, |
| 194 | class A5, |
| 195 | class C1, |
| 196 | class C2, |
| 197 | class C3, |
| 198 | class C4, |
| 199 | class C5> |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 200 | class SigslotTester5 : public sigslot::has_slots<> { |
| 201 | public: |
| 202 | SigslotTester5(sigslot::signal5<A1, A2, A3, A4, A5>* signal, |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 203 | C1* capture1, |
| 204 | C2* capture2, |
| 205 | C3* capture3, |
| 206 | C4* capture4, |
| 207 | C5* capture5) |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 208 | : callback_count_(0), |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 209 | capture1_(capture1), |
| 210 | capture2_(capture2), |
| 211 | capture3_(capture3), |
| 212 | capture4_(capture4), |
| 213 | capture5_(capture5) { |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 214 | signal->connect(this, &SigslotTester5::OnSignalCallback); |
| 215 | } |
| 216 | |
| 217 | int callback_count() const { return callback_count_; } |
| 218 | |
| 219 | private: |
| 220 | void OnSignalCallback(A1 arg1, A2 arg2, A3 arg3, A4 arg4, A5 arg5) { |
| 221 | callback_count_++; |
| 222 | *capture1_ = arg1; |
| 223 | *capture2_ = arg2; |
| 224 | *capture3_ = arg3; |
| 225 | *capture4_ = arg4; |
| 226 | *capture5_ = arg5; |
| 227 | } |
| 228 | |
| 229 | int callback_count_; |
| 230 | C1* capture1_; |
| 231 | C2* capture2_; |
| 232 | C3* capture3_; |
| 233 | C4* capture4_; |
| 234 | C5* capture5_; |
| 235 | |
| 236 | RTC_DISALLOW_COPY_AND_ASSIGN(SigslotTester5); |
| 237 | }; |
| 238 | } // namespace rtc |
henrike@webrtc.org | 4e5f65a | 2014-06-05 20:40:11 | [diff] [blame] | 239 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 240 | #endif // RTC_BASE_SIGSLOTTESTER_H_ |