From 22787f28f08413e56373eb5af688be0634eba1af Mon Sep 17 00:00:00 2001 From: Mario Dominguez Date: Wed, 2 Oct 2024 09:31:18 +0200 Subject: [PATCH 1/3] Refs #21808: Update tests as result of 3.x API implementation Signed-off-by: Mario Dominguez --- fastdds_python/test/api/test_datareader.py | 4 ++-- fastdds_python/test/api/test_datawriter.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/fastdds_python/test/api/test_datareader.py b/fastdds_python/test/api/test_datareader.py index 211ac0e0..864dcfad 100644 --- a/fastdds_python/test/api/test_datareader.py +++ b/fastdds_python/test/api/test_datareader.py @@ -780,7 +780,7 @@ def test_get_matched_publication_data(datareader): """ pub_data = fastdds.PublicationBuiltinTopicData() ih = fastdds.InstanceHandle_t() - assert(fastdds.RETCODE_UNSUPPORTED == + assert(fastdds.RETCODE_BAD_PARAMETER == datareader.get_matched_publication_data(pub_data, ih)) @@ -790,7 +790,7 @@ def test_get_matched_publications(datareader): - DataReader::get_matched_publications """ ihs = fastdds.InstanceHandleVector() - assert(fastdds.RETCODE_UNSUPPORTED == + assert(fastdds.RETCODE_OK == datareader.get_matched_publications(ihs)) diff --git a/fastdds_python/test/api/test_datawriter.py b/fastdds_python/test/api/test_datawriter.py index 71c93e7b..8eebcac5 100644 --- a/fastdds_python/test/api/test_datawriter.py +++ b/fastdds_python/test/api/test_datawriter.py @@ -315,7 +315,7 @@ def test_get_matched_subscription_data(datawriter): """ sub_data = fastdds.SubscriptionBuiltinTopicData() ih = fastdds.InstanceHandle_t() - assert(fastdds.RETCODE_UNSUPPORTED == + assert(fastdds.RETCODE_BAD_PARAMETER == datawriter.get_matched_subscription_data(sub_data, ih)) @@ -325,7 +325,7 @@ def test_get_matched_subscriptions(datawriter): - DataWriter::get_matched_subscriptions """ ihs = fastdds.InstanceHandleVector() - assert(fastdds.RETCODE_UNSUPPORTED == + assert(fastdds.RETCODE_OK == datawriter.get_matched_subscriptions(ihs)) From e626daaa18aa10cf8633a9ea649b8cc3da57ac8c Mon Sep 17 00:00:00 2001 From: Mario Dominguez Date: Thu, 17 Oct 2024 18:48:38 +0200 Subject: [PATCH 2/3] Refs #21808: Improve tests asserting positives and negatives cases Signed-off-by: Mario Dominguez --- fastdds_python/test/api/test_datareader.py | 14 ++++++++++++-- fastdds_python/test/api/test_datawriter.py | 22 ++++++++++++++++++---- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/fastdds_python/test/api/test_datareader.py b/fastdds_python/test/api/test_datareader.py index 864dcfad..2145a2ba 100644 --- a/fastdds_python/test/api/test_datareader.py +++ b/fastdds_python/test/api/test_datareader.py @@ -773,25 +773,35 @@ def test_get_liveliness_changed_status(datareader): assert(fastdds.c_InstanceHandle_Unknown == status.last_publication_handle) -def test_get_matched_publication_data(datareader): +def test_get_matched_publication_data(datareader, datawriter): """ This test checks: - DataReader::get_matched_publication_data """ + # Check with an invalid instance handle pub_data = fastdds.PublicationBuiltinTopicData() ih = fastdds.InstanceHandle_t() assert(fastdds.RETCODE_BAD_PARAMETER == datareader.get_matched_publication_data(pub_data, ih)) + time.sleep(1) + # Check with the writer's instance handle + assert(fastdds.RETCODE_OK == + datareader.get_matched_publication_data(pub_data, datawriter.get_instance_handle())) + assert(pub_data.guid == datawriter.guid()) -def test_get_matched_publications(datareader): +def test_get_matched_publications(datareader, datawriter): """ This test checks: - DataReader::get_matched_publications """ ihs = fastdds.InstanceHandleVector() + time.sleep(1) assert(fastdds.RETCODE_OK == datareader.get_matched_publications(ihs)) + # The datawriter (added in the fixture) is the only + # one that should be matched + assert(1 == ihs.size()) def test_get_requested_deadline_missed_status(datareader): diff --git a/fastdds_python/test/api/test_datawriter.py b/fastdds_python/test/api/test_datawriter.py index 8eebcac5..95bbd896 100644 --- a/fastdds_python/test/api/test_datawriter.py +++ b/fastdds_python/test/api/test_datawriter.py @@ -308,26 +308,40 @@ def test_get_liveliness_lost_status(datawriter): assert(0 == status.total_count_change) -def test_get_matched_subscription_data(datawriter): +def test_get_matched_subscription_data(datawriter, reader_topic, subscriber): """ This test checks: - DataWriter::get_matched_subscription_data """ + # Check with an invalid instance handle sub_data = fastdds.SubscriptionBuiltinTopicData() ih = fastdds.InstanceHandle_t() assert(fastdds.RETCODE_BAD_PARAMETER == datawriter.get_matched_subscription_data(sub_data, ih)) + # Add a reader and check that the datawriter has matched subscriptions + datareader = subscriber.create_datareader(reader_topic, fastdds.DATAREADER_QOS_DEFAULT) + time.sleep(1) + assert(fastdds.RETCODE_OK == + datawriter.get_matched_subscription_data(sub_data, datareader.get_instance_handle())) + assert(sub_data.guid == datareader.guid()) + assert(fastdds.RETCODE_OK == + subscriber.delete_datareader(datareader)) -def test_get_matched_subscriptions(datawriter): +def test_get_matched_subscriptions(datawriter, reader_topic, subscriber): """ This test checks: - DataWriter::get_matched_subscriptions """ ihs = fastdds.InstanceHandleVector() + # Add a reader and check that the datawriter has matched subscriptions + datareader = subscriber.create_datareader(reader_topic, fastdds.DATAREADER_QOS_DEFAULT) + time.sleep(1) + assert(fastdds.RETCODE_OK == datawriter.get_matched_subscriptions(ihs)) + assert(1 == ihs.size()) + assert(ihs[0] == datareader.get_instance_handle()) assert(fastdds.RETCODE_OK == - datawriter.get_matched_subscriptions(ihs)) - + subscriber.delete_datareader(datareader)) def test_get_offered_deadline_missed_status(datawriter): """ From 7dd6e8d77bcb426fd907bcfffa79ce0056741f17 Mon Sep 17 00:00:00 2001 From: Mario Dominguez Date: Mon, 21 Oct 2024 10:10:04 +0200 Subject: [PATCH 3/3] Refs #21808: Apply second rev Signed-off-by: Mario Dominguez --- fastdds_python/test/api/test_datareader.py | 1 + fastdds_python/test/api/test_datawriter.py | 29 ++++++++++++++-------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/fastdds_python/test/api/test_datareader.py b/fastdds_python/test/api/test_datareader.py index 2145a2ba..5cedbd72 100644 --- a/fastdds_python/test/api/test_datareader.py +++ b/fastdds_python/test/api/test_datareader.py @@ -802,6 +802,7 @@ def test_get_matched_publications(datareader, datawriter): # The datawriter (added in the fixture) is the only # one that should be matched assert(1 == ihs.size()) + assert(ihs[0] == datawriter.get_instance_handle()) def test_get_requested_deadline_missed_status(datareader): diff --git a/fastdds_python/test/api/test_datawriter.py b/fastdds_python/test/api/test_datawriter.py index 95bbd896..1d61d7b8 100644 --- a/fastdds_python/test/api/test_datawriter.py +++ b/fastdds_python/test/api/test_datawriter.py @@ -102,6 +102,23 @@ def subscriber(reader_participant): return reader_participant.create_subscriber(fastdds.SUBSCRIBER_QOS_DEFAULT) +@pytest.fixture +def datareader(reader_participant, reader_topic, subscriber): + datareader = subscriber.create_datareader( + reader_topic, fastdds.DATAREADER_QOS_DEFAULT) + + yield datareader + + assert(fastdds.RETCODE_OK == + subscriber.delete_datareader(datareader)) + assert(fastdds.RETCODE_OK == + reader_participant.delete_topic(reader_topic)) + assert(fastdds.RETCODE_OK == + reader_participant.delete_subscriber(subscriber)) + factory = fastdds.DomainParticipantFactory.get_instance() + assert(fastdds.RETCODE_OK == + factory.delete_participant(reader_participant)) + def test_assert_liveliness(manual_liveliness_datawriter_qos, datawriter): """ This test checks: @@ -308,7 +325,7 @@ def test_get_liveliness_lost_status(datawriter): assert(0 == status.total_count_change) -def test_get_matched_subscription_data(datawriter, reader_topic, subscriber): +def test_get_matched_subscription_data(datawriter, datareader): """ This test checks: - DataWriter::get_matched_subscription_data @@ -319,29 +336,21 @@ def test_get_matched_subscription_data(datawriter, reader_topic, subscriber): assert(fastdds.RETCODE_BAD_PARAMETER == datawriter.get_matched_subscription_data(sub_data, ih)) - # Add a reader and check that the datawriter has matched subscriptions - datareader = subscriber.create_datareader(reader_topic, fastdds.DATAREADER_QOS_DEFAULT) time.sleep(1) assert(fastdds.RETCODE_OK == datawriter.get_matched_subscription_data(sub_data, datareader.get_instance_handle())) assert(sub_data.guid == datareader.guid()) - assert(fastdds.RETCODE_OK == - subscriber.delete_datareader(datareader)) -def test_get_matched_subscriptions(datawriter, reader_topic, subscriber): +def test_get_matched_subscriptions(datawriter, datareader): """ This test checks: - DataWriter::get_matched_subscriptions """ ihs = fastdds.InstanceHandleVector() - # Add a reader and check that the datawriter has matched subscriptions - datareader = subscriber.create_datareader(reader_topic, fastdds.DATAREADER_QOS_DEFAULT) time.sleep(1) assert(fastdds.RETCODE_OK == datawriter.get_matched_subscriptions(ihs)) assert(1 == ihs.size()) assert(ihs[0] == datareader.get_instance_handle()) - assert(fastdds.RETCODE_OK == - subscriber.delete_datareader(datareader)) def test_get_offered_deadline_missed_status(datawriter): """