diff --git a/velodyne_pointcloud/tests/issue_84_float_intensities.yaml b/velodyne_pointcloud/params/issue_84_float_intensities.yaml similarity index 100% rename from velodyne_pointcloud/tests/issue_84_float_intensities.yaml rename to velodyne_pointcloud/params/issue_84_float_intensities.yaml diff --git a/velodyne_pointcloud/tests/CMakeLists.txt b/velodyne_pointcloud/tests/CMakeLists.txt index 624d46dd5..6295af554 100644 --- a/velodyne_pointcloud/tests/CMakeLists.txt +++ b/velodyne_pointcloud/tests/CMakeLists.txt @@ -10,10 +10,21 @@ ament_target_dependencies(test_row_step velodyne_msgs ) -# C++ gtests -# catkin_add_gtest(test_calibration test_calibration.cpp) -# add_dependencies(test_calibration ${catkin_EXPORTED_TARGETS}) -# target_link_libraries(test_calibration velodyne_rawdata ${catkin_LIBRARIES}) +ament_add_gtest(test_calibration + test_calibration.cpp +) + +target_link_libraries(test_calibration + velodyne_rawdata +) + +ament_target_dependencies(test_calibration + rclcpp +) + +target_link_libraries(test_calibration + ${YAML_CPP_LIBRARIES} +) # # Download packet capture (PCAP) files containing test data. # # Store them in devel-space, so rostest can easily find them. diff --git a/velodyne_pointcloud/tests/test_calibration.cpp b/velodyne_pointcloud/tests/test_calibration.cpp index 406219dc9..b5f925e13 100644 --- a/velodyne_pointcloud/tests/test_calibration.cpp +++ b/velodyne_pointcloud/tests/test_calibration.cpp @@ -32,29 +32,35 @@ #include -#include +#include + #include #include using namespace velodyne_pointcloud; // NOLINT +std::string get_package_path() +{ + std::string g_package_name("velodyne_pointcloud"); + return ament_index_cpp::get_package_share_directory(g_package_name); +} + /////////////////////////////////////////////////////////////// // Test cases /////////////////////////////////////////////////////////////// TEST(Calibration, missing_file) { - Calibration calibration(false); - calibration.read("./no_such_file.yaml"); - EXPECT_FALSE(calibration.initialized); + EXPECT_THROW( + {Calibration calibration("/no_such_file.yaml");}, + std::runtime_error + ); } TEST(Calibration, vlp16) { - std::string g_package_path = ros::package::getPath("velodyne_pointcloud"); - Calibration calibration(g_package_path + "/params/VLP16db.yaml", false); - EXPECT_TRUE(calibration.initialized); + Calibration calibration(get_package_path() + "/params/VLP16db.yaml"); ASSERT_EQ(calibration.num_lasers, 16); // check some values for the first laser: @@ -76,9 +82,7 @@ TEST(Calibration, vlp16) TEST(Calibration, hdl32e) { - std::string g_package_path = ros::package::getPath("velodyne_pointcloud"); - Calibration calibration(g_package_path + "/params/32db.yaml", false); - EXPECT_TRUE(calibration.initialized); + Calibration calibration(get_package_path() + "/params/32db.yaml"); ASSERT_EQ(calibration.num_lasers, 32); // check some values for the first laser: @@ -100,9 +104,7 @@ TEST(Calibration, hdl32e) TEST(Calibration, hdl64e) { - std::string g_package_path = ros::package::getPath("velodyne_pointcloud"); - Calibration calibration(g_package_path + "/params/64e_utexas.yaml", false); - EXPECT_TRUE(calibration.initialized); + Calibration calibration(get_package_path() + "/params/64e_utexas.yaml"); ASSERT_EQ(calibration.num_lasers, 64); // check some values for the first laser: @@ -124,10 +126,7 @@ TEST(Calibration, hdl64e) TEST(Calibration, hdl64e_s21) { - std::string g_package_path = ros::package::getPath("velodyne_pointcloud"); - Calibration calibration( - g_package_path + "/params/64e_s2.1-sztaki.yaml", false); - EXPECT_TRUE(calibration.initialized); + Calibration calibration(get_package_path() + "/params/64e_s2.1-sztaki.yaml"); ASSERT_EQ(calibration.num_lasers, 64); // check some values for the first laser: @@ -149,10 +148,7 @@ TEST(Calibration, hdl64e_s21) TEST(Calibration, hdl64e_s2_float_intensities) { - std::string g_package_path = ros::package::getPath("velodyne_pointcloud"); - Calibration calibration( - g_package_path + "/tests/issue_84_float_intensities.yaml", false); - EXPECT_TRUE(calibration.initialized); + Calibration calibration(get_package_path() + "/params/issue_84_float_intensities.yaml"); ASSERT_EQ(calibration.num_lasers, 64); // check some values for the first laser: @@ -179,11 +175,3 @@ TEST(Calibration, hdl64e_s2_float_intensities) EXPECT_EQ(laser.max_intensity, 255); EXPECT_EQ(laser.min_intensity, 0); } - -// Run all the tests that were declared with TEST() -int main(int argc, char ** argv) -{ - testing::InitGoogleTest(&argc, argv); - init_global_data(); - return RUN_ALL_TESTS(); -}