diff --git a/fastdds_python/src/swig/fastdds/dds/topic/TypeSupport.i b/fastdds_python/src/swig/fastdds/dds/topic/TypeSupport.i index 1e9b71d1..02e47539 100644 --- a/fastdds_python/src/swig/fastdds/dds/topic/TypeSupport.i +++ b/fastdds_python/src/swig/fastdds/dds/topic/TypeSupport.i @@ -41,4 +41,11 @@ { return new eprosima::fastdds::dds::TypeSupport(ptr); } + + %apply SWIGTYPE *DISOWN { eprosima::fastdds::dds::TopicDataType* ptr }; + void set(eprosima::fastdds::dds::TopicDataType* ptr) + { + self->reset(ptr); + } + } diff --git a/fastdds_python/test/api/test_datareader.py b/fastdds_python/test/api/test_datareader.py index 103025f8..6ee1ea05 100644 --- a/fastdds_python/test/api/test_datareader.py +++ b/fastdds_python/test/api/test_datareader.py @@ -6,6 +6,7 @@ win32api.LoadLibrary('test_complete') import fastdds +import pytest import test_complete @@ -14,30 +15,108 @@ def __init__(self): super().__init__() -def create_querycondition(): - """ - This test checks: - - DataReader::create_querycondition - - DataReader::delete_contained_entities - """ +@pytest.fixture +def participant(): factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( + return factory.create_participant( 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - subscriber = participant.create_subscriber(fastdds.SUBSCRIBER_QOS_DEFAULT) - assert(subscriber is not None) - test_type = fastdds.TypeSupport( + + +@pytest.fixture +def subscriber(participant): + return participant.create_subscriber(fastdds.SUBSCRIBER_QOS_DEFAULT) + + +@pytest.fixture +def test_type(): + return fastdds.TypeSupport( test_complete.CompleteTestTypePubSubType()) + + +@pytest.fixture +def test_keyed_type(test_type): + test_type.set(test_complete.KeyedCompleteTestTypePubSubType()) + + +@pytest.fixture +def topic(participant, test_type): + participant.register_type(test_type, test_type.get_type_name()) + return participant.create_topic( + "Complete", test_type.get_type_name(), fastdds.TOPIC_QOS_DEFAULT) + + +@pytest.fixture +def datareader_qos(): + return fastdds.DataReaderQos() + + +@pytest.fixture +def transient_datareader_qos(datareader_qos): + datareader_qos.durability().kind = fastdds.TRANSIENT_LOCAL_DURABILITY_QOS + datareader_qos.reliability().kind = fastdds.RELIABLE_RELIABILITY_QOS + return datareader_qos + + +@pytest.fixture +def datareader(participant, topic, subscriber, datareader_qos): + datareader = subscriber.create_datareader(topic, datareader_qos) + + yield datareader + + assert(fastdds.ReturnCode_t.RETCODE_OK == + subscriber.delete_datareader(datareader)) + assert(fastdds.ReturnCode_t.RETCODE_OK == + participant.delete_topic(topic)) + assert(fastdds.ReturnCode_t.RETCODE_OK == + participant.delete_subscriber(subscriber)) + factory = fastdds.DomainParticipantFactory.get_instance() assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.register_type(test_type, test_type.get_type_name())) - topic = participant.create_topic( + factory.delete_participant(participant)) + + +@pytest.fixture +def writer_participant(): + factory = fastdds.DomainParticipantFactory.get_instance() + return factory.create_participant( + 0, fastdds.PARTICIPANT_QOS_DEFAULT) + + +@pytest.fixture +def writer_topic(writer_participant, test_type): + writer_participant.register_type(test_type, test_type.get_type_name()) + return writer_participant.create_topic( "Complete", test_type.get_type_name(), fastdds.TOPIC_QOS_DEFAULT) - assert(topic is not None) - datareader = subscriber.create_datareader( - topic, fastdds.DATAREADER_QOS_DEFAULT) - assert(datareader is not None) + +@pytest.fixture +def publisher(writer_participant): + return writer_participant.create_publisher(fastdds.PUBLISHER_QOS_DEFAULT) + + +@pytest.fixture +def datawriter(writer_participant, writer_topic, publisher): + datawriter = publisher.create_datawriter( + writer_topic, fastdds.DATAWRITER_QOS_DEFAULT) + + yield datawriter + + assert(fastdds.ReturnCode_t.RETCODE_OK == + publisher.delete_datawriter(datawriter)) + assert(fastdds.ReturnCode_t.RETCODE_OK == + writer_participant.delete_topic(writer_topic)) + assert(fastdds.ReturnCode_t.RETCODE_OK == + writer_participant.delete_publisher(publisher)) + factory = fastdds.DomainParticipantFactory.get_instance() + assert(fastdds.ReturnCode_t.RETCODE_OK == + factory.delete_participant(writer_participant)) + + +def test_create_querycondition(datareader): + """ + This test checks: + - DataReader::create_querycondition + - DataReader::delete_contained_entities + """ sv = fastdds.SampleStateKindVector() vv = fastdds.ViewStateKindVector() iv = fastdds.InstanceStateKindVector() @@ -49,40 +128,13 @@ def create_querycondition(): assert(fastdds.ReturnCode_t.RETCODE_OK == datareader.delete_contained_entities()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - subscriber.delete_datareader(datareader)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_subscriber(subscriber)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_create_readcondition(): +def test_create_readcondition(datareader): """ This test checks: - DataReader::create_readcondition - DataReader::delete_readcondition """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - subscriber = participant.create_subscriber(fastdds.SUBSCRIBER_QOS_DEFAULT) - assert(subscriber is not None) - test_type = fastdds.TypeSupport( - test_complete.CompleteTestTypePubSubType()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.register_type(test_type, test_type.get_type_name())) - topic = participant.create_topic( - "Complete", test_type.get_type_name(), fastdds.TOPIC_QOS_DEFAULT) - assert(topic is not None) - datareader = subscriber.create_datareader( - topic, fastdds.DATAREADER_QOS_DEFAULT) - assert(datareader is not None) - sv = fastdds.SampleStateKindVector() vv = fastdds.ViewStateKindVector() iv = fastdds.InstanceStateKindVector() @@ -92,96 +144,38 @@ def test_create_readcondition(): assert(fastdds.ReturnCode_t.RETCODE_UNSUPPORTED == datareader.delete_readcondition(readcondition)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - subscriber.delete_datareader(datareader)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_subscriber(subscriber)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_get_first_untaken(): +def test_get_first_untaken(transient_datareader_qos, datareader, + datawriter): """ This test checks: - DataReader::get_first_untaken_info """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - subscriber = participant.create_subscriber(fastdds.SUBSCRIBER_QOS_DEFAULT) - assert(subscriber is not None) - test_type = fastdds.TypeSupport( - test_complete.CompleteTestTypePubSubType()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.register_type(test_type, test_type.get_type_name())) - topic = participant.create_topic( - "Complete", test_type.get_type_name(), fastdds.TOPIC_QOS_DEFAULT) - assert(topic is not None) - datareader_qos = fastdds.DataReaderQos() - datareader_qos.durability().kind = fastdds.TRANSIENT_LOCAL_DURABILITY_QOS - datareader = subscriber.create_datareader( - topic, datareader_qos) - assert(datareader is not None) - info = fastdds.SampleInfo() assert(fastdds.ReturnCode_t.RETCODE_NO_DATA == datareader.get_first_untaken_info(info)) + qos = datareader.get_qos() + assert(fastdds.TRANSIENT_LOCAL_DURABILITY_QOS == qos.durability().kind) + qos = datawriter.get_qos() + assert(fastdds.TRANSIENT_LOCAL_DURABILITY_QOS == qos.durability().kind) - publisher = participant.create_publisher(fastdds.PUBLISHER_QOS_DEFAULT) - assert(publisher is not None) - datawriter = publisher.create_datawriter( - topic, fastdds.DATAWRITER_QOS_DEFAULT) - assert(datawriter is not None) sample = test_complete.CompleteTestType() sample.int16_field(255) assert(datawriter.write(sample)) - assert(datareader.wait_for_unread_message(fastdds.Duration_t(5, 0))) + assert(datareader.wait_for_unread_message( + fastdds.Duration_t(5, 0))) assert(fastdds.ReturnCode_t.RETCODE_OK == datareader.get_first_untaken_info(info)) assert(info.valid_data) - assert(fastdds.ReturnCode_t.RETCODE_OK == - publisher.delete_datawriter(datawriter)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - subscriber.delete_datareader(datareader)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_publisher(publisher)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_subscriber(subscriber)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_get_instance_handle(): +def test_get_instance_handle(datareader): """ This test checks: - DataReader::guid - DataReader::get_instance_handle """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - subscriber = participant.create_subscriber(fastdds.SUBSCRIBER_QOS_DEFAULT) - assert(subscriber is not None) - test_type = fastdds.TypeSupport( - test_complete.KeyedCompleteTestTypePubSubType()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.register_type(test_type, test_type.get_type_name())) - topic = participant.create_topic( - "Complete", test_type.get_type_name(), fastdds.TOPIC_QOS_DEFAULT) - assert(topic is not None) - datareader = subscriber.create_datareader( - topic, fastdds.DATAREADER_QOS_DEFAULT) - guid = datareader.guid() assert(fastdds.c_Guid_Unknown != guid) ih = datareader.get_instance_handle() @@ -193,56 +187,21 @@ def test_get_instance_handle(): for i in range(0, 4): assert(guid.entityId.value[i] == ih.value[12+i]) - assert(fastdds.ReturnCode_t.RETCODE_OK == - subscriber.delete_datareader(datareader)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_subscriber(subscriber)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_get_key_value(): +def test_get_key_value(test_keyed_type, datareader): """ This test checks: - DataReader::get_key_value """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - subscriber = participant.create_subscriber(fastdds.SUBSCRIBER_QOS_DEFAULT) - assert(subscriber is not None) - test_type = fastdds.TypeSupport( - test_complete.KeyedCompleteTestTypePubSubType()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.register_type(test_type, test_type.get_type_name())) - topic = participant.create_topic( - "Complete", test_type.get_type_name(), fastdds.TOPIC_QOS_DEFAULT) - assert(topic is not None) - datareader = subscriber.create_datareader( - topic, fastdds.DATAREADER_QOS_DEFAULT) - assert(datareader is not None) - sample = test_complete.KeyedCompleteTestType() + sample.id(255) ih = fastdds.InstanceHandle_t() assert(fastdds.ReturnCode_t.RETCODE_UNSUPPORTED == datareader.get_key_value(sample, ih)) assert(fastdds.c_InstanceHandle_Unknown == ih) - assert(fastdds.ReturnCode_t.RETCODE_OK == - subscriber.delete_datareader(datareader)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_subscriber(subscriber)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_get_set_listener(): +def test_get_set_listener(datareader): """ This test checks: - DataReader::get_listener @@ -251,31 +210,15 @@ def test_get_set_listener(): - StatusMask::operator == - StatusMask::operator << """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - subscriber = participant.create_subscriber(fastdds.SUBSCRIBER_QOS_DEFAULT) - assert(subscriber is not None) - test_type = fastdds.TypeSupport( - test_complete.KeyedCompleteTestTypePubSubType()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.register_type(test_type, test_type.get_type_name())) - topic = participant.create_topic( - "Complete", test_type.get_type_name(), fastdds.TOPIC_QOS_DEFAULT) - assert(topic is not None) - datareader = subscriber.create_datareader( - topic, fastdds.DATAREADER_QOS_DEFAULT) - assert(datareader is not None) - # Overload 1 listener = DataReaderListener() assert(listener is not None) assert(fastdds.ReturnCode_t.RETCODE_OK == datareader.set_listener(listener)) assert(datareader.get_listener() == listener) - assert(fastdds.StatusMask.all() == datareader.get_status_mask()) + assert(fastdds.StatusMask.all() == + datareader.get_status_mask()) + datareader.set_listener(None) def test(status_mask_1, status_mask_2): """ @@ -287,12 +230,14 @@ def test(status_mask_1, status_mask_2): datareader.set_listener(listener, status_mask_1)) assert(datareader.get_listener() == listener) assert(status_mask_1 == datareader.get_status_mask()) + datareader.set_listener(None) listener = DataReaderListener() assert(listener is not None) assert(fastdds.ReturnCode_t.RETCODE_OK == datareader.set_listener(listener, status_mask_2)) assert(datareader.get_listener() == listener) assert(status_mask_2 == datareader.get_status_mask()) + datareader.set_listener(None) # Overload 2: Different status masks test(fastdds.StatusMask.all(), fastdds.StatusMask_all()) @@ -354,77 +299,23 @@ def test(status_mask_1, status_mask_2): fastdds.StatusMask.subscription_matched(), m) - assert(fastdds.ReturnCode_t.RETCODE_OK == - subscriber.delete_datareader(datareader)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_subscriber(subscriber)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_get_listening_locators(): +def test_get_listening_locators(datareader): """ This test checks: - DataReader::get_listening_locators """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - subscriber = participant.create_subscriber(fastdds.SUBSCRIBER_QOS_DEFAULT) - assert(subscriber is not None) - test_type = fastdds.TypeSupport( - test_complete.KeyedCompleteTestTypePubSubType()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.register_type(test_type, test_type.get_type_name())) - topic = participant.create_topic( - "Complete", test_type.get_type_name(), fastdds.TOPIC_QOS_DEFAULT) - assert(topic is not None) - datareader = subscriber.create_datareader( - topic, fastdds.DATAREADER_QOS_DEFAULT) - assert(datareader is not None) - locator_list = fastdds.LocatorList() assert(fastdds.ReturnCode_t.RETCODE_OK == datareader.get_listening_locators(locator_list)) assert(0 < locator_list.size()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - subscriber.delete_datareader(datareader)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_subscriber(subscriber)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_get_liveliness_changed_status(): +def test_get_liveliness_changed_status(datareader): """ This test checks: - DataReader::get_liveliness_changed_status """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - subscriber = participant.create_subscriber(fastdds.SUBSCRIBER_QOS_DEFAULT) - assert(subscriber is not None) - test_type = fastdds.TypeSupport( - test_complete.KeyedCompleteTestTypePubSubType()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.register_type(test_type, test_type.get_type_name())) - topic = participant.create_topic( - "Complete", test_type.get_type_name(), fastdds.TOPIC_QOS_DEFAULT) - assert(topic is not None) - datareader = subscriber.create_datareader( - topic, fastdds.DATAREADER_QOS_DEFAULT) - assert(datareader is not None) - status = fastdds.LivelinessChangedStatus() assert(fastdds.ReturnCode_t.RETCODE_OK == datareader.get_liveliness_changed_status(status)) @@ -434,114 +325,33 @@ def test_get_liveliness_changed_status(): assert(0 == status.not_alive_count_change) assert(fastdds.c_InstanceHandle_Unknown == status.last_publication_handle) - assert(fastdds.ReturnCode_t.RETCODE_OK == - subscriber.delete_datareader(datareader)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_subscriber(subscriber)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_get_matched_publication_data(): +def test_get_matched_publication_data(datareader): """ This test checks: - DataWriter::get_matched_publication_data """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - subscriber = participant.create_subscriber(fastdds.SUBSCRIBER_QOS_DEFAULT) - assert(subscriber is not None) - test_type = fastdds.TypeSupport( - test_complete.KeyedCompleteTestTypePubSubType()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.register_type(test_type, test_type.get_type_name())) - topic = participant.create_topic( - "Complete", test_type.get_type_name(), fastdds.TOPIC_QOS_DEFAULT) - assert(topic is not None) - datareader = subscriber.create_datareader( - topic, fastdds.DATAREADER_QOS_DEFAULT) - assert(datareader is not None) - pub_data = fastdds.PublicationBuiltinTopicData() ih = fastdds.InstanceHandle_t() assert(fastdds.ReturnCode_t.RETCODE_UNSUPPORTED == datareader.get_matched_publication_data(pub_data, ih)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - subscriber.delete_datareader(datareader)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_subscriber(subscriber)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_get_matched_publications(): +def test_get_matched_publications(datareader): """ This test checks: - DataReader::get_matched_publications """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - subscriber = participant.create_subscriber(fastdds.SUBSCRIBER_QOS_DEFAULT) - assert(subscriber is not None) - test_type = fastdds.TypeSupport( - test_complete.KeyedCompleteTestTypePubSubType()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.register_type(test_type, test_type.get_type_name())) - topic = participant.create_topic( - "Complete", test_type.get_type_name(), fastdds.TOPIC_QOS_DEFAULT) - assert(topic is not None) - datareader = subscriber.create_datareader( - topic, fastdds.DATAREADER_QOS_DEFAULT) - assert(datareader is not None) - ihs = fastdds.InstanceHandleVector() assert(fastdds.ReturnCode_t.RETCODE_UNSUPPORTED == datareader.get_matched_publications(ihs)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - subscriber.delete_datareader(datareader)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_subscriber(subscriber)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_get_requested_deadline_missed_status(): +def test_get_requested_deadline_missed_status(datareader): """ This test checks: - DataReader::get_requested_deadline_missed_status """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - subscriber = participant.create_subscriber(fastdds.SUBSCRIBER_QOS_DEFAULT) - assert(subscriber is not None) - test_type = fastdds.TypeSupport( - test_complete.KeyedCompleteTestTypePubSubType()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.register_type(test_type, test_type.get_type_name())) - topic = participant.create_topic( - "Complete", test_type.get_type_name(), fastdds.TOPIC_QOS_DEFAULT) - assert(topic is not None) - datareader = subscriber.create_datareader( - topic, fastdds.DATAREADER_QOS_DEFAULT) - assert(datareader is not None) - status = fastdds.RequestedDeadlineMissedStatus() assert(fastdds.ReturnCode_t.RETCODE_OK == datareader.get_requested_deadline_missed_status(status)) @@ -549,39 +359,12 @@ def test_get_requested_deadline_missed_status(): assert(0 == status.total_count_change) assert(fastdds.c_InstanceHandle_Unknown == status.last_instance_handle) - assert(fastdds.ReturnCode_t.RETCODE_OK == - subscriber.delete_datareader(datareader)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_subscriber(subscriber)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_get_requested_incompatible_qos_status(): +def test_get_requested_incompatible_qos_status(datareader): """ This test checks: - DataReader::get_requested_deadline_missed_status """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - subscriber = participant.create_subscriber(fastdds.SUBSCRIBER_QOS_DEFAULT) - assert(subscriber is not None) - test_type = fastdds.TypeSupport( - test_complete.KeyedCompleteTestTypePubSubType()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.register_type(test_type, test_type.get_type_name())) - topic = participant.create_topic( - "Complete", test_type.get_type_name(), fastdds.TOPIC_QOS_DEFAULT) - assert(topic is not None) - datareader = subscriber.create_datareader( - topic, fastdds.DATAREADER_QOS_DEFAULT) - assert(datareader is not None) - status = fastdds.RequestedIncompatibleQosStatus() assert(fastdds.ReturnCode_t.RETCODE_OK == datareader.get_requested_incompatible_qos_status(status)) @@ -595,117 +378,36 @@ def test_get_requested_incompatible_qos_status(): assert(id == policy.policy_id) id += 1 - assert(fastdds.ReturnCode_t.RETCODE_OK == - subscriber.delete_datareader(datareader)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_subscriber(subscriber)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_get_sample_lost_status(): +def test_get_sample_lost_status(datareader): """ This test checks: - DataReader::get_sample_lost_status """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - subscriber = participant.create_subscriber(fastdds.SUBSCRIBER_QOS_DEFAULT) - assert(subscriber is not None) - test_type = fastdds.TypeSupport( - test_complete.KeyedCompleteTestTypePubSubType()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.register_type(test_type, test_type.get_type_name())) - topic = participant.create_topic( - "Complete", test_type.get_type_name(), fastdds.TOPIC_QOS_DEFAULT) - assert(topic is not None) - datareader = subscriber.create_datareader( - topic, fastdds.DATAREADER_QOS_DEFAULT) - assert(datareader is not None) - status = fastdds.SampleLostStatus() assert(fastdds.ReturnCode_t.RETCODE_UNSUPPORTED == datareader.get_sample_lost_status(status)) assert(0 == status.total_count) assert(0 == status.total_count_change) - assert(fastdds.ReturnCode_t.RETCODE_OK == - subscriber.delete_datareader(datareader)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_subscriber(subscriber)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_get_sample_rejected_status(): +def test_get_sample_rejected_status(datareader): """ This test checks: - DataReader::get_sample_rejected_status """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - subscriber = participant.create_subscriber(fastdds.SUBSCRIBER_QOS_DEFAULT) - assert(subscriber is not None) - test_type = fastdds.TypeSupport( - test_complete.KeyedCompleteTestTypePubSubType()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.register_type(test_type, test_type.get_type_name())) - topic = participant.create_topic( - "Complete", test_type.get_type_name(), fastdds.TOPIC_QOS_DEFAULT) - assert(topic is not None) - datareader = subscriber.create_datareader( - topic, fastdds.DATAREADER_QOS_DEFAULT) - assert(datareader is not None) - status = fastdds.SampleRejectedStatus() assert(fastdds.ReturnCode_t.RETCODE_UNSUPPORTED == datareader.get_sample_rejected_status(status)) assert(0 == status.total_count) assert(0 == status.total_count_change) - assert(fastdds.ReturnCode_t.RETCODE_OK == - subscriber.delete_datareader(datareader)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_subscriber(subscriber)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_get_subscription_matched_status(): +def test_get_subscription_matched_status(datareader): """ This test checks: - DataReader::get_subscription_matched_status """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - subscriber = participant.create_subscriber(fastdds.SUBSCRIBER_QOS_DEFAULT) - assert(subscriber is not None) - test_type = fastdds.TypeSupport( - test_complete.KeyedCompleteTestTypePubSubType()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.register_type(test_type, test_type.get_type_name())) - topic = participant.create_topic( - "Complete", test_type.get_type_name(), fastdds.TOPIC_QOS_DEFAULT) - assert(topic is not None) - datareader = subscriber.create_datareader( - topic, fastdds.DATAREADER_QOS_DEFAULT) - assert(datareader is not None) - status = fastdds.SubscriptionMatchedStatus() assert(fastdds.ReturnCode_t.RETCODE_OK == datareader.get_subscription_matched_status(status)) @@ -715,177 +417,55 @@ def test_get_subscription_matched_status(): assert(0 == status.current_count_change) assert(fastdds.c_InstanceHandle_Unknown == status.last_publication_handle) - assert(fastdds.ReturnCode_t.RETCODE_OK == - subscriber.delete_datareader(datareader)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_subscriber(subscriber)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_get_subscriber(): +def test_get_subscriber(subscriber, datareader): """ This test checks: - DataReader::get_subscriber """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - subscriber = participant.create_subscriber(fastdds.SUBSCRIBER_QOS_DEFAULT) - assert(subscriber is not None) - test_type = fastdds.TypeSupport( - test_complete.KeyedCompleteTestTypePubSubType()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.register_type(test_type, test_type.get_type_name())) - topic = participant.create_topic( - "Complete", test_type.get_type_name(), fastdds.TOPIC_QOS_DEFAULT) - assert(topic is not None) - datareader = subscriber.create_datareader( - topic, fastdds.DATAREADER_QOS_DEFAULT) - assert(datareader is not None) - sub = datareader.get_subscriber() assert(sub == subscriber) - assert(fastdds.ReturnCode_t.RETCODE_OK == - subscriber.delete_datareader(datareader)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_subscriber(subscriber)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_get_topicdescription(): +def test_get_topicdescription(topic, datareader): """ This test checks: - DataReader::get_topicdescription """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - subscriber = participant.create_subscriber(fastdds.SUBSCRIBER_QOS_DEFAULT) - assert(subscriber is not None) - test_type = fastdds.TypeSupport( - test_complete.KeyedCompleteTestTypePubSubType()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.register_type(test_type, test_type.get_type_name())) - topic = participant.create_topic( - "Complete", test_type.get_type_name(), fastdds.TOPIC_QOS_DEFAULT) - assert(topic is not None) - datareader = subscriber.create_datareader( - topic, fastdds.DATAREADER_QOS_DEFAULT) - assert(datareader is not None) - topic_aux = datareader.get_topicdescription() assert(topic.get_impl() == topic_aux.get_impl()) assert(topic.get_type_name() == topic_aux.get_type_name()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - subscriber.delete_datareader(datareader)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_subscriber(subscriber)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_get_unread_count(): +def test_get_unread_count(transient_datareader_qos, datareader, + datawriter): """ This test checks: - DataReader::get_unread_count """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - subscriber = participant.create_subscriber(fastdds.SUBSCRIBER_QOS_DEFAULT) - assert(subscriber is not None) - test_type = fastdds.TypeSupport( - test_complete.CompleteTestTypePubSubType()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.register_type(test_type, test_type.get_type_name())) - topic = participant.create_topic( - "Complete", test_type.get_type_name(), fastdds.TOPIC_QOS_DEFAULT) - assert(topic is not None) - datareader_qos = fastdds.DataReaderQos() - datareader_qos.durability().kind = fastdds.TRANSIENT_LOCAL_DURABILITY_QOS - datareader = subscriber.create_datareader( - topic, datareader_qos) - assert(datareader is not None) - assert(0 == datareader.get_unread_count()) - publisher = participant.create_publisher(fastdds.PUBLISHER_QOS_DEFAULT) - assert(publisher is not None) - datawriter = publisher.create_datawriter( - topic, fastdds.DATAWRITER_QOS_DEFAULT) - assert(datawriter is not None) sample = test_complete.CompleteTestType() sample.int16_field(255) assert(datawriter.write(sample)) - assert(datareader.wait_for_unread_message(fastdds.Duration_t(5, 0))) + assert(datareader.wait_for_unread_message( + fastdds.Duration_t(5, 0))) assert(1 == datareader.get_unread_count()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - publisher.delete_datawriter(datawriter)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - subscriber.delete_datareader(datareader)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_publisher(publisher)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_subscriber(subscriber)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_is_sample_valid(): +def test_is_sample_valid(transient_datareader_qos, datareader, + datawriter): """ This test checks: - DataReader::is_sample_valid """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - subscriber = participant.create_subscriber(fastdds.SUBSCRIBER_QOS_DEFAULT) - assert(subscriber is not None) - test_type = fastdds.TypeSupport( - test_complete.CompleteTestTypePubSubType()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.register_type(test_type, test_type.get_type_name())) - topic = participant.create_topic( - "Complete", test_type.get_type_name(), fastdds.TOPIC_QOS_DEFAULT) - assert(topic is not None) - datareader_qos = fastdds.DataReaderQos() - datareader_qos.durability().kind = fastdds.TRANSIENT_LOCAL_DURABILITY_QOS - datareader = subscriber.create_datareader( - topic, datareader_qos) - assert(datareader is not None) - - publisher = participant.create_publisher(fastdds.PUBLISHER_QOS_DEFAULT) - assert(publisher is not None) - datawriter = publisher.create_datawriter( - topic, fastdds.DATAWRITER_QOS_DEFAULT) - assert(datawriter is not None) sample = test_complete.CompleteTestType() sample.int16_field(255) assert(datawriter.write(sample)) - assert(datareader.wait_for_unread_message(fastdds.Duration_t(5, 0))) + assert(datareader.wait_for_unread_message( + fastdds.Duration_t(5, 0))) data = test_complete.CompleteTestType() info = fastdds.SampleInfo() assert(fastdds.ReturnCode_t.RETCODE_OK == @@ -893,101 +473,41 @@ def test_is_sample_valid(): assert(datareader.is_sample_valid(data, info)) assert(sample.int16_field() == data.int16_field()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - publisher.delete_datawriter(datawriter)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - subscriber.delete_datareader(datareader)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_publisher(publisher)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_subscriber(subscriber)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_lookup_instance(): +def test_lookup_instance(test_keyed_type, datareader): """ This test checks: - DataReader::lookup_instance """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - subscriber = participant.create_subscriber(fastdds.SUBSCRIBER_QOS_DEFAULT) - assert(subscriber is not None) - test_type = fastdds.TypeSupport( - test_complete.KeyedCompleteTestTypePubSubType()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.register_type(test_type, test_type.get_type_name())) - topic = participant.create_topic( - "Complete", test_type.get_type_name(), fastdds.TOPIC_QOS_DEFAULT) - assert(topic is not None) - datareader = subscriber.create_datareader( - topic, fastdds.DATAREADER_QOS_DEFAULT) - assert(datareader is not None) - sample = test_complete.KeyedCompleteTestType() sample.id(3) ih = datareader.lookup_instance(sample) assert(fastdds.c_InstanceHandle_Unknown == ih) - assert(fastdds.ReturnCode_t.RETCODE_OK == - subscriber.delete_datareader(datareader)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_subscriber(subscriber)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_read(): +def test_read(transient_datareader_qos, datareader, + datawriter): """ This test checks: - DataReader::read - DataReader::return_loan """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - subscriber = participant.create_subscriber(fastdds.SUBSCRIBER_QOS_DEFAULT) - assert(subscriber is not None) - test_type = fastdds.TypeSupport( - test_complete.CompleteTestTypePubSubType()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.register_type(test_type, test_type.get_type_name())) - topic = participant.create_topic( - "Complete", test_type.get_type_name(), fastdds.TOPIC_QOS_DEFAULT) - assert(topic is not None) - datareader = subscriber.create_datareader( - topic, fastdds.DATAREADER_QOS_DEFAULT) - assert(datareader is not None) - data_seq = test_complete.CompleteTestTypeSeq() info_seq = fastdds.SampleInfoSeq() - assert(fastdds.ReturnCode_t.RETCODE_NO_DATA == datareader.read( - data_seq, info_seq, fastdds.LENGTH_UNLIMITED, - fastdds.ANY_SAMPLE_STATE, fastdds.ANY_VIEW_STATE, - fastdds.ANY_INSTANCE_STATE)) + assert(fastdds.ReturnCode_t.RETCODE_NO_DATA == + datareader.read( + data_seq, info_seq, fastdds.LENGTH_UNLIMITED, + fastdds.ANY_SAMPLE_STATE, fastdds.ANY_VIEW_STATE, + fastdds.ANY_INSTANCE_STATE)) assert(0 == len(data_seq)) assert(0 == len(info_seq)) - publisher = participant.create_publisher(fastdds.PUBLISHER_QOS_DEFAULT) - assert(publisher is not None) - datawriter = publisher.create_datawriter( - topic, fastdds.DATAWRITER_QOS_DEFAULT) - assert(datawriter is not None) sample = test_complete.CompleteTestType() sample.int16_field(255) assert(datawriter.write(sample)) - assert(datareader.wait_for_unread_message(fastdds.Duration_t(5, 0))) + assert(datareader.wait_for_unread_message( + fastdds.Duration_t(5, 0))) assert(fastdds.ReturnCode_t.RETCODE_OK == datareader.read( data_seq, info_seq, fastdds.LENGTH_UNLIMITED, fastdds.ANY_SAMPLE_STATE, fastdds.ANY_VIEW_STATE, @@ -999,44 +519,14 @@ def test_read(): assert(fastdds.ReturnCode_t.RETCODE_OK == datareader.return_loan(data_seq, info_seq)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - publisher.delete_datawriter(datawriter)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - subscriber.delete_datareader(datareader)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_publisher(publisher)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_subscriber(subscriber)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_read_instance(): +def test_read_instance(transient_datareader_qos, test_keyed_type, + datareader, datawriter): """ This test checks: - DataReader::read_instance - DataReader::return_loan """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - subscriber = participant.create_subscriber(fastdds.SUBSCRIBER_QOS_DEFAULT) - assert(subscriber is not None) - test_type = fastdds.TypeSupport( - test_complete.KeyedCompleteTestTypePubSubType()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.register_type(test_type, test_type.get_type_name())) - topic = participant.create_topic( - "Complete", test_type.get_type_name(), fastdds.TOPIC_QOS_DEFAULT) - assert(topic is not None) - datareader = subscriber.create_datareader( - topic, fastdds.DATAREADER_QOS_DEFAULT) - assert(datareader is not None) - data_seq = test_complete.KeyedCompleteTestTypeSeq() info_seq = fastdds.SampleInfoSeq() ih = fastdds.InstanceHandle_t() @@ -1048,66 +538,33 @@ def test_read_instance(): assert(0 == len(data_seq)) assert(0 == len(info_seq)) - publisher = participant.create_publisher(fastdds.PUBLISHER_QOS_DEFAULT) - assert(publisher is not None) - datawriter = publisher.create_datawriter( - topic, fastdds.DATAWRITER_QOS_DEFAULT) - assert(datawriter is not None) sample = test_complete.KeyedCompleteTestType() - sample.int16_field(255) + sample.id(255) ih = datawriter.register_instance(sample) assert(datawriter.write(sample, ih)) - assert(datareader.wait_for_unread_message(fastdds.Duration_t(5, 0))) - assert(fastdds.ReturnCode_t.RETCODE_OK == datareader.read_instance( - data_seq, info_seq, fastdds.LENGTH_UNLIMITED, ih, - fastdds.ANY_SAMPLE_STATE, fastdds.ANY_VIEW_STATE, - fastdds.ANY_INSTANCE_STATE)) + assert(datareader.wait_for_unread_message( + fastdds.Duration_t(5, 0))) + assert(fastdds.ReturnCode_t.RETCODE_OK == + datareader.read_instance( + data_seq, info_seq, fastdds.LENGTH_UNLIMITED, ih, + fastdds.ANY_SAMPLE_STATE, fastdds.ANY_VIEW_STATE, + fastdds.ANY_INSTANCE_STATE)) assert(1 == len(data_seq)) assert(1 == len(info_seq)) assert(info_seq[0].valid_data is True) - assert(sample.int16_field() == data_seq[0].int16_field()) + assert(sample.id() == data_seq[0].id()) assert(fastdds.ReturnCode_t.RETCODE_OK == datareader.return_loan(data_seq, info_seq)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - publisher.delete_datawriter(datawriter)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - subscriber.delete_datareader(datareader)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_publisher(publisher)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_subscriber(subscriber)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_read_next_instance(): +def test_read_next_instance(transient_datareader_qos, test_keyed_type, + datareader, datawriter): """ This test checks: - DataReader::read_next_instance - DataReader::return_loan """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - subscriber = participant.create_subscriber(fastdds.SUBSCRIBER_QOS_DEFAULT) - assert(subscriber is not None) - test_type = fastdds.TypeSupport( - test_complete.KeyedCompleteTestTypePubSubType()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.register_type(test_type, test_type.get_type_name())) - topic = participant.create_topic( - "Complete", test_type.get_type_name(), fastdds.TOPIC_QOS_DEFAULT) - assert(topic is not None) - datareader = subscriber.create_datareader( - topic, fastdds.DATAREADER_QOS_DEFAULT) - assert(datareader is not None) - data_seq = test_complete.KeyedCompleteTestTypeSeq() info_seq = fastdds.SampleInfoSeq() ih = fastdds.InstanceHandle_t() @@ -1119,143 +576,72 @@ def test_read_next_instance(): assert(0 == len(data_seq)) assert(0 == len(info_seq)) - publisher = participant.create_publisher(fastdds.PUBLISHER_QOS_DEFAULT) - assert(publisher is not None) - datawriter = publisher.create_datawriter( - topic, fastdds.DATAWRITER_QOS_DEFAULT) - assert(datawriter is not None) sample = test_complete.KeyedCompleteTestType() - sample.int16_field(255) + sample.id(255) assert(datawriter.write(sample)) - assert(datareader.wait_for_unread_message(fastdds.Duration_t(5, 0))) - assert(fastdds.ReturnCode_t.RETCODE_OK == datareader.read_next_instance( - data_seq, info_seq, fastdds.LENGTH_UNLIMITED, ih, - fastdds.ANY_SAMPLE_STATE, fastdds.ANY_VIEW_STATE, - fastdds.ANY_INSTANCE_STATE)) + assert(datareader.wait_for_unread_message( + fastdds.Duration_t(5, 0))) + assert(fastdds.ReturnCode_t.RETCODE_OK == + datareader.read_next_instance( + data_seq, info_seq, fastdds.LENGTH_UNLIMITED, ih, + fastdds.ANY_SAMPLE_STATE, fastdds.ANY_VIEW_STATE, + fastdds.ANY_INSTANCE_STATE)) assert(1 == len(data_seq)) assert(1 == len(info_seq)) assert(info_seq[0].valid_data is True) - assert(sample.int16_field() == data_seq[0].int16_field()) + assert(sample.id() == data_seq[0].id()) assert(fastdds.ReturnCode_t.RETCODE_OK == datareader.return_loan(data_seq, info_seq)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - publisher.delete_datawriter(datawriter)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - subscriber.delete_datareader(datareader)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_publisher(publisher)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_subscriber(subscriber)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_read_next_sample(): +def test_read_next_sample(transient_datareader_qos, datareader, + datawriter): """ This test checks: - DataReader::read_next_sample """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - subscriber = participant.create_subscriber(fastdds.SUBSCRIBER_QOS_DEFAULT) - assert(subscriber is not None) - test_type = fastdds.TypeSupport( - test_complete.CompleteTestTypePubSubType()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.register_type(test_type, test_type.get_type_name())) - topic = participant.create_topic( - "Complete", test_type.get_type_name(), fastdds.TOPIC_QOS_DEFAULT) - assert(topic is not None) - datareader_qos = fastdds.DataReaderQos() - datareader_qos.durability().kind = fastdds.TRANSIENT_LOCAL_DURABILITY_QOS - datareader = subscriber.create_datareader( - topic, datareader_qos) - assert(datareader is not None) - data = test_complete.CompleteTestType() info = fastdds.SampleInfo() - assert(fastdds.ReturnCode_t.RETCODE_NO_DATA == datareader.read_next_sample( - data, info)) + assert(fastdds.ReturnCode_t.RETCODE_NO_DATA == + datareader.read_next_sample( + data, info)) - publisher = participant.create_publisher(fastdds.PUBLISHER_QOS_DEFAULT) - assert(publisher is not None) - datawriter = publisher.create_datawriter( - topic, fastdds.DATAWRITER_QOS_DEFAULT) - assert(datawriter is not None) sample = test_complete.CompleteTestType() sample.int16_field(255) assert(datawriter.write(sample)) - assert(datareader.wait_for_unread_message(fastdds.Duration_t(5, 0))) + assert(datareader.wait_for_unread_message( + fastdds.Duration_t(5, 0))) assert(fastdds.ReturnCode_t.RETCODE_OK == datareader.read_next_sample(data, info)) assert(info.valid_data) assert(sample.int16_field() == data.int16_field()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - publisher.delete_datawriter(datawriter)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - subscriber.delete_datareader(datareader)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_publisher(publisher)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_subscriber(subscriber)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_take(): +def test_take(transient_datareader_qos, datareader, + datawriter): """ This test checks: - DataReader::take - DataReader::return_loan """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - subscriber = participant.create_subscriber(fastdds.SUBSCRIBER_QOS_DEFAULT) - assert(subscriber is not None) - test_type = fastdds.TypeSupport( - test_complete.CompleteTestTypePubSubType()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.register_type(test_type, test_type.get_type_name())) - topic = participant.create_topic( - "Complete", test_type.get_type_name(), fastdds.TOPIC_QOS_DEFAULT) - assert(topic is not None) - datareader = subscriber.create_datareader( - topic, fastdds.DATAREADER_QOS_DEFAULT) - assert(datareader is not None) - data_seq = test_complete.CompleteTestTypeSeq() info_seq = fastdds.SampleInfoSeq() - assert(fastdds.ReturnCode_t.RETCODE_NO_DATA == datareader.take( - data_seq, info_seq, fastdds.LENGTH_UNLIMITED, - fastdds.ANY_SAMPLE_STATE, fastdds.ANY_VIEW_STATE, - fastdds.ANY_INSTANCE_STATE)) + assert(fastdds.ReturnCode_t.RETCODE_NO_DATA == + datareader.take( + data_seq, info_seq, fastdds.LENGTH_UNLIMITED, + fastdds.ANY_SAMPLE_STATE, fastdds.ANY_VIEW_STATE, + fastdds.ANY_INSTANCE_STATE)) assert(0 == len(data_seq)) assert(0 == len(info_seq)) - publisher = participant.create_publisher(fastdds.PUBLISHER_QOS_DEFAULT) - assert(publisher is not None) - datawriter = publisher.create_datawriter( - topic, fastdds.DATAWRITER_QOS_DEFAULT) - assert(datawriter is not None) sample = test_complete.CompleteTestType() sample.int16_field(255) assert(datawriter.write(sample)) - assert(datareader.wait_for_unread_message(fastdds.Duration_t(5, 0))) + assert(datareader.wait_for_unread_message( + fastdds.Duration_t(5, 0))) assert(fastdds.ReturnCode_t.RETCODE_OK == datareader.take( data_seq, info_seq, fastdds.LENGTH_UNLIMITED, fastdds.ANY_SAMPLE_STATE, fastdds.ANY_VIEW_STATE, @@ -1267,44 +653,14 @@ def test_take(): assert(fastdds.ReturnCode_t.RETCODE_OK == datareader.return_loan(data_seq, info_seq)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - publisher.delete_datawriter(datawriter)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - subscriber.delete_datareader(datareader)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_publisher(publisher)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_subscriber(subscriber)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_take_instance(): +def test_take_instance(transient_datareader_qos, test_keyed_type, + datareader, datawriter): """ This test checks: - DataReader::take_instance - DataReader::return_loan """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - subscriber = participant.create_subscriber(fastdds.SUBSCRIBER_QOS_DEFAULT) - assert(subscriber is not None) - test_type = fastdds.TypeSupport( - test_complete.KeyedCompleteTestTypePubSubType()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.register_type(test_type, test_type.get_type_name())) - topic = participant.create_topic( - "Complete", test_type.get_type_name(), fastdds.TOPIC_QOS_DEFAULT) - assert(topic is not None) - datareader = subscriber.create_datareader( - topic, fastdds.DATAREADER_QOS_DEFAULT) - assert(datareader is not None) - data_seq = test_complete.KeyedCompleteTestTypeSeq() info_seq = fastdds.SampleInfoSeq() ih = fastdds.InstanceHandle_t() @@ -1316,66 +672,33 @@ def test_take_instance(): assert(0 == len(data_seq)) assert(0 == len(info_seq)) - publisher = participant.create_publisher(fastdds.PUBLISHER_QOS_DEFAULT) - assert(publisher is not None) - datawriter = publisher.create_datawriter( - topic, fastdds.DATAWRITER_QOS_DEFAULT) - assert(datawriter is not None) sample = test_complete.KeyedCompleteTestType() - sample.int16_field(255) + sample.id(255) ih = datawriter.register_instance(sample) assert(datawriter.write(sample, ih)) - assert(datareader.wait_for_unread_message(fastdds.Duration_t(5, 0))) - assert(fastdds.ReturnCode_t.RETCODE_OK == datareader.take_instance( - data_seq, info_seq, fastdds.LENGTH_UNLIMITED, ih, - fastdds.ANY_SAMPLE_STATE, fastdds.ANY_VIEW_STATE, - fastdds.ANY_INSTANCE_STATE)) + assert(datareader.wait_for_unread_message( + fastdds.Duration_t(5, 0))) + assert(fastdds.ReturnCode_t.RETCODE_OK == + datareader.take_instance( + data_seq, info_seq, fastdds.LENGTH_UNLIMITED, ih, + fastdds.ANY_SAMPLE_STATE, fastdds.ANY_VIEW_STATE, + fastdds.ANY_INSTANCE_STATE)) assert(1 == len(data_seq)) assert(1 == len(info_seq)) assert(info_seq[0].valid_data is True) - assert(sample.int16_field() == data_seq[0].int16_field()) + assert(sample.id() == data_seq[0].id()) assert(fastdds.ReturnCode_t.RETCODE_OK == datareader.return_loan(data_seq, info_seq)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - publisher.delete_datawriter(datawriter)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - subscriber.delete_datareader(datareader)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_publisher(publisher)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_subscriber(subscriber)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_take_next_instance(): +def test_take_next_instance(transient_datareader_qos, test_keyed_type, + datareader, datawriter): """ This test checks: - DataReader::take_next_instance - DataReader::return_loan """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - subscriber = participant.create_subscriber(fastdds.SUBSCRIBER_QOS_DEFAULT) - assert(subscriber is not None) - test_type = fastdds.TypeSupport( - test_complete.KeyedCompleteTestTypePubSubType()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.register_type(test_type, test_type.get_type_name())) - topic = participant.create_topic( - "Complete", test_type.get_type_name(), fastdds.TOPIC_QOS_DEFAULT) - assert(topic is not None) - datareader = subscriber.create_datareader( - topic, fastdds.DATAREADER_QOS_DEFAULT) - assert(datareader is not None) - data_seq = test_complete.KeyedCompleteTestTypeSeq() info_seq = fastdds.SampleInfoSeq() ih = fastdds.InstanceHandle_t() @@ -1387,203 +710,72 @@ def test_take_next_instance(): assert(0 == len(data_seq)) assert(0 == len(info_seq)) - publisher = participant.create_publisher(fastdds.PUBLISHER_QOS_DEFAULT) - assert(publisher is not None) - datawriter = publisher.create_datawriter( - topic, fastdds.DATAWRITER_QOS_DEFAULT) - assert(datawriter is not None) sample = test_complete.KeyedCompleteTestType() - sample.int16_field(255) + sample.id(255) assert(datawriter.write(sample)) - assert(datareader.wait_for_unread_message(fastdds.Duration_t(5, 0))) - assert(fastdds.ReturnCode_t.RETCODE_OK == datareader.take_next_instance( - data_seq, info_seq, fastdds.LENGTH_UNLIMITED, ih, - fastdds.ANY_SAMPLE_STATE, fastdds.ANY_VIEW_STATE, - fastdds.ANY_INSTANCE_STATE)) + assert(datareader.wait_for_unread_message( + fastdds.Duration_t(5, 0))) + assert(fastdds.ReturnCode_t.RETCODE_OK == + datareader.take_next_instance( + data_seq, info_seq, fastdds.LENGTH_UNLIMITED, ih, + fastdds.ANY_SAMPLE_STATE, fastdds.ANY_VIEW_STATE, + fastdds.ANY_INSTANCE_STATE)) assert(1 == len(data_seq)) assert(1 == len(info_seq)) assert(info_seq[0].valid_data is True) - assert(sample.int16_field() == data_seq[0].int16_field()) + assert(sample.id() == data_seq[0].id()) assert(fastdds.ReturnCode_t.RETCODE_OK == datareader.return_loan(data_seq, info_seq)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - publisher.delete_datawriter(datawriter)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - subscriber.delete_datareader(datareader)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_publisher(publisher)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_subscriber(subscriber)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_take_next_sample(): +def test_take_next_sample(transient_datareader_qos, datareader, + datawriter): """ This test checks: - DataReader::take_next_sample """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - subscriber = participant.create_subscriber(fastdds.SUBSCRIBER_QOS_DEFAULT) - assert(subscriber is not None) - test_type = fastdds.TypeSupport( - test_complete.CompleteTestTypePubSubType()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.register_type(test_type, test_type.get_type_name())) - topic = participant.create_topic( - "Complete", test_type.get_type_name(), fastdds.TOPIC_QOS_DEFAULT) - assert(topic is not None) - datareader_qos = fastdds.DataReaderQos() - datareader_qos.durability().kind = fastdds.TRANSIENT_LOCAL_DURABILITY_QOS - datareader = subscriber.create_datareader( - topic, datareader_qos) - assert(datareader is not None) - data = test_complete.CompleteTestType() info = fastdds.SampleInfo() - assert(fastdds.ReturnCode_t.RETCODE_NO_DATA == datareader.take_next_sample( - data, info)) + assert(fastdds.ReturnCode_t.RETCODE_NO_DATA == + datareader.take_next_sample( + data, info)) - publisher = participant.create_publisher(fastdds.PUBLISHER_QOS_DEFAULT) - assert(publisher is not None) - datawriter = publisher.create_datawriter( - topic, fastdds.DATAWRITER_QOS_DEFAULT) - assert(datawriter is not None) sample = test_complete.CompleteTestType() sample.int16_field(255) assert(datawriter.write(sample)) - assert(datareader.wait_for_unread_message(fastdds.Duration_t(5, 0))) + assert(datareader.wait_for_unread_message( + fastdds.Duration_t(5, 0))) assert(fastdds.ReturnCode_t.RETCODE_OK == datareader.take_next_sample(data, info)) assert(info.valid_data) assert(sample.int16_field() == data.int16_field()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - publisher.delete_datawriter(datawriter)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - subscriber.delete_datareader(datareader)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_publisher(publisher)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_subscriber(subscriber)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_get_type(): +def test_get_type(test_type, datareader): """ This test checks: - DataReader::type """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - subscriber = participant.create_subscriber(fastdds.SUBSCRIBER_QOS_DEFAULT) - assert(subscriber is not None) - test_type = fastdds.TypeSupport( - test_complete.KeyedCompleteTestTypePubSubType()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.register_type(test_type, test_type.get_type_name())) - topic = participant.create_topic( - "Complete", test_type.get_type_name(), fastdds.TOPIC_QOS_DEFAULT) - assert(topic is not None) - datareader = subscriber.create_datareader( - topic, fastdds.DATAREADER_QOS_DEFAULT) - assert(datareader is not None) - test_type_aux = datareader.type() assert(test_type == test_type_aux) assert(test_type.get_type_name() == test_type_aux.get_type_name()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - subscriber.delete_datareader(datareader)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_subscriber(subscriber)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_wait_for_historical_data(): +def test_wait_for_historical_data(datareader): """ This test checks: - DataReader::wait_for_historical_data """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - subscriber = participant.create_subscriber(fastdds.SUBSCRIBER_QOS_DEFAULT) - assert(subscriber is not None) - test_type = fastdds.TypeSupport( - test_complete.KeyedCompleteTestTypePubSubType()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.register_type(test_type, test_type.get_type_name())) - topic = participant.create_topic( - "Complete", test_type.get_type_name(), fastdds.TOPIC_QOS_DEFAULT) - assert(topic is not None) - datareader = subscriber.create_datareader( - topic, fastdds.DATAREADER_QOS_DEFAULT) - assert(datareader is not None) - assert(fastdds.ReturnCode_t.RETCODE_UNSUPPORTED == - datareader.wait_for_historical_data(fastdds.Duration_t(0, 100))) - - assert(fastdds.ReturnCode_t.RETCODE_OK == - subscriber.delete_datareader(datareader)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_subscriber(subscriber)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) + datareader.wait_for_historical_data( + fastdds.Duration_t(0, 100))) -def test_wait_for_unread_message(): +def test_wait_for_unread_message(datareader): """ This test checks: - DataReader::wait_for_unread_message """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - subscriber = participant.create_subscriber(fastdds.SUBSCRIBER_QOS_DEFAULT) - assert(subscriber is not None) - test_type = fastdds.TypeSupport( - test_complete.KeyedCompleteTestTypePubSubType()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.register_type(test_type, test_type.get_type_name())) - topic = participant.create_topic( - "Complete", test_type.get_type_name(), fastdds.TOPIC_QOS_DEFAULT) - assert(topic is not None) - datareader = subscriber.create_datareader( - topic, fastdds.DATAREADER_QOS_DEFAULT) - assert(datareader is not None) - assert(not datareader.wait_for_unread_message(fastdds.Duration_t(0, 100))) - - assert(fastdds.ReturnCode_t.RETCODE_OK == - subscriber.delete_datareader(datareader)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_subscriber(subscriber)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) diff --git a/fastdds_python/test/api/test_datawriter.py b/fastdds_python/test/api/test_datawriter.py index f3b762aa..7b6d8907 100644 --- a/fastdds_python/test/api/test_datawriter.py +++ b/fastdds_python/test/api/test_datawriter.py @@ -1,6 +1,7 @@ import datetime import fastdds +import pytest import test_complete @@ -9,33 +10,60 @@ def __init__(self): super().__init__() -def test_assert_liveliness(): - """ - This test checks: - - DataWriter::assert_liveliness - """ +@pytest.fixture +def participant(): factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 10, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - publisher = participant.create_publisher(fastdds.PUBLISHER_QOS_DEFAULT) - assert(publisher is not None) - test_type = fastdds.TypeSupport( - test_complete.KeyedCompleteTestTypePubSubType()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.register_type(test_type, test_type.get_type_name())) - topic = participant.create_topic( + return factory.create_participant( + 0, fastdds.PARTICIPANT_QOS_DEFAULT) + + +@pytest.fixture +def publisher(participant): + return participant.create_publisher(fastdds.PUBLISHER_QOS_DEFAULT) + + +@pytest.fixture +def test_type(): + return fastdds.TypeSupport( + test_complete.CompleteTestTypePubSubType()) + + +@pytest.fixture +def test_keyed_type(test_type): + test_type.set(test_complete.KeyedCompleteTestTypePubSubType()) + + +@pytest.fixture +def topic(participant, test_type): + participant.register_type(test_type, test_type.get_type_name()) + return participant.create_topic( "Complete", test_type.get_type_name(), fastdds.TOPIC_QOS_DEFAULT) - assert(topic is not None) - datawriter_qos = fastdds.DataWriterQos() + + +@pytest.fixture +def datawriter_qos(): + return fastdds.DataWriterQos() + + +@pytest.fixture +def manual_liveliness_datawriter_qos(datawriter_qos): datawriter_qos.liveliness().kind = \ fastdds.MANUAL_BY_PARTICIPANT_LIVELINESS_QOS + return datawriter_qos + + +@pytest.fixture +def keep_all_datawriter_qos(datawriter_qos): + datawriter_qos.history().kind = \ + fastdds.KEEP_ALL_HISTORY_QOS + return datawriter_qos + + +@pytest.fixture +def datawriter(participant, topic, publisher, datawriter_qos): datawriter = publisher.create_datawriter(topic, datawriter_qos) - assert(datawriter is not None) - assert(fastdds.ReturnCode_t.RETCODE_OK == - datawriter.assert_liveliness()) + yield datawriter assert(fastdds.ReturnCode_t.RETCODE_OK == publisher.delete_datawriter(datawriter)) @@ -43,76 +71,39 @@ def test_assert_liveliness(): participant.delete_topic(topic)) assert(fastdds.ReturnCode_t.RETCODE_OK == participant.delete_publisher(publisher)) + factory = fastdds.DomainParticipantFactory.get_instance() assert(fastdds.ReturnCode_t.RETCODE_OK == factory.delete_participant(participant)) -def test_clear_history(): +def test_assert_liveliness(manual_liveliness_datawriter_qos, datawriter): """ This test checks: - - DataWriter::clear_history + - DataWriter::assert_liveliness """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - publisher = participant.create_publisher(fastdds.PUBLISHER_QOS_DEFAULT) - assert(publisher is not None) - test_type = fastdds.TypeSupport( - test_complete.KeyedCompleteTestTypePubSubType()) assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.register_type(test_type, test_type.get_type_name())) - topic = participant.create_topic( - "Complete", test_type.get_type_name(), fastdds.TOPIC_QOS_DEFAULT) - assert(topic is not None) - datawriter_qos = fastdds.DataWriterQos() - datawriter_qos.history().kind = \ - fastdds.KEEP_ALL_HISTORY_QOS - datawriter = publisher.create_datawriter(topic, datawriter_qos) - assert(datawriter is not None) + datawriter.assert_liveliness()) - sample = test_complete.KeyedCompleteTestType() - sample.id(4) + +def test_clear_history(keep_all_datawriter_qos, datawriter): + """ + This test checks: + - DataWriter::clear_history + """ + sample = test_complete.CompleteTestType() + sample.int16_field(4) assert(datawriter.write(sample)) assert([fastdds.ReturnCode_t.RETCODE_OK, 1] == datawriter.clear_history()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - publisher.delete_datawriter(datawriter)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_publisher(publisher)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_dispose(): +def test_dispose(test_keyed_type, datawriter): """ This test checks: - DataWriter::dispose - DataWriter::dispose_w_timestamp - DataWriter::unregister_instance """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - publisher = participant.create_publisher(fastdds.PUBLISHER_QOS_DEFAULT) - assert(publisher is not None) - test_type = fastdds.TypeSupport( - test_complete.KeyedCompleteTestTypePubSubType()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.register_type(test_type, test_type.get_type_name())) - topic = participant.create_topic( - "Complete", test_type.get_type_name(), fastdds.TOPIC_QOS_DEFAULT) - assert(topic is not None) - datawriter = publisher.create_datawriter( - topic, fastdds.DATAWRITER_QOS_DEFAULT) - assert(datawriter is not None) - # Overload 1 sample = test_complete.KeyedCompleteTestType() sample.id(1) @@ -139,39 +130,13 @@ def test_dispose(): assert(fastdds.ReturnCode_t.RETCODE_UNSUPPORTED == datawriter.dispose_w_timestamp(sample, ih, timestamp)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - publisher.delete_datawriter(datawriter)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_publisher(publisher)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_get_instance_handle(): +def test_get_instance_handle(datawriter): """ This test checks: - DataWriter::guid - DataWriter::get_instance_handle """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - publisher = participant.create_publisher(fastdds.PUBLISHER_QOS_DEFAULT) - assert(publisher is not None) - test_type = fastdds.TypeSupport( - test_complete.KeyedCompleteTestTypePubSubType()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.register_type(test_type, test_type.get_type_name())) - topic = participant.create_topic( - "Complete", test_type.get_type_name(), fastdds.TOPIC_QOS_DEFAULT) - assert(topic is not None) - datawriter = publisher.create_datawriter( - topic, fastdds.DATAWRITER_QOS_DEFAULT) - guid = datawriter.guid() assert(fastdds.c_Guid_Unknown != guid) ih = datawriter.get_instance_handle() @@ -183,94 +148,31 @@ def test_get_instance_handle(): for i in range(0, 4): assert(guid.entityId.value[i] == ih.value[12+i]) - assert(fastdds.ReturnCode_t.RETCODE_OK == - publisher.delete_datawriter(datawriter)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_publisher(publisher)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_get_key_value(): +def test_get_key_value(test_keyed_type, datawriter): """ This test checks: - DataWriter::get_key_value """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - publisher = participant.create_publisher(fastdds.PUBLISHER_QOS_DEFAULT) - assert(publisher is not None) - test_type = fastdds.TypeSupport( - test_complete.KeyedCompleteTestTypePubSubType()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.register_type(test_type, test_type.get_type_name())) - topic = participant.create_topic( - "Complete", test_type.get_type_name(), fastdds.TOPIC_QOS_DEFAULT) - assert(topic is not None) - datawriter = publisher.create_datawriter( - topic, fastdds.DATAWRITER_QOS_DEFAULT) - assert(datawriter is not None) - sample = test_complete.KeyedCompleteTestType() ih = fastdds.InstanceHandle_t() assert(fastdds.ReturnCode_t.RETCODE_UNSUPPORTED == datawriter.get_key_value(sample, ih)) assert(fastdds.c_InstanceHandle_Unknown == ih) - assert(fastdds.ReturnCode_t.RETCODE_OK == - publisher.delete_datawriter(datawriter)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_publisher(publisher)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_get_sending_locators(): +def test_get_sending_locators(datawriter): """ This test checks: - DataWriter::get_sending_locators """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - publisher = participant.create_publisher(fastdds.PUBLISHER_QOS_DEFAULT) - assert(publisher is not None) - test_type = fastdds.TypeSupport( - test_complete.KeyedCompleteTestTypePubSubType()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.register_type(test_type, test_type.get_type_name())) - topic = participant.create_topic( - "Complete", test_type.get_type_name(), fastdds.TOPIC_QOS_DEFAULT) - assert(topic is not None) - datawriter = publisher.create_datawriter( - topic, fastdds.DATAWRITER_QOS_DEFAULT) - assert(datawriter is not None) - locator_list = fastdds.LocatorList() assert(fastdds.ReturnCode_t.RETCODE_OK == datawriter.get_sending_locators(locator_list)) assert(0 < locator_list.size()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - publisher.delete_datawriter(datawriter)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_publisher(publisher)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_get_set_listener(): +def test_get_set_listener(datawriter): """ This test checks: - DataWriter::get_listener @@ -279,24 +181,6 @@ def test_get_set_listener(): - StatusMask::operator == - StatusMask::operator << """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - publisher = participant.create_publisher(fastdds.PUBLISHER_QOS_DEFAULT) - assert(publisher is not None) - test_type = fastdds.TypeSupport( - test_complete.KeyedCompleteTestTypePubSubType()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.register_type(test_type, test_type.get_type_name())) - topic = participant.create_topic( - "Complete", test_type.get_type_name(), fastdds.TOPIC_QOS_DEFAULT) - assert(topic is not None) - datawriter = publisher.create_datawriter( - topic, fastdds.DATAWRITER_QOS_DEFAULT) - assert(datawriter is not None) - # Overload 1 listener = DataWriterListener() assert(listener is not None) @@ -304,6 +188,7 @@ def test_get_set_listener(): datawriter.set_listener(listener)) assert(datawriter.get_listener() == listener) assert(fastdds.StatusMask.all() == datawriter.get_status_mask()) + datawriter.set_listener(None) def test(status_mask_1, status_mask_2): """ @@ -312,15 +197,17 @@ def test(status_mask_1, status_mask_2): listener = DataWriterListener() assert(listener is not None) assert(fastdds.ReturnCode_t.RETCODE_OK == - datawriter.set_listener(listener, status_mask_1)) + datawriter.set_listener(listener, status_mask_1)) assert(datawriter.get_listener() == listener) assert(status_mask_1 == datawriter.get_status_mask()) + datawriter.set_listener(None) listener = DataWriterListener() assert(listener is not None) assert(fastdds.ReturnCode_t.RETCODE_OK == datawriter.set_listener(listener, status_mask_2)) assert(datawriter.get_listener() == listener) assert(status_mask_2 == datawriter.get_status_mask()) + datawriter.set_listener(None) # Overload 2: Different status masks test(fastdds.StatusMask.all(), fastdds.StatusMask_all()) @@ -382,153 +269,45 @@ def test(status_mask_1, status_mask_2): fastdds.StatusMask.subscription_matched(), m) - assert(fastdds.ReturnCode_t.RETCODE_OK == - publisher.delete_datawriter(datawriter)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_publisher(publisher)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_get_liveliness_lost_status(): +def test_get_liveliness_lost_status(datawriter): """ This test checks: - DataWriter::get_liveliness_lost_status """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - publisher = participant.create_publisher(fastdds.PUBLISHER_QOS_DEFAULT) - assert(publisher is not None) - test_type = fastdds.TypeSupport( - test_complete.KeyedCompleteTestTypePubSubType()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.register_type(test_type, test_type.get_type_name())) - topic = participant.create_topic( - "Complete", test_type.get_type_name(), fastdds.TOPIC_QOS_DEFAULT) - assert(topic is not None) - datawriter = publisher.create_datawriter( - topic, fastdds.DATAWRITER_QOS_DEFAULT) - assert(datawriter is not None) - status = fastdds.LivelinessLostStatus() assert(fastdds.ReturnCode_t.RETCODE_OK == datawriter.get_liveliness_lost_status(status)) assert(0 == status.total_count) assert(0 == status.total_count_change) - assert(fastdds.ReturnCode_t.RETCODE_OK == - publisher.delete_datawriter(datawriter)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_publisher(publisher)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_get_matched_subscription_data(): +def test_get_matched_subscription_data(datawriter): """ This test checks: - DataWriter::get_matched_subscription_data """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - publisher = participant.create_publisher(fastdds.PUBLISHER_QOS_DEFAULT) - assert(publisher is not None) - test_type = fastdds.TypeSupport( - test_complete.KeyedCompleteTestTypePubSubType()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.register_type(test_type, test_type.get_type_name())) - topic = participant.create_topic( - "Complete", test_type.get_type_name(), fastdds.TOPIC_QOS_DEFAULT) - assert(topic is not None) - datawriter = publisher.create_datawriter( - topic, fastdds.DATAWRITER_QOS_DEFAULT) - assert(datawriter is not None) - sub_data = fastdds.SubscriptionBuiltinTopicData() ih = fastdds.InstanceHandle_t() assert(fastdds.ReturnCode_t.RETCODE_UNSUPPORTED == datawriter.get_matched_subscription_data(sub_data, ih)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - publisher.delete_datawriter(datawriter)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_publisher(publisher)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_get_matched_subscriptions(): +def test_get_matched_subscriptions(datawriter): """ This test checks: - DataWriter::get_matched_subscriptions """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - publisher = participant.create_publisher(fastdds.PUBLISHER_QOS_DEFAULT) - assert(publisher is not None) - test_type = fastdds.TypeSupport( - test_complete.KeyedCompleteTestTypePubSubType()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.register_type(test_type, test_type.get_type_name())) - topic = participant.create_topic( - "Complete", test_type.get_type_name(), fastdds.TOPIC_QOS_DEFAULT) - assert(topic is not None) - datawriter = publisher.create_datawriter( - topic, fastdds.DATAWRITER_QOS_DEFAULT) - assert(datawriter is not None) - ihs = fastdds.InstanceHandleVector() assert(fastdds.ReturnCode_t.RETCODE_UNSUPPORTED == datawriter.get_matched_subscriptions(ihs)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - publisher.delete_datawriter(datawriter)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_publisher(publisher)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_get_offered_deadline_missed_status(): +def test_get_offered_deadline_missed_status(datawriter): """ This test checks: - DataWriter::get_offered_deadline_missed_status """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - publisher = participant.create_publisher(fastdds.PUBLISHER_QOS_DEFAULT) - assert(publisher is not None) - test_type = fastdds.TypeSupport( - test_complete.KeyedCompleteTestTypePubSubType()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.register_type(test_type, test_type.get_type_name())) - topic = participant.create_topic( - "Complete", test_type.get_type_name(), fastdds.TOPIC_QOS_DEFAULT) - assert(topic is not None) - datawriter = publisher.create_datawriter( - topic, fastdds.DATAWRITER_QOS_DEFAULT) - assert(datawriter is not None) - status = fastdds.OfferedDeadlineMissedStatus() assert(fastdds.ReturnCode_t.RETCODE_OK == datawriter.get_offered_deadline_missed_status(status)) @@ -536,39 +315,12 @@ def test_get_offered_deadline_missed_status(): assert(0 == status.total_count_change) assert(fastdds.c_InstanceHandle_Unknown == status.last_instance_handle) - assert(fastdds.ReturnCode_t.RETCODE_OK == - publisher.delete_datawriter(datawriter)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_publisher(publisher)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_get_offered_incompatible_qos_status(): +def test_get_offered_incompatible_qos_status(datawriter): """ This test checks: - DataWriter::get_offered_deadline_missed_status """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - publisher = participant.create_publisher(fastdds.PUBLISHER_QOS_DEFAULT) - assert(publisher is not None) - test_type = fastdds.TypeSupport( - test_complete.KeyedCompleteTestTypePubSubType()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.register_type(test_type, test_type.get_type_name())) - topic = participant.create_topic( - "Complete", test_type.get_type_name(), fastdds.TOPIC_QOS_DEFAULT) - assert(topic is not None) - datawriter = publisher.create_datawriter( - topic, fastdds.DATAWRITER_QOS_DEFAULT) - assert(datawriter is not None) - status = fastdds.OfferedIncompatibleQosStatus() assert(fastdds.ReturnCode_t.RETCODE_OK == datawriter.get_offered_incompatible_qos_status(status)) @@ -582,39 +334,12 @@ def test_get_offered_incompatible_qos_status(): assert(id == policy.policy_id) id += 1 - assert(fastdds.ReturnCode_t.RETCODE_OK == - publisher.delete_datawriter(datawriter)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_publisher(publisher)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_get_publication_matched_status(): +def test_get_publication_matched_status(datawriter): """ This test checks: - DataWriter::get_publication_matched_status """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - publisher = participant.create_publisher(fastdds.PUBLISHER_QOS_DEFAULT) - assert(publisher is not None) - test_type = fastdds.TypeSupport( - test_complete.KeyedCompleteTestTypePubSubType()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.register_type(test_type, test_type.get_type_name())) - topic = participant.create_topic( - "Complete", test_type.get_type_name(), fastdds.TOPIC_QOS_DEFAULT) - assert(topic is not None) - datawriter = publisher.create_datawriter( - topic, fastdds.DATAWRITER_QOS_DEFAULT) - assert(datawriter is not None) - status = fastdds.PublicationMatchedStatus() assert(fastdds.ReturnCode_t.RETCODE_OK == datawriter.get_publication_matched_status(status)) @@ -624,165 +349,48 @@ def test_get_publication_matched_status(): assert(0 == status.current_count_change) assert(fastdds.c_InstanceHandle_Unknown == status.last_subscription_handle) - assert(fastdds.ReturnCode_t.RETCODE_OK == - publisher.delete_datawriter(datawriter)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_publisher(publisher)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_get_publisher(): +def test_get_publisher(publisher, datawriter): """ This test checks: - DataWriter::get_publisher """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - publisher = participant.create_publisher(fastdds.PUBLISHER_QOS_DEFAULT) - assert(publisher is not None) - test_type = fastdds.TypeSupport( - test_complete.KeyedCompleteTestTypePubSubType()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.register_type(test_type, test_type.get_type_name())) - topic = participant.create_topic( - "Complete", test_type.get_type_name(), fastdds.TOPIC_QOS_DEFAULT) - assert(topic is not None) - datawriter = publisher.create_datawriter( - topic, fastdds.DATAWRITER_QOS_DEFAULT) - assert(datawriter is not None) - pub = datawriter.get_publisher() assert(pub == publisher) - assert(fastdds.ReturnCode_t.RETCODE_OK == - publisher.delete_datawriter(datawriter)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_publisher(publisher)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_get_type(): +def test_get_type(test_type, datawriter): """ This test checks: - DataWriter::get_type """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - publisher = participant.create_publisher(fastdds.PUBLISHER_QOS_DEFAULT) - assert(publisher is not None) - test_type = fastdds.TypeSupport( - test_complete.KeyedCompleteTestTypePubSubType()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.register_type(test_type, test_type.get_type_name())) - topic = participant.create_topic( - "Complete", test_type.get_type_name(), fastdds.TOPIC_QOS_DEFAULT) - assert(topic is not None) - datawriter = publisher.create_datawriter( - topic, fastdds.DATAWRITER_QOS_DEFAULT) - assert(datawriter is not None) - test_type_aux = datawriter.get_type() assert(test_type == test_type_aux) assert(test_type.get_type_name() == test_type_aux.get_type_name()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - publisher.delete_datawriter(datawriter)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_publisher(publisher)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_get_topic(): +def test_get_topic(topic, datawriter): """ This test checks: - DataWriter::get_topic """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - publisher = participant.create_publisher(fastdds.PUBLISHER_QOS_DEFAULT) - assert(publisher is not None) - test_type = fastdds.TypeSupport( - test_complete.KeyedCompleteTestTypePubSubType()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.register_type(test_type, test_type.get_type_name())) - topic = participant.create_topic( - "Complete", test_type.get_type_name(), fastdds.TOPIC_QOS_DEFAULT) - assert(topic is not None) - datawriter = publisher.create_datawriter( - topic, fastdds.DATAWRITER_QOS_DEFAULT) - assert(datawriter is not None) - topic_aux = datawriter.get_topic() assert(topic == topic_aux) assert(topic.get_type_name() == topic_aux.get_type_name()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - publisher.delete_datawriter(datawriter)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_publisher(publisher)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_lookup_instance(): +def test_lookup_instance(test_keyed_type, datawriter): """ This test checks: - DataWriter::lookup_instance """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - publisher = participant.create_publisher(fastdds.PUBLISHER_QOS_DEFAULT) - assert(publisher is not None) - test_type = fastdds.TypeSupport( - test_complete.KeyedCompleteTestTypePubSubType()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.register_type(test_type, test_type.get_type_name())) - topic = participant.create_topic( - "Complete", test_type.get_type_name(), fastdds.TOPIC_QOS_DEFAULT) - assert(topic is not None) - datawriter = publisher.create_datawriter( - topic, fastdds.DATAWRITER_QOS_DEFAULT) - assert(datawriter is not None) - sample = test_complete.KeyedCompleteTestType() sample.id(3) ih = datawriter.lookup_instance(sample) assert(fastdds.c_InstanceHandle_Unknown == ih) - assert(fastdds.ReturnCode_t.RETCODE_OK == - publisher.delete_datawriter(datawriter)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_publisher(publisher)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_register_instance(): +def test_register_instance(test_keyed_type, datawriter): """ This test checks: - DataWriter::register_instance @@ -790,24 +398,6 @@ def test_register_instance(): - DataWriter::unregister_instance - DataWriter::unregister_instance_w_timestamp """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - publisher = participant.create_publisher(fastdds.PUBLISHER_QOS_DEFAULT) - assert(publisher is not None) - test_type = fastdds.TypeSupport( - test_complete.KeyedCompleteTestTypePubSubType()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.register_type(test_type, test_type.get_type_name())) - topic = participant.create_topic( - "Complete", test_type.get_type_name(), fastdds.TOPIC_QOS_DEFAULT) - assert(topic is not None) - datawriter = publisher.create_datawriter( - topic, fastdds.DATAWRITER_QOS_DEFAULT) - assert(datawriter is not None) - # Overload 1 sample = test_complete.KeyedCompleteTestType() sample.id(1) @@ -837,39 +427,12 @@ def test_register_instance(): assert(fastdds.ReturnCode_t.RETCODE_UNSUPPORTED == datawriter.unregister_instance_w_timestamp(sample, ih, timestamp)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - publisher.delete_datawriter(datawriter)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_publisher(publisher)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_wait_for_acknowledgments(): +def test_wait_for_acknowledgments(test_keyed_type, datawriter): """ This test checks: - DataWriter::wait_for_acknowledgments """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - publisher = participant.create_publisher(fastdds.PUBLISHER_QOS_DEFAULT) - assert(publisher is not None) - test_type = fastdds.TypeSupport( - test_complete.KeyedCompleteTestTypePubSubType()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.register_type(test_type, test_type.get_type_name())) - topic = participant.create_topic( - "Complete", test_type.get_type_name(), fastdds.TOPIC_QOS_DEFAULT) - assert(topic is not None) - datawriter = publisher.create_datawriter( - topic, fastdds.DATAWRITER_QOS_DEFAULT) - assert(datawriter is not None) - # Overload 1 sample = test_complete.KeyedCompleteTestType() sample.id(3) @@ -884,40 +447,13 @@ def test_wait_for_acknowledgments(): datawriter.wait_for_acknowledgments( sample, ih, fastdds.Duration_t(1, 0))) - assert(fastdds.ReturnCode_t.RETCODE_OK == - publisher.delete_datawriter(datawriter)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_publisher(publisher)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_write(): +def test_write(test_keyed_type, datawriter): """ This test checks: - DataWriter::write - DataWriter::write_w_timestamp """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - publisher = participant.create_publisher(fastdds.PUBLISHER_QOS_DEFAULT) - assert(publisher is not None) - test_type = fastdds.TypeSupport( - test_complete.KeyedCompleteTestTypePubSubType()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.register_type(test_type, test_type.get_type_name())) - topic = participant.create_topic( - "Complete", test_type.get_type_name(), fastdds.TOPIC_QOS_DEFAULT) - assert(topic is not None) - datawriter = publisher.create_datawriter( - topic, fastdds.DATAWRITER_QOS_DEFAULT) - assert(datawriter is not None) - # Overload 1 sample = test_complete.KeyedCompleteTestType() assert(datawriter.write(sample)) @@ -956,12 +492,3 @@ def test_write(): assert(fastdds.ReturnCode_t.RETCODE_UNSUPPORTED == datawriter.write_w_timestamp(sample, ih, timestamp)) assert(fastdds.c_InstanceHandle_Unknown == ih) - - assert(fastdds.ReturnCode_t.RETCODE_OK == - publisher.delete_datawriter(datawriter)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_publisher(publisher)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) diff --git a/fastdds_python/test/api/test_domainparticipant.py b/fastdds_python/test/api/test_domainparticipant.py index 79a557f0..16891326 100644 --- a/fastdds_python/test/api/test_domainparticipant.py +++ b/fastdds_python/test/api/test_domainparticipant.py @@ -1,4 +1,5 @@ import fastdds +import pytest import test_complete @@ -22,17 +23,38 @@ def __init__(self): super().__init__() -def test_contains_entity(): +@pytest.fixture +def not_autoenable_factory(): + factory = fastdds.DomainParticipantFactory.get_instance() + factory_qos = fastdds.DomainParticipantFactoryQos() + factory.get_qos(factory_qos) + factory_qos.entity_factory().autoenable_created_entities = False + factory.set_qos(factory_qos) + return factory + + +@pytest.fixture +def participant_qos(): + return fastdds.DomainParticipantQos() + + +@pytest.fixture +def testname_participant_qos(participant_qos): + participant_qos.name('TestName') + return participant_qos + + +@pytest.fixture +def participant(participant_qos): + factory = fastdds.DomainParticipantFactory.get_instance() + return factory.create_participant(0, participant_qos) + + +def test_contains_entity(participant): """ This test checks: - DomainParticipant::contains_entity """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - publisher = participant.create_publisher(fastdds.PUBLISHER_QOS_DEFAULT) assert(publisher is not None) @@ -42,11 +64,9 @@ def test_contains_entity(): assert(fastdds.ReturnCode_t.RETCODE_OK == participant.delete_publisher(publisher)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) -def test_create_and_delete_publisher(): +def test_create_and_delete_publisher(participant): """ This test checks: - DomainParticipant::create_publisher @@ -55,11 +75,6 @@ def test_create_and_delete_publisher(): - StatusMask::operator == - StatusMask::operator << """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) listener = PublisherListener() assert(listener is not None) @@ -160,11 +175,8 @@ def test(status_mask_1, status_mask_2, listnr=None): m, listener) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_create_and_delete_subscriber(): +def test_create_and_delete_subscriber(participant): """ This test checks: - DomainParticipant::create_subscriber @@ -173,11 +185,6 @@ def test_create_and_delete_subscriber(): - StatusMask::operator == - StatusMask::operator << """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) listener = SubscriberListener() assert(listener is not None) @@ -278,11 +285,8 @@ def test(status_mask_1, status_mask_2, listnr=None): m, listener) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_create_and_delete_topic(): +def test_create_and_delete_topic(participant): """ This test checks: - DomainParticipant::create_topic @@ -291,11 +295,6 @@ def test_create_and_delete_topic(): - StatusMask::operator == - StatusMask::operator << """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) listener = TopicListener() assert(listener is not None) @@ -409,17 +408,8 @@ def test(status_mask_1, status_mask_2, listnr=None): m, listener) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - - -def test_delete_contained_entities(): - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) +def test_delete_contained_entities(participant): publisher = participant.create_publisher( fastdds.PUBLISHER_QOS_DEFAULT) assert(publisher is not None) @@ -434,57 +424,35 @@ def test_delete_contained_entities(): assert(topic is not None) # Cannot delete participant without deleting its contained entities + factory = fastdds.DomainParticipantFactory.get_instance() assert(fastdds.ReturnCode_t.RETCODE_PRECONDITION_NOT_MET == factory.delete_participant(participant)) assert(fastdds.ReturnCode_t.RETCODE_OK == participant.delete_contained_entities()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_enable(): +def test_enable(not_autoenable_factory, participant): """ This test checks: - DomainParticipant::enable - DomainParticipant::is_enabled """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - factory_qos = fastdds.DomainParticipantFactoryQos() - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.get_qos(factory_qos)) - factory_qos.entity_factory().autoenable_created_entities = False - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.set_qos(factory_qos)) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - assert(not participant.is_enabled()) assert(fastdds.ReturnCode_t.RETCODE_OK == participant.enable()) assert(participant.is_enabled()) - - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) + factory_qos = fastdds.DomainParticipantFactoryQos() factory_qos.entity_factory().autoenable_created_entities = True assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.set_qos(factory_qos)) + not_autoenable_factory.set_qos(factory_qos)) -def test_find_topic(): +def test_find_topic(participant): """ This test checks: - DomainParticipant::find_topic """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - test_type = fastdds.TypeSupport(test_complete.CompleteTestTypePubSubType()) assert(fastdds.ReturnCode_t.RETCODE_OK == participant.register_type(test_type, test_type.get_type_name())) @@ -502,40 +470,25 @@ def test_find_topic(): assert(fastdds.ReturnCode_t.RETCODE_OK == participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) -def test_get_builtin_subscriber(): +def test_get_builtin_subscriber(participant): """ This test checks: - DomainParticipant::get_builtin_subscriber """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - builtin_subscriber = participant.get_builtin_subscriber() assert(builtin_subscriber is None) # assert(builtin_subscriber.is_enabled()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_get_discovered_participants(): +def test_get_discovered_participants(participant): """ This test checks: - DomainParticipant::get_discovered_participants - DomainParticipant::get_discovered_participant_data """ factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) participant2 = factory.create_participant( 0, fastdds.PARTICIPANT_QOS_DEFAULT) assert(participant2 is not None) @@ -544,6 +497,9 @@ def test_get_discovered_participants(): assert(fastdds.ReturnCode_t.RETCODE_UNSUPPORTED == participant.get_discovered_participants(ihs)) + assert(fastdds.ReturnCode_t.RETCODE_OK == + factory.delete_participant(participant2)) + def test_get_domain_id(): """ @@ -562,18 +518,12 @@ def test_get_domain_id(): factory.delete_participant(participant)) -def test_get_instance_handle(): +def test_get_instance_handle(participant): """ This test checks: - DomainParticipant::get_instance_handle - DomainParticipant::guid """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - ih = participant.get_instance_handle() assert(ih is not None) # assert(ih.isDefined()) @@ -591,11 +541,8 @@ def test_get_instance_handle(): for i in range(0, 4): assert(guid.entityId.value[i] == ih.value[12+i]) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_get_set_listener(): +def test_get_set_listener(participant): """ This test checks: - DomainParticipant::get_listener @@ -604,12 +551,6 @@ def test_get_set_listener(): - StatusMask::operator == - StatusMask::operator << """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 7, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - # Overload 1 listener = DomainParticipantListener() assert(listener is not None) @@ -617,6 +558,7 @@ def test_get_set_listener(): participant.set_listener(listener)) assert(participant.get_listener() == listener) assert(fastdds.StatusMask.all() == participant.get_status_mask()) + participant.set_listener(None) def test(status_mask_1, status_mask_2): """ @@ -628,12 +570,14 @@ def test(status_mask_1, status_mask_2): participant.set_listener(listener, status_mask_1)) assert(participant.get_listener() == listener) assert(status_mask_1 == participant.get_status_mask()) + participant.set_listener(None) listener = DomainParticipantListener() assert(listener is not None) assert(fastdds.ReturnCode_t.RETCODE_OK == participant.set_listener(listener, status_mask_2)) assert(participant.get_listener() == listener) assert(status_mask_2 == participant.get_status_mask()) + participant.set_listener(None) # Overload 3: Different status masks test(fastdds.StatusMask.all(), fastdds.StatusMask_all()) @@ -695,41 +639,23 @@ def test(status_mask_1, status_mask_2): fastdds.StatusMask.subscription_matched(), m) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_get_partitipant_names(): +def test_get_partitipant_names(testname_participant_qos, participant): """ This test checks: - DomainParticipant::get_participant_names """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - qos = fastdds.DomainParticipantQos() - qos.name('TestName') - participant = factory.create_participant(0, qos) - assert(participant is not None) - names = participant.get_participant_names() assert('TestName' == names[0]) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_get_set_qos(): +def test_get_set_qos(participant): """ This test checks: - DomainParticipant::get_qos - DomainParticipant::set_qos """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) qos = fastdds.DomainParticipantQos() - participant = factory.create_participant(0, qos) - assert(participant is not None) - assert(fastdds.ReturnCode_t.RETCODE_OK == participant.get_qos(qos)) qos.user_data().push_back(1) qos.user_data().push_back(2) @@ -745,101 +671,56 @@ def test_get_set_qos(): assert(1 == qos2.user_data()[0]) assert(2 == qos2.user_data()[1]) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_ignore_participant(): +def test_ignore_participant(participant): """ This test checks: - DomainParticipant::ignore_participant """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - ih = fastdds.InstanceHandle_t() ih.value = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16) assert(fastdds.ReturnCode_t.RETCODE_UNSUPPORTED == participant.ignore_participant(ih)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_ignore_publication(): +def test_ignore_publication(participant): """ This test checks: - DomainParticipant::ignore_publication """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - ih = fastdds.InstanceHandle_t() ih.value = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16) assert(fastdds.ReturnCode_t.RETCODE_UNSUPPORTED == participant.ignore_publication(ih)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_ignore_subscription(): +def test_ignore_subscription(participant): """ This test checks: - DomainParticipant::ignore_subscription """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - ih = fastdds.InstanceHandle_t() ih.value = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16) assert(fastdds.ReturnCode_t.RETCODE_UNSUPPORTED == participant.ignore_subscription(ih)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_ignore_topic(): +def test_ignore_topic(participant): """ This test checks: - DomainParticipant::ignore_topic """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - ih = fastdds.InstanceHandle_t() ih.value = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16) assert(fastdds.ReturnCode_t.RETCODE_UNSUPPORTED == participant.ignore_topic(ih)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_lookup_topicdescription(): +def test_lookup_topicdescription(participant): """ This test checks: - DomainParticipant::lookup_topicdescription """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - test_type = fastdds.TypeSupport(test_complete.CompleteTestTypePubSubType()) assert(fastdds.ReturnCode_t.RETCODE_OK == participant.register_type(test_type, test_type.get_type_name())) @@ -855,413 +736,3 @@ def test_lookup_topicdescription(): assert(fastdds.ReturnCode_t.RETCODE_OK == participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - - - -# -# -# /** -# * Create a Publisher in this Participant. -# * -# * @param profile_name Publisher profile name. -# * @param listener Pointer to the listener (default: nullptr) -# * @param mask StatusMask that holds statuses the listener responds to (default: all) -# * @return Pointer to the created Publisher. -# */ -# RTPS_DllAPI Publisher* create_publisher_with_profile( -# const std::string& profile_name, -# PublisherListener* listener = nullptr, -# const StatusMask& mask = StatusMask::all()); -# -# /** -# * Create a Subscriber in this Participant. -# * -# * @param profile_name Subscriber profile name. -# * @param listener Pointer to the listener (default: nullptr) -# * @param mask StatusMask that holds statuses the listener responds to (default: all) -# * @return Pointer to the created Subscriber. -# */ -# RTPS_DllAPI Subscriber* create_subscriber_with_profile( -# const std::string& profile_name, -# SubscriberListener* listener = nullptr, -# const StatusMask& mask = StatusMask::all()); -# -# -# * Create a Topic in this Participant. -# * -# * @param topic_name Name of the Topic. -# * @param type_name Data type of the Topic. -# * @param profile_name Topic profile name. -# * @param listener Pointer to the listener (default: nullptr) -# * @param mask StatusMask that holds statuses the listener responds to (default: all) -# * @return Pointer to the created Topic. -# */ -# RTPS_DllAPI Topic* create_topic_with_profile( -# const std::string& topic_name, -# const std::string& type_name, -# const std::string& profile_name, -# TopicListener* listener = nullptr, -# const StatusMask& mask = StatusMask::all()); -# -# /** -# * Create a ContentFilteredTopic in this Participant. -# * -# * @param name Name of the ContentFilteredTopic -# * @param related_topic Related Topic to being subscribed -# * @param filter_expression Logic expression to create filter -# * @param expression_parameters Parameters to filter content -# * @return Pointer to the created ContentFilteredTopic. -# * @return nullptr if @c related_topic does not belong to this participant. -# * @return nullptr if a topic with the specified @c name has already been created. -# * @return nullptr if a filter cannot be created with the specified @c filter_expression and -# * @c expression_parameters. -# */ -# RTPS_DllAPI ContentFilteredTopic* create_contentfilteredtopic( -# const std::string& name, -# Topic* related_topic, -# const std::string& filter_expression, -# const std::vector& expression_parameters); -# -# /** -# * Create a ContentFilteredTopic in this Participant using a custom filter. -# * -# * @param name Name of the ContentFilteredTopic -# * @param related_topic Related Topic to being subscribed -# * @param filter_expression Logic expression to create filter -# * @param expression_parameters Parameters to filter content -# * @param filter_class_name Name of the filter class to use -# * -# * @return Pointer to the created ContentFilteredTopic. -# * @return nullptr if @c related_topic does not belong to this participant. -# * @return nullptr if a topic with the specified @c name has already been created. -# * @return nullptr if a filter cannot be created with the specified @c filter_expression and -# * @c expression_parameters. -# * @return nullptr if the specified @c filter_class_name has not been registered. -# */ -# RTPS_DllAPI ContentFilteredTopic* create_contentfilteredtopic( -# const std::string& name, -# Topic* related_topic, -# const std::string& filter_expression, -# const std::vector& expression_parameters, -# const char* filter_class_name); -# -# /** -# * Deletes an existing ContentFilteredTopic. -# * -# * @param a_contentfilteredtopic ContentFilteredTopic to be deleted -# * @return RETCODE_BAD_PARAMETER if the topic passed is a nullptr, RETCODE_PRECONDITION_NOT_MET if the topic does not belong to -# * this participant or if it is referenced by any entity and RETCODE_OK if the ContentFilteredTopic was deleted. -# */ -# RTPS_DllAPI ReturnCode_t delete_contentfilteredtopic( -# const ContentFilteredTopic* a_contentfilteredtopic); -# -# /** -# * Create a MultiTopic in this Participant. -# * -# * @param name Name of the MultiTopic -# * @param type_name Result type of the MultiTopic -# * @param subscription_expression Logic expression to combine filter -# * @param expression_parameters Parameters to subscription content -# * @return Pointer to the created ContentFilteredTopic, nullptr in error case -# */ -# RTPS_DllAPI MultiTopic* create_multitopic( -# const std::string& name, -# const std::string& type_name, -# const std::string& subscription_expression, -# const std::vector& expression_parameters); -# -# /** -# * Deletes an existing MultiTopic. -# * -# * @param a_multitopic MultiTopic to be deleted -# * @return RETCODE_BAD_PARAMETER if the topic passed is a nullptr, RETCODE_PRECONDITION_NOT_MET if the topic does not belong to -# * this participant or if it is referenced by any entity and RETCODE_OK if the Topic was deleted. -# */ -# RTPS_DllAPI ReturnCode_t delete_multitopic( -# const MultiTopic* a_multitopic); -# -# /** -# * This operation manually asserts the liveliness of the DomainParticipant. -# * This is used in combination with the LIVELINESS QoS policy to indicate to the Service that the entity -# * remains active. -# * -# * This operation needs to only be used if the DomainParticipant contains DataWriter entities with -# * the LIVELINESS set to MANUAL_BY_PARTICIPANT and it only affects the liveliness of those DataWriter entities. -# * Otherwise, it has no effect. -# * -# * @note Writing data via the write operation on a DataWriter asserts liveliness on the DataWriter itself and its -# * DomainParticipant. Consequently the use of assert_liveliness is only needed if the application is not -# * writing data regularly. -# * -# * @return RETCODE_OK if the liveliness was asserted, RETCODE_ERROR otherwise. -# */ -# RTPS_DllAPI ReturnCode_t assert_liveliness(); -# -# /** -# * Fills the PublisherQos with the values of the XML profile. -# * -# * @param profile_name Publisher profile name. -# * @param qos PublisherQos object where the qos is returned. -# * @return RETCODE_OK if the profile exists. RETCODE_BAD_PARAMETER otherwise. -# */ -# RTPS_DllAPI ReturnCode_t get_publisher_qos_from_profile( -# const std::string& profile_name, -# PublisherQos& qos) const; -# -# -# /** -# * Fills the SubscriberQos with the values of the XML profile. -# * -# * @param profile_name Subscriber profile name. -# * @param qos SubscriberQos object where the qos is returned. -# * @return RETCODE_OK if the profile exists. RETCODE_BAD_PARAMETER otherwise. -# */ -# RTPS_DllAPI ReturnCode_t get_subscriber_qos_from_profile( -# const std::string& profile_name, -# SubscriberQos& qos) const; -# -# -# /** -# * Fills the TopicQos with the values of the XML profile. -# * -# * @param profile_name Topic profile name. -# * @param qos TopicQos object where the qos is returned. -# * @return RETCODE_OK if the profile exists. RETCODE_BAD_PARAMETER otherwise. -# */ -# RTPS_DllAPI ReturnCode_t get_topic_qos_from_profile( -# const std::string& profile_name, -# TopicQos& qos) const; -# -# /** -# * Retrieves the list of topics that have been discovered in the domain and are not "ignored". -# * -# * @param[out] topic_handles Reference to the vector where discovered topics will be returned -# * @return RETCODE_OK if everything correct, error code otherwise -# */ -# RTPS_DllAPI ReturnCode_t get_discovered_topics( -# std::vector& topic_handles) const; -# -# /** -# * Retrieves the Topic data of a discovered not ignored topic. -# * -# * @param[out] topic_data Reference to the TopicBuiltinTopicData object to return the data -# * @param topic_handle InstanceHandle of Topic to retrieve the data from -# * @return RETCODE_OK if everything correct, PRECONDITION_NOT_MET if topic does not exist -# */ -# RTPS_DllAPI ReturnCode_t get_discovered_topic_data( -# builtin::TopicBuiltinTopicData& topic_data, -# const InstanceHandle_t& topic_handle) const; -# -# /** -# * This operation checks whether or not the given handle represents an Entity that was created from the -# * DomainParticipant. -# * -# * @param a_handle InstanceHandle of the entity to look for. -# * @param recursive The containment applies recursively. That is, it applies both to entities -# * (TopicDescription, Publisher, or Subscriber) created directly using the DomainParticipant as well as -# * entities created using a contained Publisher, or Subscriber as the factory, and so forth. (default: true) -# * @return True if entity is contained. False otherwise. -# */ -# RTPS_DllAPI bool contains_entity( -# const InstanceHandle_t& a_handle, -# bool recursive = true) const; -# -# /** -# * This operation returns the current value of the time that the service uses to time-stamp data-writes -# * and to set the reception-timestamp for the data-updates it receives. -# * -# * @param current_time Time_t reference where the current time is returned -# * @return RETCODE_OK -# */ -# RTPS_DllAPI ReturnCode_t get_current_time( -# fastrtps::Time_t& current_time) const; -# -# // DomainParticipant methods specific from Fast-DDS -# -# /** -# * Register a type in this participant. -# * -# * @param type TypeSupport. -# * @param type_name The name that will be used to identify the Type. -# * @return RETCODE_BAD_PARAMETER if the size of the name is 0, RERCODE_PRECONDITION_NOT_MET if there is another TypeSupport -# * with the same name and RETCODE_OK if it is correctly registered. -# */ -# RTPS_DllAPI ReturnCode_t register_type( -# TypeSupport type, -# const std::string& type_name); -# -# /** -# * Register a type in this participant. -# * -# * @param type TypeSupport. -# * @return RETCODE_BAD_PARAMETER if the size of the name is 0, RERCODE_PRECONDITION_NOT_MET if there is another TypeSupport -# * with the same name and RETCODE_OK if it is correctly registered. -# */ -# RTPS_DllAPI ReturnCode_t register_type( -# TypeSupport type); -# -# /** -# * Unregister a type in this participant. -# * -# * @param typeName Name of the type -# * @return RETCODE_BAD_PARAMETER if the size of the name is 0, RERCODE_PRECONDITION_NOT_MET if there are entities using that -# * TypeSupport and RETCODE_OK if it is correctly unregistered. -# */ -# RTPS_DllAPI ReturnCode_t unregister_type( -# const std::string& typeName); -# -# /** -# * This method gives access to a registered type based on its name. -# * -# * @param type_name Name of the type -# * @return TypeSupport corresponding to the type_name -# */ -# RTPS_DllAPI TypeSupport find_type( -# const std::string& type_name) const; -# -# /** -# * @brief Getter for the participant names -# * -# * @return Vector with the names -# */ -# RTPS_DllAPI std::vector get_participant_names() const; -# -# /** -# * This method can be used when using a StaticEndpointDiscovery mechanism different that the one -# * included in FastRTPS, for example when communicating with other implementations. -# * It indicates the Participant that an Endpoint from the XML has been discovered and -# * should be activated. -# * -# * @param partguid Participant GUID_t. -# * @param userId User defined ID as shown in the XML file. -# * @param kind EndpointKind (WRITER or READER) -# * @return True if correctly found and activated. -# */ -# RTPS_DllAPI bool new_remote_endpoint_discovered( -# const fastrtps::rtps::GUID_t& partguid, -# uint16_t userId, -# fastrtps::rtps::EndpointKind_t kind); -# -# /** -# * @brief Getter for the resource event -# * -# * @return A reference to the resource event -# */ -# RTPS_DllAPI fastrtps::rtps::ResourceEvent& get_resource_event() const; -# -# /** -# * When a DomainParticipant receives an incomplete list of TypeIdentifiers in a -# * PublicationBuiltinTopicData or SubscriptionBuiltinTopicData, it may request the additional type -# * dependencies by invoking the getTypeDependencies operation. -# * -# * @param in TypeIdentifier sequence -# * @return SampleIdentity -# */ -# RTPS_DllAPI fastrtps::rtps::SampleIdentity get_type_dependencies( -# const fastrtps::types::TypeIdentifierSeq& in) const; -# -# /** -# * A DomainParticipant may invoke the operation getTypes to retrieve the TypeObjects associated with a -# * list of TypeIdentifiers. -# * -# * @param in TypeIdentifier sequence -# * @return SampleIdentity -# */ -# RTPS_DllAPI fastrtps::rtps::SampleIdentity get_types( -# const fastrtps::types::TypeIdentifierSeq& in) const; -# -# /** -# * Helps the user to solve all dependencies calling internally to the typelookup service -# * and registers the resulting dynamic type. -# * The registration will be perform asynchronously and the user will be notified through the -# * given callback, which receives the type_name as unique argument. -# * If the type is already registered, the function will return true, but the callback will not be called. -# * If the given type_information is enough to build the type without using the typelookup service, -# * it will return true and the callback will be never called. -# * -# * @param type_information -# * @param type_name -# * @param callback -# * @return true if type is already available (callback will not be called). false if type isn't available yet -# * (the callback will be called if negotiation is success, and ignored in other case). -# */ -# RTPS_DllAPI ReturnCode_t register_remote_type( -# const fastrtps::types::TypeInformation& type_information, -# const std::string& type_name, -# std::function& callback); -# -# /** -# * Register a custom content filter factory, which can be used to create a ContentFilteredTopic. -# * -# * DDS specifies a SQL-like content filter to be used by content filtered topics. -# * If this filter does not meet your filtering requirements, you can register a custom filter factory. -# * -# * To use a custom filter, a factory for it must be registered in the following places: -# * -# * - In any application that uses the custom filter factory to create a ContentFilteredTopic and the corresponding -# * DataReader. -# * -# * - In each application that writes the data to the applications mentioned above. -# * -# * For example, suppose Application A on the subscription side creates a Topic named X and a ContentFilteredTopic -# * named filteredX (and a corresponding DataReader), using a previously registered content filter factory, myFilterFactory. -# * With only that, you will have filtering at the subscription side. -# * If you also want to perform filtering in any application that publishes Topic X, then you also need to register -# * the same definition of the ContentFilterFactory myFilterFactory in that application. -# * -# * Each @c filter_class_name can only be used to register a content filter factory once per DomainParticipant. -# * -# * @param filter_class_name Name of the filter class. Cannot be nullptr, must not exceed 255 characters, and must -# * be unique within this DomainParticipant. -# * @param filter_factory Factory of content filters to be registered. Cannot be nullptr. -# * -# * @return RETCODE_BAD_PARAMETER if any parameter is nullptr, or the filter_class_name exceeds 255 characters. -# * @return RETCODE_PRECONDITION_NOT_MET if the filter_class_name has been already registered. -# * @return RETCODE_PRECONDITION_NOT_MET if filter_class_name is FASTDDS_SQLFILTER_NAME. -# * @return RETCODE_OK if the filter is correctly registered. -# */ -# RTPS_DllAPI ReturnCode_t register_content_filter_factory( -# const char* filter_class_name, -# IContentFilterFactory* const filter_factory); -# -# /** -# * Lookup a custom content filter factory previously registered with register_content_filter_factory. -# * -# * @param filter_class_name Name of the filter class. Cannot be nullptr. -# * -# * @return nullptr if the given filter_class_name has not been previously registered on this DomainParticipant. -# * Otherwise, the content filter factory previously registered with the given filter_class_name. -# */ -# RTPS_DllAPI IContentFilterFactory* lookup_content_filter_factory( -# const char* filter_class_name); -# -# /** -# * Unregister a custom content filter factory previously registered with register_content_filter_factory. -# * -# * A filter_class_name can be unregistered only if it has been previously registered to the DomainParticipant with -# * register_content_filter_factory. -# * -# * The unregistration of filter is not allowed if there are any existing ContentFilteredTopic objects that are -# * using the filter. -# * -# * If there is any existing discovered DataReader with the same filter_class_name, filtering on the writer side will be -# * stopped, but this operation will not fail. -# * -# * @param filter_class_name Name of the filter class. Cannot be nullptr. -# * -# * @return RETCODE_BAD_PARAMETER if the filter_class_name is nullptr. -# * @return RERCODE_PRECONDITION_NOT_MET if the filter_class_name has not been previously registered. -# * @return RERCODE_PRECONDITION_NOT_MET if there is any ContentFilteredTopic referencing the filter. -# * @return RETCODE_OK if the filter is correctly unregistered. -# */ -# RTPS_DllAPI ReturnCode_t unregister_content_filter_factory( -# const char* filter_class_name); -# -# /** -# * @brief Check if the Participant has any Publisher, Subscriber or Topic -# * -# * @return true if any, false otherwise. -# */ -# bool has_active_entities(); diff --git a/fastdds_python/test/api/test_publisher.py b/fastdds_python/test/api/test_publisher.py index 587dadc7..6546eb08 100644 --- a/fastdds_python/test/api/test_publisher.py +++ b/fastdds_python/test/api/test_publisher.py @@ -1,4 +1,5 @@ import fastdds +import pytest import test_complete @@ -12,32 +13,61 @@ def __init__(self): super().__init__() -def test_coherent_changes(): +@pytest.fixture +def participant_qos(): + return fastdds.DomainParticipantQos() + + +@pytest.fixture +def not_autoenable_participant_qos(participant_qos): + participant_qos.entity_factory().autoenable_created_entities = False + return participant_qos + + +@pytest.fixture +def participant(participant_qos): + factory = fastdds.DomainParticipantFactory.get_instance() + return factory.create_participant(0, participant_qos) + + +@pytest.fixture +def publisher(participant, topic): + publisher = participant.create_publisher( + fastdds.PUBLISHER_QOS_DEFAULT) + + yield publisher + + assert(fastdds.ReturnCode_t.RETCODE_OK == + participant.delete_publisher(publisher)) + assert(fastdds.ReturnCode_t.RETCODE_OK == + participant.delete_topic(topic)) + factory = fastdds.DomainParticipantFactory.get_instance() + assert(fastdds.ReturnCode_t.RETCODE_OK == + factory.delete_participant(participant)) + + +@pytest.fixture +def topic(participant): + test_type = fastdds.TypeSupport( + test_complete.CompleteTestTypePubSubType()) + participant.register_type(test_type, test_type.get_type_name()) + return participant.create_topic( + "Complete", test_type.get_type_name(), fastdds.TOPIC_QOS_DEFAULT) + + +def test_coherent_changes(publisher): """ This test checks: - Publisher::begin_coherent_changes - Publisher::end_coherent_changes """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - publisher = participant.create_publisher(fastdds.PUBLISHER_QOS_DEFAULT) - assert(publisher is not None) - assert(fastdds.ReturnCode_t.RETCODE_UNSUPPORTED == publisher.begin_coherent_changes()) assert(fastdds.ReturnCode_t.RETCODE_UNSUPPORTED == publisher.end_coherent_changes()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_publisher(publisher)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_create_and_delete_datawriter(): +def test_create_and_delete_datawriter(topic, publisher): """ This test checks: - Publisher::create_datawriter @@ -46,20 +76,6 @@ def test_create_and_delete_datawriter(): - StatusMask::operator == - StatusMask::operator << """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - publisher = participant.create_publisher(fastdds.PUBLISHER_QOS_DEFAULT) - assert(publisher is not None) - test_type = fastdds.TypeSupport(test_complete.CompleteTestTypePubSubType()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.register_type(test_type, test_type.get_type_name())) - # Overload 1 - Success - topic = participant.create_topic( - "Complete", "CompleteTestType", fastdds.TOPIC_QOS_DEFAULT) - assert(topic is not None) listener = DataWriterListener() assert(listener is not None) @@ -161,32 +177,12 @@ def test(status_mask_1, status_mask_2, listnr=None): m, listener) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_publisher(publisher)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_deleted_contained_entities(): +def test_deleted_contained_entities(participant, topic, publisher): """ This test checks: - Publisher::delete_contained_entities """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - publisher = participant.create_publisher(fastdds.PUBLISHER_QOS_DEFAULT) - assert(publisher is not None) - test_type = fastdds.TypeSupport(test_complete.CompleteTestTypePubSubType()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.register_type(test_type, test_type.get_type_name())) - topic = participant.create_topic( - "Complete", "CompleteTestType", fastdds.TOPIC_QOS_DEFAULT) - assert(topic is not None) datawriter = publisher.create_datawriter( topic, fastdds.DATAWRITER_QOS_DEFAULT) assert(datawriter is not None) @@ -199,59 +195,25 @@ def test_deleted_contained_entities(): publisher.delete_contained_entities()) assert(publisher.has_datawriters() is False) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_publisher(publisher)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_enable(): +def test_enable(not_autoenable_participant_qos, publisher): """ This test checks: - Publisher::enable - Publisher::is_enabled """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - qos = fastdds.DomainParticipantQos() - qos.entity_factory().autoenable_created_entities = False - participant = factory.create_participant(0, qos) - assert(participant is not None) - publisher = participant.create_publisher(fastdds.PUBLISHER_QOS_DEFAULT) - assert(publisher is not None) - assert(not publisher.is_enabled()) assert(fastdds.ReturnCode_t.RETCODE_OK == publisher.enable()) assert(publisher.is_enabled()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_publisher(publisher)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_get_datawriters(): +def test_get_datawriters(topic, publisher): """ This test checks: - Publisher::get_datawriters - Publisher::has_datawriters """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - publisher = participant.create_publisher(fastdds.PUBLISHER_QOS_DEFAULT) - assert(publisher is not None) - test_type = fastdds.TypeSupport(test_complete.CompleteTestTypePubSubType()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.register_type(test_type, test_type.get_type_name())) - topic = participant.create_topic( - "Complete", "CompleteTestType", fastdds.TOPIC_QOS_DEFAULT) - assert(topic is not None) datawriter = publisher.create_datawriter( topic, fastdds.DATAWRITER_QOS_DEFAULT) assert(datawriter is not None) @@ -264,28 +226,14 @@ def test_get_datawriters(): assert(fastdds.ReturnCode_t.RETCODE_OK == publisher.delete_datawriter(datawriter)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_publisher(publisher)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) -def test_get_instance_handle(): +def test_get_instance_handle(participant, publisher): """ This test checks: - Publisher::get_instance_handle - Publisher::guid """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - publisher = participant.create_publisher(fastdds.PUBLISHER_QOS_DEFAULT) - assert(publisher is not None) - ih = publisher.get_instance_handle() assert(ih is not None) assert(ih.isDefined()) @@ -298,52 +246,24 @@ def test_get_instance_handle(): for i in range(0, 12): assert(guid.guidPrefix.value[i] == ih.value[i]) - # for i in range(0, 4): - # assert(guid.entityId.value[i] == ih.value[12+i]) - - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_publisher(publisher)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_get_participant(): +def test_get_participant(participant, publisher): """ This test checks: - Publisher::get_participant """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - publisher = participant.create_publisher(fastdds.PUBLISHER_QOS_DEFAULT) - assert(publisher is not None) - participant2 = publisher.get_participant() assert(participant2 is not None) assert(participant == participant2) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_publisher(publisher)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_get_set_qos(): +def test_get_set_qos(publisher): """ This test checks: - Publisher::get_qos - Publisher::set_qos """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) qos = fastdds.PublisherQos() - publisher = participant.create_publisher(qos) - assert(publisher is not None) qos.partition().push_back('PartitionTest') qos.partition().push_back('PartitionTest2') @@ -358,13 +278,8 @@ def test_get_set_qos(): assert('PartitionTest' == qos.partition()[0]) assert('PartitionTest2' == qos.partition()[1]) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_publisher(publisher)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_get_set_listener(): +def test_get_set_listener(publisher): """ This test checks: - Publisher::get_listener @@ -373,14 +288,6 @@ def test_get_set_listener(): - StatusMask::operator == - StatusMask::operator << """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - publisher = participant.create_publisher(fastdds.PUBLISHER_QOS_DEFAULT) - assert(publisher is not None) - # Overload 1 listener = PublisherListener() assert(listener is not None) @@ -388,6 +295,7 @@ def test_get_set_listener(): publisher.set_listener(listener)) assert(publisher.get_listener() == listener) assert(fastdds.StatusMask.all() == publisher.get_status_mask()) + publisher.set_listener(None) def test(status_mask_1, status_mask_2): """ @@ -399,12 +307,14 @@ def test(status_mask_1, status_mask_2): publisher.set_listener(listener, status_mask_1)) assert(publisher.get_listener() == listener) assert(status_mask_1 == publisher.get_status_mask()) + publisher.set_listener(None) listener = PublisherListener() assert(listener is not None) assert(fastdds.ReturnCode_t.RETCODE_OK == publisher.set_listener(listener, status_mask_2)) assert(publisher.get_listener() == listener) assert(status_mask_2 == publisher.get_status_mask()) + publisher.set_listener(None) # Overload 2: Different status masks test(fastdds.StatusMask.all(), fastdds.StatusMask_all()) @@ -466,31 +376,12 @@ def test(status_mask_1, status_mask_2): fastdds.StatusMask.subscription_matched(), m) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_publisher(publisher)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_lookup_datawriter(): +def test_lookup_datawriter(topic, publisher): """ This test checks: - Publisher::lookup_datawriter """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - publisher = participant.create_publisher(fastdds.PUBLISHER_QOS_DEFAULT) - assert(publisher is not None) - test_type = fastdds.TypeSupport(test_complete.CompleteTestTypePubSubType()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.register_type(test_type, test_type.get_type_name())) - # Overload 1 - Success - topic = participant.create_topic( - "Complete", "CompleteTestType", fastdds.TOPIC_QOS_DEFAULT) - assert(topic is not None) datawriter = publisher.create_datawriter( topic, fastdds.DATAWRITER_QOS_DEFAULT) assert(datawriter is not None) @@ -501,97 +392,25 @@ def test_lookup_datawriter(): assert(fastdds.ReturnCode_t.RETCODE_OK == publisher.delete_datawriter(datawriter)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_publisher(publisher)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) -def test_suspend_publications(): +def test_suspend_publications(publisher): """ This test checks: - Publisher::suspend_publications - Publisher::resume_publications """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - publisher = participant.create_publisher(fastdds.PUBLISHER_QOS_DEFAULT) - assert(publisher is not None) - assert(fastdds.ReturnCode_t.RETCODE_UNSUPPORTED == publisher.suspend_publications()) assert(fastdds.ReturnCode_t.RETCODE_UNSUPPORTED == publisher.resume_publications()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_publisher(publisher)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_wait_for_acknowlegments(): +def test_wait_for_acknowlegments(publisher): """ This test checks: - Publisher::wait_for_acknowledgments """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - publisher = participant.create_publisher(fastdds.PUBLISHER_QOS_DEFAULT) - assert(publisher is not None) - assert(fastdds.ReturnCode_t.RETCODE_OK == publisher.wait_for_acknowledgments(fastdds.Duration_t(3, 0))) # TODO Test a timeout - - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_publisher(publisher)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - - -# -# /** -# * This operation creates a DataWriter. The returned DataWriter will be attached and belongs to the Publisher. -# * -# * @param topic Topic the DataWriter will be listening -# * @param profile_name DataWriter profile name. -# * @param listener Pointer to the listener (default: nullptr). -# * @param mask StatusMask that holds statuses the listener responds to (default: all). -# * @return Pointer to the created DataWriter. nullptr if failed. -# */ -# RTPS_DllAPI DataWriter* create_datawriter_with_profile( -# Topic* topic, -# const std::string& profile_name, -# DataWriterListener* listener = nullptr, -# const StatusMask& mask = StatusMask::all()); -# -# -# /** -# * @brief Copies TopicQos into the corresponding DataWriterQos -# * -# * @param[out] writer_qos -# * @param[in] topic_qos -# * @return RETCODE_OK if successful, an error code otherwise -# */ -# RTPS_DllAPI ReturnCode_t copy_from_topic_qos( -# fastdds::dds::DataWriterQos& writer_qos, -# const fastdds::dds::TopicQos& topic_qos) const; -# -# /** -# * Fills the DataWriterQos with the values of the XML profile. -# * -# * @param profile_name DataWriter profile name. -# * @param qos DataWriterQos object where the qos is returned. -# * @return RETCODE_OK if the profile exists. RETCODE_BAD_PARAMETER otherwise. -# */ -# RTPS_DllAPI ReturnCode_t get_datawriter_qos_from_profile( -# const std::string& profile_name, -# DataWriterQos& qos) const; diff --git a/fastdds_python/test/api/test_subscriber.py b/fastdds_python/test/api/test_subscriber.py index 07c65718..200156af 100644 --- a/fastdds_python/test/api/test_subscriber.py +++ b/fastdds_python/test/api/test_subscriber.py @@ -1,4 +1,5 @@ import fastdds +import pytest import test_complete @@ -12,31 +13,60 @@ def __init__(self): super().__init__() -def test_access(): +@pytest.fixture +def participant_qos(): + return fastdds.DomainParticipantQos() + + +@pytest.fixture +def not_autoenable_participant_qos(participant_qos): + participant_qos.entity_factory().autoenable_created_entities = False + return participant_qos + + +@pytest.fixture +def participant(participant_qos): + factory = fastdds.DomainParticipantFactory.get_instance() + return factory.create_participant(0, participant_qos) + + +@pytest.fixture +def subscriber(participant, topic): + subscriber = participant.create_subscriber( + fastdds.SUBSCRIBER_QOS_DEFAULT) + + yield subscriber + + assert(fastdds.ReturnCode_t.RETCODE_OK == + participant.delete_subscriber(subscriber)) + assert(fastdds.ReturnCode_t.RETCODE_OK == + participant.delete_topic(topic)) + factory = fastdds.DomainParticipantFactory.get_instance() + assert(fastdds.ReturnCode_t.RETCODE_OK == + factory.delete_participant(participant)) + + +@pytest.fixture +def topic(participant): + test_type = fastdds.TypeSupport( + test_complete.CompleteTestTypePubSubType()) + participant.register_type(test_type, test_type.get_type_name()) + return participant.create_topic( + "Complete", test_type.get_type_name(), fastdds.TOPIC_QOS_DEFAULT) + + +def test_access(subscriber): """ This test checks: - ::resume_publications """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - subscriber = participant.create_subscriber(fastdds.SUBSCRIBER_QOS_DEFAULT) - assert(subscriber is not None) - assert(fastdds.ReturnCode_t.RETCODE_UNSUPPORTED == subscriber.begin_access()) assert(fastdds.ReturnCode_t.RETCODE_UNSUPPORTED == subscriber.end_access()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_subscriber(subscriber)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_create_and_delete_datareader(): +def test_create_and_delete_datareader(topic, subscriber): """ This test checks: - Subscriber::create_datareader @@ -45,20 +75,6 @@ def test_create_and_delete_datareader(): - StatusMask::operator == - StatusMask::operator << """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - subscriber = participant.create_subscriber(fastdds.SUBSCRIBER_QOS_DEFAULT) - assert(subscriber is not None) - test_type = fastdds.TypeSupport(test_complete.CompleteTestTypePubSubType()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.register_type(test_type, test_type.get_type_name())) - # Overload 1 - Success - topic = participant.create_topic( - "Complete", "CompleteTestType", fastdds.TOPIC_QOS_DEFAULT) - assert(topic is not None) listener = DataReaderListener() assert(listener is not None) @@ -160,32 +176,12 @@ def test(status_mask_1, status_mask_2, listnr=None): m, listener) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_subscriber(subscriber)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_deleted_contained_entities(): +def test_delete_contained_entities(participant, topic, subscriber): """ This test checks: - Subscriber::delete_contained_entities """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - subscriber = participant.create_subscriber(fastdds.SUBSCRIBER_QOS_DEFAULT) - assert(subscriber is not None) - test_type = fastdds.TypeSupport(test_complete.CompleteTestTypePubSubType()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.register_type(test_type, test_type.get_type_name())) - topic = participant.create_topic( - "Complete", "CompleteTestType", fastdds.TOPIC_QOS_DEFAULT) - assert(topic is not None) datareader = subscriber.create_datareader( topic, fastdds.DATAREADER_QOS_DEFAULT) assert(datareader is not None) @@ -199,59 +195,25 @@ def test_deleted_contained_entities(): assert(subscriber.has_datareaders() is False) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_subscriber(subscriber)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_enable(): +def test_enable(not_autoenable_participant_qos, subscriber): """ This test checks: - Subscriber::enable - Subscriber::is_enabled """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - qos = fastdds.DomainParticipantQos() - qos.entity_factory().autoenable_created_entities = False - participant = factory.create_participant(0, qos) - assert(participant is not None) - subscriber = participant.create_subscriber(fastdds.SUBSCRIBER_QOS_DEFAULT) - assert(subscriber is not None) - assert(not subscriber.is_enabled()) assert(fastdds.ReturnCode_t.RETCODE_OK == subscriber.enable()) assert(subscriber.is_enabled()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_subscriber(subscriber)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_get_datareaders(): +def test_get_datareaders(topic, subscriber): """ This test checks: - Subscriber::get_datareaders - Subscriber::has_datareaders """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - subscriber = participant.create_subscriber(fastdds.SUBSCRIBER_QOS_DEFAULT) - assert(subscriber is not None) - test_type = fastdds.TypeSupport(test_complete.CompleteTestTypePubSubType()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.register_type(test_type, test_type.get_type_name())) - topic = participant.create_topic( - "Complete", "CompleteTestType", fastdds.TOPIC_QOS_DEFAULT) - assert(topic is not None) datareader = subscriber.create_datareader( topic, fastdds.DATAREADER_QOS_DEFAULT) assert(datareader is not None) @@ -264,28 +226,14 @@ def test_get_datareaders(): assert(fastdds.ReturnCode_t.RETCODE_OK == subscriber.delete_datareader(datareader)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_subscriber(subscriber)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) -def test_get_instance_handle(): +def test_get_instance_handle(participant, subscriber): """ This test checks: - Subscriber::get_instance_handle - Subscriber::guid """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - subscriber = participant.create_subscriber(fastdds.SUBSCRIBER_QOS_DEFAULT) - assert(subscriber is not None) - ih = subscriber.get_instance_handle() assert(ih is not None) assert(ih.isDefined()) @@ -298,53 +246,24 @@ def test_get_instance_handle(): for i in range(0, 12): assert(guid.guidPrefix.value[i] == ih.value[i]) - # for i in range(0, 4): - # assert(guid.entityId.value[i] == ih.value[12+i]) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_subscriber(subscriber)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - - -def test_get_participant(): +def test_get_participant(participant, subscriber): """ This test checks: - Subscriber::get_participant """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - subscriber = participant.create_subscriber(fastdds.SUBSCRIBER_QOS_DEFAULT) - assert(subscriber is not None) - participant2 = subscriber.get_participant() assert(participant2 is not None) assert(participant == participant2) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_subscriber(subscriber)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_get_set_qos(): +def test_get_set_qos(subscriber): """ This test checks: - Subscriber::get_qos - Subscriber::set_qos """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) qos = fastdds.SubscriberQos() - subscriber = participant.create_subscriber(qos) - assert(subscriber is not None) - qos.partition().push_back('PartitionTest') qos.partition().push_back('PartitionTest2') assert(fastdds.ReturnCode_t.RETCODE_OK == @@ -354,17 +273,8 @@ def test_get_set_qos(): assert(fastdds.ReturnCode_t.RETCODE_OK == subscriber.get_qos(qos2)) - assert(2 == len(qos.partition())) - assert('PartitionTest' == qos.partition()[0]) - assert('PartitionTest2' == qos.partition()[1]) - - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_subscriber(subscriber)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_get_set_listener(): +def test_get_set_listener(subscriber): """ This test checks: - Publisher::get_listener @@ -373,14 +283,6 @@ def test_get_set_listener(): - StatusMask::operator == - StatusMask::operator << """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - subscriber = participant.create_subscriber(fastdds.SUBSCRIBER_QOS_DEFAULT) - assert(subscriber is not None) - # Overload 1 listener = SubscriberListener() assert(listener is not None) @@ -388,6 +290,7 @@ def test_get_set_listener(): subscriber.set_listener(listener)) assert(subscriber.get_listener() == listener) assert(fastdds.StatusMask.all() == subscriber.get_status_mask()) + subscriber.set_listener(None) def test(status_mask_1, status_mask_2): """ @@ -399,12 +302,14 @@ def test(status_mask_1, status_mask_2): subscriber.set_listener(listener, status_mask_1)) assert(subscriber.get_listener() == listener) assert(status_mask_1 == subscriber.get_status_mask()) + subscriber.set_listener(None) listener = SubscriberListener() assert(listener is not None) assert(fastdds.ReturnCode_t.RETCODE_OK == subscriber.set_listener(listener, status_mask_2)) assert(subscriber.get_listener() == listener) assert(status_mask_2 == subscriber.get_status_mask()) + subscriber.set_listener(None) # Overload 2: Different status masks test(fastdds.StatusMask.all(), fastdds.StatusMask_all()) @@ -466,31 +371,12 @@ def test(status_mask_1, status_mask_2): fastdds.StatusMask.subscription_matched(), m) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_subscriber(subscriber)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) - -def test_lookup_datareader(): +def test_lookup_datareader(topic, subscriber): """ This test checks: - subscriber::lookup_datareader """ - factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( - 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - subscriber = participant.create_subscriber(fastdds.SUBSCRIBER_QOS_DEFAULT) - assert(subscriber is not None) - test_type = fastdds.TypeSupport(test_complete.CompleteTestTypePubSubType()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.register_type(test_type, test_type.get_type_name())) - # Overload 1 - Success - topic = participant.create_topic( - "Complete", "CompleteTestType", fastdds.TOPIC_QOS_DEFAULT) - assert(topic is not None) datareader = subscriber.create_datareader( topic, fastdds.DATAREADER_QOS_DEFAULT) assert(datareader is not None) @@ -501,9 +387,3 @@ def test_lookup_datareader(): assert(fastdds.ReturnCode_t.RETCODE_OK == subscriber.delete_datareader(datareader)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_subscriber(subscriber)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant)) diff --git a/fastdds_python/test/api/test_waitset.py b/fastdds_python/test/api/test_waitset.py index 57863334..3695a110 100644 --- a/fastdds_python/test/api/test_waitset.py +++ b/fastdds_python/test/api/test_waitset.py @@ -1,32 +1,89 @@ import fastdds +import pytest import test_complete -def test_waitset(): +@pytest.fixture +def participant(): factory = fastdds.DomainParticipantFactory.get_instance() - assert(factory is not None) - participant = factory.create_participant( + return factory.create_participant( 0, fastdds.PARTICIPANT_QOS_DEFAULT) - assert(participant is not None) - publisher = participant.create_publisher(fastdds.PUBLISHER_QOS_DEFAULT) - assert(publisher is not None) - subscriber = participant.create_subscriber(fastdds.SUBSCRIBER_QOS_DEFAULT) - assert(subscriber is not None) - test_type = fastdds.TypeSupport(test_complete.CompleteTestTypePubSubType()) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.register_type(test_type, test_type.get_type_name())) - topic = participant.create_topic( - "Complete", "CompleteTestType", fastdds.TOPIC_QOS_DEFAULT) - assert(topic is not None) - datawriter_qos = fastdds.DataWriterQos() - datawriter_qos.reliability().kind = fastdds.BEST_EFFORT_RELIABILITY_QOS - datawriter = publisher.create_datawriter(topic, datawriter_qos) - assert(datawriter is not None) + + +@pytest.fixture +def subscriber(participant): + return participant.create_subscriber(fastdds.SUBSCRIBER_QOS_DEFAULT) + + +@pytest.fixture +def topic(participant): + test_type = fastdds.TypeSupport( + test_complete.CompleteTestTypePubSubType()) + participant.register_type(test_type, test_type.get_type_name()) + return participant.create_topic( + "Complete", test_type.get_type_name(), fastdds.TOPIC_QOS_DEFAULT) + + +@pytest.fixture +def datareader(participant, topic, subscriber): datareader_qos = fastdds.DataReaderQos() datareader_qos.reliability().kind = fastdds.RELIABLE_RELIABILITY_QOS datareader = subscriber.create_datareader(topic, datareader_qos) - assert(datareader is not None) + yield datareader + + assert(fastdds.ReturnCode_t.RETCODE_OK == + subscriber.delete_datareader(datareader)) + assert(fastdds.ReturnCode_t.RETCODE_OK == + participant.delete_topic(topic)) + assert(fastdds.ReturnCode_t.RETCODE_OK == + participant.delete_subscriber(subscriber)) + factory = fastdds.DomainParticipantFactory.get_instance() + assert(fastdds.ReturnCode_t.RETCODE_OK == + factory.delete_participant(participant)) + + +@pytest.fixture +def writer_participant(): + factory = fastdds.DomainParticipantFactory.get_instance() + return factory.create_participant( + 0, fastdds.PARTICIPANT_QOS_DEFAULT) + + +@pytest.fixture +def writer_topic(writer_participant): + test_type = fastdds.TypeSupport( + test_complete.CompleteTestTypePubSubType()) + writer_participant.register_type(test_type, test_type.get_type_name()) + return writer_participant.create_topic( + "Complete", test_type.get_type_name(), fastdds.TOPIC_QOS_DEFAULT) + + +@pytest.fixture +def publisher(writer_participant): + return writer_participant.create_publisher(fastdds.PUBLISHER_QOS_DEFAULT) + + +@pytest.fixture +def datawriter(writer_participant, writer_topic, publisher): + datawriter_qos = fastdds.DataWriterQos() + datawriter_qos.reliability().kind = fastdds.BEST_EFFORT_RELIABILITY_QOS + datawriter = publisher.create_datawriter(writer_topic, datawriter_qos) + + yield datawriter + + assert(fastdds.ReturnCode_t.RETCODE_OK == + publisher.delete_datawriter(datawriter)) + assert(fastdds.ReturnCode_t.RETCODE_OK == + writer_participant.delete_topic(writer_topic)) + assert(fastdds.ReturnCode_t.RETCODE_OK == + writer_participant.delete_publisher(publisher)) + factory = fastdds.DomainParticipantFactory.get_instance() + assert(fastdds.ReturnCode_t.RETCODE_OK == + factory.delete_participant(writer_participant)) + + +def test_waitset(datareader, datawriter): status_cond = datareader.get_statuscondition() guard_cond = fastdds.GuardCondition() waitset = fastdds.WaitSet() @@ -75,16 +132,3 @@ def test_waitset(): waitset.detach_condition(status_cond)) assert(fastdds.ReturnCode_t.RETCODE_OK == waitset.detach_condition(guard_cond)) - - assert(fastdds.ReturnCode_t.RETCODE_OK == - subscriber.delete_datareader(datareader)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - publisher.delete_datawriter(datawriter)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_topic(topic)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_publisher(publisher)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - participant.delete_subscriber(subscriber)) - assert(fastdds.ReturnCode_t.RETCODE_OK == - factory.delete_participant(participant))