Skip to content

Commit

Permalink
Add missing qos and set as default qos
Browse files Browse the repository at this point in the history
Signed-off-by: elianalf <[email protected]>
  • Loading branch information
elianalf committed Apr 29, 2024
1 parent f732b85 commit fe98236
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 10 deletions.
51 changes: 45 additions & 6 deletions test/blackbox/common/DDSBlackboxTestsDataReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,8 @@ TEST(DDSDataReader, default_qos_large_history_depth)

/*
* This test creates a DataReader using DATAREADER_QOS_USE_TOPIC_QOS and checks if DataReader QoS
* are correctly set from Topic QoS. It also checks if one of the QoS that is not in common with Topic QoS
* is correctly set as the default one.
* are correctly set from Topic QoS. It also checks if the QoS that is not in common with Topic QoS
* is correctly set as the default ones.
*/
TEST(DDSDataReader, datareader_qos_use_topic_qos)
{
Expand Down Expand Up @@ -455,6 +455,9 @@ TEST(DDSDataReader, datareader_qos_use_topic_qos)
HistoryQosPolicy history;
history.kind = eprosima::fastdds::dds::KEEP_ALL_HISTORY_QOS;
topic_qos.history(history);
LifespanQosPolicy lifespan;
lifespan.duration = {5, 0};
topic_qos.lifespan(lifespan);

DomainParticipant* participant_ =
DomainParticipantFactory::get_instance()->create_participant(0, PARTICIPANT_QOS_DEFAULT);
Expand All @@ -464,15 +467,41 @@ TEST(DDSDataReader, datareader_qos_use_topic_qos)
type_support_.reset(new HelloWorldPubSubType());
type_support_.register_type(participant_, "HelloWorld");
Topic* topic_ = participant_->create_topic("HelloWorldTopic", "HelloWorld", topic_qos);
//Set default qos
SubscriberQos s_qos;
s_qos.presentation().access_scope = eprosima::fastdds::dds::TOPIC_PRESENTATION_QOS;
std::vector<std::string> part; //Getter function
part.push_back("part1");
s_qos.partition().names(part);
GroupDataQosPolicy group_data;
std::vector<eprosima::fastrtps::rtps::octet> vec;
eprosima::fastrtps::rtps::octet val = 3;
vec.push_back(val);
group_data.data_vec(vec);
s_qos.group_data(group_data);
EntityFactoryQosPolicy entity_factory;
entity_factory.autoenable_created_entities = false;
s_qos.entity_factory(entity_factory);
participant_->set_default_subscriber_qos(s_qos);
Subscriber* subscriber_ = participant_->create_subscriber(SUBSCRIBER_QOS_DEFAULT);
ASSERT_NE(subscriber_, nullptr);
DataReaderQos r_qos;
r_qos.reader_data_lifecycle().autopurge_no_writer_samples_delay = {3, 0};
r_qos.user_data().push_back(0);
RTPSEndpointQos endpoint_;
endpoint_.entity_id = 1;
r_qos.endpoint(endpoint_);
ReaderResourceLimitsQos reader_limits;
reader_limits.matched_publisher_allocation = ResourceLimitedContainerConfig::fixed_size_configuration(1u);
r_qos.reader_resource_limits(reader_limits);
r_qos.data_sharing().off();
subscriber_->set_default_datareader_qos(r_qos);
// Create DataReader with DATAREADER_QOS_USE_TOPIC_QOS
DataReader* reader_;
reader_ = subscriber_->create_datareader(topic_, DATAREADER_QOS_USE_TOPIC_QOS);
ASSERT_NE(reader_, nullptr);

// Check if DataReader QoS have been correctly set from Topic QoS
DataReaderQos r_qos;
// Check if DataReader QoS have been correctly set from Topic Qos
reader_->get_qos(r_qos);
ASSERT_EQ(r_qos.durability_service().history_kind, eprosima::fastdds::dds::KEEP_ALL_HISTORY_QOS);
ASSERT_EQ(r_qos.reliability().kind, eprosima::fastdds::dds::RELIABLE_RELIABILITY_QOS);
Expand All @@ -484,8 +513,18 @@ TEST(DDSDataReader, datareader_qos_use_topic_qos)
ASSERT_EQ(r_qos.ownership().kind, eprosima::fastdds::dds::EXCLUSIVE_OWNERSHIP_QOS);
ASSERT_EQ(r_qos.type_consistency().representation.m_value[0], DataRepresentationId_t::XCDR2_DATA_REPRESENTATION);
ASSERT_EQ(r_qos.history().kind, eprosima::fastdds::dds::KEEP_ALL_HISTORY_QOS);
// Check default QoS
ASSERT_EQ(r_qos.data_sharing().kind(), eprosima::fastdds::dds::AUTO);
ASSERT_EQ(r_qos.lifespan().duration, 5);
// Check if QoS have been correctly set from Default Qos
subscriber_->get_qos(s_qos);
ASSERT_EQ(s_qos.presentation().access_scope, eprosima::fastdds::dds::TOPIC_PRESENTATION_QOS);
ASSERT_EQ(s_qos.partition().names()[0], "part1");
ASSERT_EQ(s_qos.group_data(), group_data);
ASSERT_EQ(s_qos.entity_factory().autoenable_created_entities, false);
ASSERT_EQ(r_qos.reader_data_lifecycle().autopurge_no_writer_samples_delay.seconds, 3);
ASSERT_EQ(r_qos.user_data()[0], 0);
ASSERT_EQ(r_qos.endpoint().entity_id, 1);
ASSERT_EQ(r_qos.reader_resource_limits().matched_publisher_allocation.initial, 1u);
ASSERT_EQ(r_qos.data_sharing().kind(), eprosima::fastdds::dds::OFF);
}

#ifdef INSTANTIATE_TEST_SUITE_P
Expand Down
56 changes: 52 additions & 4 deletions test/blackbox/common/DDSBlackboxTestsDataWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,8 @@ TEST(DDSDataWriter, default_qos_large_history_depth)

/*
* This test creates a DataWriter using DATAWRITER_QOS_USE_TOPIC_QOS and checks if DataWriter QoS
* are correctly set from Topic QoS. It also checks if one of the QoS that is not in common with Topic QoS
* is correctly set as the default one.
* are correctly set from Topic QoS. It also checks if the QoS that is not in common with Topic QoS
* is correctly set as the default ones.
*/
TEST(DDSDataWriter, datawriter_qos_use_topic_qos)
{
Expand Down Expand Up @@ -476,6 +476,9 @@ TEST(DDSDataWriter, datawriter_qos_use_topic_qos)
HistoryQosPolicy history;
history.kind = eprosima::fastdds::dds::KEEP_ALL_HISTORY_QOS;
topic_qos.history(history);
LifespanQosPolicy lifespan_;
lifespan_.duration = {5, 0};
topic_qos.lifespan(lifespan_);

DomainParticipant* participant_ =
DomainParticipantFactory::get_instance()->create_participant(0, PARTICIPANT_QOS_DEFAULT);
Expand All @@ -484,15 +487,45 @@ TEST(DDSDataWriter, datawriter_qos_use_topic_qos)
type_support_.reset(new HelloWorldPubSubType());
type_support_.register_type(participant_, "HelloWorld");
Topic* topic_ = participant_->create_topic("HelloWorldTopic", "HelloWorld", topic_qos);

// Set publisher default qos
PublisherQos p_qos;
p_qos.presentation().access_scope = eprosima::fastdds::dds::TOPIC_PRESENTATION_QOS;
std::vector<std::string> part;
part.push_back("part1");
p_qos.partition().names(part);
GroupDataQosPolicy group_data;
std::vector<eprosima::fastrtps::rtps::octet> vec;
vec.push_back(3);
group_data.data_vec(vec);
p_qos.group_data(group_data);
EntityFactoryQosPolicy entity_factory;
entity_factory.autoenable_created_entities = false;
p_qos.entity_factory(entity_factory);
participant_->set_default_publisher_qos(p_qos);
Publisher* publisher_ = participant_->create_publisher(PUBLISHER_QOS_DEFAULT);
ASSERT_NE(publisher_, nullptr);
// Create DataWriter with DATAWRITER_QOS_USE_TOPIC_QOS
// Set datawriter default qos
DataWriterQos w_qos;
w_qos.ownership_strength().value = 1;
PublishModeQosPolicy publish_mode;
publish_mode.kind = eprosima::fastdds::dds::ASYNCHRONOUS_PUBLISH_MODE;
w_qos.publish_mode(publish_mode);
w_qos.writer_data_lifecycle().autodispose_unregistered_instances = false;
w_qos.user_data().push_back(0);
RTPSEndpointQos endpoint_;
endpoint_.entity_id = 1;
w_qos.endpoint(endpoint_);
WriterResourceLimitsQos writer_limits;
writer_limits.matched_subscriber_allocation = ResourceLimitedContainerConfig::fixed_size_configuration(1u);
w_qos.writer_resource_limits(writer_limits);
w_qos.data_sharing().off();
publisher_->set_default_datawriter_qos(w_qos);
DataWriter* writer_;
writer_ = publisher_->create_datawriter(topic_, DATAWRITER_QOS_USE_TOPIC_QOS);
ASSERT_NE(writer_, nullptr);

// Check if DataWriter QoS have been correctly set from Topic QoS
DataWriterQos w_qos;
writer_->get_qos(w_qos);
ASSERT_EQ(w_qos.durability_service().history_kind, eprosima::fastdds::dds::KEEP_ALL_HISTORY_QOS);
ASSERT_EQ(w_qos.reliability().kind, eprosima::fastdds::dds::BEST_EFFORT_RELIABILITY_QOS);
Expand All @@ -505,6 +538,21 @@ TEST(DDSDataWriter, datawriter_qos_use_topic_qos)
ASSERT_EQ(w_qos.ownership().kind, eprosima::fastdds::dds::EXCLUSIVE_OWNERSHIP_QOS);
ASSERT_EQ(w_qos.history().kind, eprosima::fastdds::dds::KEEP_ALL_HISTORY_QOS);
ASSERT_EQ(w_qos.representation().m_value[0], DataRepresentationId_t::XCDR2_DATA_REPRESENTATION);
ASSERT_EQ(w_qos.lifespan().duration, 5);
publisher_->get_qos(p_qos);
// Check if QoS have been correctly set from Default Qos
ASSERT_EQ(p_qos.presentation().access_scope, eprosima::fastdds::dds::TOPIC_PRESENTATION_QOS);
ASSERT_EQ(p_qos.partition().names()[0], "part1");
ASSERT_EQ(p_qos.group_data(), group_data);
ASSERT_EQ(p_qos.entity_factory().autoenable_created_entities, false);
ASSERT_EQ(w_qos.ownership_strength().value, 1);
ASSERT_EQ(w_qos.publish_mode().kind, eprosima::fastdds::dds::ASYNCHRONOUS_PUBLISH_MODE);
ASSERT_EQ(w_qos.writer_data_lifecycle().autodispose_unregistered_instances, false);
ASSERT_EQ(w_qos.user_data()[0], 0);
ASSERT_EQ(w_qos.endpoint().entity_id, 1);
ASSERT_EQ(w_qos.writer_resource_limits().matched_subscriber_allocation.initial, 1u);
ASSERT_EQ(w_qos.data_sharing().kind(), eprosima::fastdds::dds::OFF);

}

#ifdef INSTANTIATE_TEST_SUITE_P
Expand Down
18 changes: 18 additions & 0 deletions test/unittest/dds/publisher/PublisherTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,18 @@ TEST(PublisherTests, datawriter_copy_from_topic_qos)
// Set custom DataWriter QoS
DataWriterQos w_qos;
w_qos.ownership_strength().value = 1;
PublishModeQosPolicy publish_mode;
publish_mode.kind = eprosima::fastdds::dds::ASYNCHRONOUS_PUBLISH_MODE;
w_qos.publish_mode(publish_mode);
w_qos.writer_data_lifecycle().autodispose_unregistered_instances = false;
w_qos.user_data().push_back(0);
RTPSEndpointQos endpoint_;
endpoint_.entity_id = 1;
w_qos.endpoint(endpoint_);
WriterResourceLimitsQos writer_limits;
writer_limits.matched_subscriber_allocation = eprosima::fastrtps::ResourceLimitedContainerConfig::fixed_size_configuration(1u);
w_qos.writer_resource_limits(writer_limits);
w_qos.data_sharing().off();
DomainParticipant* participant =
DomainParticipantFactory::get_instance()->create_participant(0, PARTICIPANT_QOS_DEFAULT);
ASSERT_NE(participant, nullptr);
Expand All @@ -909,6 +921,12 @@ TEST(PublisherTests, datawriter_copy_from_topic_qos)
ASSERT_EQ(w_qos.history().kind, KEEP_ALL_HISTORY_QOS);
// Check if DataWriter QoS previously set are correct
ASSERT_EQ(w_qos.ownership_strength().value, 1);
ASSERT_EQ(w_qos.publish_mode().kind, eprosima::fastdds::dds::ASYNCHRONOUS_PUBLISH_MODE);
ASSERT_EQ(w_qos.writer_data_lifecycle().autodispose_unregistered_instances, false);
ASSERT_EQ(w_qos.user_data()[0], 0);
ASSERT_EQ(w_qos.endpoint().entity_id, 1);
ASSERT_EQ(w_qos.writer_resource_limits().matched_subscriber_allocation.initial, 1u);
ASSERT_EQ(w_qos.data_sharing().kind(), eprosima::fastdds::dds::OFF);
}

} // namespace dds
Expand Down
12 changes: 12 additions & 0 deletions test/unittest/dds/subscriber/SubscriberTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,14 @@ TEST(SubscriberTests, datareader_copy_from_topic_qos)

// Set custom DataReader QoS
DataReaderQos r_qos;
r_qos.reader_data_lifecycle().autopurge_no_writer_samples_delay = {3, 0};
r_qos.user_data().push_back(0);
RTPSEndpointQos endpoint_;
endpoint_.entity_id = 1;
r_qos.endpoint(endpoint_);
ReaderResourceLimitsQos reader_limits;
reader_limits.matched_publisher_allocation = eprosima::fastrtps::ResourceLimitedContainerConfig::fixed_size_configuration(1u);
r_qos.reader_resource_limits(reader_limits);
r_qos.data_sharing().off();
DomainParticipant* participant =
DomainParticipantFactory::get_instance()->create_participant(0, PARTICIPANT_QOS_DEFAULT);
Expand All @@ -1066,6 +1074,10 @@ TEST(SubscriberTests, datareader_copy_from_topic_qos)
ASSERT_EQ(r_qos.destination_order().kind, eprosima::fastdds::dds::BY_SOURCE_TIMESTAMP_DESTINATIONORDER_QOS);
ASSERT_EQ(r_qos.history().kind, KEEP_ALL_HISTORY_QOS);
// Check if DataReader QoS previously set are correct
ASSERT_EQ(r_qos.reader_data_lifecycle().autopurge_no_writer_samples_delay.seconds, 3);
ASSERT_EQ(r_qos.user_data()[0], 0);
ASSERT_EQ(r_qos.endpoint().entity_id, 1);
ASSERT_EQ(r_qos.reader_resource_limits().matched_publisher_allocation.initial, 1u);
ASSERT_EQ(r_qos.data_sharing().kind(), eprosima::fastdds::dds::OFF);
}

Expand Down

0 comments on commit fe98236

Please sign in to comment.