#include "common.hpp"
#include "MediaSoupErrors.hpp"
#include "RTC/SCTP/packet/ErrorCause.hpp"
#include "RTC/SCTP/packet/Parameter.hpp"
#include "RTC/SCTP/packet/errorCauses/MissingMandatoryParameterErrorCause.hpp"
#include "RTC/SCTP/sctpCommon.hpp"
#include <catch2/catch_test_macros.hpp>
#include <cstring>
SCENARIO("Invalid Stream Identifier Error Cause (2)", "[serializable][sctp][errorcause]")
{
sctpCommon::ResetBuffers();
SECTION("MissingMandatoryParameterErrorCause::Parse() succeeds")
{
alignas(4) uint8_t buffer[] =
{
0x00, 0x02, 0x00, 0x0E,
0x00, 0x00, 0x00, 0x03,
0x00, 0x05, 0x00, 0x06,
0x00, 0x09, 0x00, 0x00,
0xAA, 0xBB, 0xCC, 0xDD,
0xAA, 0xBB, 0xCC, 0xDD,
0xAA, 0xBB, 0xCC
};
auto* errorCause = RTC::SCTP::MissingMandatoryParameterErrorCause::Parse(buffer, sizeof(buffer));
CHECK_SCTP_ERROR_CAUSE(
errorCause,
buffer,
sizeof(buffer),
16,
RTC::SCTP::ErrorCause::ErrorCauseCode::MISSING_MANDATORY_PARAMETER,
false);
REQUIRE(errorCause->GetNumberOfMissingParameters() == 3);
REQUIRE(
errorCause->GetMissingParameterTypeAt(0) == RTC::SCTP::Parameter::ParameterType::IPV4_ADDRESS);
REQUIRE(
errorCause->GetMissingParameterTypeAt(1) == RTC::SCTP::Parameter::ParameterType::IPV6_ADDRESS);
REQUIRE(
errorCause->GetMissingParameterTypeAt(2) ==
RTC::SCTP::Parameter::ParameterType::COOKIE_PRESERVATIVE);
REQUIRE(errorCause->GetBuffer()[14] == 0);
REQUIRE(errorCause->GetBuffer()[15] == 0);
errorCause->Serialize(sctpCommon::SerializeBuffer, sizeof(sctpCommon::SerializeBuffer));
std::memset(buffer, 0x00, sizeof(buffer));
CHECK_SCTP_ERROR_CAUSE(
errorCause,
sctpCommon::SerializeBuffer,
sizeof(sctpCommon::SerializeBuffer),
16,
RTC::SCTP::ErrorCause::ErrorCauseCode::MISSING_MANDATORY_PARAMETER,
false);
REQUIRE(errorCause->GetNumberOfMissingParameters() == 3);
REQUIRE(
errorCause->GetMissingParameterTypeAt(0) == RTC::SCTP::Parameter::ParameterType::IPV4_ADDRESS);
REQUIRE(
errorCause->GetMissingParameterTypeAt(1) == RTC::SCTP::Parameter::ParameterType::IPV6_ADDRESS);
REQUIRE(
errorCause->GetMissingParameterTypeAt(2) ==
RTC::SCTP::Parameter::ParameterType::COOKIE_PRESERVATIVE);
REQUIRE(errorCause->GetBuffer()[14] == 0);
REQUIRE(errorCause->GetBuffer()[15] == 0);
auto* clonedErrorCause =
errorCause->Clone(sctpCommon::CloneBuffer, sizeof(sctpCommon::CloneBuffer));
std::memset(sctpCommon::SerializeBuffer, 0x00, sizeof(sctpCommon::SerializeBuffer));
delete errorCause;
CHECK_SCTP_ERROR_CAUSE(
clonedErrorCause,
sctpCommon::CloneBuffer,
sizeof(sctpCommon::CloneBuffer),
16,
RTC::SCTP::ErrorCause::ErrorCauseCode::MISSING_MANDATORY_PARAMETER,
false);
REQUIRE(clonedErrorCause->GetNumberOfMissingParameters() == 3);
REQUIRE(
clonedErrorCause->GetMissingParameterTypeAt(0) ==
RTC::SCTP::Parameter::ParameterType::IPV4_ADDRESS);
REQUIRE(
clonedErrorCause->GetMissingParameterTypeAt(1) ==
RTC::SCTP::Parameter::ParameterType::IPV6_ADDRESS);
REQUIRE(
clonedErrorCause->GetMissingParameterTypeAt(2) ==
RTC::SCTP::Parameter::ParameterType::COOKIE_PRESERVATIVE);
REQUIRE(clonedErrorCause->GetBuffer()[14] == 0);
REQUIRE(clonedErrorCause->GetBuffer()[15] == 0);
delete clonedErrorCause;
}
SECTION("MissingMandatoryParameterErrorCause::Parse() fails")
{
alignas(4) uint8_t buffer1[] =
{
0x03, 0xE7, 0x00, 0x0E,
0x00, 0x00, 0x00, 0x03,
0x00, 0x05, 0x00, 0x06,
0x00, 0x09, 0x00, 0x00,
};
REQUIRE(!RTC::SCTP::MissingMandatoryParameterErrorCause::Parse(buffer1, sizeof(buffer1)));
alignas(4) uint8_t buffer2[] =
{
0x00, 0x02, 0x00, 0x0E,
0x00, 0x00, 0x00, 0x02,
0x00, 0x05, 0x00, 0x06,
0x00, 0x09, 0x00, 0x00,
};
REQUIRE(!RTC::SCTP::MissingMandatoryParameterErrorCause::Parse(buffer2, sizeof(buffer2)));
alignas(4) uint8_t buffer3[] =
{
0x00, 0x02, 0x00, 0x08,
0x00, 0x00, 0x00, 0x02,
0x00, 0x05, 0x00, 0x06,
};
REQUIRE(!RTC::SCTP::MissingMandatoryParameterErrorCause::Parse(buffer3, sizeof(buffer3)));
}
SECTION("MissingMandatoryParameterErrorCause::Factory() succeeds")
{
auto* errorCause = RTC::SCTP::MissingMandatoryParameterErrorCause::Factory(
sctpCommon::FactoryBuffer, sizeof(sctpCommon::FactoryBuffer));
CHECK_SCTP_ERROR_CAUSE(
errorCause,
sctpCommon::FactoryBuffer,
sizeof(sctpCommon::FactoryBuffer),
8,
RTC::SCTP::ErrorCause::ErrorCauseCode::MISSING_MANDATORY_PARAMETER,
false);
REQUIRE(errorCause->GetNumberOfMissingParameters() == 0);
errorCause->AddMissingParameterType(RTC::SCTP::Parameter::ParameterType::IPV4_ADDRESS);
errorCause->AddMissingParameterType(RTC::SCTP::Parameter::ParameterType::IPV6_ADDRESS);
errorCause->AddMissingParameterType(RTC::SCTP::Parameter::ParameterType::COOKIE_PRESERVATIVE);
CHECK_SCTP_ERROR_CAUSE(
errorCause,
sctpCommon::FactoryBuffer,
sizeof(sctpCommon::FactoryBuffer),
16,
RTC::SCTP::ErrorCause::ErrorCauseCode::MISSING_MANDATORY_PARAMETER,
false);
REQUIRE(errorCause->GetNumberOfMissingParameters() == 3);
REQUIRE(
errorCause->GetMissingParameterTypeAt(0) == RTC::SCTP::Parameter::ParameterType::IPV4_ADDRESS);
REQUIRE(
errorCause->GetMissingParameterTypeAt(1) == RTC::SCTP::Parameter::ParameterType::IPV6_ADDRESS);
REQUIRE(
errorCause->GetMissingParameterTypeAt(2) ==
RTC::SCTP::Parameter::ParameterType::COOKIE_PRESERVATIVE);
REQUIRE(errorCause->GetBuffer()[14] == 0);
REQUIRE(errorCause->GetBuffer()[15] == 0);
auto* parsedErrorCause = RTC::SCTP::MissingMandatoryParameterErrorCause::Parse(
errorCause->GetBuffer(), errorCause->GetLength());
delete errorCause;
CHECK_SCTP_ERROR_CAUSE(
parsedErrorCause,
sctpCommon::FactoryBuffer,
16,
16,
RTC::SCTP::ErrorCause::ErrorCauseCode::MISSING_MANDATORY_PARAMETER,
false);
REQUIRE(parsedErrorCause->GetNumberOfMissingParameters() == 3);
REQUIRE(
parsedErrorCause->GetMissingParameterTypeAt(0) ==
RTC::SCTP::Parameter::ParameterType::IPV4_ADDRESS);
REQUIRE(
parsedErrorCause->GetMissingParameterTypeAt(1) ==
RTC::SCTP::Parameter::ParameterType::IPV6_ADDRESS);
REQUIRE(
parsedErrorCause->GetMissingParameterTypeAt(2) ==
RTC::SCTP::Parameter::ParameterType::COOKIE_PRESERVATIVE);
REQUIRE(parsedErrorCause->GetBuffer()[14] == 0);
REQUIRE(parsedErrorCause->GetBuffer()[15] == 0);
delete parsedErrorCause;
}
}