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
073a2da4
Commit
073a2da4
authored
Jul 15, 2019
by
Gennadiy Civil
Browse files
Preparation for including docs in round-trip with OSS
parent
01573aa0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
32 deletions
+4
-32
googlemock/docs/cook_book.md
googlemock/docs/cook_book.md
+4
-32
No files found.
googlemock/docs/cook_book.md
View file @
073a2da4
...
...
@@ -1138,29 +1138,6 @@ Note that the predicate function / functor doesn't have to return `bool`. It
works as long as the return value can be used as the condition in in statement
`if (condition) ...`
.
#### Using Callbacks as Matchers
Callbacks are widely used in
`google3`
. Conceptually, a
`ResultCallback1<bool,
T>`
is just a predicate on argument of type
`T`
. Naturally, we sometimes would
want to use such a callback as a matcher.
gMock gives you two function templates in namespace
`testing`
to turn callbacks
into matchers.
The first is
`Truly(callback)`
. It matches
`argument`
iff
`callback->Run(argument)`
returns
`true`
.
The second is
`AddressSatisfies(callback)`
, which matches
`argument`
whenever
`callback->Run(&argument)`
returns
`true`
.
The callbacks used in
`Truly()`
and
`AddressSatisfies()`
must be permanent (e.g.
those returned by
`NewPermanentCallback()`
), or you'll get a run-time error. The
matcher takes ownership of the callback, so you don't need to worry about
deleting it.
For examples, see
google3/testing/base/internal/gmock_utils/callback-matchers_test.cc.
#### Matching Arguments that Are Not Copyable
When you do an
`EXPECT_CALL(mock_obj, Foo(bar))`
, gMock saves away a copy of
...
...
@@ -2167,16 +2144,11 @@ Note that both `ON_CALL` and `EXPECT_CALL` have the same "later statements take
precedence" rule, but they don't interact. That is,
`EXPECT_CALL`
s have their
own precedence order distinct from the
`ON_CALL`
precedence order.
#### Using Functions/Methods/Functors/Lambdas/Callbacks as Actions {#FunctionsAsActions}
If the built-in actions don't suit you, you can easily use an existing callable
(function,
`std::function`
, method, functor, lambda, or
`google3`
permanent
callback) as an action. Note that
`Callback`
or member function must be wrapped
with
`Invoke()`
, whereas lambdas and functors will work by themselves.
#### Using Functions/Methods/Functors/Lambdas as Actions {#FunctionsAsActions}
```
cpp
using
::
testing
::
_
;
using
::
testing
::
Invoke
;
If the built-in actions don't suit you, you can use an existing callable
(function,
`std::function`
, method, functor, lambda as an action.
```cpp
using ::testing::_;
using ::testing::Invoke;
class MockFoo : public Foo {
public:
...
...
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