Skip to content
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

Added parameterized test for spawner.py #1160

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 33 additions & 17 deletions controller_manager/test/test_spawner_unspawner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ using ::testing::_;
using ::testing::Return;

using namespace std::chrono_literals;
class TestLoadController : public ControllerManagerFixture<controller_manager::ControllerManager>
class TestLoadController
: public ControllerManagerFixture<controller_manager::ControllerManager>,
public ::testing::WithParamInterface<std::vector<std::variant<std::string, int, char, uint8_t>>>
{
void SetUp() override
{
Expand Down Expand Up @@ -243,22 +245,6 @@ TEST_F(TestLoadController, multi_ctrls_test_type_in_param)
}
}

TEST_F(TestLoadController, spawner_test_type_in_arg)
{
// Provide controller type via -t argument
EXPECT_EQ(
call_spawner(
"ctrl_2 -c test_controller_manager -t " +
std::string(test_controller::TEST_CONTROLLER_CLASS_NAME)),
0);

ASSERT_EQ(cm_->get_loaded_controllers().size(), 1ul);
auto ctrl_2 = cm_->get_loaded_controllers()[0];
ASSERT_EQ(ctrl_2.info.name, "ctrl_2");
ASSERT_EQ(ctrl_2.info.type, test_controller::TEST_CONTROLLER_CLASS_NAME);
ASSERT_EQ(ctrl_2.c->get_state().id(), lifecycle_msgs::msg::State::PRIMARY_STATE_ACTIVE);
}

TEST_F(TestLoadController, unload_on_kill)
{
// Launch spawner with unload on kill
Expand All @@ -274,3 +260,33 @@ TEST_F(TestLoadController, unload_on_kill)

ASSERT_EQ(cm_->get_loaded_controllers().size(), 0ul);
}

INSTANTIATE_TEST_SUITE_P(
SpawnerTestParameterizedAllParameters, TestLoadController,
::testing::Values(std::vector<std::variant<std::string, int, char, uint8_t>>{
"ctrl_2 -c test_controller_manager -t " +
std::string(test_controller::TEST_CONTROLLER_CLASS_NAME),
0, 1, "ctrl_2", test_controller::TEST_CONTROLLER_CLASS_NAME,
lifecycle_msgs::msg::State::PRIMARY_STATE_ACTIVE}));

TEST_P(TestLoadController, SpawnerTestAllParameters)
{
auto vector_of_params = GetParam();

std::string call_spawner_argument = std::get<std::string>(vector_of_params[0]);
int call_spawner_return_value = std::get<int>(vector_of_params[1]);
int number_of_loaded_controllers = std::get<int>(vector_of_params[2]);
std::string controller_name = std::get<std::string>(vector_of_params[3]);
std::string controller_class_name = std::get<std::string>(vector_of_params[4]);
static uint8_t lifecycle_state = std::get<uint8_t>(vector_of_params[5]);

EXPECT_EQ(

call_spawner(call_spawner_argument), call_spawner_return_value);

ASSERT_EQ(cm_->get_loaded_controllers().size(), number_of_loaded_controllers);
auto ctrl_2 = cm_->get_loaded_controllers()[0];
ASSERT_EQ(ctrl_2.info.name, controller_name);
ASSERT_EQ(ctrl_2.info.type, controller_class_name);
ASSERT_EQ(ctrl_2.c->get_state().id(), lifecycle_state);
}
Loading