Public Member Functions | Protected Attributes | List of all members
testing::AsyncTest Class Reference

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_ {}
 

Detailed Description

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:

void asyncCall(std::function<void()> fun)
{
std::thread t(fun);
t.detach();
}

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:

class MyTest : public testing::Test, public testing::AsyncTest
{
public:
MOCK_METHOD0(myMethod, void());
};
TEST_F(MyTest, testCase)
{
EXPECT_CALL(*this, myMethod()).Times(1).WillOnce(ACTION_OPEN_BARRIER_VOID("myMethod"));
asyncCall(std::bind(&MyTest::myMethod, this));
BARRIER("myMethod");
}

Definition at line 64 of file async_test.h.

Member Function Documentation

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.

Parameters
clear_eventEvent 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.

Parameters
clear_eventsList 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.

Parameters
eventThe event that is triggered

Definition at line 52 of file async_test.cpp.

Member Data Documentation

std::set<std::string> testing::AsyncTest::clear_events_ {}
protected

Definition at line 94 of file async_test.h.

std::condition_variable testing::AsyncTest::cv_
protected

Definition at line 93 of file async_test.h.

std::mutex testing::AsyncTest::m_
protected

Definition at line 92 of file async_test.h.

std::set<std::string> testing::AsyncTest::waitlist_ {}
protected

Definition at line 95 of file async_test.h.


The documentation for this class was generated from the following files:


pilz_testutils
Author(s):
autogenerated on Tue Feb 2 2021 03:50:13