henrike@webrtc.org | 4e5f65a | 2014-06-05 20:40:11 +0000 | [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 06:47:31 +0200 | [diff] [blame] | 15 | #ifndef RTC_BASE_SIGSLOTTESTER_H_ |
| 16 | #define RTC_BASE_SIGSLOTTESTER_H_ |
henrike@webrtc.org | 4e5f65a | 2014-06-05 20:40:11 +0000 | [diff] [blame] | 17 | |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [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 +0000 | [diff] [blame] | 20 | |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 21 | |
| 22 | // SigslotTester(s) are utility classes to check if signals owned by an |
| 23 | // object are being invoked at the right time and with the right arguments. |
| 24 | // They are meant to be used in tests. Tests must provide "capture" pointers |
| 25 | // (i.e. address of variables) where the arguments from the signal callback |
| 26 | // can be stored. |
| 27 | // |
| 28 | // Example: |
| 29 | // /* Some signal */ |
| 30 | // sigslot::signal1<const std::string&> foo; |
| 31 | // |
| 32 | // /* We want to monitor foo in some test. Note how signal argument is |
| 33 | // const std::string&, but capture-type is std::string. Capture type |
| 34 | // must be type that can be assigned to. */ |
| 35 | // std::string capture; |
| 36 | // SigslotTester1<const std::string&, std::string> slot(&foo, &capture); |
| 37 | // foo.emit("hello"); |
| 38 | // EXPECT_EQ(1, slot.callback_count()); |
| 39 | // EXPECT_EQ("hello", capture); |
| 40 | // /* See unit-tests for more examples */ |
| 41 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 42 | #include "rtc_base/constructormagic.h" |
| 43 | #include "rtc_base/sigslot.h" |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 44 | |
| 45 | namespace rtc { |
| 46 | |
| 47 | // Base version for testing signals that passes no arguments. |
| 48 | class SigslotTester0 : public sigslot::has_slots<> { |
| 49 | public: |
| 50 | explicit SigslotTester0(sigslot::signal0<>* signal) : callback_count_(0) { |
| 51 | signal->connect(this, &SigslotTester0::OnSignalCallback); |
| 52 | } |
| 53 | |
| 54 | int callback_count() const { return callback_count_; } |
| 55 | |
| 56 | private: |
| 57 | void OnSignalCallback() { callback_count_++; } |
| 58 | int callback_count_; |
| 59 | |
| 60 | RTC_DISALLOW_COPY_AND_ASSIGN(SigslotTester0); |
| 61 | }; |
| 62 | |
| 63 | // Versions below are for testing signals that pass arguments. For all the |
| 64 | // templates below: |
| 65 | // - A1-A5 is the type of the argument i in the callback. Signals may and often |
| 66 | // do use const-references here for efficiency. |
| 67 | // - C1-C5 is the type of the variable to capture argument i. These should be |
| 68 | // non-const value types suitable for use as lvalues. |
| 69 | |
| 70 | template <class A1, class C1> |
| 71 | class SigslotTester1 : public sigslot::has_slots<> { |
| 72 | public: |
| 73 | SigslotTester1(sigslot::signal1<A1>* signal, |
| 74 | C1* capture1) |
| 75 | : callback_count_(0), |
| 76 | capture1_(capture1) { |
| 77 | signal->connect(this, &SigslotTester1::OnSignalCallback); |
| 78 | } |
| 79 | |
| 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_; |
| 90 | |
| 91 | RTC_DISALLOW_COPY_AND_ASSIGN(SigslotTester1); |
| 92 | }; |
| 93 | |
| 94 | template <class A1, class A2, class C1, class C2> |
| 95 | class SigslotTester2 : public sigslot::has_slots<> { |
| 96 | public: |
| 97 | SigslotTester2(sigslot::signal2<A1, A2>* signal, |
| 98 | C1* capture1, C2* capture2) |
| 99 | : callback_count_(0), |
| 100 | capture1_(capture1), capture2_(capture2) { |
| 101 | signal->connect(this, &SigslotTester2::OnSignalCallback); |
| 102 | } |
| 103 | |
| 104 | int callback_count() const { return callback_count_; } |
| 105 | |
| 106 | private: |
| 107 | void OnSignalCallback(A1 arg1, A2 arg2) { |
| 108 | callback_count_++; |
| 109 | *capture1_ = arg1; |
| 110 | *capture2_ = arg2; |
| 111 | } |
| 112 | |
| 113 | int callback_count_; |
| 114 | C1* capture1_; |
| 115 | C2* capture2_; |
| 116 | |
| 117 | RTC_DISALLOW_COPY_AND_ASSIGN(SigslotTester2); |
| 118 | }; |
| 119 | |
| 120 | template <class A1, class A2, class A3, class C1, class C2, class C3> |
| 121 | class SigslotTester3 : public sigslot::has_slots<> { |
| 122 | public: |
| 123 | SigslotTester3(sigslot::signal3<A1, A2, A3>* signal, |
| 124 | C1* capture1, C2* capture2, C3* capture3) |
| 125 | : callback_count_(0), |
| 126 | capture1_(capture1), capture2_(capture2), capture3_(capture3) { |
| 127 | signal->connect(this, &SigslotTester3::OnSignalCallback); |
| 128 | } |
| 129 | |
| 130 | int callback_count() const { return callback_count_; } |
| 131 | |
| 132 | private: |
| 133 | void OnSignalCallback(A1 arg1, A2 arg2, A3 arg3) { |
| 134 | callback_count_++; |
| 135 | *capture1_ = arg1; |
| 136 | *capture2_ = arg2; |
| 137 | *capture3_ = arg3; |
| 138 | } |
| 139 | |
| 140 | int callback_count_; |
| 141 | C1* capture1_; |
| 142 | C2* capture2_; |
| 143 | C3* capture3_; |
| 144 | |
| 145 | RTC_DISALLOW_COPY_AND_ASSIGN(SigslotTester3); |
| 146 | }; |
| 147 | |
| 148 | template <class A1, class A2, class A3, class A4, class C1, class C2, class C3, |
| 149 | class C4> |
| 150 | class SigslotTester4 : public sigslot::has_slots<> { |
| 151 | public: |
| 152 | SigslotTester4(sigslot::signal4<A1, A2, A3, A4>* signal, |
| 153 | C1* capture1, C2* capture2, C3* capture3, C4* capture4) |
| 154 | : callback_count_(0), |
| 155 | capture1_(capture1), capture2_(capture2), capture3_(capture3), |
| 156 | capture4_(capture4) { |
| 157 | signal->connect(this, &SigslotTester4::OnSignalCallback); |
| 158 | } |
| 159 | |
| 160 | int callback_count() const { return callback_count_; } |
| 161 | |
| 162 | private: |
| 163 | void OnSignalCallback(A1 arg1, A2 arg2, A3 arg3, A4 arg4) { |
| 164 | callback_count_++; |
| 165 | *capture1_ = arg1; |
| 166 | *capture2_ = arg2; |
| 167 | *capture3_ = arg3; |
| 168 | *capture4_ = arg4; |
| 169 | } |
| 170 | |
| 171 | int callback_count_; |
| 172 | C1* capture1_; |
| 173 | C2* capture2_; |
| 174 | C3* capture3_; |
| 175 | C4* capture4_; |
| 176 | |
| 177 | RTC_DISALLOW_COPY_AND_ASSIGN(SigslotTester4); |
| 178 | }; |
| 179 | |
| 180 | template <class A1, class A2, class A3, class A4, class A5, class C1, class C2, |
| 181 | class C3, class C4, class C5> |
| 182 | class SigslotTester5 : public sigslot::has_slots<> { |
| 183 | public: |
| 184 | SigslotTester5(sigslot::signal5<A1, A2, A3, A4, A5>* signal, |
| 185 | C1* capture1, C2* capture2, C3* capture3, C4* capture4, |
| 186 | C5* capture5) |
| 187 | : callback_count_(0), |
| 188 | capture1_(capture1), capture2_(capture2), capture3_(capture3), |
| 189 | capture4_(capture4), capture5_(capture5) { |
| 190 | signal->connect(this, &SigslotTester5::OnSignalCallback); |
| 191 | } |
| 192 | |
| 193 | int callback_count() const { return callback_count_; } |
| 194 | |
| 195 | private: |
| 196 | void OnSignalCallback(A1 arg1, A2 arg2, A3 arg3, A4 arg4, A5 arg5) { |
| 197 | callback_count_++; |
| 198 | *capture1_ = arg1; |
| 199 | *capture2_ = arg2; |
| 200 | *capture3_ = arg3; |
| 201 | *capture4_ = arg4; |
| 202 | *capture5_ = arg5; |
| 203 | } |
| 204 | |
| 205 | int callback_count_; |
| 206 | C1* capture1_; |
| 207 | C2* capture2_; |
| 208 | C3* capture3_; |
| 209 | C4* capture4_; |
| 210 | C5* capture5_; |
| 211 | |
| 212 | RTC_DISALLOW_COPY_AND_ASSIGN(SigslotTester5); |
| 213 | }; |
| 214 | } // namespace rtc |
henrike@webrtc.org | 4e5f65a | 2014-06-05 20:40:11 +0000 | [diff] [blame] | 215 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 216 | #endif // RTC_BASE_SIGSLOTTESTER_H_ |