diff --git a/CMakeLists.txt b/CMakeLists.txt index e6b1101..d228414 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -155,4 +155,24 @@ if (GLOG_FOUND AND catkin_FOUND AND LPP_BUILD_TESTS) target_link_libraries(${DEFAULT_TESTS} glog gtest ${catkin_LIBRARIES}) target_compile_definitions(${DEFAULT_TESTS} PRIVATE MODE_DEFAULT) target_compile_options(${DEFAULT_TESTS} PRIVATE "-fcompare-debug-second") + + ##### Nolog Tests ##### + set(NOLOG_TESTS "test_nolog") + add_executable(${NOLOG_TESTS} test/test_entry_point.cpp + #test/nolog/test_common.cc + test/nolog/test_nolog_basic.cc + #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_rosprintf.cc + #test/nolog/test_nolog_timed.cc + #test/nolog/test_nolog_vlog.cc + #test/nolog/test_severity_conversions.cc + ) + + target_include_directories(${NOLOG_TESTS} PRIVATE ${LPP_INCLUDE_DIRECTORIES} test/nolog) + target_link_libraries(${NOLOG_TESTS} glog gtest ${catkin_LIBRARIES}) + target_compile_definitions(${NOLOG_TESTS} PRIVATE MODE_NOLOG) + target_compile_options(${NOLOG_TESTS} PRIVATE "-fcompare-debug-second") endif () diff --git a/include/log++.h b/include/log++.h index 0151f7d..297cc9f 100644 --- a/include/log++.h +++ b/include/log++.h @@ -43,7 +43,7 @@ #include #include -#if !defined MODE_LPP && !defined MODE_GLOG && !defined MODE_ROSLOG && !defined MODE_DEFAULT +#if !defined MODE_LPP && !defined MODE_GLOG && !defined MODE_ROSLOG && !defined MODE_DEFAULT && !defined MODE_NOLOG #define MODE_DEFAULT #warning "No mode defined. Selected MODE_DEFAULT"; #endif @@ -56,10 +56,11 @@ * * Defining MODE_DEFAULT will prevent errors from being generated for each logging function that is called. */ -#if defined(MODE_LPP) + defined(MODE_GLOG) + defined(MODE_ROSLOG) + defined(MODE_DEFAULT) > 1 +#if defined(MODE_LPP) + defined(MODE_GLOG) + defined(MODE_ROSLOG) + defined(MODE_DEFAULT) + defined(MODE_NOLOG) > 1 #undef MODE_LPP #undef MODE_GLOG #undef MODE_ROSLOG +#undef MODE_NOLOG #define MODE_DEFAULT #error "More than one mode is defined" #endif @@ -427,6 +428,22 @@ LPP_INTL::InternalPolicyLog(LPP_GET_KEY(), n, LPP_INTL::BaseSeverity::DEBUG, LPP #define LOG_3(severity, cond, x) if (cond) LPP_INTL::InternalLog(LPP_INTL::LppSeverity::severity) << x // NOLINT(bugprone-macro-parentheses) #endif + +//! MODE_NOLOG + +#ifdef MODE_NOLOG +#define DLOG(severity) (void) LPP_INTL::GlogSeverity::severity; InternalLog() +#define LOG_1(severity) (void) LPP_INTL::GlogSeverity::severity; InternalLog() + +#define LOG_2(severity, x) (void) LPP_INTL::LppSeverity::severity; InternalLog() << x + +#define ROS_DEBUG_STREAM(x) (void) x +#define ROS_INFO_STREAM(x) (void) x +#define ROS_WARN_STREAM(x) (void) x +#define ROS_ERROR_STREAM(x) (void) x +#define ROS_FATAL_STREAM(x) (void) x +#endif + namespace lpp { namespace internal { diff --git a/test/nolog/test_nolog_basic.cc b/test/nolog/test_nolog_basic.cc new file mode 100644 index 0000000..b16667f --- /dev/null +++ b/test/nolog/test_nolog_basic.cc @@ -0,0 +1,108 @@ +// +// Created by acey on 06.09.23. +// + +#include +#include +#include + +TEST(nolog_basic, glog_syntax_severity_debug){ + LOG_INIT(*test_argv); + DLOG(INFO) << "TEst"; + + std::string output = LPP_CAPTURE_STDOUT(DLOG(INFO) << "Test"); + ASSERT_EQ("", output); +} + +TEST(nolog_basic, glog_syntax_severity_info){ + LOG_INIT(*test_argv); + + std::string output = LPP_CAPTURE_STDOUT(LOG(INFO) << "Test123"); + ASSERT_EQ("", output); +} + +TEST(nolog_basic, glog_syntax_severity_warning){ + LOG_INIT(*test_argv); + + std::string output = LPP_CAPTURE_STDERR(LOG(WARNING) << "Test"); + ASSERT_EQ("", output); +} + +TEST(nolog_basic, glog_syntax_severity_error){ + LOG_INIT(*test_argv); + + std::string output = LPP_CAPTURE_STDERR(LOG(ERROR) << "Test"); + ASSERT_EQ("", output); +} + +TEST(nolog_basic, glog_syntax_severity_fatal){ + LOG_INIT(*test_argv); + + std::string output = LPP_CAPTURE_STDERR(LOG(FATAL) << "Test"); + ASSERT_EQ("", output); +} + +//! ################ lpp ################ +TEST(nolog_basic, lpp_syntax_severity_debug){ + LOG_INIT(*test_argv); + + std::string output = LPP_CAPTURE_STDOUT(LOG(D, "" << "Test")); + ASSERT_EQ("", output); +} + +TEST(nolog_basic, lpp_syntax_severity_info){ + LOG_INIT(*test_argv); + + std::string output = LPP_CAPTURE_STDOUT(LOG(I, "" << "Test")); + ASSERT_EQ("", output); +} + +TEST(nolog_basic, lpp_syntax_severity_warning){ + LOG_INIT(*test_argv); + + std::string output = LPP_CAPTURE_STDERR(LOG(W, "" << "Test")); + ASSERT_EQ("", output); +} + +TEST(nolog_basic, lpp_syntax_severity_error){ + LOG_INIT(*test_argv); + + std::string output = LPP_CAPTURE_STDERR(LOG(E, "" << "Test")); + ASSERT_EQ("", output); +} + +//! ################ Roslog ################ +TEST(nolog_basic, roslog_syntax_severity_debug){ + LOG_INIT(*test_argv); + + std::string output = LPP_CAPTURE_STDOUT(ROS_DEBUG_STREAM("Test")); + ASSERT_EQ("", output); +} + +TEST(nolog_basic, roslog_syntax_severity_info){ + LOG_INIT(*test_argv); + + std::string output = LPP_CAPTURE_STDOUT(ROS_INFO_STREAM("Test")); + ASSERT_EQ("", output); +} + +TEST(nolog_basic, roslog_syntax_severity_warning){ + LOG_INIT(*test_argv); + + std::string output = LPP_CAPTURE_STDERR(ROS_WARN_STREAM("Test")); + ASSERT_EQ("", output); +} + +TEST(nolog_basic, roslog_syntax_severity_error){ + LOG_INIT(*test_argv); + + std::string output = LPP_CAPTURE_STDERR(ROS_ERROR_STREAM("Test")); + ASSERT_EQ("", output); +} + +TEST(nolog_basic, roslog_syntax_severity_fatal){ + LOG_INIT(*test_argv); + + std::string output = LPP_CAPTURE_STDERR(ROS_FATAL_STREAM("Test")); + ASSERT_EQ("", output); +} \ No newline at end of file