Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Ar-Ray-code committed Nov 22, 2023
1 parent 27d3df6 commit 90cbd6f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
10 changes: 10 additions & 0 deletions panel_detector_plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ if(BUILD_TESTING)
set(ament_cmake_copyright_FOUND TRUE)
set(ament_cmake_cpplint_FOUND TRUE)
ament_lint_auto_find_test_dependencies()

find_package(ament_cmake_gtest REQUIRED)
find_package(ament_cmake_gmock REQUIRED)

set(TEST_TARGETS
test_publish_center)
foreach(TARGET ${TEST_TARGETS})
ament_add_gtest(${TARGET} test/src/${TARGET}.cpp)
target_link_libraries(${TARGET} ${PROJECT_NAME} ${OpenCV_LIBRARIES})
endforeach()
endif()

pluginlib_export_plugin_description_file(panel_detector_base panel_detector_plugins.xml)
Expand Down
34 changes: 34 additions & 0 deletions panel_detector_plugins/test/src/test_publish_center.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <gtest/gtest.h>
#include <opencv2/opencv.hpp>
#include <panel_detector_base/panel_detector_base.hpp>
#include <panel_detector_param/panel_detector_param.hpp>
#include <panel_detector_plugins/publish_center.hpp>
#include <rclcpp/rclcpp.hpp>

class TestErrorMsgGenerator : public ::testing::Test
{
protected:
std::unique_ptr<panel_detector_plugins::PublishCenter> target_class_;
std::shared_ptr<panel_detector_parameters::ParamListener> param_listener_;

virtual void SetUp()
{
rclcpp::init(0, nullptr);
auto node = std::make_shared<rclcpp::Node>("test_node");

this->target_class_ =
std::make_unique<panel_detector_plugins::PublishCenter>();

this->param_listener_ =
std::make_shared<panel_detector_parameters::ParamListener>(
node->get_node_parameters_interface());
this->target_class_->init(*this->param_listener_);
}
};

TEST_F(TestErrorMsgGenerator, test_default)
{
auto result = this->target_class_->detect(cv::Mat(480, 640, CV_8UC3));
EXPECT_EQ(result.detections[0].bbox.center.position.x, 320);
EXPECT_EQ(result.detections[0].bbox.center.position.y, 240);
}

0 comments on commit 90cbd6f

Please sign in to comment.