Skip to content

Commit e626daa

Browse files
committed
Refs #21808: Improve tests asserting positives and negatives cases
Signed-off-by: Mario Dominguez <mariodominguez@eprosima.com>
1 parent 22787f2 commit e626daa

2 files changed

Lines changed: 30 additions & 6 deletions

File tree

fastdds_python/test/api/test_datareader.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -773,25 +773,35 @@ 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()
783784
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()
799+
time.sleep(1)
793800
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())
795805

796806

797807
def test_get_requested_deadline_missed_status(datareader):

fastdds_python/test/api/test_datawriter.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -308,26 +308,40 @@ def test_get_liveliness_lost_status(datawriter):
308308
assert(0 == status.total_count_change)
309309

310310

311-
def test_get_matched_subscription_data(datawriter):
311+
def test_get_matched_subscription_data(datawriter, reader_topic, subscriber):
312312
"""
313313
This test checks:
314314
- DataWriter::get_matched_subscription_data
315315
"""
316+
# Check with an invalid instance handle
316317
sub_data = fastdds.SubscriptionBuiltinTopicData()
317318
ih = fastdds.InstanceHandle_t()
318319
assert(fastdds.RETCODE_BAD_PARAMETER ==
319320
datawriter.get_matched_subscription_data(sub_data, ih))
320321

322+
# Add a reader and check that the datawriter has matched subscriptions
323+
datareader = subscriber.create_datareader(reader_topic, fastdds.DATAREADER_QOS_DEFAULT)
324+
time.sleep(1)
325+
assert(fastdds.RETCODE_OK ==
326+
datawriter.get_matched_subscription_data(sub_data, datareader.get_instance_handle()))
327+
assert(sub_data.guid == datareader.guid())
328+
assert(fastdds.RETCODE_OK ==
329+
subscriber.delete_datareader(datareader))
321330

322-
def test_get_matched_subscriptions(datawriter):
331+
def test_get_matched_subscriptions(datawriter, reader_topic, subscriber):
323332
"""
324333
This test checks:
325334
- DataWriter::get_matched_subscriptions
326335
"""
327336
ihs = fastdds.InstanceHandleVector()
337+
# Add a reader and check that the datawriter has matched subscriptions
338+
datareader = subscriber.create_datareader(reader_topic, fastdds.DATAREADER_QOS_DEFAULT)
339+
time.sleep(1)
340+
assert(fastdds.RETCODE_OK == datawriter.get_matched_subscriptions(ihs))
341+
assert(1 == ihs.size())
342+
assert(ihs[0] == datareader.get_instance_handle())
328343
assert(fastdds.RETCODE_OK ==
329-
datawriter.get_matched_subscriptions(ihs))
330-
344+
subscriber.delete_datareader(datareader))
331345

332346
def test_get_offered_deadline_missed_status(datawriter):
333347
"""

0 commit comments

Comments
 (0)