diff --git a/nano/test_common/testutil.hpp b/nano/test_common/testutil.hpp index 60821e7d..a2706dc3 100644 --- a/nano/test_common/testutil.hpp +++ b/nano/test_common/testutil.hpp @@ -115,6 +115,46 @@ ASSERT_FALSE (condition); \ } +namespace nano::test +{ +template +class start_stop_guard +{ +public: + explicit start_stop_guard (Ts &... refs_a) : + refs{ std::forward (refs_a)... } + { + std::apply ([] (Ts &... refs) { (refs.start (), ...); }, refs); + } + + ~start_stop_guard () + { + std::apply ([] (Ts &... refs) { (refs.stop (), ...); }, refs); + } + +private: + std::tuple refs; +}; + +template +class stop_guard +{ +public: + explicit stop_guard (Ts &... refs_a) : + refs{ std::forward (refs_a)... } + { + } + + ~stop_guard () + { + std::apply ([] (Ts &... refs) { (refs.stop (), ...); }, refs); + } + +private: + std::tuple refs; +}; +} + /* Convenience globals for gtest projects */ namespace nano { @@ -233,28 +273,6 @@ namespace test std::atomic required_count; }; - /** - * A helper that calls `start` from constructor and `stop` from destructor - */ - template - 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); } -} +} \ No newline at end of file