From 5d0da84fdd76e279d3adc255ad70881772a182b0 Mon Sep 17 00:00:00 2001 From: "Minju, Lee" <70446214+leeminju531@users.noreply.github.com> Date: Tue, 19 Sep 2023 06:13:11 +0900 Subject: [PATCH] fix the depth to relative in list_parameters (#2300) * fix the depth to relative in list_parameters Signed-off-by: leeminju531 --- rclcpp/src/rclcpp/node_interfaces/node_parameters.cpp | 2 +- rclcpp/test/rclcpp/node_interfaces/test_node_parameters.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/rclcpp/src/rclcpp/node_interfaces/node_parameters.cpp b/rclcpp/src/rclcpp/node_interfaces/node_parameters.cpp index b4c899ff9b..922ce9e4d1 100644 --- a/rclcpp/src/rclcpp/node_interfaces/node_parameters.cpp +++ b/rclcpp/src/rclcpp/node_interfaces/node_parameters.cpp @@ -1059,7 +1059,7 @@ NodeParameters::list_parameters(const std::vector & prefixes, uint6 if (depth == rcl_interfaces::srv::ListParameters::Request::DEPTH_RECURSIVE) { return true; } - std::string substr = kv.first.substr(prefix.length()); + std::string substr = kv.first.substr(prefix.length() + 1); return separators_less_than_depth(substr); } return false; diff --git a/rclcpp/test/rclcpp/node_interfaces/test_node_parameters.cpp b/rclcpp/test/rclcpp/node_interfaces/test_node_parameters.cpp index 9113c96ca5..16884489be 100644 --- a/rclcpp/test/rclcpp/node_interfaces/test_node_parameters.cpp +++ b/rclcpp/test/rclcpp/node_interfaces/test_node_parameters.cpp @@ -95,15 +95,15 @@ TEST_F(TestNodeParameters, list_parameters) std::find(list_result2.names.begin(), list_result2.names.end(), parameter_name), list_result2.names.end()); - // Check prefixes + // Check prefixes and the depth relative to the given prefixes const std::string parameter_name2 = "prefix.new_parameter"; const rclcpp::ParameterValue value2(true); const rcl_interfaces::msg::ParameterDescriptor descriptor2; const auto added_parameter_value2 = node_parameters->declare_parameter(parameter_name2, value2, descriptor2, false); - EXPECT_EQ(value.get(), added_parameter_value.get()); + EXPECT_EQ(value2.get(), added_parameter_value2.get()); prefixes = {"prefix"}; - auto list_result3 = node_parameters->list_parameters(prefixes, 2u); + auto list_result3 = node_parameters->list_parameters(prefixes, 1u); EXPECT_EQ(1u, list_result3.names.size()); EXPECT_NE( std::find(list_result3.names.begin(), list_result3.names.end(), parameter_name2),