Skip to content

Commit

Permalink
feat: simplify node and topic names
Browse files Browse the repository at this point in the history
Signed-off-by: Berkay Karaman <[email protected]>
  • Loading branch information
brkay54 authored and xmfcx committed Mar 15, 2024
1 parent 75c683f commit e07cdf6
Showing 1 changed file with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<rclcpp::Node>("PublishedTimePublisher_test_node");
node_ = std::make_shared<rclcpp::Node>(base_name + "_node");

// Create a publisher
test_publisher_ =
node_->create_publisher<std_msgs::msg::Header>("PublishedTimePublisher_test_topic", 1);
test_publisher_ = node_->create_publisher<std_msgs::msg::Header>(base_name, 1);

// Create a PublishedTimePublisher
published_time_publisher_ =
std::make_shared<tier4_autoware_utils::PublishedTimePublisher>(node_.get());

// Create a subscriber
test_subscriber_ = node_->create_subscription<autoware_internal_msgs::msg::PublishedTime>(
"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_);
}
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit e07cdf6

Please sign in to comment.