diff options
author | Abseil Team <absl-team@google.com> | 2021-04-07 20:17:57 (GMT) |
---|---|---|
committer | Dino Radaković <dinor@google.com> | 2021-04-08 06:39:39 (GMT) |
commit | 6a5eb807493214be733d4cbb9f07f22fde25284f (patch) | |
tree | e83045b21f437f2121fc32f8c5b42a76e72cf333 /docs/gmock_cook_book.md | |
parent | 8a65bc0303fc2cac63fe177f41b8348a988884cd (diff) | |
download | googletest-6a5eb807493214be733d4cbb9f07f22fde25284f.zip googletest-6a5eb807493214be733d4cbb9f07f22fde25284f.tar.gz googletest-6a5eb807493214be733d4cbb9f07f22fde25284f.tar.bz2 |
Googletest export
Update the example for Notify to use a lambda.
It is much less boilerplate and easier to remember.
PiperOrigin-RevId: 367284222
Diffstat (limited to 'docs/gmock_cook_book.md')
-rw-r--r-- | docs/gmock_cook_book.md | 10 |
1 files changed, 1 insertions, 9 deletions
diff --git a/docs/gmock_cook_book.md b/docs/gmock_cook_book.md index a9f9edc..c6a9991 100644 --- a/docs/gmock_cook_book.md +++ b/docs/gmock_cook_book.md @@ -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. ```cpp -using ::testing::DoAll; -using ::testing::InvokeWithoutArgs; -using ::testing::Return; - class MockEventDispatcher : public EventDispatcher { MOCK_METHOD(bool, DispatchEvent, (int32), (override)); }; -ACTION_P(Notify, notification) { - notification->Notify(); -} - TEST(EventQueueTest, EnqueueEventTest) { MockEventDispatcher mock_event_dispatcher; EventQueue event_queue(&mock_event_dispatcher); @@ -2724,7 +2716,7 @@ TEST(EventQueueTest, EnqueueEventTest) { const int32 kEventId = 321; absl::Notification done; EXPECT_CALL(mock_event_dispatcher, DispatchEvent(kEventId)) - .WillOnce(Notify(&done)); + .WillOnce([&done] { done.Notify(); }); event_queue.EnqueueEvent(kEventId); done.WaitForNotification(); |