From b3e8d554a963226531e2a4db69a23e1f91b3d9ab Mon Sep 17 00:00:00 2001 From: goes Date: Mon, 6 May 2024 20:41:58 +0800 Subject: [PATCH] reformat Signed-off-by: goes --- .../include/nav2_util/validate_messages.hpp | 19 +- nav2_util/test/test_validation_messages.cpp | 172 +++++++++--------- 2 files changed, 95 insertions(+), 96 deletions(-) diff --git a/nav2_util/include/nav2_util/validate_messages.hpp b/nav2_util/include/nav2_util/validate_messages.hpp index 89a7264e4b..b646cb1c0f 100644 --- a/nav2_util/include/nav2_util/validate_messages.hpp +++ b/nav2_util/include/nav2_util/validate_messages.hpp @@ -56,11 +56,11 @@ bool validateMsg(const double & num) } template -bool validateMsg(const std::array& msg) { +bool validateMsg(const std::array & msg) +{ // @brief double-array value check - for (const auto& element : msg) - { - if(!validateMsg(element)) {return false;} + for (const auto & element : msg) { + if (!validateMsg(element)) {return false;} } return true; @@ -125,22 +125,21 @@ bool validateMsg(const geometry_msgs::msg::Pose & msg) bool validateMsg(const geometry_msgs::msg::PoseWithCovariance & msg) { // check sub-type - if(!validateMsg(msg.pose)) {return false;} - if(!validateMsg(msg.covariance)) {return false;} - + if (!validateMsg(msg.pose)) {return false;} + if (!validateMsg(msg.covariance)) {return false;} + return true; } bool validateMsg(const geometry_msgs::msg::PoseWithCovarianceStamped & msg) { // check sub-type - if(!validateMsg(msg.header)) {return false;} - if(!validateMsg(msg.pose)) {return false;} + if (!validateMsg(msg.header)) {return false;} + if (!validateMsg(msg.pose)) {return false;} return true; } - // Function to verify map meta information bool validateMsg(const nav_msgs::msg::MapMetaData & msg) { diff --git a/nav2_util/test/test_validation_messages.cpp b/nav2_util/test/test_validation_messages.cpp index c972984df7..634fa5d500 100644 --- a/nav2_util/test/test_validation_messages.cpp +++ b/nav2_util/test/test_validation_messages.cpp @@ -244,34 +244,34 @@ TEST(ValidateMessagesTest, OccupancyGridCheck) { EXPECT_FALSE(nav2_util::validateMsg(invalid_occupancy_grid)); } -TEST(ValidateMessagesTest, PoseWithCovarianceCheck){ +TEST(ValidateMessagesTest, PoseWithCovarianceCheck) { geometry_msgs::msg::PoseWithCovariance validate_msg = { // covariance {0.25, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, - 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, - 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.06853891909122467}, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.06853891909122467}, // pose { - // position - {0.50010401010515571, 1.7468730211257935, 0.0}, - // orientation - {0.9440542194053062, 0.0, 0.0, -0.32979028309372299} + // position + {0.50010401010515571, 1.7468730211257935, 0.0}, + // orientation + {0.9440542194053062, 0.0, 0.0, -0.32979028309372299} } }; EXPECT_TRUE(nav2_util::validateMsg(validate_msg)); - geometry_msgs::msg::PoseWithCovariance - invalidate_msg = { + geometry_msgs::msg::PoseWithCovariance + invalidate_msg = { // covariance {0.25, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, NAN, 0.0, NAN, 0.0, 0.0, 0.0, 0.0, 0.0, - 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, - 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.06853891909122467}, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.06853891909122467}, // pose { - // position - {0.50010401010515571, 1.7468730211257935, 0.0}, - // orientation - {0.9440542194053062, 0.0, 0.0, -0.32979028309372299} + // position + {0.50010401010515571, 1.7468730211257935, 0.0}, + // orientation + {0.9440542194053062, 0.0, 0.0, -0.32979028309372299} } }; EXPECT_FALSE(nav2_util::validateMsg(invalidate_msg)); @@ -279,103 +279,103 @@ TEST(ValidateMessagesTest, PoseWithCovarianceCheck){ invalidate_msg = { // covariance {0.25, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, - 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, - 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.06853891909122467}, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.06853891909122467}, // pose { - // position - {NAN, 1.7468730211257935, 0.0}, - // orientation - {0.9440542194053062, 0.0, 0.0, -0.32979028309372299} + // position + {NAN, 1.7468730211257935, 0.0}, + // orientation + {0.9440542194053062, 0.0, 0.0, -0.32979028309372299} } }; EXPECT_FALSE(nav2_util::validateMsg(invalidate_msg)); } -TEST(ValidateMessagesTest, PoseWithCovarianceStampedCheck){ +TEST(ValidateMessagesTest, PoseWithCovarianceStampedCheck) { geometry_msgs::msg::PoseWithCovarianceStamped validate_msg = { - // Header + // Header + { + // frame_id + "map", + // stamp { - // frame_id - "map", - // stamp - { - 1711029956, // sec - 146734875 // nanosec - } - }, - // Pose + 1711029956, // sec + 146734875 // nanosec + } + }, + // Pose + { + // covariance + {0.25, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.06853891909122467}, + // pose { - // covariance - {0.25, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, - 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, - 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.06853891909122467}, - // pose - { - // position - {0.50010401010515571, 1.7468730211257935, 0.0}, - // orientation - {0.9440542194053062, 0.0, 0.0, -0.32979028309372299} - } + // position + {0.50010401010515571, 1.7468730211257935, 0.0}, + // orientation + {0.9440542194053062, 0.0, 0.0, -0.32979028309372299} } + } }; EXPECT_TRUE(nav2_util::validateMsg(validate_msg)); geometry_msgs::msg::PoseWithCovarianceStamped - invalidate_msg = { - // Header + invalidate_msg = { + // Header + { + // frame_id + "map", + // stamp { - // frame_id - "map", - // stamp - { - 1711029956, // sec - 146734875 // nanosec - } - }, - // Pose + 1711029956, // sec + 146734875 // nanosec + } + }, + // Pose + { + // covariance + {0.25, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, NAN, 0.0, NAN, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.06853891909122467}, + // pose { - // covariance - {0.25, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, NAN, 0.0, NAN, 0.0, 0.0, 0.0, 0.0, 0.0, - 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, - 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.06853891909122467}, - // pose - { - // position - {0.50010401010515571, 1.7468730211257935, 0.0}, - // orientation - {0.9440542194053062, 0.0, 0.0, -0.32979028309372299} - } + // position + {0.50010401010515571, 1.7468730211257935, 0.0}, + // orientation + {0.9440542194053062, 0.0, 0.0, -0.32979028309372299} } + } }; EXPECT_FALSE(nav2_util::validateMsg(invalidate_msg)); invalidate_msg = { - // Header + // Header + { + // frame_id + "", + // stamp { - // frame_id - "", - // stamp - { - 1711029956, // sec - 146734875 // nanosec - } - }, - // Pose + 1711029956, // sec + 146734875 // nanosec + } + }, + // Pose + { + // covariance + {0.25, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.06853891909122467}, + // pose { - // covariance - {0.25, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, - 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, - 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.06853891909122467}, - // pose - { - // position - {0.50010401010515571, 1.7468730211257935, 0.0}, - // orientation - {0.9440542194053062, 0.0, 0.0, -0.32979028309372299} - } + // position + {0.50010401010515571, 1.7468730211257935, 0.0}, + // orientation + {0.9440542194053062, 0.0, 0.0, -0.32979028309372299} } + } }; EXPECT_FALSE(nav2_util::validateMsg(invalidate_msg)); }