提交 f0d87fe2 authored 作者: José Luis Millán's avatar José Luis Millán

Tests: add RTCP BYE tests

上级 ad52aaf2
...@@ -29,14 +29,15 @@ namespace RTC { namespace RTCP ...@@ -29,14 +29,15 @@ namespace RTC { namespace RTCP
return nullptr; return nullptr;
} }
packet->AddSsrc(Utils::Byte::Get4Bytes(data+offset, 0)); packet->AddSsrc(ntohl(Utils::Byte::Get4Bytes(data, offset)));
offset += sizeof(uint32_t); offset += sizeof(uint32_t);
} }
if (count == 0) if (len - offset > 0)
{ {
size_t length = size_t(Utils::Byte::Get1Byte(data+offset, 0)); size_t length = size_t(Utils::Byte::Get1Byte(data, offset));
if (sizeof(uint8_t) + length <= len-offset) offset += sizeof(uint8_t);
if (length <= len-offset)
{ {
packet->SetReason(std::string((char*)data+offset, length)); packet->SetReason(std::string((char*)data+offset, length));
} }
...@@ -53,16 +54,21 @@ namespace RTC { namespace RTCP ...@@ -53,16 +54,21 @@ namespace RTC { namespace RTCP
size_t offset = Packet::Serialize(data); size_t offset = Packet::Serialize(data);
// SSRCs.
for (auto ssrc : this->ssrcs) for (auto ssrc : this->ssrcs)
{ {
std::memcpy(data, &ssrc, sizeof(uint32_t)); Utils::Byte::Set4Bytes(data, offset, htonl(ssrc));
offset += sizeof(uint32_t); offset += sizeof(uint32_t);
} }
if (!this->reason.empty()) if (!this->reason.empty())
{ {
// Length field.
Utils::Byte::Set1Byte(data, offset, this->reason.length()); Utils::Byte::Set1Byte(data, offset, this->reason.length());
offset += sizeof(uint8_t); // Length field. offset += sizeof(uint8_t);
// Reason field.
std::memcpy(data+offset, this->reason.c_str(), this->reason.length());
offset += this->reason.length(); offset += this->reason.length();
} }
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "RTC/RTCP/Sdes.h" #include "RTC/RTCP/Sdes.h"
#include "RTC/RTCP/SenderReport.h" #include "RTC/RTCP/SenderReport.h"
#include "RTC/RTCP/ReceiverReport.h" #include "RTC/RTCP/ReceiverReport.h"
#include "RTC/RTCP/Bye.h"
#include "Logger.h" #include "Logger.h"
#include <string> #include <string>
...@@ -305,5 +306,40 @@ FCTMF_SUITE_BGN(test_rtcp) ...@@ -305,5 +306,40 @@ FCTMF_SUITE_BGN(test_rtcp)
} }
FCT_TEST_END() FCT_TEST_END()
FCT_TEST_BGN(create_parse_bye)
{
uint32_t ssrc1 = 1111;
uint32_t ssrc2 = 2222;
std::string reason("hasta la vista");
// Create local Bye packet and check content.
// ByePacket();
ByePacket bye1;
bye1.AddSsrc(ssrc1);
bye1.AddSsrc(ssrc2);
bye1.SetReason(reason);
ByePacket::Iterator it = bye1.Begin();
fct_chk_eq_int(*(it), ssrc1);
fct_chk_eq_int(*(++it), ssrc2);
fct_chk(bye1.GetReason() == reason);
// Locally store the content of the packet.
uint8_t buffer[bye1.GetSize()];
bye1.Serialize(buffer);
// Parse the buffer of the previous packet and check content.
ByePacket* bye2 = ByePacket::Parse(buffer, sizeof(buffer));
it = bye2->Begin();
fct_chk_eq_int(*(it), ssrc1);
fct_chk_eq_int(*(++it), ssrc2);
fct_chk(bye2->GetReason() == reason);
}
FCT_TEST_END()
} }
FCTMF_SUITE_END(); FCTMF_SUITE_END();
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论