Skip to content

Commit

Permalink
MODE_NOLOG: Added support for glog's LOG_STRING()
Browse files Browse the repository at this point in the history
  • Loading branch information
4c3y committed Sep 7, 2023
1 parent ec672b9 commit b5c2f33
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions include/log++.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<decltype(n)>); InternalLog()
#define DLOG_IF_EVERY_N(severity, cond, n) (void) LPP_INTL::GlogSeverity::severity; static_assert(std::is_same<decltype(cond), bool>::value && std::is_integral_v<decltype(n)>); 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<decltype(ptr), std::vector<std::string>*>::value || std::is_same<decltype(ptr), std::nullptr_t>::value); InternalLog()

//ros
#define ROS_DEBUG_STREAM(x) (void) x
Expand Down
83 changes: 83 additions & 0 deletions test/nolog/test_nolog_log_string.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
//
// Created by acey on 07.09.23.
//

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

TEST(nolog_log_string, severity_info) {
LOG_INIT(*test_argv);

std::vector<std::string> 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<std::string> 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<std::string> 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<std::string> 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, "");
}

0 comments on commit b5c2f33

Please sign in to comment.