VaKeR CYBER ARMY
Logo of a company Server : Apache/2.4.41 (Ubuntu)
System : Linux absol.cf 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64
User : www-data ( 33)
PHP Version : 7.4.33
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Directory :  /proc/thread-self/root/usr/local/lib/node_modules/mediasoup/worker/test/src/RTC/RTCP/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //proc/thread-self/root/usr/local/lib/node_modules/mediasoup/worker/test/src/RTC/RTCP/TestSdes.cpp
#include "common.hpp"
#include "RTC/RTCP/Sdes.hpp"
#include <catch.hpp>
#include <cstring> // std::memcmp()
#include <string>

using namespace RTC::RTCP;

namespace TestSdes
{
	// RTCP Sdes Packet.

	// clang-format off
	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
	};
	// clang-format on

	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 verify(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);
	}
} // namespace TestSdes

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);

		verify(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);

		verify(&chunk);
	}
}

VaKeR 2022