Debian Codegraph @

src/external/googletest/googlemock/include/gmock/gmock-nice-strict.h

raw symbols SCIP
1 // Copyright 2008, Google Inc.cxx . . $ `<file>/src/external/googletest/googlemock/include/gmock/gmock-nice-strict.h`/
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above
11 // copyright notice, this list of conditions and the following disclaimer
12 // in the documentation and/or other materials provided with the
13 // distribution.
14 // * Neither the name of Google Inc. nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30 // Implements class templates NiceMock, NaggyMock, and StrictMock.
31 //
32 // Given a mock class MockFoo that is created using Google Mock,
33 // NiceMock<MockFoo> is a subclass of MockFoo that allows
34 // uninteresting calls (i.e. calls to mock methods that have no
35 // EXPECT_CALL specs), NaggyMock<MockFoo> is a subclass of MockFoo
36 // that prints a warning when an uninteresting call occurs, and
37 // StrictMock<MockFoo> is a subclass of MockFoo that treats all
38 // uninteresting calls as errors.
39 //
40 // Currently a mock is naggy by default, so MockFoo and
41 // NaggyMock<MockFoo> behave like the same. However, we will soon
42 // switch the default behavior of mocks to be nice, as that in general
43 // leads to more maintainable tests. When that happens, MockFoo will
44 // stop behaving like NaggyMock<MockFoo> and start behaving like
45 // NiceMock<MockFoo>.
46 //
47 // NiceMock, NaggyMock, and StrictMock "inherit" the constructors of
48 // their respective base class. Therefore you can write
49 // NiceMock<MockFoo>(5, "a") to construct a nice mock where MockFoo
50 // has a constructor that accepts (int, const char*), for example.
51 //
52 // A known limitation is that NiceMock<MockFoo>, NaggyMock<MockFoo>,
53 // and StrictMock<MockFoo> only works for mock methods defined using
54 // the MOCK_METHOD* family of macros DIRECTLY in the MockFoo class.
55 // If a mock method is defined in a base class of MockFoo, the "nice"
56 // or "strict" modifier may not affect it, depending on the compiler.
57 // In particular, nesting NiceMock, NaggyMock, and StrictMock is NOT
58 // supported.
59
60 // IWYU pragma: private, include "gmock/gmock.h"
61 // IWYU pragma: friend gmock/.*
62
63 #ifndef GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_NICE_STRICT_H_
64 #define GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_NICE_STRICT_H_cxx . . $ `src/external/googletest/googlemock/include/gmock/gmock-nice-strict.h:64:9`!
65
66 #include <cstdint>
67 #include <type_traits>
68
69 #include "gmock/gmock-spec-builders.h"cxx . . $ `<file>/src/external/googletest/googlemock/include/gmock/gmock-spec-builders.h`/
70 #include "gmock/internal/gmock-port.h"cxx . . $ `<file>/src/external/googletest/googlemock/include/gmock/internal/gmock-port.h`/
71
72 namespace testingcxx . . $ testing/ {
73 template <class MockClass>
74 class NiceMockcxx . . $ testing/NiceMock#;
75 template <class MockClass>
76 class NaggyMockcxx . . $ testing/NaggyMock#;
77 template <class MockClass>
78 class StrictMockcxx . . $ testing/StrictMock#;
79
80 namespace internalcxx . . $ testing/internal/ {
81 template <typename T>
82 stdcxx . . $ std/::true_type StrictnessModifierProbecxx . . $ testing/internal/StrictnessModifierProbe(1ff74a8a14bd24c3).(const NiceMockcxx . . $ testing/NiceMock#<T>&);
83 template <typename T>
84 stdcxx . . $ std/::true_type StrictnessModifierProbecxx . . $ testing/internal/StrictnessModifierProbe(31351117a4fdd02d).(const NaggyMockcxx . . $ testing/NaggyMock#<T>&);
85 template <typename T>
86 stdcxx . . $ std/::true_type StrictnessModifierProbecxx . . $ testing/internal/StrictnessModifierProbe(ce152463a50fb2fb).(const StrictMockcxx . . $ testing/StrictMock#<T>&);
87 stdcxx . . $ std/::false_type StrictnessModifierProbecxx . . $ testing/internal/StrictnessModifierProbe(8dc8d43ad6747387).(...);
88
89 template <typename T>
90 constexpr bool HasStrictnessModifiercxx . . $ testing/internal/HasStrictnessModifier(c9857a73d68e59ba).() {
91 return decltype(StrictnessModifierProbe(std::declval<const T&>()))::value;
92 }
93
94 // Base classes that register and deregister with testing::Mock to alter the
95 // default behavior around uninteresting calls. Inheriting from one of these
96 // classes first and then MockClass ensures the MockClass constructor is run
97 // after registration, and that the MockClass destructor runs before
98 // deregistration. This guarantees that MockClass's constructor and destructor
99 // run with the same level of strictness as its instance methods.
100
101 #if defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_WINDOWS_MINGW) && \
102 (defined(_MSC_VER) || defined(__clang__cxx . . $ `<built-in>:3:9`!))
103 // We need to mark these classes with this declspec to ensure that
104 // the empty base class optimization is performed.
105 #define GTEST_INTERNAL_EMPTY_BASE_CLASS __declspec(empty_bases)
106 #else
107 #define GTEST_INTERNAL_EMPTY_BASE_CLASScxx . . $ `src/external/googletest/googlemock/include/gmock/gmock-nice-strict.h:107:9`!
108 #endif
109
110 template <typename Base>
111 class NiceMockImplcxx . . $ testing/internal/NiceMockImpl# {
112 public:
113 NiceMockImplcxx . . $ testing/internal/NiceMockImpl#`NiceMockImpl<MockClass>`(49f6e7a06ebc5aa8).() {
114 ::testingcxx . . $ testing/::Mockcxx . . $ testing/Mock#::AllowUninterestingCallscxx . . $ testing/Mock#AllowUninterestingCalls(2c44cd906ae4e829).(reinterpret_cast<uintptr_tcxx . . $ uintptr_t#>(this));
115 }
116
117 ~cxx . . $ testing/internal/NiceMockImpl#`~NiceMockImpl<MockClass>`(49f6e7a06ebc5aa8).NiceMockImpl() {
118 ::testingcxx . . $ testing/::Mockcxx . . $ testing/Mock#::UnregisterCallReactioncxx . . $ testing/Mock#UnregisterCallReaction(2c44cd906ae4e829).(reinterpret_cast<uintptr_tcxx . . $ uintptr_t#>(this));
119 }
120 };
121
122 template <typename Base>
123 class NaggyMockImplcxx . . $ testing/internal/NaggyMockImpl# {
124 public:
125 NaggyMockImplcxx . . $ testing/internal/NaggyMockImpl#`NaggyMockImpl<MockClass>`(49f6e7a06ebc5aa8).() {
126 ::testingcxx . . $ testing/::Mockcxx . . $ testing/Mock#::WarnUninterestingCallscxx . . $ testing/Mock#WarnUninterestingCalls(2c44cd906ae4e829).(reinterpret_cast<uintptr_tcxx . . $ uintptr_t#>(this));
127 }
128
129 ~cxx . . $ testing/internal/NaggyMockImpl#`~NaggyMockImpl<MockClass>`(49f6e7a06ebc5aa8).NaggyMockImpl() {
130 ::testingcxx . . $ testing/::Mockcxx . . $ testing/Mock#::UnregisterCallReactioncxx . . $ testing/Mock#UnregisterCallReaction(2c44cd906ae4e829).(reinterpret_cast<uintptr_tcxx . . $ uintptr_t#>(this));
131 }
132 };
133
134 template <typename Base>
135 class StrictMockImplcxx . . $ testing/internal/StrictMockImpl# {
136 public:
137 StrictMockImplcxx . . $ testing/internal/StrictMockImpl#`StrictMockImpl<MockClass>`(49f6e7a06ebc5aa8).() {
138 ::testingcxx . . $ testing/::Mockcxx . . $ testing/Mock#::FailUninterestingCallscxx . . $ testing/Mock#FailUninterestingCalls(2c44cd906ae4e829).(reinterpret_cast<uintptr_tcxx . . $ uintptr_t#>(this));
139 }
140
141 ~cxx . . $ testing/internal/StrictMockImpl#`~StrictMockImpl<MockClass>`(49f6e7a06ebc5aa8).StrictMockImpl() {
142 ::testingcxx . . $ testing/::Mockcxx . . $ testing/Mock#::UnregisterCallReactioncxx . . $ testing/Mock#UnregisterCallReaction(2c44cd906ae4e829).(reinterpret_cast<uintptr_tcxx . . $ uintptr_t#>(this));
143 }
144 };
145
146 } // namespace internal
147
148 template <class MockClass>
149 class GTEST_INTERNAL_EMPTY_BASE_CLASScxx . . $ `src/external/googletest/googlemock/include/gmock/gmock-nice-strict.h:107:9`! NiceMockcxx . . $ testing/NiceMock#
150 : private internalcxx . . $ testing/internal/::NiceMockImplcxx . . $ testing/internal/NiceMockImpl#<MockClass>,
151 public MockClass {
152 public:
153 static_assert(!internalcxx . . $ testing/internal/::HasStrictnessModifiercxx . . $ testing/internal/HasStrictnessModifier(c9857a73d68e59ba).<MockClass>(),
154 "Can't apply NiceMock to a class hierarchy that already has a "
155 "strictness modifier. See "
156 "https://google.github.io/googletest/"
157 "gmock_cook_book.html#NiceStrictNaggy");
158 NiceMockcxx . . $ testing/NiceMock#`NiceMock<MockClass>`(49f6e7a06ebc5aa8).() : MockClass() {
159 static_assert(sizeof(*this) == sizeof(MockClass),
160 "The impl subclass shouldn't introduce any padding");
161 }
162
163 // Ideally, we would inherit base class's constructors through a using
164 // declaration, which would preserve their visibility. However, many existing
165 // tests rely on the fact that current implementation reexports protected
166 // constructors as public. These tests would need to be cleaned up first.
167
168 // Single argument constructor is special-cased so that it can be
169 // made explicit.
170 template <typename A>
171 explicit NiceMockcxx . . $ testing/NiceMock#`NiceMock<MockClass>`(4f6c0277e8680150).(A&& arg) : MockClass(stdcxx . . $ std/::forwardcxx . . $ std/forward(f56228ea88711827).<A>(arg)) {
172 static_assert(sizeof(*this) == sizeof(MockClass),
173 "The impl subclass shouldn't introduce any padding");
174 }
175
176 template <typename TArg1, typename TArg2, typename... An>
177 NiceMockcxx . . $ testing/NiceMock#`NiceMock<MockClass>`(19960202ebf9a3ff).(TArg1&& arg1, TArg2&& arg2, An&&... args)
178 : MockClass(stdcxx . . $ std/::forwardcxx . . $ std/forward(f56228ea88711827).<TArg1>(arg1), stdcxx . . $ std/::forwardcxx . . $ std/forward(f56228ea88711827).<TArg2>(arg2),
179 stdcxx . . $ std/::forwardcxx . . $ std/forward(f56228ea88711827).<An>(args)...) {
180 static_assert(sizeof(*this) == sizeof(MockClass),
181 "The impl subclass shouldn't introduce any padding");
182 }
183
184 private:
185 NiceMockcxx . . $ testing/NiceMock#`NiceMock<MockClass>`(89a6695487ee5f12).(const NiceMock&) = delete;
186 NiceMock& operatorcxx . . $ testing/NiceMock#`operator=`(49c9fb250d6e759c).=(const NiceMock&) = delete;
187 };
188
189 template <class MockClass>
190 class GTEST_INTERNAL_EMPTY_BASE_CLASScxx . . $ `src/external/googletest/googlemock/include/gmock/gmock-nice-strict.h:107:9`! NaggyMockcxx . . $ testing/NaggyMock#
191 : private internalcxx . . $ testing/internal/::NaggyMockImplcxx . . $ testing/internal/NaggyMockImpl#<MockClass>,
192 public MockClass {
193 static_assert(!internalcxx . . $ testing/internal/::HasStrictnessModifiercxx . . $ testing/internal/HasStrictnessModifier(c9857a73d68e59ba).<MockClass>(),
194 "Can't apply NaggyMock to a class hierarchy that already has a "
195 "strictness modifier. See "
196 "https://google.github.io/googletest/"
197 "gmock_cook_book.html#NiceStrictNaggy");
198
199 public:
200 NaggyMockcxx . . $ testing/NaggyMock#`NaggyMock<MockClass>`(49f6e7a06ebc5aa8).() : MockClass() {
201 static_assert(sizeof(*this) == sizeof(MockClass),
202 "The impl subclass shouldn't introduce any padding");
203 }
204
205 // Ideally, we would inherit base class's constructors through a using
206 // declaration, which would preserve their visibility. However, many existing
207 // tests rely on the fact that current implementation reexports protected
208 // constructors as public. These tests would need to be cleaned up first.
209
210 // Single argument constructor is special-cased so that it can be
211 // made explicit.
212 template <typename A>
213 explicit NaggyMockcxx . . $ testing/NaggyMock#`NaggyMock<MockClass>`(4f6c0277e8680150).(A&& arg) : MockClass(stdcxx . . $ std/::forwardcxx . . $ std/forward(f56228ea88711827).<A>(arg)) {
214 static_assert(sizeof(*this) == sizeof(MockClass),
215 "The impl subclass shouldn't introduce any padding");
216 }
217
218 template <typename TArg1, typename TArg2, typename... An>
219 NaggyMockcxx . . $ testing/NaggyMock#`NaggyMock<MockClass>`(19960202ebf9a3ff).(TArg1&& arg1, TArg2&& arg2, An&&... args)
220 : MockClass(stdcxx . . $ std/::forwardcxx . . $ std/forward(f56228ea88711827).<TArg1>(arg1), stdcxx . . $ std/::forwardcxx . . $ std/forward(f56228ea88711827).<TArg2>(arg2),
221 stdcxx . . $ std/::forwardcxx . . $ std/forward(f56228ea88711827).<An>(args)...) {
222 static_assert(sizeof(*this) == sizeof(MockClass),
223 "The impl subclass shouldn't introduce any padding");
224 }
225
226 private:
227 NaggyMockcxx . . $ testing/NaggyMock#`NaggyMock<MockClass>`(443dacefb68a959).(const NaggyMock&) = delete;
228 NaggyMock& operatorcxx . . $ testing/NaggyMock#`operator=`(3e3b603b2bcf3ec2).=(const NaggyMock&) = delete;
229 };
230
231 template <class MockClass>
232 class GTEST_INTERNAL_EMPTY_BASE_CLASScxx . . $ `src/external/googletest/googlemock/include/gmock/gmock-nice-strict.h:107:9`! StrictMockcxx . . $ testing/StrictMock#
233 : private internalcxx . . $ testing/internal/::StrictMockImplcxx . . $ testing/internal/StrictMockImpl#<MockClass>,
234 public MockClass {
235 public:
236 static_assert(
237 !internalcxx . . $ testing/internal/::HasStrictnessModifiercxx . . $ testing/internal/HasStrictnessModifier(c9857a73d68e59ba).<MockClass>(),
238 "Can't apply StrictMock to a class hierarchy that already has a "
239 "strictness modifier. See "
240 "https://google.github.io/googletest/"
241 "gmock_cook_book.html#NiceStrictNaggy");
242 StrictMockcxx . . $ testing/StrictMock#`StrictMock<MockClass>`(49f6e7a06ebc5aa8).() : MockClass() {
243 static_assert(sizeof(*this) == sizeof(MockClass),
244 "The impl subclass shouldn't introduce any padding");
245 }
246
247 // Ideally, we would inherit base class's constructors through a using
248 // declaration, which would preserve their visibility. However, many existing
249 // tests rely on the fact that current implementation reexports protected
250 // constructors as public. These tests would need to be cleaned up first.
251
252 // Single argument constructor is special-cased so that it can be
253 // made explicit.
254 template <typename A>
255 explicit StrictMockcxx . . $ testing/StrictMock#`StrictMock<MockClass>`(4f6c0277e8680150).(A&& arg) : MockClass(stdcxx . . $ std/::forwardcxx . . $ std/forward(f56228ea88711827).<A>(arg)) {
256 static_assert(sizeof(*this) == sizeof(MockClass),
257 "The impl subclass shouldn't introduce any padding");
258 }
259
260 template <typename TArg1, typename TArg2, typename... An>
261 StrictMockcxx . . $ testing/StrictMock#`StrictMock<MockClass>`(19960202ebf9a3ff).(TArg1&& arg1, TArg2&& arg2, An&&... args)
262 : MockClass(stdcxx . . $ std/::forwardcxx . . $ std/forward(f56228ea88711827).<TArg1>(arg1), stdcxx . . $ std/::forwardcxx . . $ std/forward(f56228ea88711827).<TArg2>(arg2),
263 stdcxx . . $ std/::forwardcxx . . $ std/forward(f56228ea88711827).<An>(args)...) {
264 static_assert(sizeof(*this) == sizeof(MockClass),
265 "The impl subclass shouldn't introduce any padding");
266 }
267
268 private:
269 StrictMockcxx . . $ testing/StrictMock#`StrictMock<MockClass>`(f14cb0075ff77dee).(const StrictMock&) = delete;
270 StrictMock& operatorcxx . . $ testing/StrictMock#`operator=`(ebe09f74637d6f62).=(const StrictMock&) = delete;
271 };
272
273 #undef GTEST_INTERNAL_EMPTY_BASE_CLASScxx . . $ `src/external/googletest/googlemock/include/gmock/gmock-nice-strict.h:107:9`!
274
275 } // namespace testing
276
277 #endif // GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_NICE_STRICT_H_