Adapted logging test to Foxy

Signed-off-by: ahcorde <ahcorde@gmail.com>
This commit is contained in:
ahcorde 2020-11-03 10:51:57 +01:00 committed by Alejandro Hernández Cordero
parent d8a691f82c
commit f08c1a2bdc

View file

@ -24,12 +24,14 @@
#include "rcl/rcl.h" #include "rcl/rcl.h"
#include "rcl/subscription.h" #include "rcl/subscription.h"
#include "rcl_interfaces/msg/log.h" #include "rcl_interfaces/msg/log.h"
#include "rcl_logging_interface/rcl_logging_interface.h" #include "rcl/logging_external_interface.h"
#include "rcutils/logging_macros.h" #include "rcutils/logging_macros.h"
#include "../mocking_utils/patch.hpp" #include "../mocking_utils/patch.hpp"
#define RCL_LOGGING_RET_ERROR 2
// Define dummy comparison operators for rcutils_allocator_t type // Define dummy comparison operators for rcutils_allocator_t type
// to use with the Mimick mocking library // to use with the Mimick mocking library
MOCKING_UTILS_BOOL_OPERATOR_RETURNS_FALSE(rcutils_allocator_t, ==) MOCKING_UTILS_BOOL_OPERATOR_RETURNS_FALSE(rcutils_allocator_t, ==)
@ -173,7 +175,7 @@ TEST(TestLogging, test_failing_external_logging_configure) {
TEST(TestLogging, test_failing_logger_level_configure) { TEST(TestLogging, test_failing_logger_level_configure) {
const char * argv[] = { const char * argv[] = {
"test_logging", RCL_ROS_ARGS_FLAG, "test_logging", RCL_ROS_ARGS_FLAG,
RCL_LOG_LEVEL_FLAG, ROS_PACKAGE_NAME ":=info"}; RCL_LOG_LEVEL_FLAG, "info"};
const int argc = sizeof(argv) / sizeof(argv[0]); const int argc = sizeof(argv) / sizeof(argv[0]);
rcl_allocator_t default_allocator = rcl_get_default_allocator(); rcl_allocator_t default_allocator = rcl_get_default_allocator();
rcl_arguments_t global_arguments = rcl_get_zero_initialized_arguments(); rcl_arguments_t global_arguments = rcl_get_zero_initialized_arguments();
@ -184,15 +186,17 @@ TEST(TestLogging, test_failing_logger_level_configure) {
EXPECT_EQ(RCL_RET_OK, rcl_arguments_fini(&global_arguments)) << rcl_get_error_string().str; EXPECT_EQ(RCL_RET_OK, rcl_arguments_fini(&global_arguments)) << rcl_get_error_string().str;
}); });
{ // TODO(anyone): This part of the API is not backported to Foxy. Uncomment this block if
auto mock = mocking_utils::patch_to_fail( // someone backports this API.
"lib:rcl", rcutils_logging_set_logger_level, "failed to allocate", RCUTILS_RET_ERROR); // {
EXPECT_EQ(RCL_RET_ERROR, rcl_logging_configure(&global_arguments, &default_allocator)); // auto mock = mocking_utils::patch_to_fail(
EXPECT_TRUE(rcl_error_is_set()); // "lib:rcl", rcutils_logging_set_logger_level, "failed to allocate", RCUTILS_RET_ERROR);
rcl_reset_error(); // EXPECT_EQ(RCL_RET_ERROR, rcl_logging_configure(&global_arguments, &default_allocator));
// EXPECT_TRUE(rcl_error_is_set());
EXPECT_EQ(RCL_RET_OK, rcl_logging_fini()) << rcl_get_error_string().str; // rcl_reset_error();
} //
// EXPECT_EQ(RCL_RET_OK, rcl_logging_fini()) << rcl_get_error_string().str;
// }
} }
TEST(TestLogging, test_failing_external_logging) { TEST(TestLogging, test_failing_external_logging) {
@ -200,7 +204,7 @@ TEST(TestLogging, test_failing_external_logging) {
"test_logging", RCL_ROS_ARGS_FLAG, "test_logging", RCL_ROS_ARGS_FLAG,
"--disable-" RCL_LOG_STDOUT_FLAG_SUFFIX, "--disable-" RCL_LOG_STDOUT_FLAG_SUFFIX,
"--enable-" RCL_LOG_EXT_LIB_FLAG_SUFFIX, "--enable-" RCL_LOG_EXT_LIB_FLAG_SUFFIX,
RCL_LOG_LEVEL_FLAG, ROS_PACKAGE_NAME ":=DEBUG" RCL_LOG_LEVEL_FLAG, "debug"
}; };
const int argc = sizeof(argv) / sizeof(argv[0]); const int argc = sizeof(argv) / sizeof(argv[0]);
rcl_allocator_t default_allocator = rcl_get_default_allocator(); rcl_allocator_t default_allocator = rcl_get_default_allocator();