From b5c2f33d04f2ce46c884c74328d425de07643dad Mon Sep 17 00:00:00 2001 From: 4c3y <69460051+4c3y@users.noreply.github.com> Date: Thu, 7 Sep 2023 16:42:11 +0200 Subject: [PATCH] MODE_NOLOG: Added support for glog's LOG_STRING() --- CMakeLists.txt | 2 +- include/log++.h | 1 + test/nolog/test_nolog_log_string.cc | 83 +++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 test/nolog/test_nolog_log_string.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index 43cccc7..88d791e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -163,7 +163,7 @@ if (GLOG_FOUND AND catkin_FOUND AND LPP_BUILD_TESTS) test/nolog/test_nolog_every_n.cc test/nolog/test_nolog_first_n.cc test/nolog/test_nolog_if_every_n.cc - #test/nolog/test_nolog_log_string.cc + test/nolog/test_nolog_log_string.cc #test/nolog/test_nolog_rosprintf.cc #test/nolog/test_nolog_timed.cc #test/nolog/test_nolog_vlog.cc diff --git a/include/log++.h b/include/log++.h index a25a670..1aa9614 100644 --- a/include/log++.h +++ b/include/log++.h @@ -446,6 +446,7 @@ LPP_INTL::InternalPolicyLog(LPP_GET_KEY(), n, LPP_INTL::BaseSeverity::DEBUG, LPP #define LOG_FIRST_N(severity, n) (void) LPP_INTL::GlogSeverity::severity; static_assert(std::is_integral_v); InternalLog() #define DLOG_IF_EVERY_N(severity, cond, n) (void) LPP_INTL::GlogSeverity::severity; static_assert(std::is_same::value && std::is_integral_v); InternalLog() #define LOG_IF_EVERY_N(severity, cond, n) DLOG_IF_EVERY_N(severity, cond, n) +#define LOG_STRING(severity, ptr) (void) LPP_INTL::GlogSeverity::severity; static_assert(std::is_same*>::value || std::is_same::value); InternalLog() //ros #define ROS_DEBUG_STREAM(x) (void) x diff --git a/test/nolog/test_nolog_log_string.cc b/test/nolog/test_nolog_log_string.cc new file mode 100644 index 0000000..3a3adca --- /dev/null +++ b/test/nolog/test_nolog_log_string.cc @@ -0,0 +1,83 @@ +// +// Created by acey on 07.09.23. +// + +#include +#include +#include + +TEST(nolog_log_string, severity_info) { + LOG_INIT(*test_argv); + + std::vector errors; + + LOG_STRING(INFO, &errors) << "LOG_STRING: " + << "collected info"; + ASSERT_TRUE(errors.empty()); +} + +TEST(nolog_log_string, severity_info_null) { + LOG_INIT(*test_argv); + + std::string output = + LPP_CAPTURE_STDOUT(LOG_STRING(INFO, nullptr) << "LOG_STRING: " + << "collected info"); + ASSERT_EQ(output, ""); +} + +TEST(nolog_log_string, severity_warning) { + LOG_INIT(*test_argv); + + std::vector errors; + + LOG_STRING(WARNING, &errors) << "LOG_STRING: " + << "collected warn"; + ASSERT_TRUE(errors.empty()); +} + +TEST(nolog_log_string, severity_warning_null) { + LOG_INIT(*test_argv); + + std::string output = + LPP_CAPTURE_STDOUT(LOG_STRING(WARNING, nullptr) << "LOG_STRING: " + << "collected warn"); + ASSERT_EQ(output, ""); +} + +TEST(nolog_log_string, severity_error) { + LOG_INIT(*test_argv); + + std::vector errors; + + LOG_STRING(ERROR, &errors) << "LOG_STRING: " + << "collected error"; + ASSERT_TRUE(errors.empty()); +} + +TEST(nolog_log_string, severity_error_null) { + LOG_INIT(*test_argv); + + std::string output = + LPP_CAPTURE_STDOUT(LOG_STRING(ERROR, nullptr) << "LOG_STRING: " + << "collected error"); + ASSERT_EQ(output, ""); +} + +TEST(nolog_log_string, severity_fatal) { + LOG_INIT(*test_argv); + + std::vector errors; + + LOG_STRING(ERROR, &errors) << "LOG_STRING: " + << "collected error"; + ASSERT_TRUE(errors.empty()); +} + +TEST(nolog_log_string, severity_fatal_null) { + LOG_INIT(*test_argv); + + std::string output = + LPP_CAPTURE_STDOUT(LOG_STRING(FATAL, nullptr) << "LOG_STRING: " + << "collected fatal"); + ASSERT_EQ(output, ""); +}