Skip to content

Commit ecc860d

Browse files
authored
Update DataWriter/Reader get_matched_publication/subscription...() API tests (#188)
* Refs #21808: Update tests as result of 3.x API implementation Signed-off-by: Mario Dominguez <[email protected]> * Refs #21808: Improve tests asserting positives and negatives cases Signed-off-by: Mario Dominguez <[email protected]> * Refs #21808: Apply second rev Signed-off-by: Mario Dominguez <[email protected]> --------- Signed-off-by: Mario Dominguez <[email protected]>
1 parent f0ef709 commit ecc860d

File tree

2 files changed

+44
-10
lines changed

2 files changed

+44
-10
lines changed

fastdds_python/test/api/test_datareader.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -773,25 +773,36 @@ def test_get_liveliness_changed_status(datareader):
773773
assert(fastdds.c_InstanceHandle_Unknown == status.last_publication_handle)
774774

775775

776-
def test_get_matched_publication_data(datareader):
776+
def test_get_matched_publication_data(datareader, datawriter):
777777
"""
778778
This test checks:
779779
- DataReader::get_matched_publication_data
780780
"""
781+
# Check with an invalid instance handle
781782
pub_data = fastdds.PublicationBuiltinTopicData()
782783
ih = fastdds.InstanceHandle_t()
783-
assert(fastdds.RETCODE_UNSUPPORTED ==
784+
assert(fastdds.RETCODE_BAD_PARAMETER ==
784785
datareader.get_matched_publication_data(pub_data, ih))
785786

787+
time.sleep(1)
788+
# Check with the writer's instance handle
789+
assert(fastdds.RETCODE_OK ==
790+
datareader.get_matched_publication_data(pub_data, datawriter.get_instance_handle()))
791+
assert(pub_data.guid == datawriter.guid())
786792

787-
def test_get_matched_publications(datareader):
793+
def test_get_matched_publications(datareader, datawriter):
788794
"""
789795
This test checks:
790796
- DataReader::get_matched_publications
791797
"""
792798
ihs = fastdds.InstanceHandleVector()
793-
assert(fastdds.RETCODE_UNSUPPORTED ==
799+
time.sleep(1)
800+
assert(fastdds.RETCODE_OK ==
794801
datareader.get_matched_publications(ihs))
802+
# The datawriter (added in the fixture) is the only
803+
# one that should be matched
804+
assert(1 == ihs.size())
805+
assert(ihs[0] == datawriter.get_instance_handle())
795806

796807

797808
def test_get_requested_deadline_missed_status(datareader):

fastdds_python/test/api/test_datawriter.py

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,23 @@ def subscriber(reader_participant):
102102
return reader_participant.create_subscriber(fastdds.SUBSCRIBER_QOS_DEFAULT)
103103

104104

105+
@pytest.fixture
106+
def datareader(reader_participant, reader_topic, subscriber):
107+
datareader = subscriber.create_datareader(
108+
reader_topic, fastdds.DATAREADER_QOS_DEFAULT)
109+
110+
yield datareader
111+
112+
assert(fastdds.RETCODE_OK ==
113+
subscriber.delete_datareader(datareader))
114+
assert(fastdds.RETCODE_OK ==
115+
reader_participant.delete_topic(reader_topic))
116+
assert(fastdds.RETCODE_OK ==
117+
reader_participant.delete_subscriber(subscriber))
118+
factory = fastdds.DomainParticipantFactory.get_instance()
119+
assert(fastdds.RETCODE_OK ==
120+
factory.delete_participant(reader_participant))
121+
105122
def test_assert_liveliness(manual_liveliness_datawriter_qos, datawriter):
106123
"""
107124
This test checks:
@@ -308,26 +325,32 @@ def test_get_liveliness_lost_status(datawriter):
308325
assert(0 == status.total_count_change)
309326

310327

311-
def test_get_matched_subscription_data(datawriter):
328+
def test_get_matched_subscription_data(datawriter, datareader):
312329
"""
313330
This test checks:
314331
- DataWriter::get_matched_subscription_data
315332
"""
333+
# Check with an invalid instance handle
316334
sub_data = fastdds.SubscriptionBuiltinTopicData()
317335
ih = fastdds.InstanceHandle_t()
318-
assert(fastdds.RETCODE_UNSUPPORTED ==
336+
assert(fastdds.RETCODE_BAD_PARAMETER ==
319337
datawriter.get_matched_subscription_data(sub_data, ih))
320338

339+
time.sleep(1)
340+
assert(fastdds.RETCODE_OK ==
341+
datawriter.get_matched_subscription_data(sub_data, datareader.get_instance_handle()))
342+
assert(sub_data.guid == datareader.guid())
321343

322-
def test_get_matched_subscriptions(datawriter):
344+
def test_get_matched_subscriptions(datawriter, datareader):
323345
"""
324346
This test checks:
325347
- DataWriter::get_matched_subscriptions
326348
"""
327349
ihs = fastdds.InstanceHandleVector()
328-
assert(fastdds.RETCODE_UNSUPPORTED ==
329-
datawriter.get_matched_subscriptions(ihs))
330-
350+
time.sleep(1)
351+
assert(fastdds.RETCODE_OK == datawriter.get_matched_subscriptions(ihs))
352+
assert(1 == ihs.size())
353+
assert(ihs[0] == datareader.get_instance_handle())
331354

332355
def test_get_offered_deadline_missed_status(datawriter):
333356
"""

0 commit comments

Comments
 (0)