diff --git a/nano/test_common/testutil.hpp b/nano/test_common/testutil.hpp index 36ec9a3143..50844201ed 100644 --- a/nano/test_common/testutil.hpp +++ b/nano/test_common/testutil.hpp @@ -117,12 +117,28 @@ namespace nano::test { -template +// Concept for checking .stop() method +template +concept stoppable = requires (T a) { + { + a.stop () + } -> std::same_as; +}; + +// Concept for checking if it's callable +template +concept callable = requires (T a) { + { + a () + } -> std::same_as; +}; + +template class start_stop_guard { public: explicit start_stop_guard (Ts &... refs_a) : - refs{ std::forward (refs_a)... } + refs{ std::forward (refs_a)... } { std::apply ([] (Ts &... refs) { (refs.start (), ...); }, refs); } @@ -136,12 +152,12 @@ class start_stop_guard std::tuple refs; }; -template +template class stop_guard { public: explicit stop_guard (Ts &... refs_a) : - refs{ std::forward (refs_a)... } + refs{ std::forward (refs_a)... } { } @@ -153,6 +169,24 @@ class stop_guard private: std::tuple refs; }; + +template +class call_guard +{ +public: + explicit call_guard (Ts &&... calls_a) : + calls{ std::forward (calls_a)... } + { + } + + ~call_guard () + { + std::apply ([] (Ts &... refs) { (refs (), ...); }, calls); + } + +private: + std::tuple calls; +}; } /* Convenience globals for gtest projects */