Skip to content

Commit

Permalink
Add test to check for locale-independent double parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
henningkayser committed Jan 23, 2023
1 parent 5dba42c commit 1a427bc
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions hardware_interface/test/test_component_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,8 +465,6 @@ TEST_F(TestComponentParser, successfully_parse_valid_urdf_sensor_only)

TEST_F(TestComponentParser, successfully_parse_valid_urdf_actuator_only)
{
std::setlocale(LC_NUMERIC, "de_DE.UTF-8");

std::string urdf_to_test = std::string(ros2_control_test_assets::urdf_head) +
ros2_control_test_assets::valid_urdf_ros2_control_actuator_only +
ros2_control_test_assets::urdf_tail;
Expand Down Expand Up @@ -512,6 +510,30 @@ TEST_F(TestComponentParser, successfully_parse_valid_urdf_actuator_only)
EXPECT_EQ(transmission.parameters.at("additional_special_parameter"), "1337");
}

TEST_F(TestComponentParser, successfully_parse_locale_independent_double)
{
// Set to locale with comma-separated decimals
std::setlocale(LC_NUMERIC, "de_DE.UTF-8");

std::string urdf_to_test = std::string(ros2_control_test_assets::urdf_head) +
ros2_control_test_assets::valid_urdf_ros2_control_actuator_only +
ros2_control_test_assets::urdf_tail;

const auto control_hardware = parse_control_resources_from_urdf(urdf_to_test);
ASSERT_THAT(control_hardware, SizeIs(1));
const auto hardware_info = control_hardware.at(0);

EXPECT_EQ(hardware_info.hardware_parameters.at("example_param_write_for_sec"), "1.13");

ASSERT_THAT(hardware_info.transmissions, SizeIs(1));
const auto transmission = hardware_info.transmissions[0];
EXPECT_THAT(transmission.joints, SizeIs(1));
const auto joint = transmission.joints[0];

// Test that we still parse doubles using dot notation
EXPECT_THAT(joint.mechanical_reduction, DoubleEq(325.949));
}

TEST_F(TestComponentParser, successfully_parse_valid_urdf_system_robot_with_gpio)
{
std::string urdf_to_test =
Expand Down

0 comments on commit 1a427bc

Please sign in to comment.