Skip to content

Commit

Permalink
Add rmw_set_log_severity failure test
Browse files Browse the repository at this point in the history
Signed-off-by: Christophe Bedard <bedard.christophe@gmail.com>
  • Loading branch information
christophebedard committed May 3, 2021
1 parent e8a3487 commit 90ed0db
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions rcl/test/rcl/test_logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

#include "rcutils/logging_macros.h"

#include "rmw/rmw.h"

#include "../mocking_utils/patch.hpp"

// Define dummy comparison operators for rcutils_allocator_t type
Expand Down Expand Up @@ -195,6 +197,41 @@ TEST(TestLogging, test_failing_logger_level_configure) {
}
}

TEST(TestLogging, test_failing_rmw_set_log_severity) {
const char * argv[] = {
"test_logging", RCL_ROS_ARGS_FLAG,
RCL_LOG_LEVEL_FLAG, "debug"};
const int argc = sizeof(argv) / sizeof(argv[0]);
rcl_allocator_t default_allocator = rcl_get_default_allocator();
rcl_arguments_t global_arguments = rcl_get_zero_initialized_arguments();
ASSERT_EQ(RCL_RET_OK, rcl_parse_arguments(argc, argv, default_allocator, &global_arguments)) <<
rcl_get_error_string().str;
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT(
{
EXPECT_EQ(RCL_RET_OK, rcl_arguments_fini(&global_arguments)) << rcl_get_error_string().str;
});

{
auto mock = mocking_utils::patch_to_fail(
"lib:rcl", rmw_set_log_severity, "failed", RMW_RET_ERROR);
EXPECT_EQ(RCL_RET_ERROR, rcl_logging_configure(&global_arguments, &default_allocator));
EXPECT_TRUE(rcl_error_is_set());
rcl_reset_error();

EXPECT_EQ(RCL_RET_OK, rcl_logging_fini()) << rcl_get_error_string().str;
}

{
auto mock = mocking_utils::patch_to_fail(
"lib:rcl", rmw_set_log_severity, "not supported", RMW_RET_UNSUPPORTED);
EXPECT_EQ(RCL_RET_OK, rcl_logging_configure(&global_arguments, &default_allocator));
EXPECT_TRUE(rcl_error_is_set());
rcl_reset_error();

EXPECT_EQ(RCL_RET_OK, rcl_logging_fini()) << rcl_get_error_string().str;
}
}

TEST(TestLogging, test_failing_external_logging) {
const char * argv[] = {
"test_logging", RCL_ROS_ARGS_FLAG,
Expand Down

0 comments on commit 90ed0db

Please sign in to comment.