#include <random>
#define CATCH_CONFIG_MAIN
#include <catch2/catch_test_macros.hpp>
namespace {
{
public:
int entryDepth() const { return m_macCount; }
{
const auto count = m_underLogger.lockedCount();
if (m_macCount < count)
m_macCount = count;
return ret;
}
{
const auto count = m_underLogger.lockedCount();
if (m_macCount < count)
m_macCount = count;
return ret;
}
private:
int m_macCount{};
};
thread_local std::mt19937 g_rng{std::random_device{"/dev/urandom"}()};
int inner_2nd_return()
{
return 20;
}
int inner_return()
{
LOG_RAW(
"Inner Log {}", inner_2nd_return());
return 10;
}
std::string ignore_prelog(const std::string &s)
{
static constexpr const char PRELOG[] = "********** LOGS BEGUN **********";
auto found = s.find(PRELOG);
if (found != std::string::npos)
{
found = s.find('\n', found + strlen(PRELOG));
if (found != std::string::npos)
return s.substr(found + 1);
}
return s;
}
}
namespace bux {
namespace user {
std::unique_ptr<C_GizmoLogger> g_log;
struct C_Fixture
{
std::ostringstream m_out;
C_Fixture(): m_logger(m_out)
{
bux::user::g_log = std::make_unique<C_GizmoLogger>(m_logger);
}
auto ignore_prelog() const { return ::ignore_prelog(m_out.str()); }
};
TEST_CASE_METHOD(C_Fixture, "Empty log", "[Z]")
{
REQUIRE(m_out.str().empty());
REQUIRE(bux::user::g_log->entryDepth() == 0);
}
TEST_CASE_METHOD(C_Fixture, "One log", "[O]")
{
REQUIRE(ignore_prelog() == "The one log\n");
REQUIRE(bux::user::g_log->entryDepth() == 1);
}
TEST_CASE_METHOD(C_Fixture, "Scenario: Reentered Logs", "[S]")
{
LOG_RAW(
"Outer: Inner Return = {}", inner_return());
REQUIRE(ignore_prelog() == "Inner 2nd Log\nInner Log 20\nOuter: Inner Return = 10\n");
REQUIRE(bux::user::g_log->entryDepth() == 3);
}
#define DEF_LOGGER_TAIL_(x)
#define LOG_RAW(fmtStr,...)
std::ostream * lockLog() override
THE common namespace of bux library.