Added Mock::IsNaggy, IsNice, and IsStrict
This commit is contained in:
		
							parent
							
								
									d12a26a19d
								
							
						
					
					
						commit
						7014070b27
					
				@ -389,6 +389,16 @@ class GTEST_API_ Mock {
 | 
				
			|||||||
  static bool VerifyAndClear(void* mock_obj)
 | 
					  static bool VerifyAndClear(void* mock_obj)
 | 
				
			||||||
      GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
 | 
					      GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Returns wether the mock was created as a naggy mock (default)
 | 
				
			||||||
 | 
					  static bool IsNaggy(void* mock_obj)
 | 
				
			||||||
 | 
					      GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
 | 
				
			||||||
 | 
					  // Returns wether the mock was created as a nice mock
 | 
				
			||||||
 | 
					  static bool IsNice(void* mock_obj)
 | 
				
			||||||
 | 
					      GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
 | 
				
			||||||
 | 
					  // Returns wether the mock was created as a strict mock
 | 
				
			||||||
 | 
					  static bool IsStrict(void* mock_obj)
 | 
				
			||||||
 | 
					      GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 private:
 | 
					 private:
 | 
				
			||||||
  friend class internal::UntypedFunctionMockerBase;
 | 
					  friend class internal::UntypedFunctionMockerBase;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -707,6 +707,35 @@ bool Mock::VerifyAndClearExpectationsLocked(void* mock_obj)
 | 
				
			|||||||
  return expectations_met;
 | 
					  return expectations_met;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace {
 | 
				
			||||||
 | 
					// checks whether the specified mock_obj has a registered call reaction
 | 
				
			||||||
 | 
					bool HasCallReaction(void* mock_obj, internal::CallReaction reaction) {
 | 
				
			||||||
 | 
					  using internal::CallReaction;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  const auto found = g_uninteresting_call_reaction.find(mock_obj);
 | 
				
			||||||
 | 
					  if (found == g_uninteresting_call_reaction.cend()) {
 | 
				
			||||||
 | 
					    return internal::CallReaction::kDefault == reaction;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  return found->second == reaction;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					bool Mock::IsNaggy(void* mock_obj)
 | 
				
			||||||
 | 
					    GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) {
 | 
				
			||||||
 | 
					  internal::MutexLock l(&internal::g_gmock_mutex);
 | 
				
			||||||
 | 
					  return HasCallReaction(mock_obj, internal::CallReaction::kWarn);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					bool Mock::IsNice(void* mock_obj)
 | 
				
			||||||
 | 
					    GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) {
 | 
				
			||||||
 | 
					  internal::MutexLock l(&internal::g_gmock_mutex);
 | 
				
			||||||
 | 
					  return HasCallReaction(mock_obj, internal::CallReaction::kAllow);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					bool Mock::IsStrict(void* mock_obj)
 | 
				
			||||||
 | 
					    GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) {
 | 
				
			||||||
 | 
					  internal::MutexLock l(&internal::g_gmock_mutex);
 | 
				
			||||||
 | 
					  return HasCallReaction(mock_obj, internal::CallReaction::kFail);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Registers a mock object and a mock method it owns.
 | 
					// Registers a mock object and a mock method it owns.
 | 
				
			||||||
void Mock::Register(const void* mock_obj,
 | 
					void Mock::Register(const void* mock_obj,
 | 
				
			||||||
                    internal::UntypedFunctionMockerBase* mocker)
 | 
					                    internal::UntypedFunctionMockerBase* mocker)
 | 
				
			||||||
 | 
				
			|||||||
@ -160,6 +160,15 @@ TEST(RawMockTest, InfoForUninterestingCall) {
 | 
				
			|||||||
  GMOCK_FLAG(verbose) = saved_flag;
 | 
					  GMOCK_FLAG(verbose) = saved_flag;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					TEST(RawMockTest, IsNaggy_IsNice_IsStrict) {
 | 
				
			||||||
 | 
					  using internal::CallReaction;
 | 
				
			||||||
 | 
					  MockFoo raw_foo;
 | 
				
			||||||
 | 
					  ASSERT_EQ(CallReaction::kDefault, CallReaction::kWarn) << "precondition";
 | 
				
			||||||
 | 
					  EXPECT_TRUE (Mock::IsNaggy(&raw_foo));
 | 
				
			||||||
 | 
					  EXPECT_FALSE(Mock::IsNice(&raw_foo));
 | 
				
			||||||
 | 
					  EXPECT_FALSE(Mock::IsStrict(&raw_foo));
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Tests that a nice mock generates no warning for uninteresting calls.
 | 
					// Tests that a nice mock generates no warning for uninteresting calls.
 | 
				
			||||||
TEST(NiceMockTest, NoWarningForUninterestingCall) {
 | 
					TEST(NiceMockTest, NoWarningForUninterestingCall) {
 | 
				
			||||||
  NiceMock<MockFoo> nice_foo;
 | 
					  NiceMock<MockFoo> nice_foo;
 | 
				
			||||||
@ -253,6 +262,13 @@ TEST(NiceMockTest, AcceptsClassNamedMock) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
#endif  // !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE
 | 
					#endif  // !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					TEST(NiceMockTest, IsNaggy_IsNice_IsStrict) {
 | 
				
			||||||
 | 
					  NiceMock<MockFoo> nice_foo;
 | 
				
			||||||
 | 
					  EXPECT_FALSE(Mock::IsNaggy(&nice_foo));
 | 
				
			||||||
 | 
					  EXPECT_TRUE (Mock::IsNice(&nice_foo));
 | 
				
			||||||
 | 
					  EXPECT_FALSE(Mock::IsStrict(&nice_foo));
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if GTEST_HAS_STREAM_REDIRECTION
 | 
					#if GTEST_HAS_STREAM_REDIRECTION
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Tests that a naggy mock generates warnings for uninteresting calls.
 | 
					// Tests that a naggy mock generates warnings for uninteresting calls.
 | 
				
			||||||
@ -346,6 +362,13 @@ TEST(NaggyMockTest, AcceptsClassNamedMock) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
#endif  // !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE
 | 
					#endif  // !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					TEST(NaggyMockTest, IsNaggy_IsNice_IsStrict) {
 | 
				
			||||||
 | 
					  NaggyMock<MockFoo> naggy_foo;
 | 
				
			||||||
 | 
					  EXPECT_TRUE (Mock::IsNaggy(&naggy_foo));
 | 
				
			||||||
 | 
					  EXPECT_FALSE(Mock::IsNice(&naggy_foo));
 | 
				
			||||||
 | 
					  EXPECT_FALSE(Mock::IsStrict(&naggy_foo));
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Tests that a strict mock allows expected calls.
 | 
					// Tests that a strict mock allows expected calls.
 | 
				
			||||||
TEST(StrictMockTest, AllowsExpectedCall) {
 | 
					TEST(StrictMockTest, AllowsExpectedCall) {
 | 
				
			||||||
  StrictMock<MockFoo> strict_foo;
 | 
					  StrictMock<MockFoo> strict_foo;
 | 
				
			||||||
@ -420,5 +443,12 @@ TEST(StrictMockTest, AcceptsClassNamedMock) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
#endif  // !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE
 | 
					#endif  // !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					TEST(StrictMockTest, IsNaggy_IsNice_IsStrict) {
 | 
				
			||||||
 | 
					  StrictMock<MockFoo> strict_foo;
 | 
				
			||||||
 | 
					  EXPECT_FALSE(Mock::IsNaggy(&strict_foo));
 | 
				
			||||||
 | 
					  EXPECT_FALSE(Mock::IsNice(&strict_foo));
 | 
				
			||||||
 | 
					  EXPECT_TRUE (Mock::IsStrict(&strict_foo));
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}  // namespace gmock_nice_strict_test
 | 
					}  // namespace gmock_nice_strict_test
 | 
				
			||||||
}  // namespace testing
 | 
					}  // namespace testing
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user