<commit_before>#include "common.hpp"
#include "catch.hpp"
#include "RTC/RTCP/Sdes.hpp"
#include <string>

using namespace RTC::RTCP;

SCENARIO("RTCP SDES parsing", "[parser][rtcp][sdes]")
{
	SECTION("parse SdesChunk")
	{
		uint8_t buffer[] =
		{
			0x00, 0x00, 0x00, 0x00, // SDES SSRC
			0x01, 0x0a, 0x6f, 0x75, // SDES Item
			0x74, 0x43, 0x68, 0x61,
			0x6e, 0x6e, 0x65, 0x6c
		};

		uint32_t ssrc       = 0;
		SdesItem::Type type = SdesItem::Type::CNAME;
		std::string value   = "outChannel";
		size_t len          = value.size();
		SdesChunk* chunk    = SdesChunk::Parse(buffer, sizeof(buffer));

		REQUIRE(chunk->GetSsrc() == ssrc);

		SdesItem* item = *(chunk->Begin());

		REQUIRE(item->GetType() == type);
		REQUIRE(item->GetLength() == len);
		REQUIRE(std::string(item->GetValue(), len) == "outChannel");

		delete chunk;
	}

	SECTION("create SdesChunk")
	{
		uint32_t ssrc       = 0;
		SdesItem::Type type = SdesItem::Type::CNAME;
		std::string value   = "outChannel";
		size_t len          = value.size();
		// Create sdes item.
		SdesItem* item = new SdesItem(type, len, value.c_str());

		// Create sdes chunk.
		SdesChunk chunk(ssrc);

		chunk.AddItem(item);

		// Check chunk content.
		REQUIRE(chunk.GetSsrc() == ssrc);

		// Check item content.
		item = *(chunk.Begin());

		REQUIRE(item->GetType() == type);
		REQUIRE(item->GetLength() == len);
		REQUIRE(std::string(item->GetValue(), len) == "outChannel");
	}
}<commit_msg>Worker tests: RTCP SDES<commit_after>#include "common.hpp"
#include "catch.hpp"
#include "RTC/RTCP/Sdes.hpp"
#include <cstring> // std::memcmp()
#include <string>

using namespace RTC::RTCP;

namespace TestSdes
{
	// RTCP Sdes Packet.
	uint8_t buffer[] =
	{
		0x81, 0xca, 0x00, 0x06, // Type: 202 (SDES), Count: 1, Length: 6
		0x9f, 0x65, 0xe7, 0x42, // SSRC: 0x9f65e742
		0x01, 0x10, 0x74, 0x37, // Item Type: 1 (CNAME), Length: 16, Value: t7mkYnCm46OcINy/
		0x6d, 0x6b, 0x59, 0x6e,
		0x43, 0x6d, 0x34, 0x36,
		0x4f, 0x63, 0x49, 0x4e,
		0x79, 0x2f, 0x00, 0x00
	};

	uint8_t* chunkBuffer = buffer + sizeof(Packet::CommonHeader);

	// SDES values.
	uint32_t ssrc = 0x9f65e742;
	SdesItem::Type type = SdesItem::Type::CNAME;
	std::string value("t7mkYnCm46OcINy/");
	size_t length = 16;

	void verifyChunk(SdesChunk* chunk)
	{
		REQUIRE(chunk->GetSsrc() == ssrc);

		SdesItem* item = *(chunk->Begin());

		REQUIRE(item->GetType() == type);
		REQUIRE(item->GetLength() == length);
		REQUIRE(std::string(item->GetValue(), length) == value);
	}
}

using namespace TestSdes;

SCENARIO("RTCP SDES parsing", "[parser][rtcp][sdes]")
{
	SECTION("parse packet")
	{
		SdesPacket* packet = SdesPacket::Parse(buffer, sizeof(buffer));

		SdesChunk* chunk = *(packet->Begin());

		REQUIRE(chunk);

		verifyChunk(chunk);

		SECTION("serialize SdesChunk instance")
		{
			uint8_t serialized[sizeof(buffer) - sizeof(Packet::CommonHeader)] = {0};

			chunk->Serialize(serialized);

			SECTION("compare serialized SdesChunk with original buffer")
			{
				REQUIRE(std::memcmp(chunkBuffer, serialized, sizeof(buffer) - sizeof(Packet::CommonHeader)) == 0);
			}
		}
		delete packet;
	}

	SECTION("create SdesChunk")
	{
		SdesItem* item = new SdesItem(type, length, value.c_str());

		// Create sdes chunk.
		SdesChunk chunk(ssrc);

		chunk.AddItem(item);

		verifyChunk(&chunk);
	}
}
{'fraction_non_alphanumeric': 0.1717661314753105, 'fraction_numerical': 0.04847016055740685, 'mean_word_length': 4.08, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4991412', 'n_tokens_mistral': 1516, 'n_tokens_neox': 1327, 'n_words': 270}