mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
2570ddcb17
* Use-after-free because we free network before dht in one case. * Various unchecked allocs in tests (not so important). * We used to not check whether ping arrays were actually allocated in DHT. * `ping_kill` and `ping_array_kill` used to crash when passing NULL. Also: * Added an assert in all public API functions to ensure tox isn't NULL. The error message you get from that is a bit nicer than "Segmentation fault" when clients (or our tests) do things wrong. * Decreased the sleep time in iterate_all_wait from 20ms to 5ms. Everything seems to still work with 5ms, and this greatly decreases the amount of time spent per test run, making oomer run much faster.
65 lines
2.2 KiB
C++
65 lines
2.2 KiB
C++
#include "rtp.h"
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include "../toxcore/crypto_core.h"
|
|
|
|
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(),
|
|
};
|
|
}
|
|
|
|
TEST(Rtp, Deserialisation) {
|
|
RTPHeader const header = random_header();
|
|
|
|
uint8_t rdata[RTP_HEADER_SIZE];
|
|
EXPECT_EQ(rtp_header_pack(rdata, &header), RTP_HEADER_SIZE);
|
|
|
|
RTPHeader unpacked = {0};
|
|
EXPECT_EQ(rtp_header_unpack(rdata, &unpacked), RTP_HEADER_SIZE);
|
|
|
|
EXPECT_EQ(header.ve, unpacked.ve);
|
|
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);
|
|
}
|
|
|
|
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(reinterpret_cast<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
|