1// This file was GENERATED by command:
2// pump.py gmock-generated-nice-strict.h.pump
3// DO NOT EDIT BY HAND!!!
4
5// Copyright 2008, Google Inc.
6// All rights reserved.
7//
8// Redistribution and use in source and binary forms, with or without
9// modification, are permitted provided that the following conditions are
10// met:
11//
12// * Redistributions of source code must retain the above copyright
13// notice, this list of conditions and the following disclaimer.
14// * Redistributions in binary form must reproduce the above
15// copyright notice, this list of conditions and the following disclaimer
16// in the documentation and/or other materials provided with the
17// distribution.
18// * Neither the name of Google Inc. nor the names of its
19// contributors may be used to endorse or promote products derived from
20// this software without specific prior written permission.
21//
22// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
34
35// Implements class templates NiceMock, NaggyMock, and StrictMock.
36//
37// Given a mock class MockFoo that is created using Google Mock,
38// NiceMock<MockFoo> is a subclass of MockFoo that allows
39// uninteresting calls (i.e. calls to mock methods that have no
40// EXPECT_CALL specs), NaggyMock<MockFoo> is a subclass of MockFoo
41// that prints a warning when an uninteresting call occurs, and
42// StrictMock<MockFoo> is a subclass of MockFoo that treats all
43// uninteresting calls as errors.
44//
45// Currently a mock is naggy by default, so MockFoo and
46// NaggyMock<MockFoo> behave like the same. However, we will soon
47// switch the default behavior of mocks to be nice, as that in general
48// leads to more maintainable tests. When that happens, MockFoo will
49// stop behaving like NaggyMock<MockFoo> and start behaving like
50// NiceMock<MockFoo>.
51//
52// NiceMock, NaggyMock, and StrictMock "inherit" the constructors of
53// their respective base class. Therefore you can write
54// NiceMock<MockFoo>(5, "a") to construct a nice mock where MockFoo
55// has a constructor that accepts (int, const char*), for example.
56//
57// A known limitation is that NiceMock<MockFoo>, NaggyMock<MockFoo>,
58// and StrictMock<MockFoo> only works for mock methods defined using
59// the MOCK_METHOD* family of macros DIRECTLY in the MockFoo class.
60// If a mock method is defined in a base class of MockFoo, the "nice"
61// or "strict" modifier may not affect it, depending on the compiler.
62// In particular, nesting NiceMock, NaggyMock, and StrictMock is NOT
63// supported.
64
65// GOOGLETEST_CM0002 DO NOT DELETE
66
67#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_
68#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_
69
70#include "gmock/gmock-spec-builders.h"
71#include "gmock/internal/gmock-port.h"
72
73namespace testing {
74
75template <class MockClass>
76class NiceMock : public MockClass {
77 public:
78 NiceMock() : MockClass() {
79 ::testing::Mock::AllowUninterestingCalls(
80 internal::ImplicitCast_<MockClass*>(this));
81 }
82
83#if GTEST_LANG_CXX11
84 // Ideally, we would inherit base class's constructors through a using
85 // declaration, which would preserve their visibility. However, many existing
86 // tests rely on the fact that current implementation reexports protected
87 // constructors as public. These tests would need to be cleaned up first.
88
89 // Single argument constructor is special-cased so that it can be
90 // made explicit.
91 template <typename A>
92 explicit NiceMock(A&& arg) : MockClass(std::forward<A>(arg)) {
93 ::testing::Mock::AllowUninterestingCalls(
94 internal::ImplicitCast_<MockClass*>(this));
95 }
96
97 template <typename A1, typename A2, typename... An>
98 NiceMock(A1&& arg1, A2&& arg2, An&&... args)
99 : MockClass(std::forward<A1>(arg1), std::forward<A2>(arg2),
100 std::forward<An>(args)...) {
101 ::testing::Mock::AllowUninterestingCalls(
102 internal::ImplicitCast_<MockClass*>(this));
103 }
104#else
105 // C++98 doesn't have variadic templates, so we have to define one
106 // for each arity.
107 template <typename A1>
108 explicit NiceMock(const A1& a1) : MockClass(a1) {
109 ::testing::Mock::AllowUninterestingCalls(
110 internal::ImplicitCast_<MockClass*>(this));
111 }
112 template <typename A1, typename A2>
113 NiceMock(const A1& a1, const A2& a2) : MockClass(a1, a2) {
114 ::testing::Mock::AllowUninterestingCalls(
115 internal::ImplicitCast_<MockClass*>(this));
116 }
117
118 template <typename A1, typename A2, typename A3>
119 NiceMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) {
120 ::testing::Mock::AllowUninterestingCalls(
121 internal::ImplicitCast_<MockClass*>(this));
122 }
123
124 template <typename A1, typename A2, typename A3, typename A4>
125 NiceMock(const A1& a1, const A2& a2, const A3& a3,
126 const A4& a4) : MockClass(a1, a2, a3, a4) {
127 ::testing::Mock::AllowUninterestingCalls(
128 internal::ImplicitCast_<MockClass*>(this));
129 }
130
131 template <typename A1, typename A2, typename A3, typename A4, typename A5>
132 NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
133 const A5& a5) : MockClass(a1, a2, a3, a4, a5) {
134 ::testing::Mock::AllowUninterestingCalls(
135 internal::ImplicitCast_<MockClass*>(this));
136 }
137
138 template <typename A1, typename A2, typename A3, typename A4, typename A5,
139 typename A6>
140 NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
141 const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) {
142 ::testing::Mock::AllowUninterestingCalls(
143 internal::ImplicitCast_<MockClass*>(this));
144 }
145
146 template <typename A1, typename A2, typename A3, typename A4, typename A5,
147 typename A6, typename A7>
148 NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
149 const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5,
150 a6, a7) {
151 ::testing::Mock::AllowUninterestingCalls(
152 internal::ImplicitCast_<MockClass*>(this));
153 }
154
155 template <typename A1, typename A2, typename A3, typename A4, typename A5,
156 typename A6, typename A7, typename A8>
157 NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
158 const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a1,
159 a2, a3, a4, a5, a6, a7, a8) {
160 ::testing::Mock::AllowUninterestingCalls(
161 internal::ImplicitCast_<MockClass*>(this));
162 }
163
164 template <typename A1, typename A2, typename A3, typename A4, typename A5,
165 typename A6, typename A7, typename A8, typename A9>
166 NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
167 const A5& a5, const A6& a6, const A7& a7, const A8& a8,
168 const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) {
169 ::testing::Mock::AllowUninterestingCalls(
170 internal::ImplicitCast_<MockClass*>(this));
171 }
172
173 template <typename A1, typename A2, typename A3, typename A4, typename A5,
174 typename A6, typename A7, typename A8, typename A9, typename A10>
175 NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
176 const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9,
177 const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) {
178 ::testing::Mock::AllowUninterestingCalls(
179 internal::ImplicitCast_<MockClass*>(this));
180 }
181
182#endif // GTEST_LANG_CXX11
183
184 ~NiceMock() {
185 ::testing::Mock::UnregisterCallReaction(
186 internal::ImplicitCast_<MockClass*>(this));
187 }
188
189 private:
190 GTEST_DISALLOW_COPY_AND_ASSIGN_(NiceMock);
191};
192
193template <class MockClass>
194class NaggyMock : public MockClass {
195 public:
196 NaggyMock() : MockClass() {
197 ::testing::Mock::WarnUninterestingCalls(
198 internal::ImplicitCast_<MockClass*>(this));
199 }
200
201#if GTEST_LANG_CXX11
202 // Ideally, we would inherit base class's constructors through a using
203 // declaration, which would preserve their visibility. However, many existing
204 // tests rely on the fact that current implementation reexports protected
205 // constructors as public. These tests would need to be cleaned up first.
206
207 // Single argument constructor is special-cased so that it can be
208 // made explicit.
209 template <typename A>
210 explicit NaggyMock(A&& arg) : MockClass(std::forward<A>(arg)) {
211 ::testing::Mock::WarnUninterestingCalls(
212 internal::ImplicitCast_<MockClass*>(this));
213 }
214
215 template <typename A1, typename A2, typename... An>
216 NaggyMock(A1&& arg1, A2&& arg2, An&&... args)
217 : MockClass(std::forward<A1>(arg1), std::forward<A2>(arg2),
218 std::forward<An>(args)...) {
219 ::testing::Mock::WarnUninterestingCalls(
220 internal::ImplicitCast_<MockClass*>(this));
221 }
222#else
223 // C++98 doesn't have variadic templates, so we have to define one
224 // for each arity.
225 template <typename A1>
226 explicit NaggyMock(const A1& a1) : MockClass(a1) {
227 ::testing::Mock::WarnUninterestingCalls(
228 internal::ImplicitCast_<MockClass*>(this));
229 }
230 template <typename A1, typename A2>
231 NaggyMock(const A1& a1, const A2& a2) : MockClass(a1, a2) {
232 ::testing::Mock::WarnUninterestingCalls(
233 internal::ImplicitCast_<MockClass*>(this));
234 }
235
236 template <typename A1, typename A2, typename A3>
237 NaggyMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) {
238 ::testing::Mock::WarnUninterestingCalls(
239 internal::ImplicitCast_<MockClass*>(this));
240 }
241
242 template <typename A1, typename A2, typename A3, typename A4>
243 NaggyMock(const A1& a1, const A2& a2, const A3& a3,
244 const A4& a4) : MockClass(a1, a2, a3, a4) {
245 ::testing::Mock::WarnUninterestingCalls(
246 internal::ImplicitCast_<MockClass*>(this));
247 }
248
249 template <typename A1, typename A2, typename A3, typename A4, typename A5>
250 NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
251 const A5& a5) : MockClass(a1, a2, a3, a4, a5) {
252 ::testing::Mock::WarnUninterestingCalls(
253 internal::ImplicitCast_<MockClass*>(this));
254 }
255
256 template <typename A1, typename A2, typename A3, typename A4, typename A5,
257 typename A6>
258 NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
259 const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) {
260 ::testing::Mock::WarnUninterestingCalls(
261 internal::ImplicitCast_<MockClass*>(this));
262 }
263
264 template <typename A1, typename A2, typename A3, typename A4, typename A5,
265 typename A6, typename A7>
266 NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
267 const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5,
268 a6, a7) {
269 ::testing::Mock::WarnUninterestingCalls(
270 internal::ImplicitCast_<MockClass*>(this));
271 }
272
273 template <typename A1, typename A2, typename A3, typename A4, typename A5,
274 typename A6, typename A7, typename A8>
275 NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
276 const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a1,
277 a2, a3, a4, a5, a6, a7, a8) {
278 ::testing::Mock::WarnUninterestingCalls(
279 internal::ImplicitCast_<MockClass*>(this));
280 }
281
282 template <typename A1, typename A2, typename A3, typename A4, typename A5,
283 typename A6, typename A7, typename A8, typename A9>
284 NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
285 const A5& a5, const A6& a6, const A7& a7, const A8& a8,
286 const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) {
287 ::testing::Mock::WarnUninterestingCalls(
288 internal::ImplicitCast_<MockClass*>(this));
289 }
290
291 template <typename A1, typename A2, typename A3, typename A4, typename A5,
292 typename A6, typename A7, typename A8, typename A9, typename A10>
293 NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
294 const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9,
295 const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) {
296 ::testing::Mock::WarnUninterestingCalls(
297 internal::ImplicitCast_<MockClass*>(this));
298 }
299
300#endif // GTEST_LANG_CXX11
301
302 ~NaggyMock() {
303 ::testing::Mock::UnregisterCallReaction(
304 internal::ImplicitCast_<MockClass*>(this));
305 }
306
307 private:
308 GTEST_DISALLOW_COPY_AND_ASSIGN_(NaggyMock);
309};
310
311template <class MockClass>
312class StrictMock : public MockClass {
313 public:
314 StrictMock() : MockClass() {
315 ::testing::Mock::FailUninterestingCalls(
316 internal::ImplicitCast_<MockClass*>(this));
317 }
318
319#if GTEST_LANG_CXX11
320 // Ideally, we would inherit base class's constructors through a using
321 // declaration, which would preserve their visibility. However, many existing
322 // tests rely on the fact that current implementation reexports protected
323 // constructors as public. These tests would need to be cleaned up first.
324
325 // Single argument constructor is special-cased so that it can be
326 // made explicit.
327 template <typename A>
328 explicit StrictMock(A&& arg) : MockClass(std::forward<A>(arg)) {
329 ::testing::Mock::FailUninterestingCalls(
330 internal::ImplicitCast_<MockClass*>(this));
331 }
332
333 template <typename A1, typename A2, typename... An>
334 StrictMock(A1&& arg1, A2&& arg2, An&&... args)
335 : MockClass(std::forward<A1>(arg1), std::forward<A2>(arg2),
336 std::forward<An>(args)...) {
337 ::testing::Mock::FailUninterestingCalls(
338 internal::ImplicitCast_<MockClass*>(this));
339 }
340#else
341 // C++98 doesn't have variadic templates, so we have to define one
342 // for each arity.
343 template <typename A1>
344 explicit StrictMock(const A1& a1) : MockClass(a1) {
345 ::testing::Mock::FailUninterestingCalls(
346 internal::ImplicitCast_<MockClass*>(this));
347 }
348 template <typename A1, typename A2>
349 StrictMock(const A1& a1, const A2& a2) : MockClass(a1, a2) {
350 ::testing::Mock::FailUninterestingCalls(
351 internal::ImplicitCast_<MockClass*>(this));
352 }
353
354 template <typename A1, typename A2, typename A3>
355 StrictMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) {
356 ::testing::Mock::FailUninterestingCalls(
357 internal::ImplicitCast_<MockClass*>(this));
358 }
359
360 template <typename A1, typename A2, typename A3, typename A4>
361 StrictMock(const A1& a1, const A2& a2, const A3& a3,
362 const A4& a4) : MockClass(a1, a2, a3, a4) {
363 ::testing::Mock::FailUninterestingCalls(
364 internal::ImplicitCast_<MockClass*>(this));
365 }
366
367 template <typename A1, typename A2, typename A3, typename A4, typename A5>
368 StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
369 const A5& a5) : MockClass(a1, a2, a3, a4, a5) {
370 ::testing::Mock::FailUninterestingCalls(
371 internal::ImplicitCast_<MockClass*>(this));
372 }
373
374 template <typename A1, typename A2, typename A3, typename A4, typename A5,
375 typename A6>
376 StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
377 const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) {
378 ::testing::Mock::FailUninterestingCalls(
379 internal::ImplicitCast_<MockClass*>(this));
380 }
381
382 template <typename A1, typename A2, typename A3, typename A4, typename A5,
383 typename A6, typename A7>
384 StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
385 const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5,
386 a6, a7) {
387 ::testing::Mock::FailUninterestingCalls(
388 internal::ImplicitCast_<MockClass*>(this));
389 }
390
391 template <typename A1, typename A2, typename A3, typename A4, typename A5,
392 typename A6, typename A7, typename A8>
393 StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
394 const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a1,
395 a2, a3, a4, a5, a6, a7, a8) {
396 ::testing::Mock::FailUninterestingCalls(
397 internal::ImplicitCast_<MockClass*>(this));
398 }
399
400 template <typename A1, typename A2, typename A3, typename A4, typename A5,
401 typename A6, typename A7, typename A8, typename A9>
402 StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
403 const A5& a5, const A6& a6, const A7& a7, const A8& a8,
404 const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) {
405 ::testing::Mock::FailUninterestingCalls(
406 internal::ImplicitCast_<MockClass*>(this));
407 }
408
409 template <typename A1, typename A2, typename A3, typename A4, typename A5,
410 typename A6, typename A7, typename A8, typename A9, typename A10>
411 StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
412 const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9,
413 const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) {
414 ::testing::Mock::FailUninterestingCalls(
415 internal::ImplicitCast_<MockClass*>(this));
416 }
417
418#endif // GTEST_LANG_CXX11
419
420 ~StrictMock() {
421 ::testing::Mock::UnregisterCallReaction(
422 internal::ImplicitCast_<MockClass*>(this));
423 }
424
425 private:
426 GTEST_DISALLOW_COPY_AND_ASSIGN_(StrictMock);
427};
428
429// The following specializations catch some (relatively more common)
430// user errors of nesting nice and strict mocks. They do NOT catch
431// all possible errors.
432
433// These specializations are declared but not defined, as NiceMock,
434// NaggyMock, and StrictMock cannot be nested.
435
436template <typename MockClass>
437class NiceMock<NiceMock<MockClass> >;
438template <typename MockClass>
439class NiceMock<NaggyMock<MockClass> >;
440template <typename MockClass>
441class NiceMock<StrictMock<MockClass> >;
442
443template <typename MockClass>
444class NaggyMock<NiceMock<MockClass> >;
445template <typename MockClass>
446class NaggyMock<NaggyMock<MockClass> >;
447template <typename MockClass>
448class NaggyMock<StrictMock<MockClass> >;
449
450template <typename MockClass>
451class StrictMock<NiceMock<MockClass> >;
452template <typename MockClass>
453class StrictMock<NaggyMock<MockClass> >;
454template <typename MockClass>
455class StrictMock<StrictMock<MockClass> >;
456
457} // namespace testing
458
459#endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_
460