1// This file was GENERATED by command:
2//     pump.py sigslottester.h.pump
3// DO NOT EDIT BY HAND!!!
4
5/*
6 * libjingle
7 * Copyright 2014 Google Inc.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 *  1. Redistributions of source code must retain the above copyright notice,
13 *     this list of conditions and the following disclaimer.
14 *  2. Redistributions in binary form must reproduce the above copyright notice,
15 *     this list of conditions and the following disclaimer in the documentation
16 *     and/or other materials provided with the distribution.
17 *  3. The name of the author may not be used to endorse or promote products
18 *     derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
21 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
23 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32#ifndef TALK_BASE_SIGSLOTTESTER_H_
33#define TALK_BASE_SIGSLOTTESTER_H_
34
35// To generate sigslottester.h from sigslottester.h.pump, execute:
36// /home/build/google3/third_party/gtest/scripts/pump.py sigslottester.h.pump
37
38
39// SigslotTester(s) are utility classes to check if signals owned by an
40// object are being invoked at the right time and with the right arguments.
41// They are meant to be used in tests. Tests must provide "capture" pointers
42// (i.e. address of variables) where the arguments from the signal callback
43// can be stored.
44//
45// Example:
46//   /* Some signal */
47//   sigslot::signal1<const std::string&> foo;
48//
49//   /* We want to monitor foo in some test. Note how signal argument is
50//      const std::string&, but capture-type is std::string. Capture type
51//      must be type that can be assigned to. */
52//   std::string capture;
53//   SigslotTester1<const std::string&, std::string> slot(&foo, &capture);
54//   foo.emit("hello");
55//   EXPECT_EQ(1, slot.callback_count());
56//   EXPECT_EQ("hello", capture);
57//   /* See unit-tests for more examples */
58
59#include "talk/base/constructormagic.h"
60#include "talk/base/sigslot.h"
61
62namespace talk_base {
63
64// For all the 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
70template <class A1, class C1>
71class 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  DISALLOW_COPY_AND_ASSIGN(SigslotTester1);
92};
93
94template <class A1, class A2, class C1, class C2>
95class 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  DISALLOW_COPY_AND_ASSIGN(SigslotTester2);
118};
119
120template <class A1, class A2, class A3, class C1, class C2, class C3>
121class 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  DISALLOW_COPY_AND_ASSIGN(SigslotTester3);
146};
147
148template <class A1, class A2, class A3, class A4, class C1, class C2, class C3,
149    class C4>
150class 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  DISALLOW_COPY_AND_ASSIGN(SigslotTester4);
178};
179
180template <class A1, class A2, class A3, class A4, class A5, class C1, class C2,
181    class C3, class C4, class C5>
182class 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  DISALLOW_COPY_AND_ASSIGN(SigslotTester5);
213};
214}  // namespace talk_base
215
216#endif  // TALK_BASE_SIGSLOTTESTER_H_
217