1 // This file was GENERATED by command:
2 // pump.py gmock-generated-nice-strict.h.pump
3 // DO NOT EDIT BY HAND!!!
5 // Copyright 2008, Google Inc.
6 // All rights reserved.
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions are
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
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.
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.
34 // Author: wan@google.com (Zhanyong Wan)
36 // Implements class templates NiceMock, NaggyMock, and StrictMock.
38 // Given a mock class MockFoo that is created using Google Mock,
39 // NiceMock<MockFoo> is a subclass of MockFoo that allows
40 // uninteresting calls (i.e. calls to mock methods that have no
41 // EXPECT_CALL specs), NaggyMock<MockFoo> is a subclass of MockFoo
42 // that prints a warning when an uninteresting call occurs, and
43 // StrictMock<MockFoo> is a subclass of MockFoo that treats all
44 // uninteresting calls as errors.
46 // Currently a mock is naggy by default, so MockFoo and
47 // NaggyMock<MockFoo> behave like the same. However, we will soon
48 // switch the default behavior of mocks to be nice, as that in general
49 // leads to more maintainable tests. When that happens, MockFoo will
50 // stop behaving like NaggyMock<MockFoo> and start behaving like
53 // NiceMock, NaggyMock, and StrictMock "inherit" the constructors of
54 // their respective base class, with up-to 10 arguments. Therefore
55 // you can write NiceMock<MockFoo>(5, "a") to construct a nice mock
56 // where MockFoo has a constructor that accepts (int, const char*),
59 // A known limitation is that NiceMock<MockFoo>, NaggyMock<MockFoo>,
60 // and StrictMock<MockFoo> only works for mock methods defined using
61 // the MOCK_METHOD* family of macros DIRECTLY in the MockFoo class.
62 // If a mock method is defined in a base class of MockFoo, the "nice"
63 // or "strict" modifier may not affect it, depending on the compiler.
64 // In particular, nesting NiceMock, NaggyMock, and StrictMock is NOT
67 // Another known limitation is that the constructors of the base mock
68 // cannot have arguments passed by non-const reference, which are
69 // banned by the Google C++ style guide anyway.
71 // IWYU pragma: private, include "gmock/gmock.h"
73 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_
74 #define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_
76 #include "gmock/gmock-spec-builders.h"
77 #include "gmock/internal/gmock-port.h"
81 template <class MockClass
>
82 class NiceMock
: public MockClass
{
84 // We don't factor out the constructor body to a common method, as
85 // we have to avoid a possible clash with members of MockClass.
87 ::testing::Mock::AllowUninterestingCalls(
88 internal::ImplicitCast_
<MockClass
*>(this));
91 // C++ doesn't (yet) allow inheritance of constructors, so we have
92 // to define it for each arity.
93 template <typename A1
>
94 explicit NiceMock(const A1
& a1
) : MockClass(a1
) {
95 ::testing::Mock::AllowUninterestingCalls(
96 internal::ImplicitCast_
<MockClass
*>(this));
98 template <typename A1
, typename A2
>
99 NiceMock(const A1
& a1
, const A2
& a2
) : MockClass(a1
, a2
) {
100 ::testing::Mock::AllowUninterestingCalls(
101 internal::ImplicitCast_
<MockClass
*>(this));
104 template <typename A1
, typename A2
, typename A3
>
105 NiceMock(const A1
& a1
, const A2
& a2
, const A3
& a3
) : MockClass(a1
, a2
, a3
) {
106 ::testing::Mock::AllowUninterestingCalls(
107 internal::ImplicitCast_
<MockClass
*>(this));
110 template <typename A1
, typename A2
, typename A3
, typename A4
>
111 NiceMock(const A1
& a1
, const A2
& a2
, const A3
& a3
,
112 const A4
& a4
) : MockClass(a1
, a2
, a3
, a4
) {
113 ::testing::Mock::AllowUninterestingCalls(
114 internal::ImplicitCast_
<MockClass
*>(this));
117 template <typename A1
, typename A2
, typename A3
, typename A4
, typename A5
>
118 NiceMock(const A1
& a1
, const A2
& a2
, const A3
& a3
, const A4
& a4
,
119 const A5
& a5
) : MockClass(a1
, a2
, a3
, a4
, a5
) {
120 ::testing::Mock::AllowUninterestingCalls(
121 internal::ImplicitCast_
<MockClass
*>(this));
124 template <typename A1
, typename A2
, typename A3
, typename A4
, typename A5
,
126 NiceMock(const A1
& a1
, const A2
& a2
, const A3
& a3
, const A4
& a4
,
127 const A5
& a5
, const A6
& a6
) : MockClass(a1
, a2
, a3
, a4
, a5
, a6
) {
128 ::testing::Mock::AllowUninterestingCalls(
129 internal::ImplicitCast_
<MockClass
*>(this));
132 template <typename A1
, typename A2
, typename A3
, typename A4
, typename A5
,
133 typename A6
, typename A7
>
134 NiceMock(const A1
& a1
, const A2
& a2
, const A3
& a3
, const A4
& a4
,
135 const A5
& a5
, const A6
& a6
, const A7
& a7
) : MockClass(a1
, a2
, a3
, a4
, a5
,
137 ::testing::Mock::AllowUninterestingCalls(
138 internal::ImplicitCast_
<MockClass
*>(this));
141 template <typename A1
, typename A2
, typename A3
, typename A4
, typename A5
,
142 typename A6
, typename A7
, typename A8
>
143 NiceMock(const A1
& a1
, const A2
& a2
, const A3
& a3
, const A4
& a4
,
144 const A5
& a5
, const A6
& a6
, const A7
& a7
, const A8
& a8
) : MockClass(a1
,
145 a2
, a3
, a4
, a5
, a6
, a7
, a8
) {
146 ::testing::Mock::AllowUninterestingCalls(
147 internal::ImplicitCast_
<MockClass
*>(this));
150 template <typename A1
, typename A2
, typename A3
, typename A4
, typename A5
,
151 typename A6
, typename A7
, typename A8
, typename A9
>
152 NiceMock(const A1
& a1
, const A2
& a2
, const A3
& a3
, const A4
& a4
,
153 const A5
& a5
, const A6
& a6
, const A7
& a7
, const A8
& a8
,
154 const A9
& a9
) : MockClass(a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
) {
155 ::testing::Mock::AllowUninterestingCalls(
156 internal::ImplicitCast_
<MockClass
*>(this));
159 template <typename A1
, typename A2
, typename A3
, typename A4
, typename A5
,
160 typename A6
, typename A7
, typename A8
, typename A9
, typename A10
>
161 NiceMock(const A1
& a1
, const A2
& a2
, const A3
& a3
, const A4
& a4
,
162 const A5
& a5
, const A6
& a6
, const A7
& a7
, const A8
& a8
, const A9
& a9
,
163 const A10
& a10
) : MockClass(a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
, a10
) {
164 ::testing::Mock::AllowUninterestingCalls(
165 internal::ImplicitCast_
<MockClass
*>(this));
168 virtual ~NiceMock() {
169 ::testing::Mock::UnregisterCallReaction(
170 internal::ImplicitCast_
<MockClass
*>(this));
174 GTEST_DISALLOW_COPY_AND_ASSIGN_(NiceMock
);
177 template <class MockClass
>
178 class NaggyMock
: public MockClass
{
180 // We don't factor out the constructor body to a common method, as
181 // we have to avoid a possible clash with members of MockClass.
183 ::testing::Mock::WarnUninterestingCalls(
184 internal::ImplicitCast_
<MockClass
*>(this));
187 // C++ doesn't (yet) allow inheritance of constructors, so we have
188 // to define it for each arity.
189 template <typename A1
>
190 explicit NaggyMock(const A1
& a1
) : MockClass(a1
) {
191 ::testing::Mock::WarnUninterestingCalls(
192 internal::ImplicitCast_
<MockClass
*>(this));
194 template <typename A1
, typename A2
>
195 NaggyMock(const A1
& a1
, const A2
& a2
) : MockClass(a1
, a2
) {
196 ::testing::Mock::WarnUninterestingCalls(
197 internal::ImplicitCast_
<MockClass
*>(this));
200 template <typename A1
, typename A2
, typename A3
>
201 NaggyMock(const A1
& a1
, const A2
& a2
, const A3
& a3
) : MockClass(a1
, a2
, a3
) {
202 ::testing::Mock::WarnUninterestingCalls(
203 internal::ImplicitCast_
<MockClass
*>(this));
206 template <typename A1
, typename A2
, typename A3
, typename A4
>
207 NaggyMock(const A1
& a1
, const A2
& a2
, const A3
& a3
,
208 const A4
& a4
) : MockClass(a1
, a2
, a3
, a4
) {
209 ::testing::Mock::WarnUninterestingCalls(
210 internal::ImplicitCast_
<MockClass
*>(this));
213 template <typename A1
, typename A2
, typename A3
, typename A4
, typename A5
>
214 NaggyMock(const A1
& a1
, const A2
& a2
, const A3
& a3
, const A4
& a4
,
215 const A5
& a5
) : MockClass(a1
, a2
, a3
, a4
, a5
) {
216 ::testing::Mock::WarnUninterestingCalls(
217 internal::ImplicitCast_
<MockClass
*>(this));
220 template <typename A1
, typename A2
, typename A3
, typename A4
, typename A5
,
222 NaggyMock(const A1
& a1
, const A2
& a2
, const A3
& a3
, const A4
& a4
,
223 const A5
& a5
, const A6
& a6
) : MockClass(a1
, a2
, a3
, a4
, a5
, a6
) {
224 ::testing::Mock::WarnUninterestingCalls(
225 internal::ImplicitCast_
<MockClass
*>(this));
228 template <typename A1
, typename A2
, typename A3
, typename A4
, typename A5
,
229 typename A6
, typename A7
>
230 NaggyMock(const A1
& a1
, const A2
& a2
, const A3
& a3
, const A4
& a4
,
231 const A5
& a5
, const A6
& a6
, const A7
& a7
) : MockClass(a1
, a2
, a3
, a4
, a5
,
233 ::testing::Mock::WarnUninterestingCalls(
234 internal::ImplicitCast_
<MockClass
*>(this));
237 template <typename A1
, typename A2
, typename A3
, typename A4
, typename A5
,
238 typename A6
, typename A7
, typename A8
>
239 NaggyMock(const A1
& a1
, const A2
& a2
, const A3
& a3
, const A4
& a4
,
240 const A5
& a5
, const A6
& a6
, const A7
& a7
, const A8
& a8
) : MockClass(a1
,
241 a2
, a3
, a4
, a5
, a6
, a7
, a8
) {
242 ::testing::Mock::WarnUninterestingCalls(
243 internal::ImplicitCast_
<MockClass
*>(this));
246 template <typename A1
, typename A2
, typename A3
, typename A4
, typename A5
,
247 typename A6
, typename A7
, typename A8
, typename A9
>
248 NaggyMock(const A1
& a1
, const A2
& a2
, const A3
& a3
, const A4
& a4
,
249 const A5
& a5
, const A6
& a6
, const A7
& a7
, const A8
& a8
,
250 const A9
& a9
) : MockClass(a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
) {
251 ::testing::Mock::WarnUninterestingCalls(
252 internal::ImplicitCast_
<MockClass
*>(this));
255 template <typename A1
, typename A2
, typename A3
, typename A4
, typename A5
,
256 typename A6
, typename A7
, typename A8
, typename A9
, typename A10
>
257 NaggyMock(const A1
& a1
, const A2
& a2
, const A3
& a3
, const A4
& a4
,
258 const A5
& a5
, const A6
& a6
, const A7
& a7
, const A8
& a8
, const A9
& a9
,
259 const A10
& a10
) : MockClass(a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
, a10
) {
260 ::testing::Mock::WarnUninterestingCalls(
261 internal::ImplicitCast_
<MockClass
*>(this));
264 virtual ~NaggyMock() {
265 ::testing::Mock::UnregisterCallReaction(
266 internal::ImplicitCast_
<MockClass
*>(this));
270 GTEST_DISALLOW_COPY_AND_ASSIGN_(NaggyMock
);
273 template <class MockClass
>
274 class StrictMock
: public MockClass
{
276 // We don't factor out the constructor body to a common method, as
277 // we have to avoid a possible clash with members of MockClass.
279 ::testing::Mock::FailUninterestingCalls(
280 internal::ImplicitCast_
<MockClass
*>(this));
283 // C++ doesn't (yet) allow inheritance of constructors, so we have
284 // to define it for each arity.
285 template <typename A1
>
286 explicit StrictMock(const A1
& a1
) : MockClass(a1
) {
287 ::testing::Mock::FailUninterestingCalls(
288 internal::ImplicitCast_
<MockClass
*>(this));
290 template <typename A1
, typename A2
>
291 StrictMock(const A1
& a1
, const A2
& a2
) : MockClass(a1
, a2
) {
292 ::testing::Mock::FailUninterestingCalls(
293 internal::ImplicitCast_
<MockClass
*>(this));
296 template <typename A1
, typename A2
, typename A3
>
297 StrictMock(const A1
& a1
, const A2
& a2
, const A3
& a3
) : MockClass(a1
, a2
, a3
) {
298 ::testing::Mock::FailUninterestingCalls(
299 internal::ImplicitCast_
<MockClass
*>(this));
302 template <typename A1
, typename A2
, typename A3
, typename A4
>
303 StrictMock(const A1
& a1
, const A2
& a2
, const A3
& a3
,
304 const A4
& a4
) : MockClass(a1
, a2
, a3
, a4
) {
305 ::testing::Mock::FailUninterestingCalls(
306 internal::ImplicitCast_
<MockClass
*>(this));
309 template <typename A1
, typename A2
, typename A3
, typename A4
, typename A5
>
310 StrictMock(const A1
& a1
, const A2
& a2
, const A3
& a3
, const A4
& a4
,
311 const A5
& a5
) : MockClass(a1
, a2
, a3
, a4
, a5
) {
312 ::testing::Mock::FailUninterestingCalls(
313 internal::ImplicitCast_
<MockClass
*>(this));
316 template <typename A1
, typename A2
, typename A3
, typename A4
, typename A5
,
318 StrictMock(const A1
& a1
, const A2
& a2
, const A3
& a3
, const A4
& a4
,
319 const A5
& a5
, const A6
& a6
) : MockClass(a1
, a2
, a3
, a4
, a5
, a6
) {
320 ::testing::Mock::FailUninterestingCalls(
321 internal::ImplicitCast_
<MockClass
*>(this));
324 template <typename A1
, typename A2
, typename A3
, typename A4
, typename A5
,
325 typename A6
, typename A7
>
326 StrictMock(const A1
& a1
, const A2
& a2
, const A3
& a3
, const A4
& a4
,
327 const A5
& a5
, const A6
& a6
, const A7
& a7
) : MockClass(a1
, a2
, a3
, a4
, a5
,
329 ::testing::Mock::FailUninterestingCalls(
330 internal::ImplicitCast_
<MockClass
*>(this));
333 template <typename A1
, typename A2
, typename A3
, typename A4
, typename A5
,
334 typename A6
, typename A7
, typename A8
>
335 StrictMock(const A1
& a1
, const A2
& a2
, const A3
& a3
, const A4
& a4
,
336 const A5
& a5
, const A6
& a6
, const A7
& a7
, const A8
& a8
) : MockClass(a1
,
337 a2
, a3
, a4
, a5
, a6
, a7
, a8
) {
338 ::testing::Mock::FailUninterestingCalls(
339 internal::ImplicitCast_
<MockClass
*>(this));
342 template <typename A1
, typename A2
, typename A3
, typename A4
, typename A5
,
343 typename A6
, typename A7
, typename A8
, typename A9
>
344 StrictMock(const A1
& a1
, const A2
& a2
, const A3
& a3
, const A4
& a4
,
345 const A5
& a5
, const A6
& a6
, const A7
& a7
, const A8
& a8
,
346 const A9
& a9
) : MockClass(a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
) {
347 ::testing::Mock::FailUninterestingCalls(
348 internal::ImplicitCast_
<MockClass
*>(this));
351 template <typename A1
, typename A2
, typename A3
, typename A4
, typename A5
,
352 typename A6
, typename A7
, typename A8
, typename A9
, typename A10
>
353 StrictMock(const A1
& a1
, const A2
& a2
, const A3
& a3
, const A4
& a4
,
354 const A5
& a5
, const A6
& a6
, const A7
& a7
, const A8
& a8
, const A9
& a9
,
355 const A10
& a10
) : MockClass(a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
, a10
) {
356 ::testing::Mock::FailUninterestingCalls(
357 internal::ImplicitCast_
<MockClass
*>(this));
360 virtual ~StrictMock() {
361 ::testing::Mock::UnregisterCallReaction(
362 internal::ImplicitCast_
<MockClass
*>(this));
366 GTEST_DISALLOW_COPY_AND_ASSIGN_(StrictMock
);
369 // The following specializations catch some (relatively more common)
370 // user errors of nesting nice and strict mocks. They do NOT catch
371 // all possible errors.
373 // These specializations are declared but not defined, as NiceMock,
374 // NaggyMock, and StrictMock cannot be nested.
376 template <typename MockClass
>
377 class NiceMock
<NiceMock
<MockClass
> >;
378 template <typename MockClass
>
379 class NiceMock
<NaggyMock
<MockClass
> >;
380 template <typename MockClass
>
381 class NiceMock
<StrictMock
<MockClass
> >;
383 template <typename MockClass
>
384 class NaggyMock
<NiceMock
<MockClass
> >;
385 template <typename MockClass
>
386 class NaggyMock
<NaggyMock
<MockClass
> >;
387 template <typename MockClass
>
388 class NaggyMock
<StrictMock
<MockClass
> >;
390 template <typename MockClass
>
391 class StrictMock
<NiceMock
<MockClass
> >;
392 template <typename MockClass
>
393 class StrictMock
<NaggyMock
<MockClass
> >;
394 template <typename MockClass
>
395 class StrictMock
<StrictMock
<MockClass
> >;
397 } // namespace testing
399 #endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_