2 $$ This is a Pump source file. Please use Pump to convert
3 $$ it to gmock-generated-nice-strict.h.
5 $var n = 10 $$ The maximum arity we support.
6 // Copyright 2008, Google Inc.
7 // All rights reserved.
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions are
13 // * Redistributions of source code must retain the above copyright
14 // notice, this list of conditions and the following disclaimer.
15 // * Redistributions in binary form must reproduce the above
16 // copyright notice, this list of conditions and the following disclaimer
17 // in the documentation and/or other materials provided with the
19 // * Neither the name of Google Inc. nor the names of its
20 // contributors may be used to endorse or promote products derived from
21 // this software without specific prior written permission.
23 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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. Therefore you can write
55 // NiceMock<MockFoo>(5, "a") to construct a nice mock where MockFoo
56 // has a constructor that accepts (int, const char*), for example.
58 // A known limitation is that NiceMock<MockFoo>, NaggyMock<MockFoo>,
59 // and StrictMock<MockFoo> only works for mock methods defined using
60 // the MOCK_METHOD* family of macros DIRECTLY in the MockFoo class.
61 // If a mock method is defined in a base class of MockFoo, the "nice"
62 // or "strict" modifier may not affect it, depending on the compiler.
63 // In particular, nesting NiceMock, NaggyMock, and StrictMock is NOT
66 // GOOGLETEST_CM0002 DO NOT DELETE
68 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_
69 #define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_
71 #include "gmock/gmock-spec-builders.h"
72 #include "gmock/internal/gmock-port.h"
79 $var clazz=[[$if kind==0 [[NiceMock]]
80 $elif kind==1 [[NaggyMock]]
81 $else [[StrictMock]]]]
83 $var method=[[$if kind==0 [[AllowUninterestingCalls]]
84 $elif kind==1 [[WarnUninterestingCalls]]
85 $else [[FailUninterestingCalls]]]]
87 template <class MockClass>
88 class $clazz : public MockClass {
90 $clazz() : MockClass() {
91 ::testing::Mock::$method(
92 internal::ImplicitCast_<MockClass*>(this));
96 // Ideally, we would inherit base class's constructors through a using
97 // declaration, which would preserve their visibility. However, many existing
98 // tests rely on the fact that current implementation reexports protected
99 // constructors as public. These tests would need to be cleaned up first.
101 // Single argument constructor is special-cased so that it can be
103 template <typename A>
104 explicit $clazz(A&& arg) : MockClass(std::forward<A>(arg)) {
105 ::testing::Mock::$method(
106 internal::ImplicitCast_<MockClass*>(this));
109 template <typename A1, typename A2, typename... An>
110 $clazz(A1&& arg1, A2&& arg2, An&&... args)
111 : MockClass(std::forward<A1>(arg1), std::forward<A2>(arg2),
112 std::forward<An>(args)...) {
113 ::testing::Mock::$method(
114 internal::ImplicitCast_<MockClass*>(this));
117 // C++98 doesn't have variadic templates, so we have to define one
119 template <typename A1>
120 explicit $clazz(const A1& a1) : MockClass(a1) {
121 ::testing::Mock::$method(
122 internal::ImplicitCast_<MockClass*>(this));
128 template <$for j, [[typename A$j]]>
129 $clazz($for j, [[const A$j& a$j]]) : MockClass($for j, [[a$j]]) {
130 ::testing::Mock::$method(
131 internal::ImplicitCast_<MockClass*>(this));
136 #endif // GTEST_LANG_CXX11
139 ::testing::Mock::UnregisterCallReaction(
140 internal::ImplicitCast_<MockClass*>(this));
144 GTEST_DISALLOW_COPY_AND_ASSIGN_($clazz);
149 // The following specializations catch some (relatively more common)
150 // user errors of nesting nice and strict mocks. They do NOT catch
151 // all possible errors.
153 // These specializations are declared but not defined, as NiceMock,
154 // NaggyMock, and StrictMock cannot be nested.
156 template <typename MockClass>
157 class NiceMock<NiceMock<MockClass> >;
158 template <typename MockClass>
159 class NiceMock<NaggyMock<MockClass> >;
160 template <typename MockClass>
161 class NiceMock<StrictMock<MockClass> >;
163 template <typename MockClass>
164 class NaggyMock<NiceMock<MockClass> >;
165 template <typename MockClass>
166 class NaggyMock<NaggyMock<MockClass> >;
167 template <typename MockClass>
168 class NaggyMock<StrictMock<MockClass> >;
170 template <typename MockClass>
171 class StrictMock<NiceMock<MockClass> >;
172 template <typename MockClass>
173 class StrictMock<NaggyMock<MockClass> >;
174 template <typename MockClass>
175 class StrictMock<StrictMock<MockClass> >;
177 } // namespace testing
179 #endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_