From e07cdf61e53af45946b779b3ca8ca5ae04e175c3 Mon Sep 17 00:00:00 2001 From: Berkay Karaman Date: Wed, 13 Mar 2024 15:59:41 +0300 Subject: [PATCH] feat: simplify node and topic names Signed-off-by: Berkay Karaman --- .../src/ros/test_published_time_publisher.cpp | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/common/tier4_autoware_utils/test/src/ros/test_published_time_publisher.cpp b/common/tier4_autoware_utils/test/src/ros/test_published_time_publisher.cpp index 96965114630c2..3b55a87fd47bb 100644 --- a/common/tier4_autoware_utils/test/src/ros/test_published_time_publisher.cpp +++ b/common/tier4_autoware_utils/test/src/ros/test_published_time_publisher.cpp @@ -34,19 +34,27 @@ class PublishedTimePublisherTest : public ::testing::Test { ASSERT_TRUE(rclcpp::ok()); + // Simplify node and topic names for brevity and uniqueness + const std::string test_name = ::testing::UnitTest::GetInstance()->current_test_info()->name(); + const std::string base_name = + "published_time_publisher_" + test_name; // Base name for node and topics + const std::string suffix = "/debug/published_time"; + // Create a node - node_ = std::make_shared("PublishedTimePublisher_test_node"); + node_ = std::make_shared(base_name + "_node"); + // Create a publisher - test_publisher_ = - node_->create_publisher("PublishedTimePublisher_test_topic", 1); + test_publisher_ = node_->create_publisher(base_name, 1); + // Create a PublishedTimePublisher published_time_publisher_ = std::make_shared(node_.get()); + // Create a subscriber test_subscriber_ = node_->create_subscription( - "PublishedTimePublisher_test_topic/debug/published_time", 1, - [this](autoware_internal_msgs::msg::PublishedTime::SharedPtr msg) { - this->published_time_ = msg; + base_name + suffix, 1, + [this](autoware_internal_msgs::msg::PublishedTime::ConstSharedPtr msg) { + this->published_time_ = std::move(msg); }); rclcpp::spin_some(node_); } @@ -56,12 +64,17 @@ class PublishedTimePublisherTest : public ::testing::Test TEST_F(PublishedTimePublisherTest, PublishMsgWithHeader) { + // Check if the PublishedTimePublisher is created + ASSERT_TRUE(published_time_publisher_ != nullptr); + std_msgs::msg::Header header; header.stamp = rclcpp::Time(1234); // Use Published Time Publisher with a timestamp published_time_publisher_->publish(test_publisher_, header); rclcpp::spin_some(node_); + + // Check if the published_time_ is created ASSERT_TRUE(published_time_ != nullptr); // Check if the published time is the same as the header @@ -70,12 +83,17 @@ TEST_F(PublishedTimePublisherTest, PublishMsgWithHeader) TEST_F(PublishedTimePublisherTest, PublishMsgWithTimestamp) { + // Check if the PublishedTimePublisher is created + ASSERT_TRUE(published_time_publisher_ != nullptr); + std_msgs::msg::Header header; header.stamp = rclcpp::Time(4321); // Use Published Time Publisher with a timestamp published_time_publisher_->publish(test_publisher_, header.stamp); rclcpp::spin_some(node_); + + // Check if the published_time_ is created ASSERT_TRUE(published_time_ != nullptr); // Check if the published time is the same as the header