diff --git a/rcl_yaml_param_parser/test/test_parse_yaml.cpp b/rcl_yaml_param_parser/test/test_parse_yaml.cpp index 5714404..2916b06 100644 --- a/rcl_yaml_param_parser/test/test_parse_yaml.cpp +++ b/rcl_yaml_param_parser/test/test_parse_yaml.cpp @@ -313,9 +313,12 @@ TEST(test_file_parser, seq_map1) { ASSERT_TRUE(rcutils_exists(path)) << "No test YAML file found at " << path; rcl_params_t * params_hdl = rcl_yaml_node_struct_init(allocator); ASSERT_TRUE(NULL != params_hdl) << rcutils_get_error_string().str; + OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT( + { + rcl_yaml_node_struct_fini(params_hdl); + }); bool res = rcl_parse_yaml_file(path, params_hdl); EXPECT_FALSE(res); - // No cleanup, rcl_parse_yaml_file takes care of that if it fails. } TEST(test_file_parser, seq_map2) { @@ -337,9 +340,12 @@ TEST(test_file_parser, seq_map2) { ASSERT_TRUE(rcutils_exists(path)) << "No test YAML file found at " << path; rcl_params_t * params_hdl = rcl_yaml_node_struct_init(allocator); ASSERT_TRUE(NULL != params_hdl) << rcutils_get_error_string().str; + OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT( + { + rcl_yaml_node_struct_fini(params_hdl); + }); bool res = rcl_parse_yaml_file(path, params_hdl); EXPECT_FALSE(res); - // No cleanup, rcl_parse_yaml_file takes care of that if it fails } TEST(test_file_parser, params_with_no_node) { @@ -361,9 +367,12 @@ TEST(test_file_parser, params_with_no_node) { ASSERT_TRUE(rcutils_exists(path)) << "No test YAML file found at " << path; rcl_params_t * params_hdl = rcl_yaml_node_struct_init(allocator); ASSERT_TRUE(NULL != params_hdl) << rcutils_get_error_string().str; + OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT( + { + rcl_yaml_node_struct_fini(params_hdl); + }); bool res = rcl_parse_yaml_file(path, params_hdl); EXPECT_FALSE(res); - // No cleanup, rcl_parse_yaml_file takes care of that if it fails. } TEST(test_file_parser, no_alias_support) { @@ -385,9 +394,12 @@ TEST(test_file_parser, no_alias_support) { ASSERT_TRUE(rcutils_exists(path)) << "No test YAML file found at " << path; rcl_params_t * params_hdl = rcl_yaml_node_struct_init(allocator); ASSERT_TRUE(NULL != params_hdl) << rcutils_get_error_string().str; + OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT( + { + rcl_yaml_node_struct_fini(params_hdl); + }); bool res = rcl_parse_yaml_file(path, params_hdl); EXPECT_FALSE(res); - // No cleanup, rcl_parse_yaml_file takes care of that if it fails. } TEST(test_file_parser, empty_string) { @@ -437,9 +449,12 @@ TEST(test_file_parser, no_value1) { ASSERT_TRUE(rcutils_exists(path)) << "No test YAML file found at " << path; rcl_params_t * params_hdl = rcl_yaml_node_struct_init(allocator); ASSERT_TRUE(NULL != params_hdl) << rcutils_get_error_string().str; + OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT( + { + rcl_yaml_node_struct_fini(params_hdl); + }); bool res = rcl_parse_yaml_file(path, params_hdl); EXPECT_FALSE(res); - // No cleanup, rcl_parse_yaml_file takes care of that if it fails. } TEST(test_file_parser, indented_ns) { @@ -461,9 +476,12 @@ TEST(test_file_parser, indented_ns) { ASSERT_TRUE(rcutils_exists(path)) << "No test YAML file found at " << path; rcl_params_t * params_hdl = rcl_yaml_node_struct_init(allocator); ASSERT_TRUE(NULL != params_hdl) << rcutils_get_error_string().str; + OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT( + { + rcl_yaml_node_struct_fini(params_hdl); + }); bool res = rcl_parse_yaml_file(path, params_hdl); EXPECT_FALSE(res); - // No cleanup, rcl_parse_yaml_file takes care of that if it fails. } // Regression test for https://github.com/ros2/rcl/issues/419 @@ -486,9 +504,12 @@ TEST(test_file_parser, maximum_number_parameters) { ASSERT_TRUE(rcutils_exists(path)) << "No test YAML file found at " << path; rcl_params_t * params_hdl = rcl_yaml_node_struct_init(allocator); ASSERT_TRUE(NULL != params_hdl) << rcutils_get_error_string().str; + OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT( + { + rcl_yaml_node_struct_fini(params_hdl); + }); bool res = rcl_parse_yaml_file(path, params_hdl); EXPECT_FALSE(res); - // No cleanup, rcl_parse_yaml_file takes care of that if it fails. } // Test special float point(https://github.com/ros2/rcl/issues/555). diff --git a/rcl_yaml_param_parser/test/test_parser.cpp b/rcl_yaml_param_parser/test/test_parser.cpp index 7fbb7f8..34dc844 100644 --- a/rcl_yaml_param_parser/test/test_parser.cpp +++ b/rcl_yaml_param_parser/test/test_parser.cpp @@ -330,11 +330,9 @@ TEST(RclYamlParamParser, test_parse_file_with_bad_allocator) { bool res = rcl_parse_yaml_file(path, params_hdl); // Not verifying res is true or false here, because eventually it will come back with an ok // result. We're just trying to make sure that bad allocations are properly handled - if (res) { - // This is already freed in the case of a non-ok error in rcl_parse_yaml_file - rcl_yaml_node_struct_fini(params_hdl); - params_hdl = NULL; - } + (void)res; + rcl_yaml_node_struct_fini(params_hdl); + params_hdl = NULL; } // Check sporadic failing calloc calls @@ -347,11 +345,9 @@ TEST(RclYamlParamParser, test_parse_file_with_bad_allocator) { bool res = rcl_parse_yaml_file(path, params_hdl); // Not verifying res is true or false here, because eventually it will come back with an ok // result. We're just trying to make sure that bad allocations are properly handled - if (res) { - // This is already freed in the case of a non-ok error in rcl_parse_yaml_file - rcl_yaml_node_struct_fini(params_hdl); - params_hdl = NULL; - } + (void)res; + rcl_yaml_node_struct_fini(params_hdl); + params_hdl = NULL; } }