Skip to content

Commit

Permalink
fixed unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
mitza-oci committed Nov 13, 2023
1 parent 182acba commit 01a42a8
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions tests/unit-tests/dds/DCPS/transport/rtps_udp/RtpsSampleHeader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,23 @@

#include <dds/DCPS/transport/rtps_udp/RtpsSampleHeader.h>

#include <dds/DCPS/Message_Block_Ptr.h>

using namespace OpenDDS::DCPS;

namespace {
template <std::size_t N>
ACE_Message_Block* array_to_mb(const unsigned char (&array)[N])
{
ACE_Message_Block* mb = new ACE_Message_Block(reinterpret_cast<const char*>(array), N);
mb->wr_ptr(N);
return mb;
}
}

TEST(dds_DCPS_transport_rtps_udp_RtpsSampleHeader, DataFragValid)
{
static const char x[] = {
static const unsigned char x[] = {
0x16,0x01,0x00,0x00, // Submessage Header: DATA_FRAG, FLAG_E, 0 octets to next hdr
0x00,0x00,0x1c,0x00, // extraFlags, octetsToInlineQoS
0x00,0x00,0x00,0x00, // readerId
Expand All @@ -24,17 +36,16 @@ TEST(dds_DCPS_transport_rtps_udp_RtpsSampleHeader, DataFragValid)
0x01,0x00,0x00,0x04, // numFrags, fragSize
0x99,0x00,0x00,0x00, // sampleSize
};
ACE_Message_Block mb(&x[0], sizeof x);
mb.wr_ptr(sizeof x);
Message_Block_Ptr mb(array_to_mb(x));
RtpsSampleHeader rsh;
rsh.pdu_remaining(0x99 + sizeof x);
rsh = mb;
rsh = *mb;
ASSERT_TRUE(rsh.valid());
}

TEST(dds_DCPS_transport_rtps_udp_RtpsSampleHeader, DataFragInvalidSize)
{
static const char x[] = {
static const unsigned char x[] = {
0x16,0x01,0x00,0x00, // Submessage Header: DATA_FRAG, FLAG_E, 0 octets to next hdr
0x00,0x00,0x1c,0x00, // extraFlags, octetsToInlineQoS
0x00,0x00,0x00,0x00, // readerId
Expand All @@ -45,17 +56,16 @@ TEST(dds_DCPS_transport_rtps_udp_RtpsSampleHeader, DataFragInvalidSize)
0x01,0x00,0x00,0x00, // numFrags, fragSize
0x99,0x00,0x00,0x00, // sampleSize
};
ACE_Message_Block mb(&x[0], sizeof x);
mb.wr_ptr(sizeof x);
Message_Block_Ptr mb(array_to_mb(x));
RtpsSampleHeader rsh;
rsh.pdu_remaining(0x99 + sizeof x);
rsh = mb;
rsh = *mb;
ASSERT_FALSE(rsh.valid());
}

TEST(dds_DCPS_transport_rtps_udp_RtpsSampleHeader, DataFragInvalidStart)
{
static const char x[] = {
static const unsigned char x[] = {
0x16,0x01,0x00,0x00, // Submessage Header: DATA_FRAG, FLAG_E, 0 octets to next hdr
0x00,0x00,0x1c,0x00, // extraFlags, octetsToInlineQoS
0x00,0x00,0x00,0x00, // readerId
Expand All @@ -66,17 +76,16 @@ TEST(dds_DCPS_transport_rtps_udp_RtpsSampleHeader, DataFragInvalidStart)
0x01,0x00,0x00,0x04, // numFrags, fragSize
0x99,0x00,0x00,0x00, // sampleSize
};
ACE_Message_Block mb(&x[0], sizeof x);
mb.wr_ptr(sizeof x);
Message_Block_Ptr mb(array_to_mb(x));
RtpsSampleHeader rsh;
rsh.pdu_remaining(0x99 + sizeof x);
rsh = mb;
rsh = *mb;
ASSERT_FALSE(rsh.valid());
}

TEST(dds_DCPS_transport_rtps_udp_RtpsSampleHeader, DataFragInvalidEnd)
{
static const char x[] = {
static const unsigned char x[] = {
0x16,0x01,0x00,0x00, // Submessage Header: DATA_FRAG, FLAG_E, 0 octets to next hdr
0x00,0x00,0x1c,0x00, // extraFlags, octetsToInlineQoS
0x00,0x00,0x00,0x00, // readerId
Expand All @@ -87,11 +96,10 @@ TEST(dds_DCPS_transport_rtps_udp_RtpsSampleHeader, DataFragInvalidEnd)
0x02,0x00,0x00,0x04, // numFrags, fragSize
0x99,0x00,0x00,0x00, // sampleSize
};
ACE_Message_Block mb(&x[0], sizeof x);
mb.wr_ptr(sizeof x);
Message_Block_Ptr mb(array_to_mb(x));
RtpsSampleHeader rsh;
rsh.pdu_remaining(0x99 + sizeof x);
rsh = mb;
rsh = *mb;
ASSERT_FALSE(rsh.valid());
}

0 comments on commit 01a42a8

Please sign in to comment.