From fe9823609f1dc098e13f3b662b78cefd561b3c08 Mon Sep 17 00:00:00 2001 From: elianalf <62831776+elianalf@users.noreply.github.com> Date: Mon, 29 Apr 2024 16:26:44 +0200 Subject: [PATCH] Add missing qos and set as default qos Signed-off-by: elianalf <62831776+elianalf@users.noreply.github.com> --- .../common/DDSBlackboxTestsDataReader.cpp | 51 +++++++++++++++-- .../common/DDSBlackboxTestsDataWriter.cpp | 56 +++++++++++++++++-- .../unittest/dds/publisher/PublisherTests.cpp | 18 ++++++ .../dds/subscriber/SubscriberTests.cpp | 12 ++++ 4 files changed, 127 insertions(+), 10 deletions(-) diff --git a/test/blackbox/common/DDSBlackboxTestsDataReader.cpp b/test/blackbox/common/DDSBlackboxTestsDataReader.cpp index 8c625eff8d4..50f1fa673ad 100644 --- a/test/blackbox/common/DDSBlackboxTestsDataReader.cpp +++ b/test/blackbox/common/DDSBlackboxTestsDataReader.cpp @@ -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) { @@ -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); @@ -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 part; //Getter function + part.push_back("part1"); + s_qos.partition().names(part); + GroupDataQosPolicy group_data; + std::vector 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); @@ -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 diff --git a/test/blackbox/common/DDSBlackboxTestsDataWriter.cpp b/test/blackbox/common/DDSBlackboxTestsDataWriter.cpp index 6321ae7b294..0ef0c4990ad 100644 --- a/test/blackbox/common/DDSBlackboxTestsDataWriter.cpp +++ b/test/blackbox/common/DDSBlackboxTestsDataWriter.cpp @@ -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) { @@ -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); @@ -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 part; + part.push_back("part1"); + p_qos.partition().names(part); + GroupDataQosPolicy group_data; + std::vector 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); @@ -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 diff --git a/test/unittest/dds/publisher/PublisherTests.cpp b/test/unittest/dds/publisher/PublisherTests.cpp index 8345c1debdf..e95868e64cd 100644 --- a/test/unittest/dds/publisher/PublisherTests.cpp +++ b/test/unittest/dds/publisher/PublisherTests.cpp @@ -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); @@ -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 diff --git a/test/unittest/dds/subscriber/SubscriberTests.cpp b/test/unittest/dds/subscriber/SubscriberTests.cpp index f65255c9838..b6fcf73f6bb 100644 --- a/test/unittest/dds/subscriber/SubscriberTests.cpp +++ b/test/unittest/dds/subscriber/SubscriberTests.cpp @@ -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); @@ -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); }