Adding a flag option to change the default mock type
This commit is contained in:
		@@ -648,7 +648,8 @@ internal::CallReaction Mock::GetReactionOnUninterestingCalls(
 | 
			
		||||
        GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) {
 | 
			
		||||
  internal::MutexLock l(&internal::g_gmock_mutex);
 | 
			
		||||
  return (g_uninteresting_call_reaction.count(mock_obj) == 0) ?
 | 
			
		||||
      internal::kDefault : g_uninteresting_call_reaction[mock_obj];
 | 
			
		||||
      static_cast<internal::CallReaction>(GMOCK_FLAG(default_mock_behavior)) :
 | 
			
		||||
      g_uninteresting_call_reaction[mock_obj];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Tells Google Mock to ignore mock_obj when checking for leaked mock
 | 
			
		||||
 
 | 
			
		||||
@@ -48,6 +48,13 @@ GMOCK_DEFINE_string_(verbose, internal::kWarningVerbosity,
 | 
			
		||||
                     "  warning - prints warnings and errors.\n"
 | 
			
		||||
                     "  error   - prints errors only.");
 | 
			
		||||
 | 
			
		||||
GMOCK_DEFINE_int32_(default_mock_behavior, 1,
 | 
			
		||||
                    "Controls the default behavior of mocks."
 | 
			
		||||
                    "  Valid values:\n"
 | 
			
		||||
                    "  0 - by default, mocks act as NiceMocks.\n"
 | 
			
		||||
                    "  1 - by default, mocks act as NaggyMocks.\n"
 | 
			
		||||
                    "  2 - by default, mocks act as StrictMocks.");
 | 
			
		||||
 | 
			
		||||
namespace internal {
 | 
			
		||||
 | 
			
		||||
// Parses a string as a command line flag.  The string should have the
 | 
			
		||||
@@ -120,6 +127,19 @@ static bool ParseGoogleMockStringFlag(const char* str, const char* flag,
 | 
			
		||||
  return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static bool ParseGoogleMockIntFlag(const char* str, const char* flag,
 | 
			
		||||
                                   int* value) {
 | 
			
		||||
  // Gets the value of the flag as a string.
 | 
			
		||||
  const char* const value_str = ParseGoogleMockFlagValue(str, flag, true);
 | 
			
		||||
 | 
			
		||||
  // Aborts if the parsing failed.
 | 
			
		||||
  if (value_str == NULL) return false;
 | 
			
		||||
 | 
			
		||||
  // Sets *value to the value of the flag.
 | 
			
		||||
  *value = atoi(value_str);
 | 
			
		||||
  return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// The internal implementation of InitGoogleMock().
 | 
			
		||||
//
 | 
			
		||||
// The type parameter CharType can be instantiated to either char or
 | 
			
		||||
@@ -138,7 +158,9 @@ void InitGoogleMockImpl(int* argc, CharType** argv) {
 | 
			
		||||
    // Do we see a Google Mock flag?
 | 
			
		||||
    if (ParseGoogleMockBoolFlag(arg, "catch_leaked_mocks",
 | 
			
		||||
                                &GMOCK_FLAG(catch_leaked_mocks)) ||
 | 
			
		||||
        ParseGoogleMockStringFlag(arg, "verbose", &GMOCK_FLAG(verbose))) {
 | 
			
		||||
        ParseGoogleMockStringFlag(arg, "verbose", &GMOCK_FLAG(verbose)) ||
 | 
			
		||||
        ParseGoogleMockIntFlag(arg, "default_mock_behavior",
 | 
			
		||||
                               &GMOCK_FLAG(default_mock_behavior))) {
 | 
			
		||||
      // Yes.  Shift the remainder of the argv list left by one.  Note
 | 
			
		||||
      // that argv has (*argc + 1) elements, the last one always being
 | 
			
		||||
      // NULL.  The following loop moves the trailing NULL element as
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user