123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261 |
- #ifndef GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_NICE_STRICT_H_
- #define GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_NICE_STRICT_H_
- #include <type_traits>
- #include "gmock/gmock-spec-builders.h"
- #include "gmock/internal/gmock-port.h"
- namespace testing {
- template <class MockClass>
- class NiceMock;
- template <class MockClass>
- class NaggyMock;
- template <class MockClass>
- class StrictMock;
- namespace internal {
- template <typename T>
- std::true_type StrictnessModifierProbe(const NiceMock<T>&);
- template <typename T>
- std::true_type StrictnessModifierProbe(const NaggyMock<T>&);
- template <typename T>
- std::true_type StrictnessModifierProbe(const StrictMock<T>&);
- std::false_type StrictnessModifierProbe(...);
- template <typename T>
- constexpr bool HasStrictnessModifier() {
- return decltype(StrictnessModifierProbe(std::declval<const T&>()))::value;
- }
- #if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MINGW && \
- (defined(_MSC_VER) || defined(__clang__))
- #define GTEST_INTERNAL_EMPTY_BASE_CLASS __declspec(empty_bases)
- #else
- #define GTEST_INTERNAL_EMPTY_BASE_CLASS
- #endif
- template <typename Base>
- class NiceMockImpl {
- public:
- NiceMockImpl() { ::testing::Mock::AllowUninterestingCalls(this); }
- ~NiceMockImpl() { ::testing::Mock::UnregisterCallReaction(this); }
- };
- template <typename Base>
- class NaggyMockImpl {
- public:
- NaggyMockImpl() { ::testing::Mock::WarnUninterestingCalls(this); }
- ~NaggyMockImpl() { ::testing::Mock::UnregisterCallReaction(this); }
- };
- template <typename Base>
- class StrictMockImpl {
- public:
- StrictMockImpl() { ::testing::Mock::FailUninterestingCalls(this); }
- ~StrictMockImpl() { ::testing::Mock::UnregisterCallReaction(this); }
- };
- }
- template <class MockClass>
- class GTEST_INTERNAL_EMPTY_BASE_CLASS NiceMock
- : private internal::NiceMockImpl<MockClass>,
- public MockClass {
- public:
- static_assert(!internal::HasStrictnessModifier<MockClass>(),
- "Can't apply NiceMock to a class hierarchy that already has a "
- "strictness modifier. See "
- "https://google.github.io/googletest/"
- "gmock_cook_book.html#NiceStrictNaggy");
- NiceMock() : MockClass() {
- static_assert(sizeof(*this) == sizeof(MockClass),
- "The impl subclass shouldn't introduce any padding");
- }
-
-
-
-
-
-
- template <typename A>
- explicit NiceMock(A&& arg) : MockClass(std::forward<A>(arg)) {
- static_assert(sizeof(*this) == sizeof(MockClass),
- "The impl subclass shouldn't introduce any padding");
- }
- template <typename TArg1, typename TArg2, typename... An>
- NiceMock(TArg1&& arg1, TArg2&& arg2, An&&... args)
- : MockClass(std::forward<TArg1>(arg1), std::forward<TArg2>(arg2),
- std::forward<An>(args)...) {
- static_assert(sizeof(*this) == sizeof(MockClass),
- "The impl subclass shouldn't introduce any padding");
- }
- private:
- GTEST_DISALLOW_COPY_AND_ASSIGN_(NiceMock);
- };
- template <class MockClass>
- class GTEST_INTERNAL_EMPTY_BASE_CLASS NaggyMock
- : private internal::NaggyMockImpl<MockClass>,
- public MockClass {
- static_assert(!internal::HasStrictnessModifier<MockClass>(),
- "Can't apply NaggyMock to a class hierarchy that already has a "
- "strictness modifier. See "
- "https://google.github.io/googletest/"
- "gmock_cook_book.html#NiceStrictNaggy");
- public:
- NaggyMock() : MockClass() {
- static_assert(sizeof(*this) == sizeof(MockClass),
- "The impl subclass shouldn't introduce any padding");
- }
-
-
-
-
-
-
- template <typename A>
- explicit NaggyMock(A&& arg) : MockClass(std::forward<A>(arg)) {
- static_assert(sizeof(*this) == sizeof(MockClass),
- "The impl subclass shouldn't introduce any padding");
- }
- template <typename TArg1, typename TArg2, typename... An>
- NaggyMock(TArg1&& arg1, TArg2&& arg2, An&&... args)
- : MockClass(std::forward<TArg1>(arg1), std::forward<TArg2>(arg2),
- std::forward<An>(args)...) {
- static_assert(sizeof(*this) == sizeof(MockClass),
- "The impl subclass shouldn't introduce any padding");
- }
- private:
- GTEST_DISALLOW_COPY_AND_ASSIGN_(NaggyMock);
- };
- template <class MockClass>
- class GTEST_INTERNAL_EMPTY_BASE_CLASS StrictMock
- : private internal::StrictMockImpl<MockClass>,
- public MockClass {
- public:
- static_assert(
- !internal::HasStrictnessModifier<MockClass>(),
- "Can't apply StrictMock to a class hierarchy that already has a "
- "strictness modifier. See "
- "https://google.github.io/googletest/"
- "gmock_cook_book.html#NiceStrictNaggy");
- StrictMock() : MockClass() {
- static_assert(sizeof(*this) == sizeof(MockClass),
- "The impl subclass shouldn't introduce any padding");
- }
-
-
-
-
-
-
- template <typename A>
- explicit StrictMock(A&& arg) : MockClass(std::forward<A>(arg)) {
- static_assert(sizeof(*this) == sizeof(MockClass),
- "The impl subclass shouldn't introduce any padding");
- }
- template <typename TArg1, typename TArg2, typename... An>
- StrictMock(TArg1&& arg1, TArg2&& arg2, An&&... args)
- : MockClass(std::forward<TArg1>(arg1), std::forward<TArg2>(arg2),
- std::forward<An>(args)...) {
- static_assert(sizeof(*this) == sizeof(MockClass),
- "The impl subclass shouldn't introduce any padding");
- }
- private:
- GTEST_DISALLOW_COPY_AND_ASSIGN_(StrictMock);
- };
- #undef GTEST_INTERNAL_EMPTY_BASE_CLASS
- }
- #endif
|