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
470df42b
Commit
470df42b
authored
Feb 02, 2010
by
zhanyong.wan
Browse files
Enables tests depending on stdout capturing (by Vlad Losev).
parent
db22c227
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
124 additions
and
117 deletions
+124
-117
test/gmock-internal-utils_test.cc
test/gmock-internal-utils_test.cc
+27
-29
test/gmock-nice-strict_test.cc
test/gmock-nice-strict_test.cc
+15
-11
test/gmock-spec-builders_test.cc
test/gmock-spec-builders_test.cc
+82
-77
No files found.
test/gmock-internal-utils_test.cc
View file @
470df42b
...
@@ -538,8 +538,7 @@ TEST_F(LogIsVisibleTest, WorksWhenVerbosityIsWarning) {
...
@@ -538,8 +538,7 @@ TEST_F(LogIsVisibleTest, WorksWhenVerbosityIsWarning) {
EXPECT_TRUE
(
LogIsVisible
(
WARNING
));
EXPECT_TRUE
(
LogIsVisible
(
WARNING
));
}
}
// TODO(wan@google.com): find a way to re-enable these tests.
#if GTEST_HAS_STREAM_REDIRECTION_
#if 0
// Tests the Log() function.
// Tests the Log() function.
...
@@ -549,16 +548,16 @@ void TestLogWithSeverity(const string& verbosity, LogSeverity severity,
...
@@ -549,16 +548,16 @@ void TestLogWithSeverity(const string& verbosity, LogSeverity severity,
bool
should_print
)
{
bool
should_print
)
{
const
string
old_flag
=
GMOCK_FLAG
(
verbose
);
const
string
old_flag
=
GMOCK_FLAG
(
verbose
);
GMOCK_FLAG
(
verbose
)
=
verbosity
;
GMOCK_FLAG
(
verbose
)
=
verbosity
;
Capture
Test
Stdout();
CaptureStdout
();
Log
(
severity
,
"Test log.
\n
"
,
0
);
Log
(
severity
,
"Test log.
\n
"
,
0
);
if
(
should_print
)
{
if
(
should_print
)
{
EXPECT_
PRED2(RE::FullMatch
,
EXPECT_
THAT
(
GetCapturedStdout
().
c_str
()
,
GetCapturedTestStdout(),
ContainsRegex
(
severity
==
WARNING
?
severity
==
WARNING
?
"
\nGMOCK WARNING:\nTest log\\.\nStack trace:\n
[\\s\\S]*
" :
"^
\n
GMOCK WARNING:
\n
Test log
\\
.
\n
Stack trace:
\n
"
:
"
\nTest log\\.\nStack trace:\n
[\\s\\S]*
");
"^
\n
Test log
\\
.
\n
Stack trace:
\n
"
)
);
}
else
{
}
else
{
EXPECT_EQ("", GetCaptured
Test
Stdout());
EXPECT_
STR
EQ
(
""
,
GetCapturedStdout
()
.
c_str
()
);
}
}
GMOCK_FLAG
(
verbose
)
=
old_flag
;
GMOCK_FLAG
(
verbose
)
=
old_flag
;
}
}
...
@@ -567,18 +566,18 @@ void TestLogWithSeverity(const string& verbosity, LogSeverity severity,
...
@@ -567,18 +566,18 @@ void TestLogWithSeverity(const string& verbosity, LogSeverity severity,
// Log() doesn't include the stack trace in the output.
// Log() doesn't include the stack trace in the output.
TEST
(
LogTest
,
NoStackTraceWhenStackFramesToSkipIsNegative
)
{
TEST
(
LogTest
,
NoStackTraceWhenStackFramesToSkipIsNegative
)
{
GMOCK_FLAG
(
verbose
)
=
kInfoVerbosity
;
GMOCK_FLAG
(
verbose
)
=
kInfoVerbosity
;
Capture
Test
Stdout();
CaptureStdout
();
Log
(
INFO
,
"Test log.
\n
"
,
-
1
);
Log
(
INFO
,
"Test log.
\n
"
,
-
1
);
EXPECT_EQ("\nTest log.\n", GetCaptured
Test
Stdout());
EXPECT_
STR
EQ
(
"
\n
Test log.
\n
"
,
GetCapturedStdout
()
.
c_str
()
);
}
}
// Tests that in opt mode, a positive stack_frames_to_skip argument is
// Tests that in opt mode, a positive stack_frames_to_skip argument is
// treated as 0.
// treated as 0.
TEST
(
LogTest
,
NoSkippingStackFrameInOptMode
)
{
TEST
(
LogTest
,
NoSkippingStackFrameInOptMode
)
{
Capture
Test
Stdout();
CaptureStdout
();
Log
(
WARNING
,
"Test log.
\n
"
,
100
);
Log
(
WARNING
,
"Test log.
\n
"
,
100
);
const
s
tring log = GetCaptured
Test
Stdout();
const
S
tring
log
=
GetCapturedStdout
();
#ifdef
NDEBUG
#if
def
ined(
NDEBUG
) && GTEST_GOOGLE3_MODE_
// In opt mode, no stack frame should be skipped.
// In opt mode, no stack frame should be skipped.
EXPECT_THAT
(
log
,
ContainsRegex
(
"
\n
GMOCK WARNING:
\n
"
EXPECT_THAT
(
log
,
ContainsRegex
(
"
\n
GMOCK WARNING:
\n
"
"Test log
\\
.
\n
"
"Test log
\\
.
\n
"
...
@@ -586,10 +585,10 @@ TEST(LogTest, NoSkippingStackFrameInOptMode) {
...
@@ -586,10 +585,10 @@ TEST(LogTest, NoSkippingStackFrameInOptMode) {
".+"
));
".+"
));
#else
#else
// In dbg mode, the stack frames should be skipped.
// In dbg mode, the stack frames should be skipped.
EXPECT_EQ("\nGMOCK WARNING:\n"
EXPECT_
STR
EQ
(
"
\n
GMOCK WARNING:
\n
"
"Test log.
\n
"
"Test log.
\n
"
"Stack trace:\n", log);
"Stack trace:
\n
"
,
log
.
c_str
()
);
#endif
// NDEBUG
#endif
}
}
// Tests that all logs are printed when the value of the
// Tests that all logs are printed when the value of the
...
@@ -620,7 +619,7 @@ TEST(LogTest, OnlyWarningsArePrintedWhenVerbosityIsInvalid) {
...
@@ -620,7 +619,7 @@ TEST(LogTest, OnlyWarningsArePrintedWhenVerbosityIsInvalid) {
TestLogWithSeverity
(
"invalid"
,
WARNING
,
true
);
TestLogWithSeverity
(
"invalid"
,
WARNING
,
true
);
}
}
#endif //
0
#endif //
GTEST_HAS_STREAM_REDIRECTION_
TEST
(
TypeTraitsTest
,
true_type
)
{
TEST
(
TypeTraitsTest
,
true_type
)
{
EXPECT_TRUE
(
true_type
::
value
);
EXPECT_TRUE
(
true_type
::
value
);
...
@@ -657,18 +656,17 @@ TEST(TypeTraitsTest, remove_reference) {
...
@@ -657,18 +656,17 @@ TEST(TypeTraitsTest, remove_reference) {
EXPECT_TRUE
((
type_equals
<
double
*
,
remove_reference
<
double
*>::
type
>::
value
));
EXPECT_TRUE
((
type_equals
<
double
*
,
remove_reference
<
double
*>::
type
>::
value
));
}
}
// TODO(wan@google.com): find a way to re-enable these tests.
#if GTEST_HAS_STREAM_REDIRECTION_
#if 0
// Verifies that Log() behaves correctly for the given verbosity level
// Verifies that Log() behaves correctly for the given verbosity level
// and log severity.
// and log severity.
s
tring GrabOutput(void(*logger)(), const char* verbosity) {
S
tring
GrabOutput
(
void
(
*
logger
)(),
const
char
*
verbosity
)
{
const
string
saved_flag
=
GMOCK_FLAG
(
verbose
);
const
string
saved_flag
=
GMOCK_FLAG
(
verbose
);
GMOCK_FLAG
(
verbose
)
=
verbosity
;
GMOCK_FLAG
(
verbose
)
=
verbosity
;
Capture
Test
Stdout();
CaptureStdout
();
logger
();
logger
();
GMOCK_FLAG
(
verbose
)
=
saved_flag
;
GMOCK_FLAG
(
verbose
)
=
saved_flag
;
return GetCaptured
Test
Stdout();
return
GetCapturedStdout
();
}
}
class
DummyMock
{
class
DummyMock
{
...
@@ -692,13 +690,13 @@ TEST(ExpectCallTest, LogsWhenVerbosityIsInfo) {
...
@@ -692,13 +690,13 @@ TEST(ExpectCallTest, LogsWhenVerbosityIsInfo) {
// Verifies that EXPECT_CALL doesn't log
// Verifies that EXPECT_CALL doesn't log
// if the --gmock_verbose flag is set to "warning".
// if the --gmock_verbose flag is set to "warning".
TEST
(
ExpectCallTest
,
DoesNotLogWhenVerbosityIsWarning
)
{
TEST
(
ExpectCallTest
,
DoesNotLogWhenVerbosityIsWarning
)
{
EXPECT_EQ("", GrabOutput(ExpectCallLogger, kWarningVerbosity));
EXPECT_
STR
EQ
(
""
,
GrabOutput
(
ExpectCallLogger
,
kWarningVerbosity
)
.
c_str
()
);
}
}
// Verifies that EXPECT_CALL doesn't log
// Verifies that EXPECT_CALL doesn't log
// if the --gmock_verbose flag is set to "error".
// if the --gmock_verbose flag is set to "error".
TEST
(
ExpectCallTest
,
DoesNotLogWhenVerbosityIsError
)
{
TEST
(
ExpectCallTest
,
DoesNotLogWhenVerbosityIsError
)
{
EXPECT_EQ("", GrabOutput(ExpectCallLogger, kErrorVerbosity));
EXPECT_
STR
EQ
(
""
,
GrabOutput
(
ExpectCallLogger
,
kErrorVerbosity
)
.
c_str
()
);
}
}
void
OnCallLogger
()
{
void
OnCallLogger
()
{
...
@@ -715,13 +713,13 @@ TEST(OnCallTest, LogsWhenVerbosityIsInfo) {
...
@@ -715,13 +713,13 @@ TEST(OnCallTest, LogsWhenVerbosityIsInfo) {
// Verifies that ON_CALL doesn't log
// Verifies that ON_CALL doesn't log
// if the --gmock_verbose flag is set to "warning".
// if the --gmock_verbose flag is set to "warning".
TEST
(
OnCallTest
,
DoesNotLogWhenVerbosityIsWarning
)
{
TEST
(
OnCallTest
,
DoesNotLogWhenVerbosityIsWarning
)
{
EXPECT_EQ("", GrabOutput(OnCallLogger, kWarningVerbosity));
EXPECT_
STR
EQ
(
""
,
GrabOutput
(
OnCallLogger
,
kWarningVerbosity
)
.
c_str
()
);
}
}
// Verifies that ON_CALL doesn't log if
// Verifies that ON_CALL doesn't log if
// the --gmock_verbose flag is set to "error".
// the --gmock_verbose flag is set to "error".
TEST
(
OnCallTest
,
DoesNotLogWhenVerbosityIsError
)
{
TEST
(
OnCallTest
,
DoesNotLogWhenVerbosityIsError
)
{
EXPECT_EQ("", GrabOutput(OnCallLogger, kErrorVerbosity));
EXPECT_
STR
EQ
(
""
,
GrabOutput
(
OnCallLogger
,
kErrorVerbosity
)
.
c_str
()
);
}
}
void
OnCallAnyArgumentLogger
()
{
void
OnCallAnyArgumentLogger
()
{
...
@@ -735,7 +733,7 @@ TEST(OnCallTest, LogsAnythingArgument) {
...
@@ -735,7 +733,7 @@ TEST(OnCallTest, LogsAnythingArgument) {
HasSubstr
(
"ON_CALL(mock, TestMethodArg(_)"
));
HasSubstr
(
"ON_CALL(mock, TestMethodArg(_)"
));
}
}
#endif //
0
#endif //
GTEST_HAS_STREAM_REDIRECTION_
// Tests ArrayEq().
// Tests ArrayEq().
...
...
test/gmock-nice-strict_test.cc
View file @
470df42b
...
@@ -57,6 +57,11 @@ using testing::HasSubstr;
...
@@ -57,6 +57,11 @@ using testing::HasSubstr;
using
testing
::
NiceMock
;
using
testing
::
NiceMock
;
using
testing
::
StrictMock
;
using
testing
::
StrictMock
;
#if GTEST_HAS_STREAM_REDIRECTION_
using
testing
::
internal
::
CaptureStdout
;
using
testing
::
internal
::
GetCapturedStdout
;
#endif // GTEST_HAS_STREAM_REDIRECTION_
// Defines some mock classes needed by the tests.
// Defines some mock classes needed by the tests.
class
Foo
{
class
Foo
{
...
@@ -102,17 +107,16 @@ class MockBar {
...
@@ -102,17 +107,16 @@ class MockBar {
GTEST_DISALLOW_COPY_AND_ASSIGN_
(
MockBar
);
GTEST_DISALLOW_COPY_AND_ASSIGN_
(
MockBar
);
};
};
// TODO(wan@google.com): find a way to re-enable these tests.
#if GTEST_HAS_STREAM_REDIRECTION_
#if 0
// 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
;
Capture
Test
Stdout();
CaptureStdout
();
nice_foo
.
DoThis
();
nice_foo
.
DoThis
();
nice_foo
.
DoThat
(
true
);
nice_foo
.
DoThat
(
true
);
EXPECT_EQ("", GetCaptured
Test
Stdout());
EXPECT_
STR
EQ
(
""
,
GetCapturedStdout
()
.
c_str
()
);
}
}
// Tests that a nice mock generates no warning for uninteresting calls
// Tests that a nice mock generates no warning for uninteresting calls
...
@@ -123,9 +127,9 @@ TEST(NiceMockTest, NoWarningForUninterestingCallAfterDeath) {
...
@@ -123,9 +127,9 @@ TEST(NiceMockTest, NoWarningForUninterestingCallAfterDeath) {
ON_CALL
(
*
nice_foo
,
DoThis
())
ON_CALL
(
*
nice_foo
,
DoThis
())
.
WillByDefault
(
Invoke
(
nice_foo
,
&
MockFoo
::
Delete
));
.
WillByDefault
(
Invoke
(
nice_foo
,
&
MockFoo
::
Delete
));
Capture
Test
Stdout();
CaptureStdout
();
nice_foo
->
DoThis
();
nice_foo
->
DoThis
();
EXPECT_EQ("", GetCaptured
Test
Stdout());
EXPECT_
STR
EQ
(
""
,
GetCapturedStdout
()
.
c_str
()
);
}
}
// Tests that a nice mock generates informational logs for
// Tests that a nice mock generates informational logs for
...
@@ -134,18 +138,18 @@ TEST(NiceMockTest, InfoForUninterestingCall) {
...
@@ -134,18 +138,18 @@ TEST(NiceMockTest, InfoForUninterestingCall) {
NiceMock
<
MockFoo
>
nice_foo
;
NiceMock
<
MockFoo
>
nice_foo
;
GMOCK_FLAG
(
verbose
)
=
"info"
;
GMOCK_FLAG
(
verbose
)
=
"info"
;
Capture
Test
Stdout();
CaptureStdout
();
nice_foo
.
DoThis
();
nice_foo
.
DoThis
();
EXPECT_THAT(GetCaptured
Test
Stdout(),
EXPECT_THAT
(
GetCapturedStdout
(),
HasSubstr
(
"Uninteresting mock function call"
));
HasSubstr
(
"Uninteresting mock function call"
));
Capture
Test
Stdout();
CaptureStdout
();
nice_foo
.
DoThat
(
true
);
nice_foo
.
DoThat
(
true
);
EXPECT_THAT(GetCaptured
Test
Stdout(),
EXPECT_THAT
(
GetCapturedStdout
(),
HasSubstr
(
"Uninteresting mock function call"
));
HasSubstr
(
"Uninteresting mock function call"
));
}
}
#endif //
0
#endif //
GTEST_HAS_STREAM_REDIRECTION_
// Tests that a nice mock allows expected calls.
// Tests that a nice mock allows expected calls.
TEST
(
NiceMockTest
,
AllowsExpectedCall
)
{
TEST
(
NiceMockTest
,
AllowsExpectedCall
)
{
...
...
test/gmock-spec-builders_test.cc
View file @
470df42b
...
@@ -87,13 +87,20 @@ using testing::Mock;
...
@@ -87,13 +87,20 @@ using testing::Mock;
using
testing
::
Ne
;
using
testing
::
Ne
;
using
testing
::
Return
;
using
testing
::
Return
;
using
testing
::
Sequence
;
using
testing
::
Sequence
;
using
testing
::
internal
::
ExpectationTester
;
using
testing
::
internal
::
g_gmock_mutex
;
using
testing
::
internal
::
g_gmock_mutex
;
using
testing
::
internal
::
kErrorVerbosity
;
using
testing
::
internal
::
kErrorVerbosity
;
using
testing
::
internal
::
kInfoVerbosity
;
using
testing
::
internal
::
kInfoVerbosity
;
using
testing
::
internal
::
kWarningVerbosity
;
using
testing
::
internal
::
kWarningVerbosity
;
using
testing
::
internal
::
ExpectationTester
;
using
testing
::
internal
::
String
;
using
testing
::
internal
::
string
;
using
testing
::
internal
::
string
;
#if GTEST_HAS_STREAM_REDIRECTION_
using
testing
::
HasSubstr
;
using
testing
::
internal
::
CaptureStdout
;
using
testing
::
internal
::
GetCapturedStdout
;
#endif // GTEST_HAS_STREAM_REDIRECTION_
class
Result
{};
class
Result
{};
class
MockA
{
class
MockA
{
...
@@ -511,13 +518,12 @@ TEST(ExpectCallSyntaxTest, DefaultCardinalityIsOnce) {
...
@@ -511,13 +518,12 @@ TEST(ExpectCallSyntaxTest, DefaultCardinalityIsOnce) {
},
"to be called once"
);
},
"to be called once"
);
}
}
// TODO(wan@google.com): find a way to re-enable these tests.
#if GTEST_HAS_STREAM_REDIRECTION_
#if 0
// Tests that Google Mock doesn't print a warning when the number of
// Tests that Google Mock doesn't print a warning when the number of
// WillOnce() is adequate.
// WillOnce() is adequate.
TEST
(
ExpectCallSyntaxTest
,
DoesNotWarnOnAdequateActionCount
)
{
TEST
(
ExpectCallSyntaxTest
,
DoesNotWarnOnAdequateActionCount
)
{
Capture
Test
Stdout();
CaptureStdout
();
{
{
MockB
b
;
MockB
b
;
...
@@ -547,14 +553,13 @@ TEST(ExpectCallSyntaxTest, DoesNotWarnOnAdequateActionCount) {
...
@@ -547,14 +553,13 @@ TEST(ExpectCallSyntaxTest, DoesNotWarnOnAdequateActionCount) {
b
.
DoB
(
2
);
b
.
DoB
(
2
);
b
.
DoB
(
3
);
b
.
DoB
(
3
);
}
}
const string& output = GetCapturedTestStdout();
EXPECT_STREQ
(
""
,
GetCapturedStdout
().
c_str
());
EXPECT_EQ("", output);
}
}
// Tests that Google Mock warns on having too many actions in an
// Tests that Google Mock warns on having too many actions in an
// expectation compared to its cardinality.
// expectation compared to its cardinality.
TEST
(
ExpectCallSyntaxTest
,
WarnsOnTooManyActions
)
{
TEST
(
ExpectCallSyntaxTest
,
WarnsOnTooManyActions
)
{
Capture
Test
Stdout();
CaptureStdout
();
{
{
MockB
b
;
MockB
b
;
...
@@ -586,7 +591,7 @@ TEST(ExpectCallSyntaxTest, WarnsOnTooManyActions) {
...
@@ -586,7 +591,7 @@ TEST(ExpectCallSyntaxTest, WarnsOnTooManyActions) {
b
.
DoB
(
1
);
b
.
DoB
(
1
);
b
.
DoB
(
2
);
b
.
DoB
(
2
);
}
}
const
s
tring
&
output = GetCaptured
Test
Stdout();
const
S
tring
output
=
GetCapturedStdout
();
EXPECT_PRED_FORMAT2
(
EXPECT_PRED_FORMAT2
(
IsSubstring
,
IsSubstring
,
"Too many actions specified in EXPECT_CALL(b, DoB())...
\n
"
"Too many actions specified in EXPECT_CALL(b, DoB())...
\n
"
...
@@ -626,9 +631,9 @@ TEST(ExpectCallSyntaxTest, WarnsOnTooFewActions) {
...
@@ -626,9 +631,9 @@ TEST(ExpectCallSyntaxTest, WarnsOnTooFewActions) {
.
Times
(
Between
(
2
,
3
))
.
Times
(
Between
(
2
,
3
))
.
WillOnce
(
Return
(
1
));
.
WillOnce
(
Return
(
1
));
Capture
Test
Stdout();
CaptureStdout
();
b
.
DoB
();
b
.
DoB
();
const
s
tring
&
output = GetCaptured
Test
Stdout();
const
S
tring
output
=
GetCapturedStdout
();
EXPECT_PRED_FORMAT2
(
EXPECT_PRED_FORMAT2
(
IsSubstring
,
IsSubstring
,
"Too few actions specified in EXPECT_CALL(b, DoB())...
\n
"
"Too few actions specified in EXPECT_CALL(b, DoB())...
\n
"
...
@@ -638,7 +643,7 @@ TEST(ExpectCallSyntaxTest, WarnsOnTooFewActions) {
...
@@ -638,7 +643,7 @@ TEST(ExpectCallSyntaxTest, WarnsOnTooFewActions) {
b
.
DoB
();
b
.
DoB
();
}
}
#endif //
0
#endif //
GTEST_HAS_STREAM_REDIRECTION_
// Tests the semantics of ON_CALL().
// Tests the semantics of ON_CALL().
...
@@ -792,8 +797,7 @@ TEST(ExpectCallTest, NthMatchTakesNthAction) {
...
@@ -792,8 +797,7 @@ TEST(ExpectCallTest, NthMatchTakesNthAction) {
EXPECT_EQ
(
3
,
b
.
DoB
());
EXPECT_EQ
(
3
,
b
.
DoB
());
}
}
// TODO(wan@google.com): find a way to re-enable these tests.
#if GTEST_HAS_STREAM_REDIRECTION_
#if 0
// Tests that the default action is taken when the WillOnce(...) list is
// Tests that the default action is taken when the WillOnce(...) list is
// exhausted and there is no WillRepeatedly().
// exhausted and there is no WillRepeatedly().
...
@@ -806,29 +810,29 @@ TEST(ExpectCallTest, TakesDefaultActionWhenWillListIsExhausted) {
...
@@ -806,29 +810,29 @@ TEST(ExpectCallTest, TakesDefaultActionWhenWillListIsExhausted) {
.
WillOnce
(
Return
(
1
))
.
WillOnce
(
Return
(
1
))
.
WillOnce
(
Return
(
2
));
.
WillOnce
(
Return
(
2
));
Capture
Test
Stdout();
CaptureStdout
();
EXPECT_EQ
(
0
,
b
.
DoB
(
1
));
// Shouldn't generate a warning as the
EXPECT_EQ
(
0
,
b
.
DoB
(
1
));
// Shouldn't generate a warning as the
// expectation has no action clause at all.
// expectation has no action clause at all.
EXPECT_EQ
(
1
,
b
.
DoB
());
EXPECT_EQ
(
1
,
b
.
DoB
());
EXPECT_EQ
(
2
,
b
.
DoB
());
EXPECT_EQ
(
2
,
b
.
DoB
());
const
s
tring
&
output1 = GetCaptured
Test
Stdout();
const
S
tring
output1
=
GetCapturedStdout
();
EXPECT_EQ("", output1);
EXPECT_
STR
EQ
(
""
,
output1
.
c_str
()
);
Capture
Test
Stdout();
CaptureStdout
();
EXPECT_EQ
(
0
,
b
.
DoB
());
EXPECT_EQ
(
0
,
b
.
DoB
());
EXPECT_EQ
(
0
,
b
.
DoB
());
EXPECT_EQ
(
0
,
b
.
DoB
());
const
s
tring
&
output2 = GetCaptured
Test
Stdout();
const
S
tring
output2
=
GetCapturedStdout
();
EXPECT_
PRED2(RE::PartialMatch, output2
,
EXPECT_
THAT
(
output2
.
c_str
()
,
"Actions ran out
\\
.\n"
HasSubstr
(
"Actions ran out
in EXPECT_CALL(b, DoB())..
.
\n
"
"Called 3 times, but only 2 WillOnce
\\(\\
)s are specified
-
"
"Called 3 times, but only 2 WillOnce
(
)s are specified"
"
returning default value
\\
.");
" -
returning default value."
)
)
;
EXPECT_
PRED2(RE::PartialMatch, output2
,
EXPECT_
THAT
(
output2
.
c_str
()
,
"Actions ran out
\\
.\n"
HasSubstr
(
"Actions ran out
in EXPECT_CALL(b, DoB())..
.
\n
"
"Called 4 times, but only 2 WillOnce
\\(\\
)s are specified
-
"
"Called 4 times, but only 2 WillOnce
(
)s are specified"
"
returning default value
\\
.");
" -
returning default value."
)
)
;
}
}
#endif //
0
#endif //
GTEST_HAS_STREAM_REDIRECTION_
// Tests that the WillRepeatedly() action is taken when the WillOnce(...)
// Tests that the WillRepeatedly() action is taken when the WillOnce(...)
// list is exhausted.
// list is exhausted.
...
@@ -1779,16 +1783,15 @@ class MockC {
...
@@ -1779,16 +1783,15 @@ class MockC {
GTEST_DISALLOW_COPY_AND_ASSIGN_
(
MockC
);
GTEST_DISALLOW_COPY_AND_ASSIGN_
(
MockC
);
};
};
// TODO(wan@google.com): find a way to re-enable these tests.
#if GTEST_HAS_STREAM_REDIRECTION_
#if 0
// Tests that an uninteresting mock function call generates a warning
// Tests that an uninteresting mock function call generates a warning
// containing the stack trace.
// containing the stack trace.
TEST
(
FunctionCallMessageTest
,
UninterestingCallGeneratesFyiWithStackTrace
)
{
TEST
(
FunctionCallMessageTest
,
UninterestingCallGeneratesFyiWithStackTrace
)
{
MockC
c
;
MockC
c
;
Capture
Test
Stdout();
CaptureStdout
();
c
.
VoidMethod
(
false
,
5
,
"Hi"
,
NULL
,
Printable
(),
Unprintable
());
c
.
VoidMethod
(
false
,
5
,
"Hi"
,
NULL
,
Printable
(),
Unprintable
());
const
s
tring
&
output = GetCaptured
Test
Stdout();
const
S
tring
output
=
GetCapturedStdout
();
EXPECT_PRED_FORMAT2
(
IsSubstring
,
"GMOCK WARNING"
,
output
);
EXPECT_PRED_FORMAT2
(
IsSubstring
,
"GMOCK WARNING"
,
output
);
EXPECT_PRED_FORMAT2
(
IsSubstring
,
"Stack trace:"
,
output
);
EXPECT_PRED_FORMAT2
(
IsSubstring
,
"Stack trace:"
,
output
);
#ifndef NDEBUG
#ifndef NDEBUG
...
@@ -1797,14 +1800,14 @@ TEST(FunctionCallMessageTest, UninterestingCallGeneratesFyiWithStackTrace) {
...
@@ -1797,14 +1800,14 @@ TEST(FunctionCallMessageTest, UninterestingCallGeneratesFyiWithStackTrace) {
// Verifies that a void mock function's name appears in the stack
// Verifies that a void mock function's name appears in the stack
// trace.
// trace.
EXPECT_PRED_FORMAT2(IsSubstring, "
::MockC::
VoidMethod(", output);
EXPECT_PRED_FORMAT2
(
IsSubstring
,
"VoidMethod("
,
output
);
// Verifies that a non-void mock function's name appears in the
// Verifies that a non-void mock function's name appears in the
// stack trace.
// stack trace.
Capture
Test
Stdout();
CaptureStdout
();
c
.
NonVoidMethod
();
c
.
NonVoidMethod
();
const
s
tring
&
output2 = GetCaptured
Test
Stdout();
const
S
tring
output2
=
GetCapturedStdout
();
EXPECT_PRED_FORMAT2(IsSubstring, "
::MockC::
NonVoidMethod(", output2);
EXPECT_PRED_FORMAT2
(
IsSubstring
,
"NonVoidMethod("
,
output2
);
#endif // NDEBUG
#endif // NDEBUG
}
}
...
@@ -1813,26 +1816,27 @@ TEST(FunctionCallMessageTest, UninterestingCallGeneratesFyiWithStackTrace) {
...
@@ -1813,26 +1816,27 @@ TEST(FunctionCallMessageTest, UninterestingCallGeneratesFyiWithStackTrace) {
TEST
(
FunctionCallMessageTest
,
UninterestingCallPrintsArgumentsAndReturnValue
)
{
TEST
(
FunctionCallMessageTest
,
UninterestingCallPrintsArgumentsAndReturnValue
)
{
// A non-void mock function.
// A non-void mock function.
MockB
b
;
MockB
b
;
Capture
Test
Stdout();
CaptureStdout
();
b
.
DoB
();
b
.
DoB
();
const
s
tring
&
output1 = GetCaptured
Test
Stdout();
const
S
tring
output1
=
GetCapturedStdout
();
EXPECT_PRED_FORMAT2
(
EXPECT_PRED_FORMAT2
(
IsSubstring
,
IsSubstring
,
"Uninteresting mock function call - returning default value.
\n
"
"Uninteresting mock function call - returning default value.
\n
"
" Function call: DoB()
\n
"
" Function call: DoB()
\n
"
" Returns: 0\n", output1);
" Returns: 0
\n
"
,
output1
.
c_str
()
);
// Makes sure the return value is printed.
// Makes sure the return value is printed.
// A void mock function.
// A void mock function.
MockC
c
;
MockC
c
;
Capture
Test
Stdout();
CaptureStdout
();
c
.
VoidMethod
(
false
,
5
,
"Hi"
,
NULL
,
Printable
(),
Unprintable
());
c
.
VoidMethod
(
false
,
5
,
"Hi"
,
NULL
,
Printable
(),
Unprintable
());
const string& output2 = GetCapturedTestStdout();
const
String
output2
=
GetCapturedStdout
();
EXPECT_PRED2(RE::PartialMatch, output2,
EXPECT_THAT
(
output2
.
c_str
(),
ContainsRegex
(
"Uninteresting mock function call - returning directly
\\
.
\n
"
"Uninteresting mock function call - returning directly
\\
.
\n
"
" Function call: VoidMethod"
" Function call: VoidMethod"
"\\(false, 5, \"Hi\", NULL, @
0x\\w
+ "
"
\\
(false, 5,
\"
Hi
\"
, NULL, @
.
+ "
"Printable, 4-byte object <0000 0000>\\)");
"Printable, 4-byte object <0000 0000>
\\
)"
)
)
;
// A void function has no return value to print.
// A void function has no return value to print.
}
}
...
@@ -1844,18 +1848,21 @@ class GMockVerboseFlagTest : public testing::Test {
...
@@ -1844,18 +1848,21 @@ class GMockVerboseFlagTest : public testing::Test {
// should_print is true, the output should match the given regex and
// should_print is true, the output should match the given regex and
// contain the given function name in the stack trace. When it's
// contain the given function name in the stack trace. When it's
// false, the output should be empty.)
// false, the output should be empty.)
void VerifyOutput(const
s
tring& output, bool should_print,
void
VerifyOutput
(
const
S
tring
&
output
,
bool
should_print
,
const string&
regex
,
const
string
&
expected_substring
,
const
string
&
function_name
)
{
const
string
&
function_name
)
{
if
(
should_print
)
{
if
(
should_print
)
{
EXPECT_
PRED2(RE::PartialMatch, output, regex
);
EXPECT_
THAT
(
output
.
c_str
(),
HasSubstr
(
expected_substring
)
);
#ifndef NDEBUG
#ifndef NDEBUG
// We check the stack trace content in dbg-mode only, as opt-mode
// We check the stack trace content in dbg-mode only, as opt-mode
// may inline the call we are interested in seeing.
// may inline the call we are interested in seeing.
EXPECT_PRED_FORMAT2(IsSubstring, function_name, output);
EXPECT_THAT
(
output
.
c_str
(),
HasSubstr
(
function_name
));
#else
// Suppresses 'unused function parameter' warnings.
static_cast
<
void
>
(
function_name
);
#endif // NDEBUG
#endif // NDEBUG
}
else
{
}
else
{
EXPECT_EQ("", output);
EXPECT_
STR
EQ
(
""
,
output
.
c_str
()
);
}
}
}
}
...
@@ -1867,27 +1874,27 @@ class GMockVerboseFlagTest : public testing::Test {
...
@@ -1867,27 +1874,27 @@ class GMockVerboseFlagTest : public testing::Test {
.
WillOnce
(
Return
(
true
));
.
WillOnce
(
Return
(
true
));
// A void-returning function.
// A void-returning function.
Capture
Test
Stdout();
CaptureStdout
();
a
.
DoA
(
5
);
a
.
DoA
(
5
);
VerifyOutput
(
VerifyOutput
(
GetCaptured
Test
Stdout(),
GetCapturedStdout
(),
should_print
,
should_print
,
"
Expected m
ock function call
\\
.\n"
"
M
ock function call
matches EXPECT_CALL(a, DoA(5))..
.
\n
"
" Function call: DoA
\\(5\\
)\n"
" Function call: DoA
(5
)
\n
"
"Stack trace:",
"Stack trace:
\n
"
,
"
MockA::
DoA");
"DoA"
);
// A non-void-returning function.
// A non-void-returning function.
Capture
Test
Stdout();
CaptureStdout
();
a
.
Binary
(
2
,
1
);
a
.
Binary
(
2
,
1
);
VerifyOutput
(
VerifyOutput
(
GetCaptured
Test
Stdout(),
GetCapturedStdout
(),
should_print
,
should_print
,
"
Expected m
ock function call
\\
.\n"
"
M
ock function call
matches EXPECT_CALL(a, Binary(_, 1))..
.
\n
"
" Function call: Binary
\\
(2, 1
\\
)\n"
" Function call: Binary(2, 1)
\n
"
" Returns: true
\n
"
" Returns: true
\n
"
"Stack trace:",
"Stack trace:
\n
"
,
"
MockA::
Binary");
"Binary"
);
}
}
// Tests how the flag affects uninteresting calls.
// Tests how the flag affects uninteresting calls.
...
@@ -1895,31 +1902,29 @@ class GMockVerboseFlagTest : public testing::Test {
...
@@ -1895,31 +1902,29 @@ class GMockVerboseFlagTest : public testing::Test {
MockA
a
;
MockA
a
;
// A void-returning function.
// A void-returning function.
Capture
Test
Stdout();
CaptureStdout
();
a
.
DoA
(
5
);
a
.
DoA
(
5
);
VerifyOutput
(
VerifyOutput
(
GetCaptured
Test
Stdout(),
GetCapturedStdout
(),
should_print
,
should_print
,
"
\n
GMOCK WARNING:
\n
"
"
\n
GMOCK WARNING:
\n
"
"Uninteresting mock function call - returning directly\\.\n"
"Uninteresting mock function call - returning directly.
\n
"
" Function call: DoA\\(5\\)\n"
" Function call: DoA(5)
\n
"
"Stack trace:\n"
"Stack trace:
\n
"
,
"[\\s\\S]*",
"DoA"
);
"MockA::DoA");
// A non-void-returning function.
// A non-void-returning function.
Capture
Test
Stdout();
CaptureStdout
();
a
.
Binary
(
2
,
1
);
a
.
Binary
(
2
,
1
);
VerifyOutput
(
VerifyOutput
(
GetCaptured
Test
Stdout(),
GetCapturedStdout
(),
should_print
,
should_print
,
"
\n
GMOCK WARNING:
\n
"
"
\n
GMOCK WARNING:
\n
"
"Uninteresting mock function call - returning default value
\\
.\n"
"Uninteresting mock function call - returning default value.
\n
"
" Function call: Binary
\\
(2, 1
\\
)\n"
" Function call: Binary(2, 1)
\n
"
" Returns: false
\n
"
" Returns: false
\n
"
"Stack trace:\n"
"Stack trace:
\n
"
,
"[\\s\\S]*",
"Binary"
);
"MockA::Binary");
}
}
};
};
...
@@ -1955,7 +1960,7 @@ TEST_F(GMockVerboseFlagTest, InvalidFlagIsTreatedAsWarning) {
...
@@ -1955,7 +1960,7 @@ TEST_F(GMockVerboseFlagTest, InvalidFlagIsTreatedAsWarning) {
TestUninterestingCall
(
true
);
TestUninterestingCall
(
true
);
}
}
#endif //
0
#endif //
GTEST_HAS_STREAM_REDIRECTION_
// A helper class that generates a failure when printed. We use it to
// A helper class that generates a failure when printed. We use it to
// ensure that Google Mock doesn't print a value (even to an internal
// ensure that Google Mock doesn't print a value (even to an internal
...
...
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