diff --git a/dsr_agents/CMakeLists.txt b/dsr_agents/CMakeLists.txt index ccaa54e..90b73f3 100644 --- a/dsr_agents/CMakeLists.txt +++ b/dsr_agents/CMakeLists.txt @@ -226,6 +226,8 @@ if(BUILD_TESTING) # the following line skips the linter which checks for copyrights set(ament_cmake_copyright_FOUND TRUE) ament_lint_auto_find_test_dependencies() + + add_subdirectory(test) endif() # Export old-style CMake variables diff --git a/dsr_agents/include/dsr_agents/tf_agent.hpp b/dsr_agents/include/dsr_agents/tf_agent.hpp index bdd43f5..5d3188c 100644 --- a/dsr_agents/include/dsr_agents/tf_agent.hpp +++ b/dsr_agents/include/dsr_agents/tf_agent.hpp @@ -45,7 +45,7 @@ class TFAgent : public dsr_util::AgentNode */ explicit TFAgent(const rclcpp::NodeOptions & options = rclcpp::NodeOptions()); -private: +protected: /** * @brief Callback to receive TF messages from ROS 2. * diff --git a/dsr_agents/src/docking_agent_node.cpp b/dsr_agents/src/docking_agent_node.cpp index 1f7b683..0c4a5ef 100644 --- a/dsr_agents/src/docking_agent_node.cpp +++ b/dsr_agents/src/docking_agent_node.cpp @@ -19,6 +19,7 @@ #include "dsr_util/qt_executor.hpp" #include "dsr_agents/docking_agent.hpp" +// LCOV_EXCL_START int main(int argc, char ** argv) { QCoreApplication app(argc, argv); @@ -34,3 +35,4 @@ int main(int argc, char ** argv) rclcpp::shutdown(); return res; } +// LCOV_EXCL_STOP diff --git a/dsr_agents/src/nav_agent_node.cpp b/dsr_agents/src/nav_agent_node.cpp index ad33535..036365b 100644 --- a/dsr_agents/src/nav_agent_node.cpp +++ b/dsr_agents/src/nav_agent_node.cpp @@ -19,6 +19,7 @@ #include "dsr_util/qt_executor.hpp" #include "dsr_agents/nav_agent.hpp" +// LCOV_EXCL_START int main(int argc, char ** argv) { QCoreApplication app(argc, argv); @@ -34,3 +35,4 @@ int main(int argc, char ** argv) rclcpp::shutdown(); return res; } +// LCOV_EXCL_STOP diff --git a/dsr_agents/src/tf_agent_node.cpp b/dsr_agents/src/tf_agent_node.cpp index 04f8d08..ce8c90b 100644 --- a/dsr_agents/src/tf_agent_node.cpp +++ b/dsr_agents/src/tf_agent_node.cpp @@ -19,6 +19,7 @@ #include "dsr_util/qt_executor.hpp" #include "dsr_agents/tf_agent.hpp" +// LCOV_EXCL_START int main(int argc, char ** argv) { QCoreApplication app(argc, argv); @@ -34,3 +35,4 @@ int main(int argc, char ** argv) rclcpp::shutdown(); return res; } +// LCOV_EXCL_STOP diff --git a/dsr_agents/src/topic_agent_node.cpp b/dsr_agents/src/topic_agent_node.cpp index 033cde4..276682a 100644 --- a/dsr_agents/src/topic_agent_node.cpp +++ b/dsr_agents/src/topic_agent_node.cpp @@ -19,6 +19,7 @@ #include "dsr_util/qt_executor.hpp" #include "dsr_agents/topic_agent.hpp" +// LCOV_EXCL_START int main(int argc, char ** argv) { QCoreApplication app(argc, argv); @@ -34,3 +35,4 @@ int main(int argc, char ** argv) rclcpp::shutdown(); return res; } +// LCOV_EXCL_STOP diff --git a/dsr_agents/test/CMakeLists.txt b/dsr_agents/test/CMakeLists.txt new file mode 100644 index 0000000..c01784b --- /dev/null +++ b/dsr_agents/test/CMakeLists.txt @@ -0,0 +1,10 @@ +find_package(dsr_util REQUIRED) + +# Test for tf agent node +ament_add_gtest(test_tf_agent test_tf_agent.cpp) +target_link_libraries(test_tf_agent + + ${fastrtps_LIBRARIES} + tf_agent + ament_index_cpp::ament_index_cpp +) diff --git a/dsr_agents/test/test_tf_agent.cpp b/dsr_agents/test/test_tf_agent.cpp new file mode 100644 index 0000000..97c071b --- /dev/null +++ b/dsr_agents/test/test_tf_agent.cpp @@ -0,0 +1,53 @@ +// Copyright (c) 2024 Alberto J. Tudela Roldán +// Copyright (c) 2024 Grupo Avispa, DTE, Universidad de Málaga +// +// 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 "dsr_agents/tf_agent.hpp" +#include "dsr_util/utils/test_dsr_setup.hpp" +#include "lifecycle_msgs/msg/state.hpp" + +class TFAgentFixture : public dsr_agents::TFAgent +{ +public: + TFAgentFixture() + : dsr_agents::TFAgent() + { + } + ~TFAgentFixture() = default; +}; + +TEST_F(DsrUtilTest, tfAgentConfigure) { + // Create the node + auto agent_node = std::make_shared(); + agent_node->declare_parameter("dsr_input_file", rclcpp::ParameterValue(test_file_)); + + const auto state_after_configure = agent_node->configure(); + ASSERT_EQ(state_after_configure.id(), lifecycle_msgs::msg::State::PRIMARY_STATE_INACTIVE); + + agent_node->activate(); + agent_node->deactivate(); + agent_node->cleanup(); + agent_node->shutdown(); +} + +int main(int argc, char ** argv) +{ + QCoreApplication app(argc, argv); + testing::InitGoogleTest(&argc, argv); + rclcpp::init(argc, argv); + bool success = RUN_ALL_TESTS(); + rclcpp::shutdown(); + return success; +} diff --git a/dsr_util/CMakeLists.txt b/dsr_util/CMakeLists.txt index 49dfe1c..1c68ca1 100644 --- a/dsr_util/CMakeLists.txt +++ b/dsr_util/CMakeLists.txt @@ -124,10 +124,14 @@ install(DIRECTORY worlds DESTINATION share/${PROJECT_NAME}/ ) -install(FILES test/test_dsr.json +install(FILES test/utils/test_dsr.json DESTINATION share/${PROJECT_NAME}/test ) +install(DIRECTORY test/utils/ + DESTINATION include/${PROJECT_NAME}/${PROJECT_NAME}/utils +) + # ########### # Testing ## # ########### diff --git a/dsr_util/test/test_agent_node.cpp b/dsr_util/test/test_agent_node.cpp index a565b98..41b2165 100644 --- a/dsr_util/test/test_agent_node.cpp +++ b/dsr_util/test/test_agent_node.cpp @@ -17,7 +17,7 @@ #include "dsr_util/agent_node.hpp" #include "lifecycle_msgs/msg/state.hpp" #include "tf2_geometry_msgs/tf2_geometry_msgs.hpp" -#include "test_dsr_setup.hpp" +#include "utils/test_dsr_setup.hpp" class AgentNodeFixture : public dsr_util::AgentNode { diff --git a/dsr_util/test/test_dsr_api_ext.cpp b/dsr_util/test/test_dsr_api_ext.cpp index b0efba7..d99607d 100644 --- a/dsr_util/test/test_dsr_api_ext.cpp +++ b/dsr_util/test/test_dsr_api_ext.cpp @@ -14,7 +14,7 @@ // limitations under the License. #include "gtest/gtest.h" -#include "test_dsr_setup.hpp" +#include "utils/test_dsr_setup.hpp" TEST_F(DsrUtilTest, apiExtCreateNodeWithPriority) { auto node = G_->create_node_with_priority("test_node", 5, "test_source"); diff --git a/dsr_util/test/test_dsr.json b/dsr_util/test/utils/test_dsr.json similarity index 100% rename from dsr_util/test/test_dsr.json rename to dsr_util/test/utils/test_dsr.json diff --git a/dsr_util/test/test_dsr_setup.hpp b/dsr_util/test/utils/test_dsr_setup.hpp similarity index 95% rename from dsr_util/test/test_dsr_setup.hpp rename to dsr_util/test/utils/test_dsr_setup.hpp index ced6553..9c14e36 100644 --- a/dsr_util/test/test_dsr_setup.hpp +++ b/dsr_util/test/utils/test_dsr_setup.hpp @@ -22,8 +22,8 @@ #include #include "dsr_util/dsr_api_ext.hpp" -#ifndef TEST_DSR_SETUP_HPP_ -#define TEST_DSR_SETUP_HPP_ +#ifndef UTILS__TEST_DSR_SETUP_HPP_ +#define UTILS__TEST_DSR_SETUP_HPP_ class DSRGraphExtFixture : public dsr_util::DSRGraphExt { @@ -72,4 +72,4 @@ class DsrUtilTest : public ::testing::Test std::string test_file_; }; -#endif // TEST_DSR_SETUP_HPP_ +#endif // UTILS__TEST_DSR_SETUP_HPP_