• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // Author: wan@google.com (Zhanyong Wan)
35 
36 // Implements class templates NiceMock, NaggyMock, and StrictMock.
37 //
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.
45 //
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
51 // NiceMock<MockFoo>.
52 //
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*),
57 // for example.
58 //
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
65 // supported.
66 //
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.
70 
71 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_
72 #define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_
73 
74 #include "gmock/gmock-spec-builders.h"
75 #include "gmock/internal/gmock-port.h"
76 
77 namespace testing {
78 
79 template <class MockClass>
80 class NiceMock : public MockClass {
81  public:
82   // We don't factor out the constructor body to a common method, as
83   // we have to avoid a possible clash with members of MockClass.
NiceMock()84   NiceMock() {
85     ::testing::Mock::AllowUninterestingCalls(
86         internal::ImplicitCast_<MockClass*>(this));
87   }
88 
89   // C++ doesn't (yet) allow inheritance of constructors, so we have
90   // to define it for each arity.
91   template <typename A1>
NiceMock(const A1 & a1)92   explicit NiceMock(const A1& a1) : MockClass(a1) {
93     ::testing::Mock::AllowUninterestingCalls(
94         internal::ImplicitCast_<MockClass*>(this));
95   }
96   template <typename A1, typename A2>
NiceMock(const A1 & a1,const A2 & a2)97   NiceMock(const A1& a1, const A2& a2) : MockClass(a1, a2) {
98     ::testing::Mock::AllowUninterestingCalls(
99         internal::ImplicitCast_<MockClass*>(this));
100   }
101 
102   template <typename A1, typename A2, typename A3>
NiceMock(const A1 & a1,const A2 & a2,const A3 & a3)103   NiceMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) {
104     ::testing::Mock::AllowUninterestingCalls(
105         internal::ImplicitCast_<MockClass*>(this));
106   }
107 
108   template <typename A1, typename A2, typename A3, typename A4>
NiceMock(const A1 & a1,const A2 & a2,const A3 & a3,const A4 & a4)109   NiceMock(const A1& a1, const A2& a2, const A3& a3,
110       const A4& a4) : MockClass(a1, a2, a3, a4) {
111     ::testing::Mock::AllowUninterestingCalls(
112         internal::ImplicitCast_<MockClass*>(this));
113   }
114 
115   template <typename A1, typename A2, typename A3, typename A4, typename A5>
NiceMock(const A1 & a1,const A2 & a2,const A3 & a3,const A4 & a4,const A5 & a5)116   NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
117       const A5& a5) : MockClass(a1, a2, a3, a4, a5) {
118     ::testing::Mock::AllowUninterestingCalls(
119         internal::ImplicitCast_<MockClass*>(this));
120   }
121 
122   template <typename A1, typename A2, typename A3, typename A4, typename A5,
123       typename A6>
NiceMock(const A1 & a1,const A2 & a2,const A3 & a3,const A4 & a4,const A5 & a5,const A6 & a6)124   NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
125       const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) {
126     ::testing::Mock::AllowUninterestingCalls(
127         internal::ImplicitCast_<MockClass*>(this));
128   }
129 
130   template <typename A1, typename A2, typename A3, typename A4, typename A5,
131       typename A6, typename A7>
NiceMock(const A1 & a1,const A2 & a2,const A3 & a3,const A4 & a4,const A5 & a5,const A6 & a6,const A7 & a7)132   NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
133       const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5,
134       a6, a7) {
135     ::testing::Mock::AllowUninterestingCalls(
136         internal::ImplicitCast_<MockClass*>(this));
137   }
138 
139   template <typename A1, typename A2, typename A3, typename A4, typename A5,
140       typename A6, typename A7, typename A8>
NiceMock(const A1 & a1,const A2 & a2,const A3 & a3,const A4 & a4,const A5 & a5,const A6 & a6,const A7 & a7,const A8 & a8)141   NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
142       const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a1,
143       a2, a3, a4, a5, a6, a7, a8) {
144     ::testing::Mock::AllowUninterestingCalls(
145         internal::ImplicitCast_<MockClass*>(this));
146   }
147 
148   template <typename A1, typename A2, typename A3, typename A4, typename A5,
149       typename A6, typename A7, typename A8, typename A9>
NiceMock(const A1 & a1,const A2 & a2,const A3 & a3,const A4 & a4,const A5 & a5,const A6 & a6,const A7 & a7,const A8 & a8,const A9 & a9)150   NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
151       const A5& a5, const A6& a6, const A7& a7, const A8& a8,
152       const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) {
153     ::testing::Mock::AllowUninterestingCalls(
154         internal::ImplicitCast_<MockClass*>(this));
155   }
156 
157   template <typename A1, typename A2, typename A3, typename A4, typename A5,
158       typename A6, typename A7, typename A8, typename A9, typename A10>
NiceMock(const A1 & a1,const A2 & a2,const A3 & a3,const A4 & a4,const A5 & a5,const A6 & a6,const A7 & a7,const A8 & a8,const A9 & a9,const A10 & a10)159   NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
160       const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9,
161       const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) {
162     ::testing::Mock::AllowUninterestingCalls(
163         internal::ImplicitCast_<MockClass*>(this));
164   }
165 
~NiceMock()166   virtual ~NiceMock() {
167     ::testing::Mock::UnregisterCallReaction(
168         internal::ImplicitCast_<MockClass*>(this));
169   }
170 
171  private:
172   GTEST_DISALLOW_COPY_AND_ASSIGN_(NiceMock);
173 };
174 
175 template <class MockClass>
176 class NaggyMock : public MockClass {
177  public:
178   // We don't factor out the constructor body to a common method, as
179   // we have to avoid a possible clash with members of MockClass.
NaggyMock()180   NaggyMock() {
181     ::testing::Mock::WarnUninterestingCalls(
182         internal::ImplicitCast_<MockClass*>(this));
183   }
184 
185   // C++ doesn't (yet) allow inheritance of constructors, so we have
186   // to define it for each arity.
187   template <typename A1>
NaggyMock(const A1 & a1)188   explicit NaggyMock(const A1& a1) : MockClass(a1) {
189     ::testing::Mock::WarnUninterestingCalls(
190         internal::ImplicitCast_<MockClass*>(this));
191   }
192   template <typename A1, typename A2>
NaggyMock(const A1 & a1,const A2 & a2)193   NaggyMock(const A1& a1, const A2& a2) : MockClass(a1, a2) {
194     ::testing::Mock::WarnUninterestingCalls(
195         internal::ImplicitCast_<MockClass*>(this));
196   }
197 
198   template <typename A1, typename A2, typename A3>
NaggyMock(const A1 & a1,const A2 & a2,const A3 & a3)199   NaggyMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) {
200     ::testing::Mock::WarnUninterestingCalls(
201         internal::ImplicitCast_<MockClass*>(this));
202   }
203 
204   template <typename A1, typename A2, typename A3, typename A4>
NaggyMock(const A1 & a1,const A2 & a2,const A3 & a3,const A4 & a4)205   NaggyMock(const A1& a1, const A2& a2, const A3& a3,
206       const A4& a4) : MockClass(a1, a2, a3, a4) {
207     ::testing::Mock::WarnUninterestingCalls(
208         internal::ImplicitCast_<MockClass*>(this));
209   }
210 
211   template <typename A1, typename A2, typename A3, typename A4, typename A5>
NaggyMock(const A1 & a1,const A2 & a2,const A3 & a3,const A4 & a4,const A5 & a5)212   NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
213       const A5& a5) : MockClass(a1, a2, a3, a4, a5) {
214     ::testing::Mock::WarnUninterestingCalls(
215         internal::ImplicitCast_<MockClass*>(this));
216   }
217 
218   template <typename A1, typename A2, typename A3, typename A4, typename A5,
219       typename A6>
NaggyMock(const A1 & a1,const A2 & a2,const A3 & a3,const A4 & a4,const A5 & a5,const A6 & a6)220   NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
221       const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) {
222     ::testing::Mock::WarnUninterestingCalls(
223         internal::ImplicitCast_<MockClass*>(this));
224   }
225 
226   template <typename A1, typename A2, typename A3, typename A4, typename A5,
227       typename A6, typename A7>
NaggyMock(const A1 & a1,const A2 & a2,const A3 & a3,const A4 & a4,const A5 & a5,const A6 & a6,const A7 & a7)228   NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
229       const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5,
230       a6, a7) {
231     ::testing::Mock::WarnUninterestingCalls(
232         internal::ImplicitCast_<MockClass*>(this));
233   }
234 
235   template <typename A1, typename A2, typename A3, typename A4, typename A5,
236       typename A6, typename A7, typename A8>
NaggyMock(const A1 & a1,const A2 & a2,const A3 & a3,const A4 & a4,const A5 & a5,const A6 & a6,const A7 & a7,const A8 & a8)237   NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
238       const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a1,
239       a2, a3, a4, a5, a6, a7, a8) {
240     ::testing::Mock::WarnUninterestingCalls(
241         internal::ImplicitCast_<MockClass*>(this));
242   }
243 
244   template <typename A1, typename A2, typename A3, typename A4, typename A5,
245       typename A6, typename A7, typename A8, typename A9>
NaggyMock(const A1 & a1,const A2 & a2,const A3 & a3,const A4 & a4,const A5 & a5,const A6 & a6,const A7 & a7,const A8 & a8,const A9 & a9)246   NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
247       const A5& a5, const A6& a6, const A7& a7, const A8& a8,
248       const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) {
249     ::testing::Mock::WarnUninterestingCalls(
250         internal::ImplicitCast_<MockClass*>(this));
251   }
252 
253   template <typename A1, typename A2, typename A3, typename A4, typename A5,
254       typename A6, typename A7, typename A8, typename A9, typename A10>
NaggyMock(const A1 & a1,const A2 & a2,const A3 & a3,const A4 & a4,const A5 & a5,const A6 & a6,const A7 & a7,const A8 & a8,const A9 & a9,const A10 & a10)255   NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
256       const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9,
257       const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) {
258     ::testing::Mock::WarnUninterestingCalls(
259         internal::ImplicitCast_<MockClass*>(this));
260   }
261 
~NaggyMock()262   virtual ~NaggyMock() {
263     ::testing::Mock::UnregisterCallReaction(
264         internal::ImplicitCast_<MockClass*>(this));
265   }
266 
267  private:
268   GTEST_DISALLOW_COPY_AND_ASSIGN_(NaggyMock);
269 };
270 
271 template <class MockClass>
272 class StrictMock : public MockClass {
273  public:
274   // We don't factor out the constructor body to a common method, as
275   // we have to avoid a possible clash with members of MockClass.
StrictMock()276   StrictMock() {
277     ::testing::Mock::FailUninterestingCalls(
278         internal::ImplicitCast_<MockClass*>(this));
279   }
280 
281   // C++ doesn't (yet) allow inheritance of constructors, so we have
282   // to define it for each arity.
283   template <typename A1>
StrictMock(const A1 & a1)284   explicit StrictMock(const A1& a1) : MockClass(a1) {
285     ::testing::Mock::FailUninterestingCalls(
286         internal::ImplicitCast_<MockClass*>(this));
287   }
288   template <typename A1, typename A2>
StrictMock(const A1 & a1,const A2 & a2)289   StrictMock(const A1& a1, const A2& a2) : MockClass(a1, a2) {
290     ::testing::Mock::FailUninterestingCalls(
291         internal::ImplicitCast_<MockClass*>(this));
292   }
293 
294   template <typename A1, typename A2, typename A3>
StrictMock(const A1 & a1,const A2 & a2,const A3 & a3)295   StrictMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) {
296     ::testing::Mock::FailUninterestingCalls(
297         internal::ImplicitCast_<MockClass*>(this));
298   }
299 
300   template <typename A1, typename A2, typename A3, typename A4>
StrictMock(const A1 & a1,const A2 & a2,const A3 & a3,const A4 & a4)301   StrictMock(const A1& a1, const A2& a2, const A3& a3,
302       const A4& a4) : MockClass(a1, a2, a3, a4) {
303     ::testing::Mock::FailUninterestingCalls(
304         internal::ImplicitCast_<MockClass*>(this));
305   }
306 
307   template <typename A1, typename A2, typename A3, typename A4, typename A5>
StrictMock(const A1 & a1,const A2 & a2,const A3 & a3,const A4 & a4,const A5 & a5)308   StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
309       const A5& a5) : MockClass(a1, a2, a3, a4, a5) {
310     ::testing::Mock::FailUninterestingCalls(
311         internal::ImplicitCast_<MockClass*>(this));
312   }
313 
314   template <typename A1, typename A2, typename A3, typename A4, typename A5,
315       typename A6>
StrictMock(const A1 & a1,const A2 & a2,const A3 & a3,const A4 & a4,const A5 & a5,const A6 & a6)316   StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
317       const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) {
318     ::testing::Mock::FailUninterestingCalls(
319         internal::ImplicitCast_<MockClass*>(this));
320   }
321 
322   template <typename A1, typename A2, typename A3, typename A4, typename A5,
323       typename A6, typename A7>
StrictMock(const A1 & a1,const A2 & a2,const A3 & a3,const A4 & a4,const A5 & a5,const A6 & a6,const A7 & a7)324   StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
325       const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5,
326       a6, a7) {
327     ::testing::Mock::FailUninterestingCalls(
328         internal::ImplicitCast_<MockClass*>(this));
329   }
330 
331   template <typename A1, typename A2, typename A3, typename A4, typename A5,
332       typename A6, typename A7, typename A8>
StrictMock(const A1 & a1,const A2 & a2,const A3 & a3,const A4 & a4,const A5 & a5,const A6 & a6,const A7 & a7,const A8 & a8)333   StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
334       const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a1,
335       a2, a3, a4, a5, a6, a7, a8) {
336     ::testing::Mock::FailUninterestingCalls(
337         internal::ImplicitCast_<MockClass*>(this));
338   }
339 
340   template <typename A1, typename A2, typename A3, typename A4, typename A5,
341       typename A6, typename A7, typename A8, typename A9>
StrictMock(const A1 & a1,const A2 & a2,const A3 & a3,const A4 & a4,const A5 & a5,const A6 & a6,const A7 & a7,const A8 & a8,const A9 & a9)342   StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
343       const A5& a5, const A6& a6, const A7& a7, const A8& a8,
344       const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) {
345     ::testing::Mock::FailUninterestingCalls(
346         internal::ImplicitCast_<MockClass*>(this));
347   }
348 
349   template <typename A1, typename A2, typename A3, typename A4, typename A5,
350       typename A6, typename A7, typename A8, typename A9, typename A10>
StrictMock(const A1 & a1,const A2 & a2,const A3 & a3,const A4 & a4,const A5 & a5,const A6 & a6,const A7 & a7,const A8 & a8,const A9 & a9,const A10 & a10)351   StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
352       const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9,
353       const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) {
354     ::testing::Mock::FailUninterestingCalls(
355         internal::ImplicitCast_<MockClass*>(this));
356   }
357 
~StrictMock()358   virtual ~StrictMock() {
359     ::testing::Mock::UnregisterCallReaction(
360         internal::ImplicitCast_<MockClass*>(this));
361   }
362 
363  private:
364   GTEST_DISALLOW_COPY_AND_ASSIGN_(StrictMock);
365 };
366 
367 // The following specializations catch some (relatively more common)
368 // user errors of nesting nice and strict mocks.  They do NOT catch
369 // all possible errors.
370 
371 // These specializations are declared but not defined, as NiceMock,
372 // NaggyMock, and StrictMock cannot be nested.
373 
374 template <typename MockClass>
375 class NiceMock<NiceMock<MockClass> >;
376 template <typename MockClass>
377 class NiceMock<NaggyMock<MockClass> >;
378 template <typename MockClass>
379 class NiceMock<StrictMock<MockClass> >;
380 
381 template <typename MockClass>
382 class NaggyMock<NiceMock<MockClass> >;
383 template <typename MockClass>
384 class NaggyMock<NaggyMock<MockClass> >;
385 template <typename MockClass>
386 class NaggyMock<StrictMock<MockClass> >;
387 
388 template <typename MockClass>
389 class StrictMock<NiceMock<MockClass> >;
390 template <typename MockClass>
391 class StrictMock<NaggyMock<MockClass> >;
392 template <typename MockClass>
393 class StrictMock<StrictMock<MockClass> >;
394 
395 }  // namespace testing
396 
397 #endif  // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_
398