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
7aca8442
Commit
7aca8442
authored
Sep 18, 2020
by
Abseil Team
Committed by
Gennadiy Rozental
Sep 20, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Googletest export
Simplify FooConcrete static calls in googlemock cookbook. PiperOrigin-RevId: 332437041
parent
bb272534
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
3 additions
and
19 deletions
+3
-19
cook_book.md
googlemock/docs/cook_book.md
+3
-19
No files found.
googlemock/docs/cook_book.md
View file @
7aca8442
...
@@ -781,28 +781,12 @@ perhaps your test doesn't need to mock `Concrete()` at all (but it would be
...
@@ -781,28 +781,12 @@ perhaps your test doesn't need to mock `Concrete()` at all (but it would be
oh-so painful to have to define a new mock class whenever you don't need to mock
oh-so painful to have to define a new mock class whenever you don't need to mock
one of its methods).
one of its methods).
The trick is to leave a back door in your mock class for accessing the real
You can call
`Foo::Concrete()`
inside an action by:
methods in the base class:
```
cpp
class
MockFoo
:
public
Foo
{
public
:
// Mocking a pure method.
MOCK_METHOD
(
void
,
Pure
,
(
int
n
),
(
override
));
// Mocking a concrete method. Foo::Concrete() is shadowed.
MOCK_METHOD
(
int
,
Concrete
,
(
const
char
*
str
),
(
override
));
// Use this to call Concrete() defined in Foo.
int
FooConcrete
(
const
char
*
str
)
{
return
Foo
::
Concrete
(
str
);
}
};
```
Now, you can call
`Foo::Concrete()`
inside an action by:
```
cpp
```
cpp
...
...
EXPECT_CALL
(
foo
,
Concrete
).
WillOnce
([
&
foo
](
const
char
*
str
)
{
EXPECT_CALL
(
foo
,
Concrete
).
WillOnce
([
&
foo
](
const
char
*
str
)
{
return
foo
.
FooConcrete
(
str
);
return
foo
.
Foo
::
Concrete
(
str
);
});
});
```
```
...
@@ -811,7 +795,7 @@ or tell the mock object that you don't want to mock `Concrete()`:
...
@@ -811,7 +795,7 @@ or tell the mock object that you don't want to mock `Concrete()`:
```
cpp
```
cpp
...
...
ON_CALL
(
foo
,
Concrete
).
WillByDefault
([
&
foo
](
const
char
*
str
)
{
ON_CALL
(
foo
,
Concrete
).
WillByDefault
([
&
foo
](
const
char
*
str
)
{
return
foo
.
FooConcrete
(
str
);
return
foo
.
Foo
::
Concrete
(
str
);
});
});
```
```
...
...
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