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
6a5eb807
Commit
6a5eb807
authored
Apr 07, 2021
by
Abseil Team
Committed by
Dino Radaković
Apr 07, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Googletest export
Update the example for Notify to use a lambda. It is much less boilerplate and easier to remember. PiperOrigin-RevId: 367284222
parent
8a65bc03
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
1 addition
and
9 deletions
+1
-9
gmock_cook_book.md
docs/gmock_cook_book.md
+1
-9
No files found.
docs/gmock_cook_book.md
View file @
6a5eb807
...
@@ -2705,18 +2705,10 @@ behavior nondeterministic. A better way is to use gMock actions and
...
@@ -2705,18 +2705,10 @@ behavior nondeterministic. A better way is to use gMock actions and
`Notification`
objects to force your asynchronous test to behave synchronously.
`Notification`
objects to force your asynchronous test to behave synchronously.
```
cpp
```
cpp
using
::
testing
::
DoAll
;
using
::
testing
::
InvokeWithoutArgs
;
using
::
testing
::
Return
;
class
MockEventDispatcher
:
public
EventDispatcher
{
class
MockEventDispatcher
:
public
EventDispatcher
{
MOCK_METHOD
(
bool
,
DispatchEvent
,
(
int32
),
(
override
));
MOCK_METHOD
(
bool
,
DispatchEvent
,
(
int32
),
(
override
));
};
};
ACTION_P
(
Notify
,
notification
)
{
notification
->
Notify
();
}
TEST
(
EventQueueTest
,
EnqueueEventTest
)
{
TEST
(
EventQueueTest
,
EnqueueEventTest
)
{
MockEventDispatcher
mock_event_dispatcher
;
MockEventDispatcher
mock_event_dispatcher
;
EventQueue
event_queue
(
&
mock_event_dispatcher
);
EventQueue
event_queue
(
&
mock_event_dispatcher
);
...
@@ -2724,7 +2716,7 @@ TEST(EventQueueTest, EnqueueEventTest) {
...
@@ -2724,7 +2716,7 @@ TEST(EventQueueTest, EnqueueEventTest) {
const
int32
kEventId
=
321
;
const
int32
kEventId
=
321
;
absl
::
Notification
done
;
absl
::
Notification
done
;
EXPECT_CALL
(
mock_event_dispatcher
,
DispatchEvent
(
kEventId
))
EXPECT_CALL
(
mock_event_dispatcher
,
DispatchEvent
(
kEventId
))
.
WillOnce
(
Notify
(
&
done
)
);
.
WillOnce
(
[
&
done
]
{
done
.
Notify
();
}
);
event_queue
.
EnqueueEvent
(
kEventId
);
event_queue
.
EnqueueEvent
(
kEventId
);
done
.
WaitForNotification
();
done
.
WaitForNotification
();
...
...
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