Start/stop guards
This commit is contained in:
parent
3eb50a3276
commit
f7432195b9
1 changed files with 41 additions and 23 deletions
|
@ -115,6 +115,46 @@
|
|||
ASSERT_FALSE (condition); \
|
||||
}
|
||||
|
||||
namespace nano::test
|
||||
{
|
||||
template <class... Ts>
|
||||
class start_stop_guard
|
||||
{
|
||||
public:
|
||||
explicit start_stop_guard (Ts &... refs_a) :
|
||||
refs{ std::forward<Ts &> (refs_a)... }
|
||||
{
|
||||
std::apply ([] (Ts &... refs) { (refs.start (), ...); }, refs);
|
||||
}
|
||||
|
||||
~start_stop_guard ()
|
||||
{
|
||||
std::apply ([] (Ts &... refs) { (refs.stop (), ...); }, refs);
|
||||
}
|
||||
|
||||
private:
|
||||
std::tuple<Ts &...> refs;
|
||||
};
|
||||
|
||||
template <class... Ts>
|
||||
class stop_guard
|
||||
{
|
||||
public:
|
||||
explicit stop_guard (Ts &... refs_a) :
|
||||
refs{ std::forward<Ts &> (refs_a)... }
|
||||
{
|
||||
}
|
||||
|
||||
~stop_guard ()
|
||||
{
|
||||
std::apply ([] (Ts &... refs) { (refs.stop (), ...); }, refs);
|
||||
}
|
||||
|
||||
private:
|
||||
std::tuple<Ts &...> refs;
|
||||
};
|
||||
}
|
||||
|
||||
/* Convenience globals for gtest projects */
|
||||
namespace nano
|
||||
{
|
||||
|
@ -233,28 +273,6 @@ namespace test
|
|||
std::atomic<unsigned> required_count;
|
||||
};
|
||||
|
||||
/**
|
||||
* A helper that calls `start` from constructor and `stop` from destructor
|
||||
*/
|
||||
template <class T>
|
||||
class start_stop_guard
|
||||
{
|
||||
public:
|
||||
explicit start_stop_guard (T & ref_a) :
|
||||
ref{ ref_a }
|
||||
{
|
||||
ref.start ();
|
||||
}
|
||||
|
||||
~start_stop_guard ()
|
||||
{
|
||||
ref.stop ();
|
||||
}
|
||||
|
||||
private:
|
||||
T & ref;
|
||||
};
|
||||
|
||||
void wait_peer_connections (nano::test::system &);
|
||||
|
||||
/**
|
||||
|
@ -408,4 +426,4 @@ namespace test
|
|||
*/
|
||||
void print_all_blocks (nano::node & node);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue