Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
yangql
googletest
Commits
30c1e00a
Commit
30c1e00a
authored
Aug 29, 2017
by
Gennadiy Civil
Committed by
GitHub
Aug 29, 2017
Browse files
Merge branch 'master' into hethi/typo-xUnit
parents
fe760e9c
96f3745e
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
132 additions
and
3 deletions
+132
-3
googlemock/include/gmock/gmock-spec-builders.h
googlemock/include/gmock/gmock-spec-builders.h
+0
-1
googlemock/include/gmock/gmock.h
googlemock/include/gmock/gmock.h
+1
-0
googlemock/src/gmock-spec-builders.cc
googlemock/src/gmock-spec-builders.cc
+9
-1
googlemock/src/gmock.cc
googlemock/src/gmock.cc
+23
-1
googlemock/test/gmock-spec-builders_test.cc
googlemock/test/gmock-spec-builders_test.cc
+58
-0
googlemock/test/gmock_test.cc
googlemock/test/gmock_test.cc
+41
-0
No files found.
googlemock/include/gmock/gmock-spec-builders.h
View file @
30c1e00a
...
@@ -363,7 +363,6 @@ enum CallReaction {
...
@@ -363,7 +363,6 @@ enum CallReaction {
kAllow
,
kAllow
,
kWarn
,
kWarn
,
kFail
,
kFail
,
kDefault
=
kWarn
// By default, warn about uninteresting calls.
};
};
}
// namespace internal
}
// namespace internal
...
...
googlemock/include/gmock/gmock.h
View file @
30c1e00a
...
@@ -71,6 +71,7 @@ namespace testing {
...
@@ -71,6 +71,7 @@ namespace testing {
// Declares Google Mock flags that we want a user to use programmatically.
// Declares Google Mock flags that we want a user to use programmatically.
GMOCK_DECLARE_bool_
(
catch_leaked_mocks
);
GMOCK_DECLARE_bool_
(
catch_leaked_mocks
);
GMOCK_DECLARE_string_
(
verbose
);
GMOCK_DECLARE_string_
(
verbose
);
GMOCK_DECLARE_int32_
(
default_mock_behavior
);
// Initializes Google Mock. This must be called before running the
// Initializes Google Mock. This must be called before running the
// tests. In particular, it parses the command line for the flags
// tests. In particular, it parses the command line for the flags
...
...
googlemock/src/gmock-spec-builders.cc
View file @
30c1e00a
...
@@ -508,6 +508,13 @@ bool UntypedFunctionMockerBase::VerifyAndClearExpectationsLocked()
...
@@ -508,6 +508,13 @@ bool UntypedFunctionMockerBase::VerifyAndClearExpectationsLocked()
return
expectations_met
;
return
expectations_met
;
}
}
CallReaction
intToCallReaction
(
int
mock_behavior
)
{
if
(
mock_behavior
>=
kAllow
&&
mock_behavior
<=
kFail
)
{
return
static_cast
<
internal
::
CallReaction
>
(
mock_behavior
);
}
return
kWarn
;
}
}
// namespace internal
}
// namespace internal
// Class Mock.
// Class Mock.
...
@@ -648,7 +655,8 @@ internal::CallReaction Mock::GetReactionOnUninterestingCalls(
...
@@ -648,7 +655,8 @@ internal::CallReaction Mock::GetReactionOnUninterestingCalls(
GTEST_LOCK_EXCLUDED_
(
internal
::
g_gmock_mutex
)
{
GTEST_LOCK_EXCLUDED_
(
internal
::
g_gmock_mutex
)
{
internal
::
MutexLock
l
(
&
internal
::
g_gmock_mutex
);
internal
::
MutexLock
l
(
&
internal
::
g_gmock_mutex
);
return
(
g_uninteresting_call_reaction
.
count
(
mock_obj
)
==
0
)
?
return
(
g_uninteresting_call_reaction
.
count
(
mock_obj
)
==
0
)
?
internal
::
kDefault
:
g_uninteresting_call_reaction
[
mock_obj
];
internal
::
intToCallReaction
(
GMOCK_FLAG
(
default_mock_behavior
))
:
g_uninteresting_call_reaction
[
mock_obj
];
}
}
// Tells Google Mock to ignore mock_obj when checking for leaked mock
// Tells Google Mock to ignore mock_obj when checking for leaked mock
...
...
googlemock/src/gmock.cc
View file @
30c1e00a
...
@@ -48,6 +48,13 @@ GMOCK_DEFINE_string_(verbose, internal::kWarningVerbosity,
...
@@ -48,6 +48,13 @@ GMOCK_DEFINE_string_(verbose, internal::kWarningVerbosity,
" warning - prints warnings and errors.
\n
"
" warning - prints warnings and errors.
\n
"
" error - prints errors only."
);
" 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
{
namespace
internal
{
// Parses a string as a command line flag. The string should have the
// 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,
...
@@ -120,6 +127,19 @@ static bool ParseGoogleMockStringFlag(const char* str, const char* flag,
return
true
;
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 internal implementation of InitGoogleMock().
//
//
// The type parameter CharType can be instantiated to either char or
// The type parameter CharType can be instantiated to either char or
...
@@ -138,7 +158,9 @@ void InitGoogleMockImpl(int* argc, CharType** argv) {
...
@@ -138,7 +158,9 @@ void InitGoogleMockImpl(int* argc, CharType** argv) {
// Do we see a Google Mock flag?
// Do we see a Google Mock flag?
if
(
ParseGoogleMockBoolFlag
(
arg
,
"catch_leaked_mocks"
,
if
(
ParseGoogleMockBoolFlag
(
arg
,
"catch_leaked_mocks"
,
&
GMOCK_FLAG
(
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
// Yes. Shift the remainder of the argv list left by one. Note
// that argv has (*argc + 1) elements, the last one always being
// that argv has (*argc + 1) elements, the last one always being
// NULL. The following loop moves the trailing NULL element as
// NULL. The following loop moves the trailing NULL element as
...
...
googlemock/test/gmock-spec-builders_test.cc
View file @
30c1e00a
...
@@ -93,8 +93,11 @@ using testing::Sequence;
...
@@ -93,8 +93,11 @@ using testing::Sequence;
using
testing
::
SetArgPointee
;
using
testing
::
SetArgPointee
;
using
testing
::
internal
::
ExpectationTester
;
using
testing
::
internal
::
ExpectationTester
;
using
testing
::
internal
::
FormatFileLocation
;
using
testing
::
internal
::
FormatFileLocation
;
using
testing
::
internal
::
kAllow
;
using
testing
::
internal
::
kErrorVerbosity
;
using
testing
::
internal
::
kErrorVerbosity
;
using
testing
::
internal
::
kFail
;
using
testing
::
internal
::
kInfoVerbosity
;
using
testing
::
internal
::
kInfoVerbosity
;
using
testing
::
internal
::
kWarn
;
using
testing
::
internal
::
kWarningVerbosity
;
using
testing
::
internal
::
kWarningVerbosity
;
using
testing
::
internal
::
linked_ptr
;
using
testing
::
internal
::
linked_ptr
;
...
@@ -691,6 +694,61 @@ TEST(ExpectCallSyntaxTest, WarnsOnTooFewActions) {
...
@@ -691,6 +694,61 @@ TEST(ExpectCallSyntaxTest, WarnsOnTooFewActions) {
b
.
DoB
();
b
.
DoB
();
}
}
TEST
(
ExpectCallSyntaxTest
,
WarningIsErrorWithFlag
)
{
int
original_behavior
=
testing
::
GMOCK_FLAG
(
default_mock_behavior
);
testing
::
GMOCK_FLAG
(
default_mock_behavior
)
=
kAllow
;
CaptureStdout
();
{
MockA
a
;
a
.
DoA
(
0
);
}
std
::
string
output
=
GetCapturedStdout
();
EXPECT_TRUE
(
output
.
empty
())
<<
output
;
testing
::
GMOCK_FLAG
(
default_mock_behavior
)
=
kWarn
;
CaptureStdout
();
{
MockA
a
;
a
.
DoA
(
0
);
}
std
::
string
warning_output
=
GetCapturedStdout
();
EXPECT_PRED_FORMAT2
(
IsSubstring
,
"GMOCK WARNING"
,
warning_output
);
EXPECT_PRED_FORMAT2
(
IsSubstring
,
"Uninteresting mock function call"
,
warning_output
);
testing
::
GMOCK_FLAG
(
default_mock_behavior
)
=
kFail
;
EXPECT_NONFATAL_FAILURE
({
MockA
a
;
a
.
DoA
(
0
);
},
"Uninteresting mock function call"
);
// Out of bounds values are converted to kWarn
testing
::
GMOCK_FLAG
(
default_mock_behavior
)
=
-
1
;
CaptureStdout
();
{
MockA
a
;
a
.
DoA
(
0
);
}
warning_output
=
GetCapturedStdout
();
EXPECT_PRED_FORMAT2
(
IsSubstring
,
"GMOCK WARNING"
,
warning_output
);
EXPECT_PRED_FORMAT2
(
IsSubstring
,
"Uninteresting mock function call"
,
warning_output
);
testing
::
GMOCK_FLAG
(
default_mock_behavior
)
=
3
;
CaptureStdout
();
{
MockA
a
;
a
.
DoA
(
0
);
}
warning_output
=
GetCapturedStdout
();
EXPECT_PRED_FORMAT2
(
IsSubstring
,
"GMOCK WARNING"
,
warning_output
);
EXPECT_PRED_FORMAT2
(
IsSubstring
,
"Uninteresting mock function call"
,
warning_output
);
testing
::
GMOCK_FLAG
(
default_mock_behavior
)
=
original_behavior
;
}
#endif // GTEST_HAS_STREAM_REDIRECTION
#endif // GTEST_HAS_STREAM_REDIRECTION
// Tests the semantics of ON_CALL().
// Tests the semantics of ON_CALL().
...
...
googlemock/test/gmock_test.cc
View file @
30c1e00a
...
@@ -40,6 +40,7 @@
...
@@ -40,6 +40,7 @@
#if !defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_)
#if !defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_)
using
testing
::
GMOCK_FLAG
(
default_mock_behavior
);
using
testing
::
GMOCK_FLAG
(
verbose
);
using
testing
::
GMOCK_FLAG
(
verbose
);
using
testing
::
InitGoogleMock
;
using
testing
::
InitGoogleMock
;
...
@@ -103,6 +104,26 @@ TEST(InitGoogleMockTest, ParsesSingleFlag) {
...
@@ -103,6 +104,26 @@ TEST(InitGoogleMockTest, ParsesSingleFlag) {
TestInitGoogleMock
(
argv
,
new_argv
,
"info"
);
TestInitGoogleMock
(
argv
,
new_argv
,
"info"
);
}
}
TEST
(
InitGoogleMockTest
,
ParsesMultipleFlags
)
{
int
old_default_behavior
=
GMOCK_FLAG
(
default_mock_behavior
);
const
wchar_t
*
argv
[]
=
{
L"foo.exe"
,
L"--gmock_verbose=info"
,
L"--gmock_default_mock_behavior=2"
,
NULL
};
const
wchar_t
*
new_argv
[]
=
{
L"foo.exe"
,
NULL
};
TestInitGoogleMock
(
argv
,
new_argv
,
"info"
);
EXPECT_EQ
(
2
,
GMOCK_FLAG
(
default_mock_behavior
));
EXPECT_NE
(
2
,
old_default_behavior
);
GMOCK_FLAG
(
default_mock_behavior
)
=
old_default_behavior
;
}
TEST
(
InitGoogleMockTest
,
ParsesUnrecognizedFlag
)
{
TEST
(
InitGoogleMockTest
,
ParsesUnrecognizedFlag
)
{
const
char
*
argv
[]
=
{
const
char
*
argv
[]
=
{
"foo.exe"
,
"foo.exe"
,
...
@@ -177,6 +198,26 @@ TEST(WideInitGoogleMockTest, ParsesSingleFlag) {
...
@@ -177,6 +198,26 @@ TEST(WideInitGoogleMockTest, ParsesSingleFlag) {
TestInitGoogleMock
(
argv
,
new_argv
,
"info"
);
TestInitGoogleMock
(
argv
,
new_argv
,
"info"
);
}
}
TEST
(
WideInitGoogleMockTest
,
ParsesMultipleFlags
)
{
int
old_default_behavior
=
GMOCK_FLAG
(
default_mock_behavior
);
const
wchar_t
*
argv
[]
=
{
L"foo.exe"
,
L"--gmock_verbose=info"
,
L"--gmock_default_mock_behavior=2"
,
NULL
};
const
wchar_t
*
new_argv
[]
=
{
L"foo.exe"
,
NULL
};
TestInitGoogleMock
(
argv
,
new_argv
,
"info"
);
EXPECT_EQ
(
2
,
GMOCK_FLAG
(
default_mock_behavior
));
EXPECT_NE
(
2
,
old_default_behavior
);
GMOCK_FLAG
(
default_mock_behavior
)
=
old_default_behavior
;
}
TEST
(
WideInitGoogleMockTest
,
ParsesUnrecognizedFlag
)
{
TEST
(
WideInitGoogleMockTest
,
ParsesUnrecognizedFlag
)
{
const
wchar_t
*
argv
[]
=
{
const
wchar_t
*
argv
[]
=
{
L"foo.exe"
,
L"foo.exe"
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment