Changeset View
Changeset View
Standalone View
Standalone View
src/test/util/logging.h
Show All 11 Lines | |||||
#include <string> | #include <string> | ||||
class DebugLogHelper { | class DebugLogHelper { | ||||
const std::string m_message; | const std::string m_message; | ||||
bool m_found{false}; | bool m_found{false}; | ||||
std::list<std::function<void(const std::string &)>>::iterator | std::list<std::function<void(const std::string &)>>::iterator | ||||
m_print_connection; | m_print_connection; | ||||
//! Custom match checking function. | |||||
//! | |||||
//! Invoked with pointers to lines containing matching strings, and with | |||||
//! null if check_found() is called without any successful match. | |||||
//! | |||||
//! Can return true to enable default DebugLogHelper behavior of: | |||||
//! (1) ending search after first successful match, and | |||||
//! (2) raising an error in check_found if no match was found | |||||
//! Can return false to do the opposite in either case. | |||||
using MatchFn = std::function<bool(const std::string *line)>; | |||||
MatchFn m_match; | |||||
void check_found(); | void check_found(); | ||||
public: | public: | ||||
explicit DebugLogHelper(std::string message); | explicit DebugLogHelper( | ||||
std::string message, | |||||
MatchFn match = [](const std::string *) { return true; }); | |||||
~DebugLogHelper() { check_found(); } | ~DebugLogHelper() { check_found(); } | ||||
}; | }; | ||||
#define ASSERT_DEBUG_LOG(message) \ | #define ASSERT_DEBUG_LOG(message) \ | ||||
DebugLogHelper PASTE2(debugloghelper, __COUNTER__)(message) | DebugLogHelper PASTE2(debugloghelper, __COUNTER__)(message) | ||||
#endif // BITCOIN_TEST_UTIL_LOGGING_H | #endif // BITCOIN_TEST_UTIL_LOGGING_H |