Skip to content

Commit

Permalink
create load_parameters TEST
Browse files Browse the repository at this point in the history
  • Loading branch information
Brice committed Mar 24, 2021
1 parent 1ceb46f commit f63f6fb
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
47 changes: 47 additions & 0 deletions rclcpp/test/rclcpp/test_parameter_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -902,3 +902,50 @@ TEST_F(TestParameterClient, sync_parameter_delete_parameters) {
get_result[0].get_type(),
rcl_interfaces::msg::ParameterType::PARAMETER_NOT_SET);
}

/*
Coverage for async load_parameters
*/
TEST_F(TestParameterClient, async_parameter_load_parameters) {
auto load_node = std::make_shared<rclcpp::Node>(
"load_node",
"namespace",
rclcpp::NodeOptions().allow_undeclared_parameters(true));
auto asynchronous_client =
std::make_shared<rclcpp::AsyncParametersClient>(load_node);
// load parameters
rcpputils::fs::path test_resources_path{TEST_RESOURCES_DIRECTORY};
const std::string parameters_filepath = (
test_resources_path / "test_node" / "load_parameters.yaml").string();
auto load_future = asynchronous_client->load_parameters(parameters_filepath);
rclcpp::spin_until_future_complete(
load_node, load_future, std::chrono::milliseconds(100));
ASSERT_EQ(load_future.get()[0].successful, true);
// list parameters
auto list_parameters = asynchronous_client->list_parameters({}, 3);
rclcpp::spin_until_future_complete(
load_node, list_parameters, std::chrono::milliseconds(100));
ASSERT_EQ(
list_parameters.get().names.size(),
5);
}
/*
Coverage for sync load_parameters
*/
TEST_F(TestParameterClient, sync_parameter_load_parameters) {
auto load_node = std::make_shared<rclcpp::Node>(
"load_node",
"namespace",
rclcpp::NodeOptions().allow_undeclared_parameters(true));
auto synchronous_client =
std::make_shared<rclcpp::SyncParametersClient>(load_node);
// load parameters
rcpputils::fs::path test_resources_path{TEST_RESOURCES_DIRECTORY};
const std::string parameters_filepath = (
test_resources_path / "test_node" / "load_parameters.yaml").string();
auto load_future = synchronous_client->load_parameters(parameters_filepath);
ASSERT_EQ(load_future[0].successful, true);
// list parameters
auto list_parameters = synchronous_client->list_parameters({}, 3);
ASSERT_EQ(list_parameters.names.size(), 5);
}
18 changes: 18 additions & 0 deletions rclcpp/test/resources/test_node/load_parameters.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**:
ros__parameters:
bar: 5
foo: 3.5

/*:
load_node:
ros__parameters:
bar_foo: "ok"

namespace:
load_node:
ros__parameters:
foo_bar: true

bar:
ros__parameters:
fatal: 10

0 comments on commit f63f6fb

Please sign in to comment.