2018-01-22 06:38:08 +08:00
|
|
|
#include "rtp.h"
|
|
|
|
|
|
|
|
#include "../toxcore/crypto_core.h"
|
|
|
|
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
2018-02-02 23:37:19 +08:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
|
|
|
RTPHeader random_header()
|
|
|
|
{
|
|
|
|
return {
|
|
|
|
random_u16(),
|
|
|
|
random_u16(),
|
|
|
|
random_u16(),
|
|
|
|
random_u16(),
|
|
|
|
random_u16(),
|
|
|
|
random_u16(),
|
|
|
|
random_u16(),
|
|
|
|
random_u32(),
|
|
|
|
random_u32(),
|
|
|
|
random_u64(),
|
|
|
|
random_u32(),
|
|
|
|
random_u32(),
|
|
|
|
random_u32(),
|
|
|
|
random_u16(),
|
|
|
|
random_u16(),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-02-03 23:46:27 +08:00
|
|
|
TEST(Rtp, Deserialisation)
|
|
|
|
{
|
2018-02-02 23:37:19 +08:00
|
|
|
RTPHeader const header = random_header();
|
2018-01-22 06:38:08 +08:00
|
|
|
|
2018-02-02 23:37:19 +08:00
|
|
|
uint8_t rdata[RTP_HEADER_SIZE];
|
2018-01-22 06:38:08 +08:00
|
|
|
EXPECT_EQ(rtp_header_pack(rdata, &header), RTP_HEADER_SIZE);
|
|
|
|
|
2018-02-02 23:37:19 +08:00
|
|
|
RTPHeader unpacked = {0};
|
2018-01-22 06:38:08 +08:00
|
|
|
EXPECT_EQ(rtp_header_unpack(rdata, &unpacked), RTP_HEADER_SIZE);
|
|
|
|
|
2018-01-20 05:59:42 +08:00
|
|
|
EXPECT_EQ(header.ve, unpacked.ve);
|
2018-02-02 23:37:19 +08:00
|
|
|
EXPECT_EQ(header.pe, unpacked.pe);
|
|
|
|
EXPECT_EQ(header.xe, unpacked.xe);
|
|
|
|
EXPECT_EQ(header.cc, unpacked.cc);
|
|
|
|
EXPECT_EQ(header.ma, unpacked.ma);
|
|
|
|
EXPECT_EQ(header.pt, unpacked.pt);
|
|
|
|
EXPECT_EQ(header.sequnum, unpacked.sequnum);
|
|
|
|
EXPECT_EQ(header.timestamp, unpacked.timestamp);
|
|
|
|
EXPECT_EQ(header.ssrc, unpacked.ssrc);
|
|
|
|
EXPECT_EQ(header.flags, unpacked.flags);
|
|
|
|
EXPECT_EQ(header.offset_full, unpacked.offset_full);
|
|
|
|
EXPECT_EQ(header.data_length_full, unpacked.data_length_full);
|
|
|
|
EXPECT_EQ(header.received_length_full, unpacked.received_length_full);
|
|
|
|
EXPECT_EQ(header.offset_lower, unpacked.offset_lower);
|
|
|
|
EXPECT_EQ(header.data_length_lower, unpacked.data_length_lower);
|
2018-01-22 06:38:08 +08:00
|
|
|
}
|
2018-02-02 23:37:19 +08:00
|
|
|
|
|
|
|
TEST(Rtp, SerialisingAllOnes)
|
|
|
|
{
|
|
|
|
RTPHeader header;
|
|
|
|
memset(&header, 0xff, sizeof header);
|
|
|
|
|
|
|
|
uint8_t rdata[RTP_HEADER_SIZE];
|
|
|
|
rtp_header_pack(rdata, &header);
|
|
|
|
|
|
|
|
EXPECT_EQ(std::string((char const *)rdata, sizeof rdata),
|
|
|
|
std::string("\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"
|
|
|
|
"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"
|
|
|
|
"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"
|
|
|
|
"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"
|
|
|
|
"\x00\x00\x00\x00\x00\x00\x00\x00"
|
|
|
|
"\x00\x00\x00\x00\x00\x00\x00\x00"
|
|
|
|
"\x00\x00\x00\x00\x00\x00\x00\x00"
|
|
|
|
"\x00\x00\x00\x00\x00\x00\x00\x00"
|
|
|
|
"\x00\x00\x00\x00\x00\x00\x00\x00"
|
|
|
|
"\x00\x00\x00\x00\xFF\xFF\xFF\xFF",
|
|
|
|
RTP_HEADER_SIZE));
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|