-
Notifications
You must be signed in to change notification settings - Fork 166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix yaml parser error when meets .nan #741
Changes from all commits
2fb4342
d12c0f1
d326731
8d466b2
838881e
399c835
56a398b
1771cd9
5eb83f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
test_node: | ||
ros__parameters: | ||
isstring: [string, .nananan, .nAN, .Nan, .infinf, .INf, .infinity] | ||
nan_inf: [1.1, 2.2, .nan, .NAN, .inf, +.Inf, -.INF] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,9 +12,10 @@ | |
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include <stdio.h> | ||
#include <gtest/gtest.h> | ||
|
||
#include <cmath> | ||
|
||
#include "osrf_testing_tools_cpp/scope_exit.hpp" | ||
|
||
#include "rcl_yaml_param_parser/parser.h" | ||
|
@@ -497,6 +498,53 @@ 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; | ||
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); | ||
}); | ||
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); | ||
}); | ||
|
||
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(".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(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])); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. About inf, there are positive infinity and negative infinity. Maybe it should be
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, that make sense There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The type of return value in c++ is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, It's my bad (not to check the c++ version). |
||
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) | ||
{ | ||
::testing::InitGoogleTest(&argc, argv); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once we get ros2/rcutils#280 in, we can change this code to use
rcutils_strcasecmp
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@clalancette
FYI (#741 (comment))
The yaml spec only allows specific formats.
Besides, the existed build error doesn't seem to be caused by this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked it, the build error result from #727, the rcutils dependency has been merged, but build system still based on ros-rolling-rcutils: 1.1.0, which is the problem.
Anyway, this has no effect on this merge process.