From 281054c40476ab4fa0f91f68a566f7766e7eb752 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1aki=20Baz=20Castillo?= Date: Wed, 3 Jul 2024 14:46:45 +0200 Subject: [PATCH] Do not use unique_ptr for isntances whose lifecycle is managed by a packet or report class --- worker/test/src/RTC/RTCP/TestXr.cpp | 32 ++++++++++++++++++----------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/worker/test/src/RTC/RTCP/TestXr.cpp b/worker/test/src/RTC/RTCP/TestXr.cpp index 941fe7452d..99010115f6 100644 --- a/worker/test/src/RTC/RTCP/TestXr.cpp +++ b/worker/test/src/RTC/RTCP/TestXr.cpp @@ -131,7 +131,9 @@ SCENARIO("RTCP XrDelaySinceLastRt parsing", "[parser][rtcp][xr-dlrr]") SECTION("create RRT") { // Create local report and check content. - std::unique_ptr report1(new ReceiverReferenceTime()); + // NOTE: We cannot use unique_ptr here since the instance lifecycle will be + // managed by the packet. + auto* report1 = new ReceiverReferenceTime(); report1->SetNtpSec(11111111); report1->SetNtpFrac(22222222); @@ -146,8 +148,9 @@ SCENARIO("RTCP XrDelaySinceLastRt parsing", "[parser][rtcp][xr-dlrr]") report1->Serialize(bufferReport1); // Create a new report out of the external buffer. - std::unique_ptr report2( - ReceiverReferenceTime::Parse(bufferReport1, report1->GetSize())); + // NOTE: We cannot use unique_ptr here since the instance lifecycle will be + // managed by the packet. + auto report2 = ReceiverReferenceTime::Parse(bufferReport1, report1->GetSize()); REQUIRE(report1->GetType() == report2->GetType()); REQUIRE(report1->GetNtpSec() == report2->GetNtpSec()); @@ -157,8 +160,8 @@ SCENARIO("RTCP XrDelaySinceLastRt parsing", "[parser][rtcp][xr-dlrr]") std::unique_ptr packet1(new ExtendedReportPacket()); packet1->SetSsrc(2222); - packet1->AddReport(report1.get()); - packet1->AddReport(report2.get()); + packet1->AddReport(report1); + packet1->AddReport(report2); REQUIRE(packet1->GetType() == Type::XR); REQUIRE(packet1->GetCount() == 0); @@ -194,8 +197,12 @@ SCENARIO("RTCP XrDelaySinceLastRt parsing", "[parser][rtcp][xr-dlrr]") SECTION("create DLRR") { // Create local report and check content. - std::unique_ptr report1(new DelaySinceLastRr()); - std::unique_ptr ssrcInfo1(new DelaySinceLastRr::SsrcInfo()); + // NOTE: We cannot use unique_ptr here since the instance lifecycle will be + // managed by the packet. + auto* report1 = new DelaySinceLastRr(); + // NOTE: We cannot use unique_ptr here since the instance lifecycle will be + // managed by the report. + auto* ssrcInfo1 = new DelaySinceLastRr::SsrcInfo(); ssrcInfo1->SetSsrc(1234); ssrcInfo1->SetLastReceiverReport(11111111); @@ -206,7 +213,7 @@ SCENARIO("RTCP XrDelaySinceLastRt parsing", "[parser][rtcp][xr-dlrr]") REQUIRE(ssrcInfo1->GetDelaySinceLastReceiverReport() == 22222222); REQUIRE(ssrcInfo1->GetSize() == sizeof(DelaySinceLastRr::SsrcInfo::Body)); - report1->AddSsrcInfo(ssrcInfo1.get()); + report1->AddSsrcInfo(ssrcInfo1); // Serialize the report into an external buffer. uint8_t bufferReport1[256]{ 0 }; @@ -214,8 +221,9 @@ SCENARIO("RTCP XrDelaySinceLastRt parsing", "[parser][rtcp][xr-dlrr]") report1->Serialize(bufferReport1); // Create a new report out of the external buffer. - std::unique_ptr report2( - DelaySinceLastRr::Parse(bufferReport1, report1->GetSize())); + // NOTE: We cannot use unique_ptr here since the instance lifecycle will be + // managed by the packet. + auto report2 = DelaySinceLastRr::Parse(bufferReport1, report1->GetSize()); REQUIRE(report1->GetType() == report2->GetType()); @@ -232,8 +240,8 @@ SCENARIO("RTCP XrDelaySinceLastRt parsing", "[parser][rtcp][xr-dlrr]") std::unique_ptr packet1(new ExtendedReportPacket()); packet1->SetSsrc(2222); - packet1->AddReport(report1.get()); - packet1->AddReport(report2.get()); + packet1->AddReport(report1); + packet1->AddReport(report2); REQUIRE(packet1->GetType() == Type::XR); REQUIRE(packet1->GetCount() == 0);