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
15#ifndef WEBRTC_BASE_SIGSLOTTESTER_H_
16#define WEBRTC_BASE_SIGSLOTTESTER_H_
17
18// To generate sigslottester.h from sigslottester.h.pump, execute:
19// /home/build/google3/third_party/gtest/scripts/pump.py sigslottester.h.pump
20
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
42#include "webrtc/base/constructormagic.h"
43#include "webrtc/base/sigslot.h"
44
45namespace rtc {
46
47// For all the templates below:
48// - A1-A5 is the type of the argument i in the callback. Signals may and often
49//   do use const-references here for efficiency.
50// - C1-C5 is the type of the variable to capture argument i. These should be
51//   non-const value types suitable for use as lvalues.
52
53template <class A1, class C1>
54class SigslotTester1 : public sigslot::has_slots<> {
55 public:
56  SigslotTester1(sigslot::signal1<A1>* signal,
57                C1* capture1)
58      : callback_count_(0),
59      capture1_(capture1) {
60    signal->connect(this, &SigslotTester1::OnSignalCallback);
61  }
62
63  int callback_count() const { return callback_count_; }
64
65 private:
66  void OnSignalCallback(A1 arg1) {
67    callback_count_++;
68    *capture1_ = arg1;
69  }
70
71  int callback_count_;
72  C1* capture1_;
73
74  DISALLOW_COPY_AND_ASSIGN(SigslotTester1);
75};
76
77template <class A1, class A2, class C1, class C2>
78class SigslotTester2 : public sigslot::has_slots<> {
79 public:
80  SigslotTester2(sigslot::signal2<A1, A2>* signal,
81                C1* capture1, C2* capture2)
82      : callback_count_(0),
83      capture1_(capture1), capture2_(capture2) {
84    signal->connect(this, &SigslotTester2::OnSignalCallback);
85  }
86
87  int callback_count() const { return callback_count_; }
88
89 private:
90  void OnSignalCallback(A1 arg1, A2 arg2) {
91    callback_count_++;
92    *capture1_ = arg1;
93    *capture2_ = arg2;
94  }
95
96  int callback_count_;
97  C1* capture1_;
98  C2* capture2_;
99
100  DISALLOW_COPY_AND_ASSIGN(SigslotTester2);
101};
102
103template <class A1, class A2, class A3, class C1, class C2, class C3>
104class SigslotTester3 : public sigslot::has_slots<> {
105 public:
106  SigslotTester3(sigslot::signal3<A1, A2, A3>* signal,
107                C1* capture1, C2* capture2, C3* capture3)
108      : callback_count_(0),
109      capture1_(capture1), capture2_(capture2), capture3_(capture3) {
110    signal->connect(this, &SigslotTester3::OnSignalCallback);
111  }
112
113  int callback_count() const { return callback_count_; }
114
115 private:
116  void OnSignalCallback(A1 arg1, A2 arg2, A3 arg3) {
117    callback_count_++;
118    *capture1_ = arg1;
119    *capture2_ = arg2;
120    *capture3_ = arg3;
121  }
122
123  int callback_count_;
124  C1* capture1_;
125  C2* capture2_;
126  C3* capture3_;
127
128  DISALLOW_COPY_AND_ASSIGN(SigslotTester3);
129};
130
131template <class A1, class A2, class A3, class A4, class C1, class C2, class C3,
132    class C4>
133class SigslotTester4 : public sigslot::has_slots<> {
134 public:
135  SigslotTester4(sigslot::signal4<A1, A2, A3, A4>* signal,
136                C1* capture1, C2* capture2, C3* capture3, C4* capture4)
137      : callback_count_(0),
138      capture1_(capture1), capture2_(capture2), capture3_(capture3),
139          capture4_(capture4) {
140    signal->connect(this, &SigslotTester4::OnSignalCallback);
141  }
142
143  int callback_count() const { return callback_count_; }
144
145 private:
146  void OnSignalCallback(A1 arg1, A2 arg2, A3 arg3, A4 arg4) {
147    callback_count_++;
148    *capture1_ = arg1;
149    *capture2_ = arg2;
150    *capture3_ = arg3;
151    *capture4_ = arg4;
152  }
153
154  int callback_count_;
155  C1* capture1_;
156  C2* capture2_;
157  C3* capture3_;
158  C4* capture4_;
159
160  DISALLOW_COPY_AND_ASSIGN(SigslotTester4);
161};
162
163template <class A1, class A2, class A3, class A4, class A5, class C1, class C2,
164    class C3, class C4, class C5>
165class SigslotTester5 : public sigslot::has_slots<> {
166 public:
167  SigslotTester5(sigslot::signal5<A1, A2, A3, A4, A5>* signal,
168                C1* capture1, C2* capture2, C3* capture3, C4* capture4,
169                    C5* capture5)
170      : callback_count_(0),
171      capture1_(capture1), capture2_(capture2), capture3_(capture3),
172          capture4_(capture4), capture5_(capture5) {
173    signal->connect(this, &SigslotTester5::OnSignalCallback);
174  }
175
176  int callback_count() const { return callback_count_; }
177
178 private:
179  void OnSignalCallback(A1 arg1, A2 arg2, A3 arg3, A4 arg4, A5 arg5) {
180    callback_count_++;
181    *capture1_ = arg1;
182    *capture2_ = arg2;
183    *capture3_ = arg3;
184    *capture4_ = arg4;
185    *capture5_ = arg5;
186  }
187
188  int callback_count_;
189  C1* capture1_;
190  C2* capture2_;
191  C3* capture3_;
192  C4* capture4_;
193  C5* capture5_;
194
195  DISALLOW_COPY_AND_ASSIGN(SigslotTester5);
196};
197}  // namespace rtc
198
199#endif  // WEBRTC_BASE_SIGSLOTTESTER_H_
200