Skip to content

Commit 17c2e28

Browse files
committed
Refs #23365. Add blackbox test.
Signed-off-by: Miguel Company <miguelcompany@eprosima.com>
1 parent a548275 commit 17c2e28

1 file changed

Lines changed: 121 additions & 0 deletions

File tree

test/blackbox/common/DDSBlackboxTestsBasic.cpp

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,127 @@ TEST(DDSBasic, PidRelatedSampleIdentity)
512512
ASSERT_EQ(related_sample_identity_, info.related_sample_identity);
513513
}
514514

515+
/**
516+
* Read a parameterList from a CDRMessage.
517+
* Search for PID_RPC_MORE_REPLIES in msg.
518+
* @param [in] msg Reference to the message.
519+
* @param [out] exists_pid_rpc_more_replies True if the parameter is inside msg.
520+
* @return true if parsing was correct, false otherwise.
521+
*/
522+
bool check_rpc_has_more_replies_field(
523+
fastdds::rtps::CDRMessage_t& msg,
524+
bool& exists_pid_rpc_more_replies)
525+
{
526+
uint32_t qos_size = 0;
527+
528+
uint32_t original_pos = msg.pos;
529+
bool is_sentinel = false;
530+
while (!is_sentinel)
531+
{
532+
msg.pos = original_pos + qos_size;
533+
534+
ParameterId_t pid{PID_SENTINEL};
535+
bool valid = true;
536+
pid = (ParameterId_t)eprosima::fastdds::helpers::cdr_parse_u16(
537+
(char*)&msg.buffer[msg.pos]);
538+
msg.pos += 2;
539+
uint16_t plength = eprosima::fastdds::helpers::cdr_parse_u16(
540+
(char*)&msg.buffer[msg.pos]);
541+
msg.pos += 2;
542+
543+
if (pid == PID_SENTINEL)
544+
{
545+
// PID_SENTINEL is always considered of length 0
546+
plength = 0;
547+
is_sentinel = true;
548+
}
549+
550+
qos_size += (4 + plength);
551+
552+
// Align to 4 byte boundary and prepare for next iteration
553+
qos_size = (qos_size + 3) & ~3;
554+
555+
if (!valid || ((msg.pos + plength) > msg.length))
556+
{
557+
return false;
558+
}
559+
else if (!is_sentinel)
560+
{
561+
if (PID_RPC_MORE_REPLIES == pid)
562+
{
563+
exists_pid_rpc_more_replies = true;
564+
}
565+
}
566+
}
567+
return true;
568+
}
569+
570+
/**
571+
* This test checks that PID_RPC_MORE_REPLIES is being sent as parameter when has_more_replies is
572+
* specified in WriteParams, and that it is correctly passed into SampleInfo.
573+
*/
574+
TEST(DDSBasic, PidRpcMoreReplies)
575+
{
576+
PubSubWriter<HelloWorldPubSubType> reliable_writer(TEST_TOPIC_NAME);
577+
PubSubReader<HelloWorldPubSubType> reliable_reader(TEST_TOPIC_NAME);
578+
579+
// Test transport will be used in order to filter inlineQoS
580+
auto test_transport = std::make_shared<eprosima::fastdds::rtps::test_UDPv4TransportDescriptor>();
581+
bool exists_pid_rpc_more_replies = false;
582+
583+
test_transport->drop_data_messages_filter_ =
584+
[&exists_pid_rpc_more_replies]
585+
(eprosima::fastdds::rtps::CDRMessage_t& msg)-> bool
586+
{
587+
bool ret = check_rpc_has_more_replies_field(msg, exists_pid_rpc_more_replies);
588+
EXPECT_TRUE(ret);
589+
return false;
590+
};
591+
592+
reliable_writer.reliability(eprosima::fastdds::dds::RELIABLE_RELIABILITY_QOS)
593+
.disable_builtin_transport()
594+
.add_user_transport_to_pparams(test_transport)
595+
.init();
596+
ASSERT_TRUE(reliable_writer.isInitialized());
597+
598+
reliable_reader.reliability(eprosima::fastdds::dds::RELIABLE_RELIABILITY_QOS)
599+
.disable_builtin_transport()
600+
.add_user_transport_to_pparams(test_transport)
601+
.init();
602+
ASSERT_TRUE(reliable_reader.isInitialized());
603+
604+
reliable_writer.wait_discovery();
605+
reliable_reader.wait_discovery();
606+
607+
DataWriter& native_writer = reliable_writer.get_native_writer();
608+
609+
HelloWorld data;
610+
// Send reply associating it with the client request.
611+
eprosima::fastdds::rtps::WriteParams write_params;
612+
write_params.has_more_replies(true);
613+
614+
// Publish the value with has_more_replies set to true
615+
ReturnCode_t write_ret = native_writer.write((void*)&data, write_params);
616+
ASSERT_EQ(RETCODE_OK, write_ret);
617+
618+
DataReader& native_reader = reliable_reader.get_native_reader();
619+
620+
HelloWorld read_data;
621+
eprosima::fastdds::dds::SampleInfo info;
622+
eprosima::fastdds::dds::Duration_t timeout;
623+
timeout.seconds = 2;
624+
while (!native_reader.wait_for_unread_message(timeout))
625+
{
626+
}
627+
628+
ASSERT_EQ(RETCODE_OK,
629+
native_reader.take_next_sample((void*)&read_data, &info));
630+
631+
ASSERT_TRUE(exists_pid_rpc_more_replies);
632+
633+
ASSERT_TRUE(info.has_more_replies);
634+
}
635+
515636
/**
516637
* This test checks that PID_RELATED_SAMPLE_IDENTITY and
517638
* PID_CUSTOM_RELATED_SAMPLE_IDENTITY are being sent as parameter,

0 commit comments

Comments
 (0)