blob: 58be511ef6eedae566ad1b6dc7e08a99737d7978 [file] [log] [blame]
henrike@webrtc.org4e5f65a2014-06-05 20:40:11 +00001// 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 09:11:00 -080015#ifndef RTC_BASE_SIGSLOT_TESTER_H_
16#define RTC_BASE_SIGSLOT_TESTER_H_
henrike@webrtc.org4e5f65a2014-06-05 20:40:11 +000017
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020018// 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:11 +000020
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020021// 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
Steve Anton10542f22019-01-11 09:11:00 -080041#include "rtc_base/constructor_magic.h"
Artem Titove41c4332018-07-25 15:04:28 +020042#include "rtc_base/third_party/sigslot/sigslot.h"
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020043
44namespace rtc {
45
46// Base version for testing signals that passes no arguments.
47class 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
69template <class A1, class C1>
70class SigslotTester1 : public sigslot::has_slots<> {
71 public:
Yves Gerey665174f2018-06-19 15:03:05 +020072 SigslotTester1(sigslot::signal1<A1>* signal, C1* capture1)
73 : callback_count_(0), capture1_(capture1) {
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020074 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
91template <class A1, class A2, class C1, class C2>
92class SigslotTester2 : public sigslot::has_slots<> {
93 public:
Yves Gerey665174f2018-06-19 15:03:05 +020094 SigslotTester2(sigslot::signal2<A1, A2>* signal, C1* capture1, C2* capture2)
95 : callback_count_(0), capture1_(capture1), capture2_(capture2) {
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020096 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
115template <class A1, class A2, class A3, class C1, class C2, class C3>
116class SigslotTester3 : public sigslot::has_slots<> {
117 public:
118 SigslotTester3(sigslot::signal3<A1, A2, A3>* signal,
Yves Gerey665174f2018-06-19 15:03:05 +0200119 C1* capture1,
120 C2* capture2,
121 C3* capture3)
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +0200122 : callback_count_(0),
Yves Gerey665174f2018-06-19 15:03:05 +0200123 capture1_(capture1),
124 capture2_(capture2),
125 capture3_(capture3) {
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +0200126 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 Gerey665174f2018-06-19 15:03:05 +0200147template <class A1,
148 class A2,
149 class A3,
150 class A4,
151 class C1,
152 class C2,
153 class C3,
154 class C4>
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +0200155class SigslotTester4 : public sigslot::has_slots<> {
156 public:
157 SigslotTester4(sigslot::signal4<A1, A2, A3, A4>* signal,
Yves Gerey665174f2018-06-19 15:03:05 +0200158 C1* capture1,
159 C2* capture2,
160 C3* capture3,
161 C4* capture4)
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +0200162 : callback_count_(0),
Yves Gerey665174f2018-06-19 15:03:05 +0200163 capture1_(capture1),
164 capture2_(capture2),
165 capture3_(capture3),
166 capture4_(capture4) {
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +0200167 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 Gerey665174f2018-06-19 15:03:05 +0200190template <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 Kjellanderec78f1c2017-06-29 07:52:50 +0200200class SigslotTester5 : public sigslot::has_slots<> {
201 public:
202 SigslotTester5(sigslot::signal5<A1, A2, A3, A4, A5>* signal,
Yves Gerey665174f2018-06-19 15:03:05 +0200203 C1* capture1,
204 C2* capture2,
205 C3* capture3,
206 C4* capture4,
207 C5* capture5)
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +0200208 : callback_count_(0),
Yves Gerey665174f2018-06-19 15:03:05 +0200209 capture1_(capture1),
210 capture2_(capture2),
211 capture3_(capture3),
212 capture4_(capture4),
213 capture5_(capture5) {
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +0200214 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.org4e5f65a2014-06-05 20:40:11 +0000239
Steve Anton10542f22019-01-11 09:11:00 -0800240#endif // RTC_BASE_SIGSLOT_TESTER_H_