Skip to content

Commit

Permalink
Refs #21189. Uncrustify and doxygen.
Browse files Browse the repository at this point in the history
Signed-off-by: Miguel Company <miguelcompany@eprosima.com>
  • Loading branch information
MiguelCompany committed Jun 24, 2024
1 parent c898d85 commit a875bb7
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 76 deletions.
152 changes: 76 additions & 76 deletions test/blackbox/common/DDSBlackboxTestsROS2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,83 +80,83 @@ TEST(DDS_ROS2, test_automatic_liveliness_changed)
}

{
auto context = std::make_shared<ros2::Context>();

auto topic_name = TEST_TOPIC_NAME;
const Duration_t liveliness_duration = { 1, 0 };
const Duration_t liveliness_announcement_period = { 0, 666666666 };
LivelinessQosPolicy liveliness;
liveliness.kind = LivelinessQosPolicyKind::AUTOMATIC_LIVELINESS_QOS;
liveliness.lease_duration = liveliness_duration;
liveliness.announcement_period = liveliness_announcement_period;
ReliabilityQosPolicy reliability;
reliability.kind = RELIABLE_RELIABILITY_QOS;

TypeSupport type_support(new HelloWorldPubSubType());
auto pub = std::make_shared<ros2::PublicationNode>(context, topic_name + "/pub", topic_name, type_support);
auto sub = std::make_shared<ros2::SubscriptionNode>(context, topic_name + "/sub", topic_name, type_support);

// Configure the subscription node with a listener that will check the liveliness changed status.
int total_number_of_liveliness_events = 0;
auto sub_listener = std::make_shared<ros2::SubscriptionListener>();
sub_listener->liveliness_callback = [this, &total_number_of_liveliness_events](
const LivelinessChangedStatus& event) -> void
{
total_number_of_liveliness_events++;

// strict checking for expected events
if (total_number_of_liveliness_events == 1)
auto context = std::make_shared<ros2::Context>();

auto topic_name = TEST_TOPIC_NAME;
const Duration_t liveliness_duration = { 1, 0 };
const Duration_t liveliness_announcement_period = { 0, 666666666 };
LivelinessQosPolicy liveliness;
liveliness.kind = LivelinessQosPolicyKind::AUTOMATIC_LIVELINESS_QOS;
liveliness.lease_duration = liveliness_duration;
liveliness.announcement_period = liveliness_announcement_period;
ReliabilityQosPolicy reliability;
reliability.kind = RELIABLE_RELIABILITY_QOS;

TypeSupport type_support(new HelloWorldPubSubType());
auto pub = std::make_shared<ros2::PublicationNode>(context, topic_name + "/pub", topic_name, type_support);
auto sub = std::make_shared<ros2::SubscriptionNode>(context, topic_name + "/sub", topic_name, type_support);

// Configure the subscription node with a listener that will check the liveliness changed status.
int total_number_of_liveliness_events = 0;
auto sub_listener = std::make_shared<ros2::SubscriptionListener>();
sub_listener->liveliness_callback = [this, &total_number_of_liveliness_events](
const LivelinessChangedStatus& event) -> void
{
// publisher came alive
ASSERT_EQ(1, event.alive_count);
ASSERT_EQ(0, event.not_alive_count);
ASSERT_EQ(1, event.alive_count_change);
ASSERT_EQ(0, event.not_alive_count_change);
}
else if (total_number_of_liveliness_events == 2)
{
// publisher died
ASSERT_EQ(0, event.alive_count);
ASSERT_EQ(0, event.not_alive_count);
ASSERT_EQ(-1, event.alive_count_change);
ASSERT_EQ(0, event.not_alive_count_change);
}
};
sub->set_listener(sub_listener);

DataReaderQos reader_qos = context->subscriber()->get_default_datareader_qos();
reader_qos.liveliness(liveliness);
reader_qos.reliability(reliability);
sub->set_qos(reader_qos);

// Start the subscription node.
sub->start();

DataWriterQos writer_qos = context->publisher()->get_default_datawriter_qos();
writer_qos.liveliness(liveliness);
writer_qos.reliability(reliability);
pub->set_qos(writer_qos);

// Start the publication node.
pub->start();

// Wait some time and kill the publication node.
HelloWorld hello;
hello.message("Hello, World!");
for (uint16_t i = 0; i < 10; ++i)
{
hello.index(i);
pub->publish(&hello);
std::this_thread::sleep_for(std::chrono::milliseconds(200));
}

pub->stop();

// Wait some time and check that the liveliness changed status was triggered.
std::this_thread::sleep_for(std::chrono::seconds(6));
EXPECT_EQ(2, total_number_of_liveliness_events); // check expected number of liveliness events

sub->stop();
total_number_of_liveliness_events++;

// strict checking for expected events
if (total_number_of_liveliness_events == 1)
{
// publisher came alive
ASSERT_EQ(1, event.alive_count);
ASSERT_EQ(0, event.not_alive_count);
ASSERT_EQ(1, event.alive_count_change);
ASSERT_EQ(0, event.not_alive_count_change);
}
else if (total_number_of_liveliness_events == 2)
{
// publisher died
ASSERT_EQ(0, event.alive_count);
ASSERT_EQ(0, event.not_alive_count);
ASSERT_EQ(-1, event.alive_count_change);
ASSERT_EQ(0, event.not_alive_count_change);
}
};
sub->set_listener(sub_listener);

DataReaderQos reader_qos = context->subscriber()->get_default_datareader_qos();
reader_qos.liveliness(liveliness);
reader_qos.reliability(reliability);
sub->set_qos(reader_qos);

// Start the subscription node.
sub->start();

DataWriterQos writer_qos = context->publisher()->get_default_datawriter_qos();
writer_qos.liveliness(liveliness);
writer_qos.reliability(reliability);
pub->set_qos(writer_qos);

// Start the publication node.
pub->start();

// Wait some time and kill the publication node.
HelloWorld hello;
hello.message("Hello, World!");
for (uint16_t i = 0; i < 10; ++i)
{
hello.index(i);
pub->publish(&hello);
std::this_thread::sleep_for(std::chrono::milliseconds(200));
}

pub->stop();

// Wait some time and check that the liveliness changed status was triggered.
std::this_thread::sleep_for(std::chrono::seconds(6));
EXPECT_EQ(2, total_number_of_liveliness_events); // check expected number of liveliness events

sub->stop();
}

factory->set_library_settings(old_library_settings);
Expand Down
23 changes: 23 additions & 0 deletions test/blackbox/common/ros2/GenericHolder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,28 @@

#include <gtest/gtest.h>

// *INDENT-OFF* Uncrustify makes a mess with this kind of macros
/**
* @brief Generic holder class for a DDS entity.
* This macro generates a holder class for a DDS entity along with it's factory so that the entity is automatically
* released when the holder is destroyed.
* The generated class has a custom-named getter method to access the entity.
* The macro allows to specify the factory class, the entity class, the factory's method to release the entity and the
* getter method name.
*
* @param _Factory The class of the factory that created the entity (e.g. Publisher).
* @param _Entity The class of the entity (e.g., DataWriter).
* @param _Release The method of the factory to release the entity (e.g., delete_datawriter).
* @param _Getter The name of the getter method to access the entity (for instance, writer).
*
* Examples:
* GENERIC_HOLDER_CLASS(Publisher, DataWriter, delete_datawriter, writer) generates DataWriterHolder.
* GENERIC_HOLDER_CLASS(Subscriber, DataReader, delete_datareader, reader) generates DataReaderHolder.
* GENERIC_HOLDER_CLASS(DomainParticipant, Publisher, delete_publisher, publisher) generates PublisherHolder.
* GENERIC_HOLDER_CLASS(DomainParticipant, Subscriber, delete_subscriber, subscriber) generates SubscriberHolder.
* GENERIC_HOLDER_CLASS(DomainParticipant, Topic, delete_topic, topic) generates TopicHolder.
* GENERIC_HOLDER_CLASS(DomainParticipantFactory, DomainParticipant, delete_participant, participant) generates DomainParticipantHolder.
*/
#define GENERIC_HOLDER_CLASS(_Factory, _Entity, _Release, _Getter) \
class _Entity##Holder \
{ \
Expand Down Expand Up @@ -50,5 +72,6 @@ private: \
_Entity* entity_ = nullptr; \
\
};
// *INDENT-ON*

#endif // FASTDDS_TEST_BLACKBOX_COMMON_ROS2__GENERICHOLDER_HPP

0 comments on commit a875bb7

Please sign in to comment.