From 06e1921cf0e93babbabf818c64549b573f8808a4 Mon Sep 17 00:00:00 2001 From: 4c3y <69460051+4c3y@users.noreply.github.com> Date: Thu, 7 Sep 2023 17:39:21 +0200 Subject: [PATCH] Added missing tests in test_lpp_rosprintf.cc + refactoring --- test/lpp/test_lpp_rosprintf.cc | 68 +++++++++++++++++++--------------- 1 file changed, 39 insertions(+), 29 deletions(-) diff --git a/test/lpp/test_lpp_rosprintf.cc b/test/lpp/test_lpp_rosprintf.cc index 32720da..94d7f68 100644 --- a/test/lpp/test_lpp_rosprintf.cc +++ b/test/lpp/test_lpp_rosprintf.cc @@ -8,62 +8,72 @@ using namespace lpp::testing; -TEST(lpp_rosprintf, ros_info) { +TEST(lpp_rosprintf, ros_debug) { + LOG_INIT(*test_argv); + + std::string output = LPP_CAPTURE_STDOUT(ROS_DEBUG(ERROR_MESSAGE, 3.3, 5.5)); + ASSERT_EQ(output, "DEBUG " + EXPECTED_ERROR_MESSAGE); +} + +TEST(lpp_rosprintf, ros_debug_once) { LOG_INIT(*test_argv); - testing::internal::CaptureStdout(); - ROS_INFO(ERROR_MESSAGE, 3.3, 5.5); - std::string c = testing::internal::GetCapturedStdout(); + std::string output = LPP_CAPTURE_STDOUT(ROS_DEBUG_ONCE(ERROR_MESSAGE, 3.3, 5.5)); + ASSERT_EQ(output, "DEBUG " + EXPECTED_ERROR_MESSAGE); +} - ASSERT_EQ(c, "INFO " + EXPECTED_ERROR_MESSAGE); +TEST(lpp_rosprintf, ros_info) { + LOG_INIT(*test_argv); + + std::string output = LPP_CAPTURE_STDOUT(ROS_INFO(ERROR_MESSAGE, 3.3, 5.5)); + ASSERT_EQ(output, "INFO " + EXPECTED_ERROR_MESSAGE); } TEST(lpp_rosprintf, ros_info_once) { LOG_INIT(*test_argv); - testing::internal::CaptureStdout(); - ROS_INFO_ONCE(ERROR_MESSAGE, 3.3, 5.5); - std::string c = testing::internal::GetCapturedStdout(); - - ASSERT_EQ(c, "INFO " + EXPECTED_ERROR_MESSAGE); + std::string output = LPP_CAPTURE_STDOUT(ROS_INFO_ONCE(ERROR_MESSAGE, 3.3, 5.5)); + ASSERT_EQ(output, "INFO " + EXPECTED_ERROR_MESSAGE); } TEST(lpp_rosprintf, ros_warn) { LOG_INIT(*test_argv); - testing::internal::CaptureStdout(); - ROS_WARN(ERROR_MESSAGE, 3.3, 5.5); - std::string c = testing::internal::GetCapturedStdout(); - - ASSERT_EQ(c, "WARN " + EXPECTED_ERROR_MESSAGE); + std::string output = LPP_CAPTURE_STDOUT(ROS_WARN(ERROR_MESSAGE, 3.3, 5.5)); + ASSERT_EQ(output, "WARN " + EXPECTED_ERROR_MESSAGE); } TEST(lpp_rosprintf, ros_warn_once) { LOG_INIT(*test_argv); - testing::internal::CaptureStdout(); - ROS_WARN_ONCE(ERROR_MESSAGE, 3.3, 5.5); - std::string c = testing::internal::GetCapturedStdout(); - - ASSERT_EQ(c, "WARN " + EXPECTED_ERROR_MESSAGE); + std::string output = LPP_CAPTURE_STDOUT(ROS_WARN_ONCE(ERROR_MESSAGE, 3.3, 5.5)); + ASSERT_EQ(output, "WARN " + EXPECTED_ERROR_MESSAGE); } TEST(lpp_rosprintf, ros_error) { LOG_INIT(*test_argv); - testing::internal::CaptureStdout(); - ROS_ERROR(ERROR_MESSAGE, 3.3, 5.5); - std::string c = testing::internal::GetCapturedStdout(); - - ASSERT_EQ(c, "ERROR " + EXPECTED_ERROR_MESSAGE); + std::string output = LPP_CAPTURE_STDOUT(ROS_ERROR(ERROR_MESSAGE, 3.3, 5.5)); + ASSERT_EQ(output, "ERROR " + EXPECTED_ERROR_MESSAGE); } TEST(lpp_rosprintf, ros_error_once) { LOG_INIT(*test_argv); - testing::internal::CaptureStdout(); - ROS_ERROR_ONCE(ERROR_MESSAGE, 3.3, 5.5); - std::string c = testing::internal::GetCapturedStdout(); + std::string output = LPP_CAPTURE_STDOUT(ROS_ERROR_ONCE(ERROR_MESSAGE, 3.3, 5.5)); + ASSERT_EQ(output, "ERROR " + EXPECTED_ERROR_MESSAGE); +} + +TEST(lpp_rosprintf, ros_fatal) { + LOG_INIT(*test_argv); + + std::string output = LPP_CAPTURE_STDOUT(ROS_FATAL(ERROR_MESSAGE, 3.3, 5.5)); + ASSERT_EQ(output, "FATAL " + EXPECTED_ERROR_MESSAGE); +} + +TEST(lpp_rosprintf, ros_fatal_once) { + LOG_INIT(*test_argv); - ASSERT_EQ(c, "ERROR " + EXPECTED_ERROR_MESSAGE); + std::string output = LPP_CAPTURE_STDOUT(ROS_FATAL_ONCE(ERROR_MESSAGE, 3.3, 5.5)); + ASSERT_EQ(output, "FATAL " + EXPECTED_ERROR_MESSAGE); } \ No newline at end of file