Skip to content

Commit

Permalink
Added MODE_NOLOG, added test_nolog_basic.cc
Browse files Browse the repository at this point in the history
  • Loading branch information
4c3y committed Sep 6, 2023
1 parent dfbacd1 commit 0d239a7
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 2 deletions.
20 changes: 20 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
21 changes: 19 additions & 2 deletions include/log++.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
#include <functional>
#include <memory>

#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
Expand All @@ -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
Expand Down Expand Up @@ -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 {

Expand Down
108 changes: 108 additions & 0 deletions test/nolog/test_nolog_basic.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
//
// Created by acey on 06.09.23.
//

#include <gtest/gtest.h>
#include <test_utils.h>
#include <log++.h>

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);
}

0 comments on commit 0d239a7

Please sign in to comment.