Skip to content

Commit

Permalink
Split tests for init and config missing params
Browse files Browse the repository at this point in the history
  • Loading branch information
guihomework committed Apr 3, 2023
1 parent 8a1e588 commit 40d47f3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
38 changes: 21 additions & 17 deletions admittance_controller/test/test_admittance_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,34 @@
#include <utility>
#include <vector>

// Test on_configure returns ERROR when a required parameter is missing
TEST_P(AdmittanceControllerTestParameterizedMissingParameters, one_parameter_is_missing)
// Test on_init returns ERROR when a required parameter is missing
TEST_P(AdmittanceControllerTestParameterizedMissingParameters, one_control_parameter_is_missing)
{
auto ret = SetUpController(GetParam());
// additionally, test params required during configure only if init worked
if (ret == controller_interface::return_type::OK)
{
ASSERT_EQ(controller_->on_configure(rclcpp_lifecycle::State()), NODE_FAILURE);
}
else
{
ASSERT_EQ(ret, controller_interface::return_type::ERROR);
}
ASSERT_EQ(SetUpController(GetParam()), controller_interface::return_type::ERROR);
}

INSTANTIATE_TEST_SUITE_P(
MissingMandatoryParameterDuringConfiguration,
AdmittanceControllerTestParameterizedMissingParameters,
MissingMandatoryParameterDuringInit, AdmittanceControllerTestParameterizedMissingParameters,
::testing::Values(
"admittance.mass", "admittance.selected_axes", "admittance.stiffness",
"chainable_command_interfaces", "command_interfaces", "control.frame.id", "ft_sensor.frame.id",
"ft_sensor.name", "sensor_filter_chain.filter2.params.CoG.pos",
"sensor_filter_chain.filter2.params.sensor_frame", "joints", "kinematics.base",
"kinematics.plugin_name", "kinematics.plugin_package", "kinematics.tip", "state_interfaces"));
"ft_sensor.name", "joints", "kinematics.base", "kinematics.plugin_name",
"kinematics.plugin_package", "kinematics.tip", "state_interfaces"));

// Test on_configure returns FAILURE when a required parameter is missing
TEST_P(
AdmittanceControllerTestParameterizedMissingConfigParameters, one_config_parameter_is_missing)
{
SetUpController(GetParam());
ASSERT_EQ(controller_->on_configure(rclcpp_lifecycle::State()), NODE_FAILURE);
}

INSTANTIATE_TEST_SUITE_P(
MissingMandatoryParameterDuringConfiguration,
AdmittanceControllerTestParameterizedMissingConfigParameters,
::testing::Values(
"sensor_filter_chain.filter2.params.CoG.pos",
"sensor_filter_chain.filter2.params.sensor_frame"));

INSTANTIATE_TEST_SUITE_P(
InvalidParameterDuringConfiguration, AdmittanceControllerTestParameterizedInvalidParameters,
Expand Down
5 changes: 5 additions & 0 deletions admittance_controller/test/test_admittance_controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,11 @@ class AdmittanceControllerTestParameterizedMissingParameters
std::map<std::string, rclcpp::ParameterValue> overrides_;
};

class AdmittanceControllerTestParameterizedMissingConfigParameters
: public AdmittanceControllerTestParameterizedMissingParameters
{
};

// From the tutorial: https://www.sandordargo.com/blog/2019/04/24/parameterized-testing-with-gtest
class AdmittanceControllerTestParameterizedInvalidParameters
: public AdmittanceControllerTest,
Expand Down

0 comments on commit 40d47f3

Please sign in to comment.