blob: 92483c0b8dd87d51453935324115cd4c68ca8115 [file] [log] [blame]
henrike@webrtc.org4e5f65a2014-06-05 20:40:111// 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 Anton10542f22019-01-11 17:11:0015#ifndef RTC_BASE_SIGSLOT_TESTER_H_
16#define RTC_BASE_SIGSLOT_TESTER_H_
henrike@webrtc.org4e5f65a2014-06-05 20:40:1117
Henrik Kjellanderec78f1c2017-06-29 05:52:5018// To generate sigslottester.h from sigslottester.h.pump, execute:
19// /home/build/google3/third_party/gtest/scripts/pump.py sigslottester.h.pump
henrike@webrtc.org4e5f65a2014-06-05 20:40:1120
Henrik Kjellanderec78f1c2017-06-29 05:52:5021// 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 Titove41c4332018-07-25 13:04:2841#include "rtc_base/third_party/sigslot/sigslot.h"
Henrik Kjellanderec78f1c2017-06-29 05:52:5042
43namespace rtc {
44
45// Base version for testing signals that passes no arguments.
46class 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 Lee14af7622022-01-11 20:24:5852 SigslotTester0(const SigslotTester0&) = delete;
53 SigslotTester0& operator=(const SigslotTester0&) = delete;
54
Henrik Kjellanderec78f1c2017-06-29 05:52:5055 int callback_count() const { return callback_count_; }
56
57 private:
58 void OnSignalCallback() { callback_count_++; }
59 int callback_count_;
Henrik Kjellanderec78f1c2017-06-29 05:52:5060};
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
69template <class A1, class C1>
70class SigslotTester1 : public sigslot::has_slots<> {
71 public:
Yves Gerey665174f2018-06-19 13:03:0572 SigslotTester1(sigslot::signal1<A1>* signal, C1* capture1)
73 : callback_count_(0), capture1_(capture1) {
Henrik Kjellanderec78f1c2017-06-29 05:52:5074 signal->connect(this, &SigslotTester1::OnSignalCallback);
75 }
76
Byoungchan Lee14af7622022-01-11 20:24:5877 SigslotTester1(const SigslotTester1&) = delete;
78 SigslotTester1& operator=(const SigslotTester1&) = delete;
79
Henrik Kjellanderec78f1c2017-06-29 05:52:5080 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 Kjellanderec78f1c2017-06-29 05:52:5090};
91
92template <class A1, class A2, class C1, class C2>
93class SigslotTester2 : public sigslot::has_slots<> {
94 public:
Yves Gerey665174f2018-06-19 13:03:0595 SigslotTester2(sigslot::signal2<A1, A2>* signal, C1* capture1, C2* capture2)
96 : callback_count_(0), capture1_(capture1), capture2_(capture2) {
Henrik Kjellanderec78f1c2017-06-29 05:52:5097 signal->connect(this, &SigslotTester2::OnSignalCallback);
98 }
99
Byoungchan Lee14af7622022-01-11 20:24:58100 SigslotTester2(const SigslotTester2&) = delete;
101 SigslotTester2& operator=(const SigslotTester2&) = delete;
102
Henrik Kjellanderec78f1c2017-06-29 05:52:50103 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 Kjellanderec78f1c2017-06-29 05:52:50115};
116
117template <class A1, class A2, class A3, class C1, class C2, class C3>
118class SigslotTester3 : public sigslot::has_slots<> {
119 public:
120 SigslotTester3(sigslot::signal3<A1, A2, A3>* signal,
Yves Gerey665174f2018-06-19 13:03:05121 C1* capture1,
122 C2* capture2,
123 C3* capture3)
Henrik Kjellanderec78f1c2017-06-29 05:52:50124 : callback_count_(0),
Yves Gerey665174f2018-06-19 13:03:05125 capture1_(capture1),
126 capture2_(capture2),
127 capture3_(capture3) {
Henrik Kjellanderec78f1c2017-06-29 05:52:50128 signal->connect(this, &SigslotTester3::OnSignalCallback);
129 }
130
Byoungchan Lee14af7622022-01-11 20:24:58131 SigslotTester3(const SigslotTester3&) = delete;
132 SigslotTester3& operator=(const SigslotTester3&) = delete;
133
Henrik Kjellanderec78f1c2017-06-29 05:52:50134 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 Kjellanderec78f1c2017-06-29 05:52:50148};
149
Yves Gerey665174f2018-06-19 13:03:05150template <class A1,
151 class A2,
152 class A3,
153 class A4,
154 class C1,
155 class C2,
156 class C3,
157 class C4>
Henrik Kjellanderec78f1c2017-06-29 05:52:50158class SigslotTester4 : public sigslot::has_slots<> {
159 public:
160 SigslotTester4(sigslot::signal4<A1, A2, A3, A4>* signal,
Yves Gerey665174f2018-06-19 13:03:05161 C1* capture1,
162 C2* capture2,
163 C3* capture3,
164 C4* capture4)
Henrik Kjellanderec78f1c2017-06-29 05:52:50165 : callback_count_(0),
Yves Gerey665174f2018-06-19 13:03:05166 capture1_(capture1),
167 capture2_(capture2),
168 capture3_(capture3),
169 capture4_(capture4) {
Henrik Kjellanderec78f1c2017-06-29 05:52:50170 signal->connect(this, &SigslotTester4::OnSignalCallback);
171 }
172
Byoungchan Lee14af7622022-01-11 20:24:58173 SigslotTester4(const SigslotTester4&) = delete;
174 SigslotTester4& operator=(const SigslotTester4&) = delete;
175
Henrik Kjellanderec78f1c2017-06-29 05:52:50176 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 Kjellanderec78f1c2017-06-29 05:52:50192};
193
Yves Gerey665174f2018-06-19 13:03:05194template <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 Kjellanderec78f1c2017-06-29 05:52:50204class SigslotTester5 : public sigslot::has_slots<> {
205 public:
206 SigslotTester5(sigslot::signal5<A1, A2, A3, A4, A5>* signal,
Yves Gerey665174f2018-06-19 13:03:05207 C1* capture1,
208 C2* capture2,
209 C3* capture3,
210 C4* capture4,
211 C5* capture5)
Henrik Kjellanderec78f1c2017-06-29 05:52:50212 : callback_count_(0),
Yves Gerey665174f2018-06-19 13:03:05213 capture1_(capture1),
214 capture2_(capture2),
215 capture3_(capture3),
216 capture4_(capture4),
217 capture5_(capture5) {
Henrik Kjellanderec78f1c2017-06-29 05:52:50218 signal->connect(this, &SigslotTester5::OnSignalCallback);
219 }
220
Byoungchan Lee14af7622022-01-11 20:24:58221 SigslotTester5(const SigslotTester5&) = delete;
222 SigslotTester5& operator=(const SigslotTester5&) = delete;
223
Henrik Kjellanderec78f1c2017-06-29 05:52:50224 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 Kjellanderec78f1c2017-06-29 05:52:50242};
243} // namespace rtc
henrike@webrtc.org4e5f65a2014-06-05 20:40:11244
Steve Anton10542f22019-01-11 17:11:00245#endif // RTC_BASE_SIGSLOT_TESTER_H_