Test class that allows the handling of asynchronous test objects. More...
#include <async_test.h>
Public Member Functions | |
void | barricade (std::string clear_event) |
Will block until the event given by clear_event is triggered. Unblocks immediately, if the event was triggered in advance. More... | |
void | barricade (std::initializer_list< std::string > clear_events) |
Will block until all events given by clear_events are triggered. Events triggered in advance take effect, too. More... | |
void | triggerClearEvent (std::string event) |
Triggeres a clear event. If a call to barricade is currently pending it will unblock as soon as all clear events are triggered. Else the event is put on the waitlist. This waitlist is emptied upon a call to barricade. More... | |
Protected Attributes | |
std::set< std::string > | clear_events_ {} |
std::condition_variable | cv_ |
std::mutex | m_ |
std::set< std::string > | waitlist_ {} |
Test class that allows the handling of asynchronous test objects.
The class provides the two basic functions AsyncTest::barricade and AsyncTest::triggerClearEvent. During the test setup gates between the steps with one or more clear events. Allow passing on by calling triggerClearEvent after a test.
Usage:
Suppose you want to test a function that calls another function asynchronously, like the following example:
You expect that fun gets called, so your test thread has to wait for the completion, else it would fail. This can be achieved via:
Definition at line 64 of file async_test.h.
void testing::AsyncTest::barricade | ( | std::string | clear_event | ) |
Will block until the event given by clear_event is triggered. Unblocks immediately, if the event was triggered in advance.
clear_event | Event that allows the test to pass on |
Definition at line 26 of file async_test.cpp.
void testing::AsyncTest::barricade | ( | std::initializer_list< std::string > | clear_events | ) |
Will block until all events given by clear_events are triggered. Events triggered in advance take effect, too.
clear_events | List of events that allow the test to pass on |
Definition at line 31 of file async_test.cpp.
void testing::AsyncTest::triggerClearEvent | ( | std::string | event | ) |
Triggeres a clear event. If a call to barricade is currently pending it will unblock as soon as all clear events are triggered. Else the event is put on the waitlist. This waitlist is emptied upon a call to barricade.
event | The event that is triggered |
Definition at line 52 of file async_test.cpp.
|
protected |
Definition at line 94 of file async_test.h.
|
protected |
Definition at line 93 of file async_test.h.
|
protected |
Definition at line 92 of file async_test.h.
|
protected |
Definition at line 95 of file async_test.h.