• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // This file was GENERATED by command:
2 //     pump.py mock_callback.h.pump
3 // DO NOT EDIT BY HAND!!!
4 
5 // Copyright 2017 The Chromium Authors. All rights reserved.
6 // Use of this source code is governed by a BSD-style license that can be
7 // found in the LICENSE file.
8 
9 // Analogous to GMock's built-in MockFunction, but for base::Callback instead of
10 // std::function. It takes the full callback type as a parameter, so that it can
11 // support both OnceCallback and RepeatingCallback.
12 //
13 // Use:
14 //   using FooCallback = base::Callback<int(std::string)>;
15 //
16 //   TEST(FooTest, RunsCallbackWithBarArgument) {
17 //     base::MockCallback<FooCallback> callback;
18 //     EXPECT_CALL(callback, Run("bar")).WillOnce(Return(1));
19 //     Foo(callback.Get());
20 //   }
21 //
22 // Can be used with StrictMock and NiceMock. Caller must ensure that it outlives
23 // any base::Callback obtained from it.
24 
25 #ifndef BASE_TEST_MOCK_CALLBACK_H_
26 #define BASE_TEST_MOCK_CALLBACK_H_
27 
28 #include "base/bind.h"
29 #include "base/callback.h"
30 #include "base/macros.h"
31 #include "testing/gmock/include/gmock/gmock.h"
32 
33 namespace base {
34 
35 // clang-format off
36 
37 template <typename F>
38 class MockCallback;
39 
40 template <typename R>
41 class MockCallback<Callback<R()>> {
42  public:
43   MockCallback() = default;
44   MOCK_METHOD0_T(Run, R());
45 
Get()46   Callback<R()> Get() {
47     return Bind(&MockCallback::Run, Unretained(this));
48   }
49 
50  private:
51   DISALLOW_COPY_AND_ASSIGN(MockCallback);
52 };
53 
54 template <typename R>
55 class MockCallback<OnceCallback<R()>> {
56  public:
57   MockCallback() = default;
58   MOCK_METHOD0_T(Run, R());
59 
Get()60   OnceCallback<R()> Get() {
61     return BindOnce(&MockCallback::Run, Unretained(this));
62   }
63 
64  private:
65   DISALLOW_COPY_AND_ASSIGN(MockCallback);
66 };
67 
68 template <typename R, typename A1>
69 class MockCallback<Callback<R(A1)>> {
70  public:
71   MockCallback() = default;
72   MOCK_METHOD1_T(Run, R(A1));
73 
Get()74   Callback<R(A1)> Get() {
75     return Bind(&MockCallback::Run, Unretained(this));
76   }
77 
78  private:
79   DISALLOW_COPY_AND_ASSIGN(MockCallback);
80 };
81 
82 template <typename R, typename A1>
83 class MockCallback<OnceCallback<R(A1)>> {
84  public:
85   MockCallback() = default;
86   MOCK_METHOD1_T(Run, R(A1));
87 
Get()88   OnceCallback<R(A1)> Get() {
89     return BindOnce(&MockCallback::Run, Unretained(this));
90   }
91 
92  private:
93   DISALLOW_COPY_AND_ASSIGN(MockCallback);
94 };
95 
96 template <typename R, typename A1, typename A2>
97 class MockCallback<Callback<R(A1, A2)>> {
98  public:
99   MockCallback() = default;
100   MOCK_METHOD2_T(Run, R(A1, A2));
101 
Get()102   Callback<R(A1, A2)> Get() {
103     return Bind(&MockCallback::Run, Unretained(this));
104   }
105 
106  private:
107   DISALLOW_COPY_AND_ASSIGN(MockCallback);
108 };
109 
110 template <typename R, typename A1, typename A2>
111 class MockCallback<OnceCallback<R(A1, A2)>> {
112  public:
113   MockCallback() = default;
114   MOCK_METHOD2_T(Run, R(A1, A2));
115 
Get()116   OnceCallback<R(A1, A2)> Get() {
117     return BindOnce(&MockCallback::Run, Unretained(this));
118   }
119 
120  private:
121   DISALLOW_COPY_AND_ASSIGN(MockCallback);
122 };
123 
124 template <typename R, typename A1, typename A2, typename A3>
125 class MockCallback<Callback<R(A1, A2, A3)>> {
126  public:
127   MockCallback() = default;
128   MOCK_METHOD3_T(Run, R(A1, A2, A3));
129 
Get()130   Callback<R(A1, A2, A3)> Get() {
131     return Bind(&MockCallback::Run, Unretained(this));
132   }
133 
134  private:
135   DISALLOW_COPY_AND_ASSIGN(MockCallback);
136 };
137 
138 template <typename R, typename A1, typename A2, typename A3>
139 class MockCallback<OnceCallback<R(A1, A2, A3)>> {
140  public:
141   MockCallback() = default;
142   MOCK_METHOD3_T(Run, R(A1, A2, A3));
143 
Get()144   OnceCallback<R(A1, A2, A3)> Get() {
145     return BindOnce(&MockCallback::Run, Unretained(this));
146   }
147 
148  private:
149   DISALLOW_COPY_AND_ASSIGN(MockCallback);
150 };
151 
152 template <typename R, typename A1, typename A2, typename A3, typename A4>
153 class MockCallback<Callback<R(A1, A2, A3, A4)>> {
154  public:
155   MockCallback() = default;
156   MOCK_METHOD4_T(Run, R(A1, A2, A3, A4));
157 
Get()158   Callback<R(A1, A2, A3, A4)> Get() {
159     return Bind(&MockCallback::Run, Unretained(this));
160   }
161 
162  private:
163   DISALLOW_COPY_AND_ASSIGN(MockCallback);
164 };
165 
166 template <typename R, typename A1, typename A2, typename A3, typename A4>
167 class MockCallback<OnceCallback<R(A1, A2, A3, A4)>> {
168  public:
169   MockCallback() = default;
170   MOCK_METHOD4_T(Run, R(A1, A2, A3, A4));
171 
Get()172   OnceCallback<R(A1, A2, A3, A4)> Get() {
173     return BindOnce(&MockCallback::Run, Unretained(this));
174   }
175 
176  private:
177   DISALLOW_COPY_AND_ASSIGN(MockCallback);
178 };
179 
180 template <typename R, typename A1, typename A2, typename A3, typename A4,
181     typename A5>
182 class MockCallback<Callback<R(A1, A2, A3, A4, A5)>> {
183  public:
184   MockCallback() = default;
185   MOCK_METHOD5_T(Run, R(A1, A2, A3, A4, A5));
186 
Get()187   Callback<R(A1, A2, A3, A4, A5)> Get() {
188     return Bind(&MockCallback::Run, Unretained(this));
189   }
190 
191  private:
192   DISALLOW_COPY_AND_ASSIGN(MockCallback);
193 };
194 
195 template <typename R, typename A1, typename A2, typename A3, typename A4,
196     typename A5>
197 class MockCallback<OnceCallback<R(A1, A2, A3, A4, A5)>> {
198  public:
199   MockCallback() = default;
200   MOCK_METHOD5_T(Run, R(A1, A2, A3, A4, A5));
201 
Get()202   OnceCallback<R(A1, A2, A3, A4, A5)> Get() {
203     return BindOnce(&MockCallback::Run, Unretained(this));
204   }
205 
206  private:
207   DISALLOW_COPY_AND_ASSIGN(MockCallback);
208 };
209 
210 template <typename R, typename A1, typename A2, typename A3, typename A4,
211     typename A5, typename A6>
212 class MockCallback<Callback<R(A1, A2, A3, A4, A5, A6)>> {
213  public:
214   MockCallback() = default;
215   MOCK_METHOD6_T(Run, R(A1, A2, A3, A4, A5, A6));
216 
Get()217   Callback<R(A1, A2, A3, A4, A5, A6)> Get() {
218     return Bind(&MockCallback::Run, Unretained(this));
219   }
220 
221  private:
222   DISALLOW_COPY_AND_ASSIGN(MockCallback);
223 };
224 
225 template <typename R, typename A1, typename A2, typename A3, typename A4,
226     typename A5, typename A6>
227 class MockCallback<OnceCallback<R(A1, A2, A3, A4, A5, A6)>> {
228  public:
229   MockCallback() = default;
230   MOCK_METHOD6_T(Run, R(A1, A2, A3, A4, A5, A6));
231 
Get()232   OnceCallback<R(A1, A2, A3, A4, A5, A6)> Get() {
233     return BindOnce(&MockCallback::Run, Unretained(this));
234   }
235 
236  private:
237   DISALLOW_COPY_AND_ASSIGN(MockCallback);
238 };
239 
240 template <typename R, typename A1, typename A2, typename A3, typename A4,
241     typename A5, typename A6, typename A7>
242 class MockCallback<Callback<R(A1, A2, A3, A4, A5, A6, A7)>> {
243  public:
244   MockCallback() = default;
245   MOCK_METHOD7_T(Run, R(A1, A2, A3, A4, A5, A6, A7));
246 
Get()247   Callback<R(A1, A2, A3, A4, A5, A6, A7)> Get() {
248     return Bind(&MockCallback::Run, Unretained(this));
249   }
250 
251  private:
252   DISALLOW_COPY_AND_ASSIGN(MockCallback);
253 };
254 
255 template <typename R, typename A1, typename A2, typename A3, typename A4,
256     typename A5, typename A6, typename A7>
257 class MockCallback<OnceCallback<R(A1, A2, A3, A4, A5, A6, A7)>> {
258  public:
259   MockCallback() = default;
260   MOCK_METHOD7_T(Run, R(A1, A2, A3, A4, A5, A6, A7));
261 
Get()262   OnceCallback<R(A1, A2, A3, A4, A5, A6, A7)> Get() {
263     return BindOnce(&MockCallback::Run, Unretained(this));
264   }
265 
266  private:
267   DISALLOW_COPY_AND_ASSIGN(MockCallback);
268 };
269 
270 template <typename R, typename A1, typename A2, typename A3, typename A4,
271     typename A5, typename A6, typename A7, typename A8>
272 class MockCallback<Callback<R(A1, A2, A3, A4, A5, A6, A7, A8)>> {
273  public:
274   MockCallback() = default;
275   MOCK_METHOD8_T(Run, R(A1, A2, A3, A4, A5, A6, A7, A8));
276 
Get()277   Callback<R(A1, A2, A3, A4, A5, A6, A7, A8)> Get() {
278     return Bind(&MockCallback::Run, Unretained(this));
279   }
280 
281  private:
282   DISALLOW_COPY_AND_ASSIGN(MockCallback);
283 };
284 
285 template <typename R, typename A1, typename A2, typename A3, typename A4,
286     typename A5, typename A6, typename A7, typename A8>
287 class MockCallback<OnceCallback<R(A1, A2, A3, A4, A5, A6, A7, A8)>> {
288  public:
289   MockCallback() = default;
290   MOCK_METHOD8_T(Run, R(A1, A2, A3, A4, A5, A6, A7, A8));
291 
Get()292   OnceCallback<R(A1, A2, A3, A4, A5, A6, A7, A8)> Get() {
293     return BindOnce(&MockCallback::Run, Unretained(this));
294   }
295 
296  private:
297   DISALLOW_COPY_AND_ASSIGN(MockCallback);
298 };
299 
300 template <typename R, typename A1, typename A2, typename A3, typename A4,
301     typename A5, typename A6, typename A7, typename A8, typename A9>
302 class MockCallback<Callback<R(A1, A2, A3, A4, A5, A6, A7, A8, A9)>> {
303  public:
304   MockCallback() = default;
305   MOCK_METHOD9_T(Run, R(A1, A2, A3, A4, A5, A6, A7, A8, A9));
306 
Get()307   Callback<R(A1, A2, A3, A4, A5, A6, A7, A8, A9)> Get() {
308     return Bind(&MockCallback::Run, Unretained(this));
309   }
310 
311  private:
312   DISALLOW_COPY_AND_ASSIGN(MockCallback);
313 };
314 
315 template <typename R, typename A1, typename A2, typename A3, typename A4,
316     typename A5, typename A6, typename A7, typename A8, typename A9>
317 class MockCallback<OnceCallback<R(A1, A2, A3, A4, A5, A6, A7, A8, A9)>> {
318  public:
319   MockCallback() = default;
320   MOCK_METHOD9_T(Run, R(A1, A2, A3, A4, A5, A6, A7, A8, A9));
321 
Get()322   OnceCallback<R(A1, A2, A3, A4, A5, A6, A7, A8, A9)> Get() {
323     return BindOnce(&MockCallback::Run, Unretained(this));
324   }
325 
326  private:
327   DISALLOW_COPY_AND_ASSIGN(MockCallback);
328 };
329 
330 template <typename R, typename A1, typename A2, typename A3, typename A4,
331     typename A5, typename A6, typename A7, typename A8, typename A9,
332     typename A10>
333 class MockCallback<Callback<R(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)>> {
334  public:
335   MockCallback() = default;
336   MOCK_METHOD10_T(Run, R(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10));
337 
Get()338   Callback<R(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)> Get() {
339     return Bind(&MockCallback::Run, Unretained(this));
340   }
341 
342  private:
343   DISALLOW_COPY_AND_ASSIGN(MockCallback);
344 };
345 
346 template <typename R, typename A1, typename A2, typename A3, typename A4,
347     typename A5, typename A6, typename A7, typename A8, typename A9,
348     typename A10>
349 class MockCallback<OnceCallback<R(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)>> {
350  public:
351   MockCallback() = default;
352   MOCK_METHOD10_T(Run, R(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10));
353 
Get()354   OnceCallback<R(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)> Get() {
355     return BindOnce(&MockCallback::Run, Unretained(this));
356   }
357 
358  private:
359   DISALLOW_COPY_AND_ASSIGN(MockCallback);
360 };
361 
362 // clang-format on
363 
364 }  // namespace base
365 
366 #endif  // BASE_TEST_MOCK_CALLBACK_H_
367