#include "common.hpp"
#include "MediaSoupErrors.hpp"
#include "RTC/SCTP/packet/Parameter.hpp"
#include "RTC/SCTP/packet/parameters/CookiePreservativeParameter.hpp"
#include "RTC/SCTP/sctpCommon.hpp"
#include <catch2/catch_test_macros.hpp>
#include <cstring>
SCENARIO("Cookie Preservative Parameter (9)", "[serializable][sctp][parameter]")
{
sctpCommon::ResetBuffers();
SECTION("CookiePreservativeParameter::Parse() succeeds")
{
alignas(4) uint8_t buffer[] =
{
0x00, 0x09, 0x00, 0x08,
0xFF, 0x00, 0x11, 0x22,
0xAA, 0xBB, 0xCC
};
auto* parameter = RTC::SCTP::CookiePreservativeParameter::Parse(buffer, sizeof(buffer));
CHECK_SCTP_PARAMETER(
parameter,
buffer,
sizeof(buffer),
8,
RTC::SCTP::Parameter::ParameterType::COOKIE_PRESERVATIVE,
false,
RTC::SCTP::Parameter::ActionForUnknownParameterType::STOP);
REQUIRE(parameter->GetLifeSpanIncrement() == 4278194466);
parameter->Serialize(sctpCommon::SerializeBuffer, sizeof(sctpCommon::SerializeBuffer));
std::memset(buffer, 0x00, sizeof(buffer));
CHECK_SCTP_PARAMETER(
parameter,
sctpCommon::SerializeBuffer,
sizeof(sctpCommon::SerializeBuffer),
8,
RTC::SCTP::Parameter::ParameterType::COOKIE_PRESERVATIVE,
false,
RTC::SCTP::Parameter::ActionForUnknownParameterType::STOP);
REQUIRE(parameter->GetLifeSpanIncrement() == 4278194466);
auto* clonedParameter =
parameter->Clone(sctpCommon::CloneBuffer, sizeof(sctpCommon::CloneBuffer));
std::memset(sctpCommon::SerializeBuffer, 0x00, sizeof(sctpCommon::SerializeBuffer));
delete parameter;
CHECK_SCTP_PARAMETER(
clonedParameter,
sctpCommon::CloneBuffer,
sizeof(sctpCommon::CloneBuffer),
8,
RTC::SCTP::Parameter::ParameterType::COOKIE_PRESERVATIVE,
false,
RTC::SCTP::Parameter::ActionForUnknownParameterType::STOP);
REQUIRE(clonedParameter->GetLifeSpanIncrement() == 4278194466);
delete clonedParameter;
}
SECTION("CookiePreservativeParameter::Parse() fails")
{
alignas(4) uint8_t buffer1[] =
{
0x00, 0x06, 0x00, 0x08,
0xFF, 0x00, 0x11, 0x22,
};
REQUIRE(!RTC::SCTP::CookiePreservativeParameter::Parse(buffer1, sizeof(buffer1)));
alignas(4) uint8_t buffer2[] =
{
0x00, 0x09, 0x00, 0x07,
0xFF, 0x00, 0x11, 0x22,
};
REQUIRE(!RTC::SCTP::CookiePreservativeParameter::Parse(buffer2, sizeof(buffer2)));
alignas(4) uint8_t buffer3[] =
{
0x00, 0x09, 0x00, 0x09,
0xFF, 0x00, 0x11, 0x22,
0x69
};
REQUIRE(!RTC::SCTP::CookiePreservativeParameter::Parse(buffer3, sizeof(buffer3)));
alignas(4) uint8_t buffer4[] =
{
0x00, 0x05, 0x00, 0x08,
0xAA, 0xBB, 0xCC
};
REQUIRE(!RTC::SCTP::CookiePreservativeParameter::Parse(buffer4, sizeof(buffer4)));
}
SECTION("CookiePreservativeParameter::Factory() succeeds")
{
auto* parameter = RTC::SCTP::CookiePreservativeParameter::Factory(
sctpCommon::FactoryBuffer, sizeof(sctpCommon::FactoryBuffer));
CHECK_SCTP_PARAMETER(
parameter,
sctpCommon::FactoryBuffer,
sizeof(sctpCommon::FactoryBuffer),
8,
RTC::SCTP::Parameter::ParameterType::COOKIE_PRESERVATIVE,
false,
RTC::SCTP::Parameter::ActionForUnknownParameterType::STOP);
REQUIRE(parameter->GetLifeSpanIncrement() == 0);
parameter->SetLifeSpanIncrement(88776655);
CHECK_SCTP_PARAMETER(
parameter,
sctpCommon::FactoryBuffer,
sizeof(sctpCommon::FactoryBuffer),
8,
RTC::SCTP::Parameter::ParameterType::COOKIE_PRESERVATIVE,
false,
RTC::SCTP::Parameter::ActionForUnknownParameterType::STOP);
REQUIRE(parameter->GetLifeSpanIncrement() == 88776655);
auto* parsedParameter =
RTC::SCTP::CookiePreservativeParameter::Parse(parameter->GetBuffer(), parameter->GetLength());
delete parameter;
CHECK_SCTP_PARAMETER(
parsedParameter,
sctpCommon::FactoryBuffer,
8,
8,
RTC::SCTP::Parameter::ParameterType::COOKIE_PRESERVATIVE,
false,
RTC::SCTP::Parameter::ActionForUnknownParameterType::STOP);
REQUIRE(parsedParameter->GetLifeSpanIncrement() == 88776655);
delete parsedParameter;
}
}