Skip to content

Commit 65be47b

Browse files
committed
feat: simplify node and topic names
Signed-off-by: Berkay Karaman <brkay54@gmail.com>
1 parent f661b9a commit 65be47b

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

common/tier4_autoware_utils/test/src/ros/test_published_time_publisher.cpp

+24-6
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,27 @@ class PublishedTimePublisherTest : public ::testing::Test
3434
{
3535
ASSERT_TRUE(rclcpp::ok());
3636

37+
// Simplify node and topic names for brevity and uniqueness
38+
const std::string test_name = ::testing::UnitTest::GetInstance()->current_test_info()->name();
39+
const std::string base_name =
40+
"published_time_publisher_" + test_name; // Base name for node and topics
41+
const std::string suffix = "/debug/published_time";
42+
3743
// Create a node
38-
node_ = std::make_shared<rclcpp::Node>("PublishedTimePublisher_test_node");
44+
node_ = std::make_shared<rclcpp::Node>(base_name + "_node");
45+
3946
// Create a publisher
40-
test_publisher_ =
41-
node_->create_publisher<std_msgs::msg::Header>("PublishedTimePublisher_test_topic", 1);
47+
test_publisher_ = node_->create_publisher<std_msgs::msg::Header>(base_name, 1);
48+
4249
// Create a PublishedTimePublisher
4350
published_time_publisher_ =
4451
std::make_shared<tier4_autoware_utils::PublishedTimePublisher>(node_.get());
52+
4553
// Create a subscriber
4654
test_subscriber_ = node_->create_subscription<autoware_internal_msgs::msg::PublishedTime>(
47-
"PublishedTimePublisher_test_topic/debug/published_time", 1,
48-
[this](autoware_internal_msgs::msg::PublishedTime::SharedPtr msg) {
49-
this->published_time_ = msg;
55+
base_name + suffix, 1,
56+
[this](autoware_internal_msgs::msg::PublishedTime::ConstSharedPtr msg) {
57+
this->published_time_ = std::move(msg);
5058
});
5159
rclcpp::spin_some(node_);
5260
}
@@ -56,12 +64,17 @@ class PublishedTimePublisherTest : public ::testing::Test
5664

5765
TEST_F(PublishedTimePublisherTest, PublishMsgWithHeader)
5866
{
67+
// Check if the PublishedTimePublisher is created
68+
ASSERT_TRUE(published_time_publisher_ != nullptr);
69+
5970
std_msgs::msg::Header header;
6071
header.stamp = rclcpp::Time(1234);
6172

6273
// Use Published Time Publisher with a timestamp
6374
published_time_publisher_->publish(test_publisher_, header);
6475
rclcpp::spin_some(node_);
76+
77+
// Check if the published_time_ is created
6578
ASSERT_TRUE(published_time_ != nullptr);
6679

6780
// Check if the published time is the same as the header
@@ -70,12 +83,17 @@ TEST_F(PublishedTimePublisherTest, PublishMsgWithHeader)
7083

7184
TEST_F(PublishedTimePublisherTest, PublishMsgWithTimestamp)
7285
{
86+
// Check if the PublishedTimePublisher is created
87+
ASSERT_TRUE(published_time_publisher_ != nullptr);
88+
7389
std_msgs::msg::Header header;
7490
header.stamp = rclcpp::Time(4321);
7591

7692
// Use Published Time Publisher with a timestamp
7793
published_time_publisher_->publish(test_publisher_, header.stamp);
7894
rclcpp::spin_some(node_);
95+
96+
// Check if the published_time_ is created
7997
ASSERT_TRUE(published_time_ != nullptr);
8098

8199
// Check if the published time is the same as the header

0 commit comments

Comments
 (0)