Skip to content

Commit

Permalink
Initial agents tests
Browse files Browse the repository at this point in the history
Signed-off-by: Alberto Tudela <[email protected]>
  • Loading branch information
ajtudela committed Oct 11, 2024
1 parent b75f028 commit 26bbc00
Show file tree
Hide file tree
Showing 13 changed files with 84 additions and 7 deletions.
2 changes: 2 additions & 0 deletions dsr_agents/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion dsr_agents/include/dsr_agents/tf_agent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
2 changes: 2 additions & 0 deletions dsr_agents/src/docking_agent_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -34,3 +35,4 @@ int main(int argc, char ** argv)
rclcpp::shutdown();
return res;
}
// LCOV_EXCL_STOP
2 changes: 2 additions & 0 deletions dsr_agents/src/nav_agent_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -34,3 +35,4 @@ int main(int argc, char ** argv)
rclcpp::shutdown();
return res;
}
// LCOV_EXCL_STOP
2 changes: 2 additions & 0 deletions dsr_agents/src/tf_agent_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -34,3 +35,4 @@ int main(int argc, char ** argv)
rclcpp::shutdown();
return res;
}
// LCOV_EXCL_STOP
2 changes: 2 additions & 0 deletions dsr_agents/src/topic_agent_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -34,3 +35,4 @@ int main(int argc, char ** argv)
rclcpp::shutdown();
return res;
}
// LCOV_EXCL_STOP
10 changes: 10 additions & 0 deletions dsr_agents/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
)
53 changes: 53 additions & 0 deletions dsr_agents/test/test_tf_agent.cpp
Original file line number Diff line number Diff line change
@@ -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<TFAgentFixture>();
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;
}
6 changes: 5 additions & 1 deletion dsr_util/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 ##
# ###########
Expand Down
2 changes: 1 addition & 1 deletion dsr_util/test/test_agent_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion dsr_util/test/test_dsr_api_ext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<robot_node_type>("test_node", 5, "test_source");
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
#include <ament_index_cpp/get_package_share_directory.hpp>
#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
{
Expand Down Expand Up @@ -72,4 +72,4 @@ class DsrUtilTest : public ::testing::Test
std::string test_file_;
};

#endif // TEST_DSR_SETUP_HPP_
#endif // UTILS__TEST_DSR_SETUP_HPP_

0 comments on commit 26bbc00

Please sign in to comment.