* correctly copy state label

* correctly copy transition label

* uncrustify

* address comments

* up

* use init and fini functions from rcl
This commit is contained in:
Karsten Knese 2017-12-05 20:22:57 -08:00 committed by GitHub
parent d823982f22
commit c40f3c25c6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 272 additions and 71 deletions

View file

@ -36,6 +36,13 @@ TEST_F(TestStateWrapper, wrapper) {
EXPECT_STREQ("my_state", state.label().c_str());
}
{
std::string state_name("my_state");
rclcpp_lifecycle::State state(1, state_name);
state_name = "not_my_state";
EXPECT_STREQ("my_state", state.label().c_str());
}
{
rcl_lifecycle_state_t lc_state = {"my_c_state", 2, NULL, NULL, 0};
rclcpp_lifecycle::State c_state(lc_state.id, lc_state.label);
@ -59,9 +66,9 @@ TEST_F(TestStateWrapper, wrapper) {
EXPECT_EQ(3, c_state.id());
EXPECT_FALSE(c_state.label().empty());
EXPECT_STREQ("my_c_state", c_state.label().c_str());
delete lc_state;
}
// introduces flakiness
// unsupported behavior!
// fails when compiled with memory sanitizer

View file

@ -0,0 +1,65 @@
// Copyright 2017 Open Source Robotics Foundation, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <gtest/gtest.h>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "rclcpp_lifecycle/lifecycle_node.hpp"
class TestTransitionWrapper : public ::testing::Test
{
protected:
static void SetUpTestCase()
{
}
};
TEST_F(TestTransitionWrapper, empty_transition) {
auto a = std::make_shared<rclcpp_lifecycle::Transition>(1, "my_transition");
EXPECT_NO_THROW(a.reset());
}
TEST_F(TestTransitionWrapper, wrapper) {
{
rclcpp_lifecycle::Transition t(12, "no_states_set");
EXPECT_EQ(12, t.id());
EXPECT_STREQ("no_states_set", t.label().c_str());
}
{
std::string transition_name = "no_states_set";
rclcpp_lifecycle::Transition t(12, transition_name);
transition_name = "not_no_states_set";
EXPECT_EQ(12, t.id());
EXPECT_STREQ("no_states_set", t.label().c_str());
}
{
rclcpp_lifecycle::State start_state(1, "start_state");
rclcpp_lifecycle::State goal_state(2, "goal_state");
rclcpp_lifecycle::Transition t(
12,
"from_start_to_goal",
std::move(start_state),
std::move(goal_state));
EXPECT_EQ(12, t.id());
EXPECT_FALSE(t.label().empty());
EXPECT_STREQ("from_start_to_goal", t.label().c_str());
}
}