Skip to content

Commit

Permalink
Apply changes to TestSdes.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
jmillan committed Jul 4, 2024
1 parent 5c8afb3 commit da616e5
Showing 1 changed file with 12 additions and 23 deletions.
35 changes: 12 additions & 23 deletions worker/test/src/RTC/RTCP/TestSdes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "RTC/RTCP/Sdes.hpp"
#include <catch2/catch_test_macros.hpp>
#include <cstring> // std::memcmp()
#include <memory>
#include <string>

using namespace RTC::RTCP;
Expand Down Expand Up @@ -97,8 +98,8 @@ SCENARIO("RTCP SDES parsing", "[parser][rtcp][sdes]")
{
SECTION("parse packet 1")
{
SdesPacket* packet = SdesPacket::Parse(buffer1, sizeof(buffer1));
auto* header = reinterpret_cast<RTC::RTCP::Packet::CommonHeader*>(buffer1);
std::unique_ptr<SdesPacket> packet{ SdesPacket::Parse(buffer1, sizeof(buffer1)) };
auto* header = reinterpret_cast<RTC::RTCP::Packet::CommonHeader*>(buffer1);

REQUIRE(packet);
REQUIRE(ntohs(header->length) == 6);
Expand Down Expand Up @@ -164,14 +165,12 @@ SCENARIO("RTCP SDES parsing", "[parser][rtcp][sdes]")

REQUIRE(std::memcmp(chunk1Buffer, serialized1, 24) == 0);
}

delete packet;
}

SECTION("parse packet 2")
{
SdesPacket* packet = SdesPacket::Parse(buffer2, sizeof(buffer2));
auto* header = reinterpret_cast<RTC::RTCP::Packet::CommonHeader*>(buffer2);
std::unique_ptr<SdesPacket> packet{ SdesPacket::Parse(buffer2, sizeof(buffer2)) };
auto* header = reinterpret_cast<RTC::RTCP::Packet::CommonHeader*>(buffer2);

REQUIRE(packet);
REQUIRE(ntohs(header->length) == 13);
Expand Down Expand Up @@ -292,14 +291,12 @@ SCENARIO("RTCP SDES parsing", "[parser][rtcp][sdes]")

REQUIRE(std::memcmp(chunk2Buffer, serialized2, 24) == 0);
}

delete packet;
}

SECTION("parse packet 3")
{
SdesPacket* packet = SdesPacket::Parse(buffer3, sizeof(buffer3));
auto* header = reinterpret_cast<RTC::RTCP::Packet::CommonHeader*>(buffer3);
std::unique_ptr<SdesPacket> packet{ SdesPacket::Parse(buffer3, sizeof(buffer3)) };
auto* header = reinterpret_cast<RTC::RTCP::Packet::CommonHeader*>(buffer3);

REQUIRE(packet);
REQUIRE(ntohs(header->length) == 3);
Expand Down Expand Up @@ -364,8 +361,6 @@ SCENARIO("RTCP SDES parsing", "[parser][rtcp][sdes]")

REQUIRE(std::memcmp(chunk1Buffer, serialized1, 12) == 0);
}

delete packet;
}

SECTION("parsing a packet with missing null octects fails")
Expand All @@ -390,16 +385,14 @@ SCENARIO("RTCP SDES parsing", "[parser][rtcp][sdes]")

SdesPacket packet;
// Create a chunk and an item to obtain their size.
SdesChunk* chunk = new SdesChunk(1234 /*ssrc*/);
auto chunk = std::make_unique<SdesChunk>(1234 /*ssrc*/);
auto* item1 =
new RTC::RTCP::SdesItem(SdesItem::Type::CNAME, item1Value.size(), item1Value.c_str());

chunk->AddItem(item1);

auto chunkSize = chunk->GetSize();

delete chunk;

for (auto i{ 1 }; i <= count; ++i)
{
// Create chunk and add to packet.
Expand All @@ -422,7 +415,7 @@ SCENARIO("RTCP SDES parsing", "[parser][rtcp][sdes]")
// exceed 31.
packet.Serialize(buffer1);

auto* packet2 = static_cast<SdesPacket*>(Packet::Parse(buffer1, sizeof(buffer1)));
std::unique_ptr<SdesPacket> packet2{static_cast<SdesPacket*>(Packet::Parse(buffer1, sizeof(buffer1)))};

REQUIRE(packet2 != nullptr);
REQUIRE(packet2->GetCount() == count);
Expand All @@ -443,11 +436,10 @@ SCENARIO("RTCP SDES parsing", "[parser][rtcp][sdes]")
REQUIRE(std::string(item->GetValue()) == item1Value);
}

SdesPacket* packet3 = static_cast<SdesPacket*>(packet2->GetNext());
std::unique_ptr<SdesPacket> packet3{static_cast<SdesPacket*>(packet2->GetNext())};

REQUIRE(packet3 == nullptr);

delete packet3;
}

SECTION("create SDES packet with more than 31 chunks")
Expand All @@ -456,16 +448,14 @@ SCENARIO("RTCP SDES parsing", "[parser][rtcp][sdes]")

SdesPacket packet;
// Create a chunk and an item to obtain their size.
SdesChunk* chunk = new SdesChunk(1234 /*ssrc*/);
auto chunk = std::make_unique<SdesChunk>(1234 /*ssrc*/);
auto* item1 =
new RTC::RTCP::SdesItem(SdesItem::Type::CNAME, item1Value.size(), item1Value.c_str());

chunk->AddItem(item1);

auto chunkSize = chunk->GetSize();

delete chunk;

for (auto i{ 1 }; i <= count; ++i)
{
// Create chunk and add to packet.
Expand All @@ -487,7 +477,7 @@ SCENARIO("RTCP SDES parsing", "[parser][rtcp][sdes]")
// Serialization must contain 2 SDES packets since report count exceeds 31.
packet.Serialize(buffer1);

auto* packet2 = static_cast<SdesPacket*>(Packet::Parse(buffer1, sizeof(buffer1)));
std::unique_ptr<SdesPacket> packet2 {static_cast<SdesPacket*>(Packet::Parse(buffer1, sizeof(buffer1)))};

REQUIRE(packet2 != nullptr);
REQUIRE(packet2->GetCount() == 31);
Expand Down Expand Up @@ -529,7 +519,6 @@ SCENARIO("RTCP SDES parsing", "[parser][rtcp][sdes]")
REQUIRE(std::string(item->GetValue()) == item1Value);
}

delete packet2;
delete packet3;
}

Expand Down

0 comments on commit da616e5

Please sign in to comment.