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 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 15 | #ifndef RTC_BASE_SIGSLOT_TESTER_H_ |
| 16 | #define RTC_BASE_SIGSLOT_TESTER_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 | |
Artem Titov | e41c433 | 2018-07-25 13:04:28 | [diff] [blame] | 41 | #include "rtc_base/third_party/sigslot/sigslot.h" |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 42 | |
| 43 | namespace rtc { |
| 44 | |
| 45 | // Base version for testing signals that passes no arguments. |
| 46 | class SigslotTester0 : public sigslot::has_slots<> { |
| 47 | public: |
| 48 | explicit SigslotTester0(sigslot::signal0<>* signal) : callback_count_(0) { |
| 49 | signal->connect(this, &SigslotTester0::OnSignalCallback); |
| 50 | } |
| 51 | |
Byoungchan Lee | 14af762 | 2022-01-11 20:24:58 | [diff] [blame] | 52 | SigslotTester0(const SigslotTester0&) = delete; |
| 53 | SigslotTester0& operator=(const SigslotTester0&) = delete; |
| 54 | |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 55 | int callback_count() const { return callback_count_; } |
| 56 | |
| 57 | private: |
| 58 | void OnSignalCallback() { callback_count_++; } |
| 59 | int callback_count_; |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 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 | |
Byoungchan Lee | 14af762 | 2022-01-11 20:24:58 | [diff] [blame] | 77 | SigslotTester1(const SigslotTester1&) = delete; |
| 78 | SigslotTester1& operator=(const SigslotTester1&) = delete; |
| 79 | |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 80 | int callback_count() const { return callback_count_; } |
| 81 | |
| 82 | private: |
| 83 | void OnSignalCallback(A1 arg1) { |
| 84 | callback_count_++; |
| 85 | *capture1_ = arg1; |
| 86 | } |
| 87 | |
| 88 | int callback_count_; |
| 89 | C1* capture1_; |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 90 | }; |
| 91 | |
| 92 | template <class A1, class A2, class C1, class C2> |
| 93 | class SigslotTester2 : public sigslot::has_slots<> { |
| 94 | public: |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 95 | SigslotTester2(sigslot::signal2<A1, A2>* signal, C1* capture1, C2* capture2) |
| 96 | : callback_count_(0), capture1_(capture1), capture2_(capture2) { |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 97 | signal->connect(this, &SigslotTester2::OnSignalCallback); |
| 98 | } |
| 99 | |
Byoungchan Lee | 14af762 | 2022-01-11 20:24:58 | [diff] [blame] | 100 | SigslotTester2(const SigslotTester2&) = delete; |
| 101 | SigslotTester2& operator=(const SigslotTester2&) = delete; |
| 102 | |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 103 | int callback_count() const { return callback_count_; } |
| 104 | |
| 105 | private: |
| 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_; |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 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: |
| 120 | SigslotTester3(sigslot::signal3<A1, A2, A3>* signal, |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 121 | C1* capture1, |
| 122 | C2* capture2, |
| 123 | C3* capture3) |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 124 | : callback_count_(0), |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 125 | capture1_(capture1), |
| 126 | capture2_(capture2), |
| 127 | capture3_(capture3) { |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 128 | signal->connect(this, &SigslotTester3::OnSignalCallback); |
| 129 | } |
| 130 | |
Byoungchan Lee | 14af762 | 2022-01-11 20:24:58 | [diff] [blame] | 131 | SigslotTester3(const SigslotTester3&) = delete; |
| 132 | SigslotTester3& operator=(const SigslotTester3&) = delete; |
| 133 | |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 134 | int callback_count() const { return callback_count_; } |
| 135 | |
| 136 | private: |
| 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_; |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 148 | }; |
| 149 | |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 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> |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 158 | class SigslotTester4 : public sigslot::has_slots<> { |
| 159 | public: |
| 160 | SigslotTester4(sigslot::signal4<A1, A2, A3, A4>* signal, |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 161 | C1* capture1, |
| 162 | C2* capture2, |
| 163 | C3* capture3, |
| 164 | C4* capture4) |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 165 | : callback_count_(0), |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 166 | capture1_(capture1), |
| 167 | capture2_(capture2), |
| 168 | capture3_(capture3), |
| 169 | capture4_(capture4) { |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 170 | signal->connect(this, &SigslotTester4::OnSignalCallback); |
| 171 | } |
| 172 | |
Byoungchan Lee | 14af762 | 2022-01-11 20:24:58 | [diff] [blame] | 173 | SigslotTester4(const SigslotTester4&) = delete; |
| 174 | SigslotTester4& operator=(const SigslotTester4&) = delete; |
| 175 | |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 176 | int callback_count() const { return callback_count_; } |
| 177 | |
| 178 | private: |
| 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_; |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 192 | }; |
| 193 | |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 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> |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 204 | class SigslotTester5 : public sigslot::has_slots<> { |
| 205 | public: |
| 206 | SigslotTester5(sigslot::signal5<A1, A2, A3, A4, A5>* signal, |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 207 | C1* capture1, |
| 208 | C2* capture2, |
| 209 | C3* capture3, |
| 210 | C4* capture4, |
| 211 | C5* capture5) |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 212 | : callback_count_(0), |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 213 | capture1_(capture1), |
| 214 | capture2_(capture2), |
| 215 | capture3_(capture3), |
| 216 | capture4_(capture4), |
| 217 | capture5_(capture5) { |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 218 | signal->connect(this, &SigslotTester5::OnSignalCallback); |
| 219 | } |
| 220 | |
Byoungchan Lee | 14af762 | 2022-01-11 20:24:58 | [diff] [blame] | 221 | SigslotTester5(const SigslotTester5&) = delete; |
| 222 | SigslotTester5& operator=(const SigslotTester5&) = delete; |
| 223 | |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 224 | int callback_count() const { return callback_count_; } |
| 225 | |
| 226 | private: |
| 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_; |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 242 | }; |
| 243 | } // namespace rtc |
henrike@webrtc.org | 4e5f65a | 2014-06-05 20:40:11 | [diff] [blame] | 244 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 245 | #endif // RTC_BASE_SIGSLOT_TESTER_H_ |