From 2fb43429d277c8e5e8ea69a9d746b6e5fcbf787c Mon Sep 17 00:00:00 2001 From: Ada-King Date: Wed, 12 Aug 2020 10:26:46 +0800 Subject: [PATCH 1/9] Fix yaml parser error when meets .nan Signed-off-by: Ada-King --- rcl_yaml_param_parser/src/parser.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/rcl_yaml_param_parser/src/parser.c b/rcl_yaml_param_parser/src/parser.c index e0405d48c..8d7f20b72 100644 --- a/rcl_yaml_param_parser/src/parser.c +++ b/rcl_yaml_param_parser/src/parser.c @@ -1105,6 +1105,10 @@ static void * get_value( { errno = 0; endptr = NULL; + if(strcasecmp(value, ".nan") == 0) { + char *tmp_value = (char *)value; + strcpy(tmp_value, "nan"); + } dval = strtod(value, &endptr); if ((0 == errno) && (NULL != endptr)) { if ((NULL != endptr) && (endptr != value)) { From d12c0f1e3cdcf45f89802f95165bfe6fd211289a Mon Sep 17 00:00:00 2001 From: Ada-King Date: Wed, 12 Aug 2020 11:40:42 +0800 Subject: [PATCH 2/9] Correct code style Signed-off-by: Ada-King --- rcl_yaml_param_parser/src/parser.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rcl_yaml_param_parser/src/parser.c b/rcl_yaml_param_parser/src/parser.c index 8d7f20b72..dc8b97d99 100644 --- a/rcl_yaml_param_parser/src/parser.c +++ b/rcl_yaml_param_parser/src/parser.c @@ -1105,9 +1105,9 @@ static void * get_value( { errno = 0; endptr = NULL; - if(strcasecmp(value, ".nan") == 0) { - char *tmp_value = (char *)value; - strcpy(tmp_value, "nan"); + if (strcasecmp(value, ".nan") == 0) { + char * tmp_value = (char *)value; + snprintf(tmp_value, strlen(tmp_value), "%s", "nan"); } dval = strtod(value, &endptr); if ((0 == errno) && (NULL != endptr)) { From d32673104b2447c5b42b0f50ebe5130bb5c0d4e5 Mon Sep 17 00:00:00 2001 From: Ada-King Date: Tue, 18 Aug 2020 10:51:05 +0800 Subject: [PATCH 3/9] Modify as suggested Signed-off-by: Ada-King --- rcl_yaml_param_parser/src/parser.c | 21 ++++++-- .../test/special_float1.yaml | 8 ++++ .../test/special_float2.yaml | 8 ++++ .../test/test_parse_yaml.cpp | 48 +++++++++++++++++++ 4 files changed, 81 insertions(+), 4 deletions(-) create mode 100644 rcl_yaml_param_parser/test/special_float1.yaml create mode 100644 rcl_yaml_param_parser/test/special_float2.yaml diff --git a/rcl_yaml_param_parser/src/parser.c b/rcl_yaml_param_parser/src/parser.c index dc8b97d99..5306a83a1 100644 --- a/rcl_yaml_param_parser/src/parser.c +++ b/rcl_yaml_param_parser/src/parser.c @@ -21,6 +21,7 @@ #include #include #include +#include #include "rcl_yaml_param_parser/parser.h" #include "rcl_yaml_param_parser/types.h" @@ -1105,11 +1106,23 @@ static void * get_value( { errno = 0; endptr = NULL; - if (strcasecmp(value, ".nan") == 0) { - char * tmp_value = (char *)value; - snprintf(tmp_value, strlen(tmp_value), "%s", "nan"); + char * tmp_value = NULL; + if ((0 == strcasecmp(value, ".nan")) || + (0 == strcasecmp(value, ".inf")) || + (0 == strcasecmp(value, "+.inf")) || + (0 == strcasecmp(value, "-.inf")) || + (0 == strcasecmp(value, ".infinity")) || + (0 == strcasecmp(value, "+.infinity")) || + (0 == strcasecmp(value, "-.infinity"))) + { + tmp_value = rcutils_strdup(value, allocator); + for ( ; !isalpha(*tmp_value); ) { + tmp_value += 1; + } + dval = strtod(tmp_value, &endptr); + } else { + dval = strtod(value, &endptr); } - dval = strtod(value, &endptr); if ((0 == errno) && (NULL != endptr)) { if ((NULL != endptr) && (endptr != value)) { if (('\0' != *value) && ('\0' == *endptr)) { diff --git a/rcl_yaml_param_parser/test/special_float1.yaml b/rcl_yaml_param_parser/test/special_float1.yaml new file mode 100644 index 000000000..ac392c2d4 --- /dev/null +++ b/rcl_yaml_param_parser/test/special_float1.yaml @@ -0,0 +1,8 @@ +# config/test_yaml +--- + +lidar_ns: + lidar_1: + ros__parameters: + test_nan: [1.1, 2.2, .nan, .NAN] + test_inf: [4.4, 5.5, .inf, +.inf, -.INF, +.infinity, -.INFINITY] diff --git a/rcl_yaml_param_parser/test/special_float2.yaml b/rcl_yaml_param_parser/test/special_float2.yaml new file mode 100644 index 000000000..2af3c8a91 --- /dev/null +++ b/rcl_yaml_param_parser/test/special_float2.yaml @@ -0,0 +1,8 @@ +# config/test_yaml +--- + +lidar_ns: + lidar_1: + ros__parameters: + test_nan: [1.1, 2.2, nananana] + test_nan2: [3.3, nanananan] diff --git a/rcl_yaml_param_parser/test/test_parse_yaml.cpp b/rcl_yaml_param_parser/test/test_parse_yaml.cpp index c69114ba5..815156f46 100644 --- a/rcl_yaml_param_parser/test/test_parse_yaml.cpp +++ b/rcl_yaml_param_parser/test/test_parse_yaml.cpp @@ -497,6 +497,54 @@ TEST(test_file_parser, maximum_number_parameters) { // No cleanup, rcl_parse_yaml_file takes care of that if it fails. } +TEST(test_file_parser, special_float_point) { + rcutils_reset_error(); + EXPECT_TRUE(rcutils_get_cwd(cur_dir, 1024)) << rcutils_get_error_string().str; + rcutils_allocator_t allocator = rcutils_get_default_allocator(); + char * test_path = rcutils_join_path(cur_dir, "test", allocator); + ASSERT_TRUE(NULL != test_path) << rcutils_get_error_string().str; + OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT( + { + allocator.deallocate(test_path, allocator.state); + }); + + // Test special float point with correct value. + { + char * path = rcutils_join_path(test_path, "special_float1.yaml", allocator); + ASSERT_TRUE(NULL != path) << rcutils_get_error_string().str; + OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT( + { + allocator.deallocate(path, allocator.state); + }); + 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_TRUE(res) << rcutils_get_error_string().str; + } + + // Test special float point with improperly value. + { + char * path = rcutils_join_path(test_path, "special_float2.yaml", allocator); + ASSERT_TRUE(NULL != path) << rcutils_get_error_string().str; + OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT( + { + allocator.deallocate(path, allocator.state); + }); + 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; + bool res = rcl_parse_yaml_file(path, params_hdl); + fprintf(stderr, "%s\n", rcutils_get_error_string().str); + EXPECT_FALSE(res); + // No cleanup, rcl_parse_yaml_file takes care of that if it fails. + } +} + int32_t main(int32_t argc, char ** argv) { ::testing::InitGoogleTest(&argc, argv); From 8d466b2e4748143f059d63f2ad25ed55f49be76a Mon Sep 17 00:00:00 2001 From: Ada-King Date: Wed, 19 Aug 2020 16:24:11 +0800 Subject: [PATCH 4/9] Improve test Signed-off-by: Ada-King --- rcl_yaml_param_parser/src/parser.c | 9 ++- rcl_yaml_param_parser/test/special_float.yaml | 4 ++ .../test/special_float1.yaml | 8 --- .../test/special_float2.yaml | 8 --- .../test/test_parse_yaml.cpp | 66 +++++++++---------- 5 files changed, 40 insertions(+), 55 deletions(-) create mode 100644 rcl_yaml_param_parser/test/special_float.yaml delete mode 100644 rcl_yaml_param_parser/test/special_float1.yaml delete mode 100644 rcl_yaml_param_parser/test/special_float2.yaml diff --git a/rcl_yaml_param_parser/src/parser.c b/rcl_yaml_param_parser/src/parser.c index 5306a83a1..ea86a419f 100644 --- a/rcl_yaml_param_parser/src/parser.c +++ b/rcl_yaml_param_parser/src/parser.c @@ -1106,7 +1106,7 @@ static void * get_value( { errno = 0; endptr = NULL; - char * tmp_value = NULL; + const char * vernier_ptr = NULL; if ((0 == strcasecmp(value, ".nan")) || (0 == strcasecmp(value, ".inf")) || (0 == strcasecmp(value, "+.inf")) || @@ -1115,11 +1115,10 @@ static void * get_value( (0 == strcasecmp(value, "+.infinity")) || (0 == strcasecmp(value, "-.infinity"))) { - tmp_value = rcutils_strdup(value, allocator); - for ( ; !isalpha(*tmp_value); ) { - tmp_value += 1; + for (vernier_ptr = value; !isalpha(*vernier_ptr); ) { + vernier_ptr += 1; } - dval = strtod(tmp_value, &endptr); + dval = strtod(vernier_ptr, &endptr); } else { dval = strtod(value, &endptr); } diff --git a/rcl_yaml_param_parser/test/special_float.yaml b/rcl_yaml_param_parser/test/special_float.yaml new file mode 100644 index 000000000..d6bd2dd0f --- /dev/null +++ b/rcl_yaml_param_parser/test/special_float.yaml @@ -0,0 +1,4 @@ +test_node: + ros__parameters: + isstring: [string, .nananan, .infinf] + nan_inf: [1.1, 2.2, .nan, .NAN, .inf, +.inf, -.INF, +.infinity, -.INFINITY] diff --git a/rcl_yaml_param_parser/test/special_float1.yaml b/rcl_yaml_param_parser/test/special_float1.yaml deleted file mode 100644 index ac392c2d4..000000000 --- a/rcl_yaml_param_parser/test/special_float1.yaml +++ /dev/null @@ -1,8 +0,0 @@ -# config/test_yaml ---- - -lidar_ns: - lidar_1: - ros__parameters: - test_nan: [1.1, 2.2, .nan, .NAN] - test_inf: [4.4, 5.5, .inf, +.inf, -.INF, +.infinity, -.INFINITY] diff --git a/rcl_yaml_param_parser/test/special_float2.yaml b/rcl_yaml_param_parser/test/special_float2.yaml deleted file mode 100644 index 2af3c8a91..000000000 --- a/rcl_yaml_param_parser/test/special_float2.yaml +++ /dev/null @@ -1,8 +0,0 @@ -# config/test_yaml ---- - -lidar_ns: - lidar_1: - ros__parameters: - test_nan: [1.1, 2.2, nananana] - test_nan2: [3.3, nanananan] diff --git a/rcl_yaml_param_parser/test/test_parse_yaml.cpp b/rcl_yaml_param_parser/test/test_parse_yaml.cpp index 815156f46..7661be3a5 100644 --- a/rcl_yaml_param_parser/test/test_parse_yaml.cpp +++ b/rcl_yaml_param_parser/test/test_parse_yaml.cpp @@ -13,6 +13,7 @@ // limitations under the License. #include +#include #include #include "osrf_testing_tools_cpp/scope_exit.hpp" @@ -497,6 +498,7 @@ TEST(test_file_parser, maximum_number_parameters) { // No cleanup, rcl_parse_yaml_file takes care of that if it fails. } +// Test special float point(https://github.com/ros2/rcl/issues/555). TEST(test_file_parser, special_float_point) { rcutils_reset_error(); EXPECT_TRUE(rcutils_get_cwd(cur_dir, 1024)) << rcutils_get_error_string().str; @@ -507,42 +509,38 @@ TEST(test_file_parser, special_float_point) { { allocator.deallocate(test_path, allocator.state); }); + char * path = rcutils_join_path(test_path, "special_float.yaml", allocator); + ASSERT_TRUE(NULL != path) << rcutils_get_error_string().str; + OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT( + { + allocator.deallocate(path, allocator.state); + }); + 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); + }); - // Test special float point with correct value. - { - char * path = rcutils_join_path(test_path, "special_float1.yaml", allocator); - ASSERT_TRUE(NULL != path) << rcutils_get_error_string().str; - OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT( - { - allocator.deallocate(path, allocator.state); - }); - 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_TRUE(res) << rcutils_get_error_string().str; - } + bool res = rcl_parse_yaml_file(path, params_hdl); + EXPECT_TRUE(res) << rcutils_get_error_string().str; + rcl_variant_t * param_value = rcl_yaml_node_struct_get("test_node", "isstring", params_hdl); + ASSERT_TRUE(NULL != param_value) << rcutils_get_error_string().str; + ASSERT_TRUE(NULL != param_value->string_array_value); + EXPECT_STREQ(".nananan", param_value->string_array_value->data[1]); + EXPECT_STREQ(".infinf", param_value->string_array_value->data[2]); + param_value = rcl_yaml_node_struct_get( + "test_node", "nan_inf", params_hdl); + ASSERT_TRUE(NULL != param_value) << rcutils_get_error_string().str; + ASSERT_TRUE(NULL != param_value->double_array_value); + ASSERT_EQ(9U, param_value->double_array_value->size); + EXPECT_TRUE(isnan(param_value->double_array_value->values[2])); + EXPECT_TRUE(isnan(param_value->double_array_value->values[3])); + EXPECT_TRUE(isinf(param_value->double_array_value->values[4])); + EXPECT_TRUE(isinf(param_value->double_array_value->values[5])); - // Test special float point with improperly value. - { - char * path = rcutils_join_path(test_path, "special_float2.yaml", allocator); - ASSERT_TRUE(NULL != path) << rcutils_get_error_string().str; - OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT( - { - allocator.deallocate(path, allocator.state); - }); - 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; - bool res = rcl_parse_yaml_file(path, params_hdl); - fprintf(stderr, "%s\n", rcutils_get_error_string().str); - EXPECT_FALSE(res); - // No cleanup, rcl_parse_yaml_file takes care of that if it fails. - } + rcl_yaml_node_struct_print(params_hdl); } int32_t main(int32_t argc, char ** argv) From 838881e848fae7db6cc924bf2e672e6e634cfb9f Mon Sep 17 00:00:00 2001 From: Ada-King Date: Thu, 20 Aug 2020 10:31:45 +0800 Subject: [PATCH 5/9] Fix minor flaw Signed-off-by: Ada-King --- rcl_yaml_param_parser/test/test_parse_yaml.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/rcl_yaml_param_parser/test/test_parse_yaml.cpp b/rcl_yaml_param_parser/test/test_parse_yaml.cpp index 7661be3a5..b47af35cc 100644 --- a/rcl_yaml_param_parser/test/test_parse_yaml.cpp +++ b/rcl_yaml_param_parser/test/test_parse_yaml.cpp @@ -12,10 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include -#include #include +#include + #include "osrf_testing_tools_cpp/scope_exit.hpp" #include "rcl_yaml_param_parser/parser.h" @@ -535,12 +535,10 @@ TEST(test_file_parser, special_float_point) { ASSERT_TRUE(NULL != param_value) << rcutils_get_error_string().str; ASSERT_TRUE(NULL != param_value->double_array_value); ASSERT_EQ(9U, param_value->double_array_value->size); - EXPECT_TRUE(isnan(param_value->double_array_value->values[2])); - EXPECT_TRUE(isnan(param_value->double_array_value->values[3])); - EXPECT_TRUE(isinf(param_value->double_array_value->values[4])); - EXPECT_TRUE(isinf(param_value->double_array_value->values[5])); - - rcl_yaml_node_struct_print(params_hdl); + EXPECT_TRUE(std::isnan(param_value->double_array_value->values[2])); + EXPECT_TRUE(std::isnan(param_value->double_array_value->values[3])); + EXPECT_TRUE(std::isinf(param_value->double_array_value->values[4])); + EXPECT_TRUE(std::isinf(param_value->double_array_value->values[5])); } int32_t main(int32_t argc, char ** argv) From 399c835d0d7f99110c2458a56ba1bbe7796cbc6a Mon Sep 17 00:00:00 2001 From: Ada-King Date: Thu, 20 Aug 2020 10:51:33 +0800 Subject: [PATCH 6/9] Fix minor flaw again Signed-off-by: Ada-King --- rcl_yaml_param_parser/src/parser.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rcl_yaml_param_parser/src/parser.c b/rcl_yaml_param_parser/src/parser.c index ea86a419f..def7e83a0 100644 --- a/rcl_yaml_param_parser/src/parser.c +++ b/rcl_yaml_param_parser/src/parser.c @@ -1106,7 +1106,7 @@ static void * get_value( { errno = 0; endptr = NULL; - const char * vernier_ptr = NULL; + const char * iter_ptr = NULL; if ((0 == strcasecmp(value, ".nan")) || (0 == strcasecmp(value, ".inf")) || (0 == strcasecmp(value, "+.inf")) || @@ -1115,10 +1115,10 @@ static void * get_value( (0 == strcasecmp(value, "+.infinity")) || (0 == strcasecmp(value, "-.infinity"))) { - for (vernier_ptr = value; !isalpha(*vernier_ptr); ) { - vernier_ptr += 1; + for (iter_ptr = value; !isalpha(*iter_ptr); ) { + iter_ptr += 1; } - dval = strtod(vernier_ptr, &endptr); + dval = strtod(iter_ptr, &endptr); } else { dval = strtod(value, &endptr); } From 56a398b7e3aefa27129d6962e68e10432bf7b9be Mon Sep 17 00:00:00 2001 From: Ada-King Date: Fri, 21 Aug 2020 11:06:39 +0800 Subject: [PATCH 7/9] Satisfy windows CI Signed-off-by: Ada-King --- rcl_yaml_param_parser/include/rcl_yaml_param_parser/parser.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/rcl_yaml_param_parser/include/rcl_yaml_param_parser/parser.h b/rcl_yaml_param_parser/include/rcl_yaml_param_parser/parser.h index 3243b43de..0e71986e9 100644 --- a/rcl_yaml_param_parser/include/rcl_yaml_param_parser/parser.h +++ b/rcl_yaml_param_parser/include/rcl_yaml_param_parser/parser.h @@ -32,6 +32,10 @@ #include "rcl_yaml_param_parser/types.h" #include "rcl_yaml_param_parser/visibility_control.h" +#ifdef _WIN32 +#define strcasecmp stricmp +#endif + #ifdef __cplusplus extern "C" { From 1771cd948fea7b9dddc3a4191c8ea27f5bc29ec9 Mon Sep 17 00:00:00 2001 From: Ada-King Date: Tue, 25 Aug 2020 18:32:09 +0800 Subject: [PATCH 8/9] Change the match rule for special float Signed-off-by: Ada-King --- .../include/rcl_yaml_param_parser/parser.h | 4 ---- rcl_yaml_param_parser/src/parser.c | 19 ++++++++++++------- rcl_yaml_param_parser/test/special_float.yaml | 4 ++-- .../test/test_parse_yaml.cpp | 8 ++++++-- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/rcl_yaml_param_parser/include/rcl_yaml_param_parser/parser.h b/rcl_yaml_param_parser/include/rcl_yaml_param_parser/parser.h index 0e71986e9..3243b43de 100644 --- a/rcl_yaml_param_parser/include/rcl_yaml_param_parser/parser.h +++ b/rcl_yaml_param_parser/include/rcl_yaml_param_parser/parser.h @@ -32,10 +32,6 @@ #include "rcl_yaml_param_parser/types.h" #include "rcl_yaml_param_parser/visibility_control.h" -#ifdef _WIN32 -#define strcasecmp stricmp -#endif - #ifdef __cplusplus extern "C" { diff --git a/rcl_yaml_param_parser/src/parser.c b/rcl_yaml_param_parser/src/parser.c index def7e83a0..43354806f 100644 --- a/rcl_yaml_param_parser/src/parser.c +++ b/rcl_yaml_param_parser/src/parser.c @@ -1107,13 +1107,18 @@ static void * get_value( errno = 0; endptr = NULL; const char * iter_ptr = NULL; - if ((0 == strcasecmp(value, ".nan")) || - (0 == strcasecmp(value, ".inf")) || - (0 == strcasecmp(value, "+.inf")) || - (0 == strcasecmp(value, "-.inf")) || - (0 == strcasecmp(value, ".infinity")) || - (0 == strcasecmp(value, "+.infinity")) || - (0 == strcasecmp(value, "-.infinity"))) + if ((0 == strcmp(value, ".nan")) || + (0 == strcmp(value, ".NaN")) || + (0 == strcmp(value, ".NAN")) || + (0 == strcmp(value, ".inf")) || + (0 == strcmp(value, ".Inf")) || + (0 == strcmp(value, ".INF")) || + (0 == strcmp(value, "+.inf")) || + (0 == strcmp(value, "+.Inf")) || + (0 == strcmp(value, "+.INF")) || + (0 == strcmp(value, "-.inf")) || + (0 == strcmp(value, "-.Inf")) || + (0 == strcmp(value, "-.INF"))) { for (iter_ptr = value; !isalpha(*iter_ptr); ) { iter_ptr += 1; diff --git a/rcl_yaml_param_parser/test/special_float.yaml b/rcl_yaml_param_parser/test/special_float.yaml index d6bd2dd0f..b3215e33d 100644 --- a/rcl_yaml_param_parser/test/special_float.yaml +++ b/rcl_yaml_param_parser/test/special_float.yaml @@ -1,4 +1,4 @@ test_node: ros__parameters: - isstring: [string, .nananan, .infinf] - nan_inf: [1.1, 2.2, .nan, .NAN, .inf, +.inf, -.INF, +.infinity, -.INFINITY] + isstring: [string, .nananan, .nAN, .Nan, .infinf, .INf, .infinity] + nan_inf: [1.1, 2.2, .nan, .NAN, .inf, +.Inf, -.INF] diff --git a/rcl_yaml_param_parser/test/test_parse_yaml.cpp b/rcl_yaml_param_parser/test/test_parse_yaml.cpp index b47af35cc..e7a7f1f15 100644 --- a/rcl_yaml_param_parser/test/test_parse_yaml.cpp +++ b/rcl_yaml_param_parser/test/test_parse_yaml.cpp @@ -529,16 +529,20 @@ TEST(test_file_parser, special_float_point) { ASSERT_TRUE(NULL != param_value) << rcutils_get_error_string().str; ASSERT_TRUE(NULL != param_value->string_array_value); EXPECT_STREQ(".nananan", param_value->string_array_value->data[1]); - EXPECT_STREQ(".infinf", param_value->string_array_value->data[2]); + EXPECT_STREQ(".nAN", param_value->string_array_value->data[2]); + EXPECT_STREQ(".infinf", param_value->string_array_value->data[4]); + EXPECT_STREQ(".INf", param_value->string_array_value->data[5]); param_value = rcl_yaml_node_struct_get( "test_node", "nan_inf", params_hdl); ASSERT_TRUE(NULL != param_value) << rcutils_get_error_string().str; ASSERT_TRUE(NULL != param_value->double_array_value); - ASSERT_EQ(9U, param_value->double_array_value->size); + ASSERT_EQ(7U, param_value->double_array_value->size); + EXPECT_FALSE(std::isnan(param_value->double_array_value->values[1])); EXPECT_TRUE(std::isnan(param_value->double_array_value->values[2])); EXPECT_TRUE(std::isnan(param_value->double_array_value->values[3])); EXPECT_TRUE(std::isinf(param_value->double_array_value->values[4])); EXPECT_TRUE(std::isinf(param_value->double_array_value->values[5])); + EXPECT_TRUE(std::isinf(param_value->double_array_value->values[6])); } int32_t main(int32_t argc, char ** argv) From 5eb83f43a3b8378886922ec3c2d934b7af73eba4 Mon Sep 17 00:00:00 2001 From: Ada-King Date: Wed, 26 Aug 2020 18:28:52 +0800 Subject: [PATCH 9/9] Distinguish +.inf and -.inf Signed-off-by: Ada-King --- rcl_yaml_param_parser/src/parser.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rcl_yaml_param_parser/src/parser.c b/rcl_yaml_param_parser/src/parser.c index 43354806f..db79273b5 100644 --- a/rcl_yaml_param_parser/src/parser.c +++ b/rcl_yaml_param_parser/src/parser.c @@ -1124,6 +1124,9 @@ static void * get_value( iter_ptr += 1; } dval = strtod(iter_ptr, &endptr); + if (*value == '-') { + dval = -dval; + } } else { dval = strtod(value, &endptr); }