From 551424308f666cd228b85490d6ed93c9c180edbb Mon Sep 17 00:00:00 2001 From: Michael Carroll Date: Mon, 16 Sep 2019 13:15:41 -0500 Subject: [PATCH] Trait tests for generated actions Signed-off-by: Michael Carroll --- rclcpp_action/CMakeLists.txt | 9 ++++ rclcpp_action/test/test_traits.cpp | 72 ++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 rclcpp_action/test/test_traits.cpp diff --git a/rclcpp_action/CMakeLists.txt b/rclcpp_action/CMakeLists.txt index 727d10b158..ab3a5d8874 100644 --- a/rclcpp_action/CMakeLists.txt +++ b/rclcpp_action/CMakeLists.txt @@ -88,6 +88,15 @@ if(BUILD_TESTING) ) endif() + ament_add_gtest(test_traits test/test_traits.cpp) + if(TARGET test_traits) + ament_target_dependencies(test_traits + "test_msgs" + ) + target_link_libraries(test_traits + ${PROJECT_NAME} + ) + endif() endif() ament_package() diff --git a/rclcpp_action/test/test_traits.cpp b/rclcpp_action/test/test_traits.cpp new file mode 100644 index 0000000000..1342f543ec --- /dev/null +++ b/rclcpp_action/test/test_traits.cpp @@ -0,0 +1,72 @@ +// Copyright 2019 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 +#include + +using rosidl_generator_traits::is_message; +using rosidl_generator_traits::is_service; +using rosidl_generator_traits::is_action; +using rosidl_generator_traits::is_action_goal; +using rosidl_generator_traits::is_action_result; +using rosidl_generator_traits::is_action_feedback; + +TEST(TestActionTraits, is_action) { + using Fibonacci = test_msgs::action::Fibonacci; + + // Top level definition is an action + ASSERT_FALSE(is_message()); + ASSERT_FALSE(is_service()); + ASSERT_TRUE(is_action()); + ASSERT_FALSE(is_action_goal()); + ASSERT_FALSE(is_action_result()); + ASSERT_FALSE(is_action_feedback()); + + // Goal is an action_goal as well as a message + ASSERT_TRUE(is_message()); + ASSERT_FALSE(is_service()); + ASSERT_FALSE(is_action()); + ASSERT_TRUE(is_action_goal()); + ASSERT_FALSE(is_action_result()); + ASSERT_FALSE(is_action_feedback()); + + // Result is an action_result as well as a message + ASSERT_TRUE(is_message()); + ASSERT_FALSE(is_service()); + ASSERT_FALSE(is_action()); + ASSERT_FALSE(is_action_goal()); + ASSERT_TRUE(is_action_result()); + ASSERT_FALSE(is_action_feedback()); + + // Feedback is an action_feedback as well as a message + ASSERT_TRUE(is_message()); + ASSERT_FALSE(is_service()); + ASSERT_FALSE(is_action()); + ASSERT_FALSE(is_action_goal()); + ASSERT_FALSE(is_action_result()); + ASSERT_TRUE(is_action_feedback()); +} + +TEST(TestActionTraits, is_action_impl) { + using Fibonacci = test_msgs::action::Fibonacci; + + // Test traits on some of the internal implementation of actionlib + ASSERT_TRUE(is_service()); + ASSERT_TRUE(is_service()); + ASSERT_TRUE(is_message()); + + ASSERT_TRUE(is_service()); + ASSERT_TRUE(is_message()); +} +