Fix 394 (#419)
* copy and assignment operator for state copy and assignment operator for transition remove unused const_casts address comments check for null in copy constructor up use init and fini functions from rcl remove unused include * explicitly zero initialize state and transitions * add todo comment for follow up
This commit is contained in:
parent
c40f3c25c6
commit
6d13bcb0fc
6 changed files with 286 additions and 6 deletions
|
@ -82,3 +82,87 @@ TEST_F(TestStateWrapper, wrapper) {
|
|||
// EXPECT_STREQ("my_c_state", c_state.label().c_str());
|
||||
// }
|
||||
}
|
||||
|
||||
TEST_F(TestStateWrapper, copy_constructor) {
|
||||
auto a = std::make_shared<rclcpp_lifecycle::State>(1, "my_c_state");
|
||||
rclcpp_lifecycle::State b(*a);
|
||||
|
||||
a.reset();
|
||||
|
||||
EXPECT_EQ(1, b.id());
|
||||
EXPECT_STREQ("my_c_state", b.label().c_str());
|
||||
}
|
||||
|
||||
TEST_F(TestStateWrapper, assignment_operator) {
|
||||
auto a = std::make_shared<rclcpp_lifecycle::State>(1, "one");
|
||||
auto b = std::make_shared<rclcpp_lifecycle::State>(2, "two");
|
||||
*b = *a;
|
||||
|
||||
a.reset();
|
||||
|
||||
EXPECT_EQ(1, b->id());
|
||||
EXPECT_STREQ("one", b->label().c_str());
|
||||
}
|
||||
|
||||
TEST_F(TestStateWrapper, assignment_operator2) {
|
||||
// Non-owning State
|
||||
rcl_lifecycle_state_t * lc_state1 =
|
||||
new rcl_lifecycle_state_t{"my_c_state1", 1, NULL, NULL, 0};
|
||||
auto non_owning_state1 = std::make_shared<rclcpp_lifecycle::State>(lc_state1);
|
||||
|
||||
// Non-owning State
|
||||
rcl_lifecycle_state_t * lc_state2 =
|
||||
new rcl_lifecycle_state_t{"my_c_state2", 2, NULL, NULL, 0};
|
||||
auto non_owning_state2 = std::make_shared<rclcpp_lifecycle::State>(lc_state2);
|
||||
|
||||
*non_owning_state2 = *non_owning_state1;
|
||||
|
||||
EXPECT_EQ(1, non_owning_state2->id());
|
||||
EXPECT_STREQ("my_c_state1", non_owning_state2->label().c_str());
|
||||
|
||||
non_owning_state1.reset();
|
||||
non_owning_state2.reset();
|
||||
|
||||
delete lc_state1;
|
||||
delete lc_state2;
|
||||
}
|
||||
|
||||
TEST_F(TestStateWrapper, assignment_operator3) {
|
||||
// Non-owning State
|
||||
rcl_lifecycle_state_t * lc_state1 =
|
||||
new rcl_lifecycle_state_t{"my_c_state1", 1, NULL, NULL, 0};
|
||||
auto non_owning_state1 = std::make_shared<rclcpp_lifecycle::State>(lc_state1);
|
||||
|
||||
// owning State
|
||||
auto owning_state2 = std::make_shared<rclcpp_lifecycle::State>(2, "my_c_state2");
|
||||
|
||||
*owning_state2 = *non_owning_state1;
|
||||
|
||||
EXPECT_EQ(1, owning_state2->id());
|
||||
EXPECT_STREQ("my_c_state1", owning_state2->label().c_str());
|
||||
|
||||
non_owning_state1.reset();
|
||||
owning_state2.reset();
|
||||
|
||||
delete lc_state1;
|
||||
}
|
||||
|
||||
TEST_F(TestStateWrapper, assignment_operator4) {
|
||||
// Non-owning State
|
||||
rcl_lifecycle_state_t * lc_state1 =
|
||||
new rcl_lifecycle_state_t{"my_c_state1", 1, NULL, NULL, 0};
|
||||
auto non_owning_state1 = std::make_shared<rclcpp_lifecycle::State>(lc_state1);
|
||||
|
||||
// owning State
|
||||
auto owning_state2 = std::make_shared<rclcpp_lifecycle::State>(2, "my_c_state2");
|
||||
|
||||
*non_owning_state1 = *owning_state2;
|
||||
|
||||
EXPECT_EQ(2, non_owning_state1->id());
|
||||
EXPECT_STREQ("my_c_state2", non_owning_state1->label().c_str());
|
||||
|
||||
non_owning_state1.reset();
|
||||
owning_state2.reset();
|
||||
|
||||
delete lc_state1;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue