Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
googletest
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
googletest
Commits
e5121b5a
Commit
e5121b5a
authored
Feb 11, 2011
by
vladlosev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improves cross-platform compatibility of gmock output. This fixes issue 135.
parent
5b61ce3e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
12 deletions
+40
-12
gmock-spec-builders.h
include/gmock/gmock-spec-builders.h
+2
-2
gmock-spec-builders_test.cc
test/gmock-spec-builders_test.cc
+38
-10
No files found.
include/gmock/gmock-spec-builders.h
View file @
e5121b5a
...
@@ -575,7 +575,7 @@ class ExpectationBase {
...
@@ -575,7 +575,7 @@ class ExpectationBase {
// Describes the source file location of this expectation.
// Describes the source file location of this expectation.
void
DescribeLocationTo
(
::
std
::
ostream
*
os
)
const
{
void
DescribeLocationTo
(
::
std
::
ostream
*
os
)
const
{
*
os
<<
file
()
<<
":"
<<
line
()
<<
":
"
;
*
os
<<
FormatFileLocation
(
file
(),
line
())
<<
"
"
;
}
}
// Describes how many times a function call matching this
// Describes how many times a function call matching this
...
@@ -1527,7 +1527,7 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
...
@@ -1527,7 +1527,7 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
"returning default value.
\n
"
);
"returning default value.
\n
"
);
}
else
{
}
else
{
*
os
<<
"taking default action specified at:
\n
"
*
os
<<
"taking default action specified at:
\n
"
<<
spec
->
file
()
<<
":"
<<
spec
->
line
()
<<
":
\n
"
;
<<
FormatFileLocation
(
spec
->
file
(),
spec
->
line
())
<<
"
\n
"
;
}
}
}
}
...
...
test/gmock-spec-builders_test.cc
View file @
e5121b5a
...
@@ -43,6 +43,7 @@
...
@@ -43,6 +43,7 @@
#include "gmock/internal/gmock-port.h"
#include "gmock/internal/gmock-port.h"
#include "gtest/gtest.h"
#include "gtest/gtest.h"
#include "gtest/gtest-spi.h"
#include "gtest/gtest-spi.h"
#include "gtest/internal/gtest-port.h"
namespace
testing
{
namespace
testing
{
namespace
internal
{
namespace
internal
{
...
@@ -88,6 +89,7 @@ using testing::Ne;
...
@@ -88,6 +89,7 @@ using testing::Ne;
using
testing
::
Return
;
using
testing
::
Return
;
using
testing
::
Sequence
;
using
testing
::
Sequence
;
using
testing
::
internal
::
ExpectationTester
;
using
testing
::
internal
::
ExpectationTester
;
using
testing
::
internal
::
FormatFileLocation
;
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
;
...
@@ -797,6 +799,19 @@ TEST(ExpectCallTest, NthMatchTakesNthAction) {
...
@@ -797,6 +799,19 @@ TEST(ExpectCallTest, NthMatchTakesNthAction) {
EXPECT_EQ
(
3
,
b
.
DoB
());
EXPECT_EQ
(
3
,
b
.
DoB
());
}
}
// Tests that the WillRepeatedly() action is taken when the WillOnce(...)
// list is exhausted.
TEST
(
ExpectCallTest
,
TakesRepeatedActionWhenWillListIsExhausted
)
{
MockB
b
;
EXPECT_CALL
(
b
,
DoB
())
.
WillOnce
(
Return
(
1
))
.
WillRepeatedly
(
Return
(
2
));
EXPECT_EQ
(
1
,
b
.
DoB
());
EXPECT_EQ
(
2
,
b
.
DoB
());
EXPECT_EQ
(
2
,
b
.
DoB
());
}
#if GTEST_HAS_STREAM_REDIRECTION
#if GTEST_HAS_STREAM_REDIRECTION
// Tests that the default action is taken when the WillOnce(...) list is
// Tests that the default action is taken when the WillOnce(...) list is
...
@@ -832,21 +847,34 @@ TEST(ExpectCallTest, TakesDefaultActionWhenWillListIsExhausted) {
...
@@ -832,21 +847,34 @@ TEST(ExpectCallTest, TakesDefaultActionWhenWillListIsExhausted) {
" - returning default value."
));
" - returning default value."
));
}
}
#endif // GTEST_HAS_STREAM_REDIRECTION
TEST
(
FunctionMockerTest
,
ReportsExpectCallLocationForExhausedActions
)
{
// Tests that the WillRepeatedly() action is taken when the WillOnce(...)
// list is exhausted.
TEST
(
ExpectCallTest
,
TakesRepeatedActionWhenWillListIsExhausted
)
{
MockB
b
;
MockB
b
;
EXPECT_CALL
(
b
,
DoB
())
std
::
string
expect_call_location
=
FormatFileLocation
(
__FILE__
,
__LINE__
+
1
);
.
WillOnce
(
Return
(
1
))
EXPECT_CALL
(
b
,
DoB
()).
Times
(
AnyNumber
()).
WillOnce
(
Return
(
1
));
.
WillRepeatedly
(
Return
(
2
));
EXPECT_EQ
(
1
,
b
.
DoB
());
EXPECT_EQ
(
1
,
b
.
DoB
());
EXPECT_EQ
(
2
,
b
.
DoB
());
EXPECT_EQ
(
2
,
b
.
DoB
());
CaptureStdout
();
EXPECT_EQ
(
0
,
b
.
DoB
());
const
String
output
=
GetCapturedStdout
();
// The warning message should contain the call location.
EXPECT_PRED_FORMAT2
(
IsSubstring
,
expect_call_location
,
output
);
}
}
TEST
(
FunctionMockerTest
,
ReportsDefaultActionLocationOfUninterestingCalls
)
{
std
::
string
on_call_location
;
CaptureStdout
();
{
MockB
b
;
on_call_location
=
FormatFileLocation
(
__FILE__
,
__LINE__
+
1
);
ON_CALL
(
b
,
DoB
(
_
)).
WillByDefault
(
Return
(
0
));
b
.
DoB
(
0
);
}
EXPECT_PRED_FORMAT2
(
IsSubstring
,
on_call_location
,
GetCapturedStdout
());
}
#endif // GTEST_HAS_STREAM_REDIRECTION
// Tests that an uninteresting call performs the default action.
// Tests that an uninteresting call performs the default action.
TEST
(
UninterestingCallTest
,
DoesDefaultAction
)
{
TEST
(
UninterestingCallTest
,
DoesDefaultAction
)
{
// When there is an ON_CALL() statement, the action specified by it
// When there is an ON_CALL() statement, the action specified by it
...
...
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