63 #ifndef GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_NICE_STRICT_H_ 64 #define GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_NICE_STRICT_H_ 66 #include <type_traits> 68 #include "gmock/gmock-spec-builders.h" 69 #include "gmock/internal/gmock-port.h" 72 template <
class MockClass>
74 template <
class MockClass>
76 template <
class MockClass>
81 std::true_type StrictnessModifierProbe(
const NiceMock<T>&);
83 std::true_type StrictnessModifierProbe(
const NaggyMock<T>&);
85 std::true_type StrictnessModifierProbe(
const StrictMock<T>&);
86 std::false_type StrictnessModifierProbe(...);
89 constexpr
bool HasStrictnessModifier() {
90 return decltype(StrictnessModifierProbe(std::declval<const T&>()))::value;
100 #if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MINGW && \ 101 (defined(_MSC_VER) || defined(__clang__)) 104 #define GTEST_INTERNAL_EMPTY_BASE_CLASS __declspec(empty_bases) 106 #define GTEST_INTERNAL_EMPTY_BASE_CLASS 109 template <
typename Base>
112 NiceMockImpl() { ::testing::Mock::AllowUninterestingCalls(
this); }
114 ~NiceMockImpl() { ::testing::Mock::UnregisterCallReaction(
this); }
117 template <
typename Base>
118 class NaggyMockImpl {
120 NaggyMockImpl() { ::testing::Mock::WarnUninterestingCalls(
this); }
122 ~NaggyMockImpl() { ::testing::Mock::UnregisterCallReaction(
this); }
125 template <
typename Base>
126 class StrictMockImpl {
128 StrictMockImpl() { ::testing::Mock::FailUninterestingCalls(
this); }
130 ~StrictMockImpl() { ::testing::Mock::UnregisterCallReaction(
this); }
135 template <
class MockClass>
136 class GTEST_INTERNAL_EMPTY_BASE_CLASS NiceMock
137 :
private internal::NiceMockImpl<MockClass>,
140 static_assert(!internal::HasStrictnessModifier<MockClass>(),
141 "Can't apply NiceMock to a class hierarchy that already has a " 142 "strictness modifier. See " 143 "https://google.github.io/googletest/" 144 "gmock_cook_book.html#NiceStrictNaggy");
145 NiceMock() : MockClass() {
146 static_assert(
sizeof(*
this) ==
sizeof(MockClass),
147 "The impl subclass shouldn't introduce any padding");
157 template <
typename A>
158 explicit NiceMock(A&& arg) : MockClass(
std::forward<A>(arg)) {
159 static_assert(
sizeof(*
this) ==
sizeof(MockClass),
160 "The impl subclass shouldn't introduce any padding");
163 template <
typename TArg1,
typename TArg2,
typename... An>
164 NiceMock(TArg1&& arg1, TArg2&& arg2, An&&... args)
165 : MockClass(
std::forward<TArg1>(arg1),
std::forward<TArg2>(arg2),
166 std::forward<An>(args)...) {
167 static_assert(
sizeof(*
this) ==
sizeof(MockClass),
168 "The impl subclass shouldn't introduce any padding");
172 GTEST_DISALLOW_COPY_AND_ASSIGN_(NiceMock);
175 template <
class MockClass>
176 class GTEST_INTERNAL_EMPTY_BASE_CLASS NaggyMock
177 :
private internal::NaggyMockImpl<MockClass>,
179 static_assert(!internal::HasStrictnessModifier<MockClass>(),
180 "Can't apply NaggyMock to a class hierarchy that already has a " 181 "strictness modifier. See " 182 "https://google.github.io/googletest/" 183 "gmock_cook_book.html#NiceStrictNaggy");
186 NaggyMock() : MockClass() {
187 static_assert(
sizeof(*
this) ==
sizeof(MockClass),
188 "The impl subclass shouldn't introduce any padding");
198 template <
typename A>
199 explicit NaggyMock(A&& arg) : MockClass(
std::forward<A>(arg)) {
200 static_assert(
sizeof(*
this) ==
sizeof(MockClass),
201 "The impl subclass shouldn't introduce any padding");
204 template <
typename TArg1,
typename TArg2,
typename... An>
205 NaggyMock(TArg1&& arg1, TArg2&& arg2, An&&... args)
206 : MockClass(
std::forward<TArg1>(arg1),
std::forward<TArg2>(arg2),
207 std::forward<An>(args)...) {
208 static_assert(
sizeof(*
this) ==
sizeof(MockClass),
209 "The impl subclass shouldn't introduce any padding");
213 GTEST_DISALLOW_COPY_AND_ASSIGN_(NaggyMock);
216 template <
class MockClass>
217 class GTEST_INTERNAL_EMPTY_BASE_CLASS StrictMock
218 :
private internal::StrictMockImpl<MockClass>,
222 !internal::HasStrictnessModifier<MockClass>(),
223 "Can't apply StrictMock to a class hierarchy that already has a " 224 "strictness modifier. See " 225 "https://google.github.io/googletest/" 226 "gmock_cook_book.html#NiceStrictNaggy");
227 StrictMock() : MockClass() {
228 static_assert(
sizeof(*
this) ==
sizeof(MockClass),
229 "The impl subclass shouldn't introduce any padding");
239 template <
typename A>
240 explicit StrictMock(A&& arg) : MockClass(
std::forward<A>(arg)) {
241 static_assert(
sizeof(*
this) ==
sizeof(MockClass),
242 "The impl subclass shouldn't introduce any padding");
245 template <
typename TArg1,
typename TArg2,
typename... An>
246 StrictMock(TArg1&& arg1, TArg2&& arg2, An&&... args)
247 : MockClass(
std::forward<TArg1>(arg1),
std::forward<TArg2>(arg2),
248 std::forward<An>(args)...) {
249 static_assert(
sizeof(*
this) ==
sizeof(MockClass),
250 "The impl subclass shouldn't introduce any padding");
254 GTEST_DISALLOW_COPY_AND_ASSIGN_(StrictMock);
257 #undef GTEST_INTERNAL_EMPTY_BASE_CLASS 261 #endif // GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_NICE_STRICT_H_ Definition: gmock-actions.h:154
Definition: gtest-internal.h:1322