2021-01-13 11:14:18 +00:00
|
|
|
#define TEST_NO_MAIN
|
|
|
|
#include "acutest.h"
|
|
|
|
|
|
|
|
#include <src/net-utils.h>
|
|
|
|
|
|
|
|
using namespace Net;
|
|
|
|
|
|
|
|
void TestNetUtilsInternetChecksum()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
const char buffer[] = {1, 2, 3, 4, 5, 6, 7, 8};
|
2021-01-18 14:41:35 +00:00
|
|
|
const auto checksum = Utils::InternetChecksum(buffer, sizeof(buffer));
|
2021-01-13 11:14:18 +00:00
|
|
|
TEST_CHECK(checksum == 61419);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const char buffer[] = {1, 2, 3, 4, 5, 6, 7};
|
2021-01-18 14:41:35 +00:00
|
|
|
const auto checksum = Utils::InternetChecksum(buffer, sizeof(buffer));
|
2021-01-13 11:14:18 +00:00
|
|
|
TEST_CHECK(checksum == 61427);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const char buffer[] = {};
|
2021-01-18 14:41:35 +00:00
|
|
|
const auto checksum = Utils::InternetChecksum(buffer, sizeof(buffer));
|
2021-01-13 11:14:18 +00:00
|
|
|
TEST_CHECK(checksum == 65535);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestNetUtilsCrc32()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
const uint8_t buffer[] = {1, 2, 3, 4, 5, 6, 7, 8};
|
2021-01-18 14:41:35 +00:00
|
|
|
const auto checksum = Utils::Crc32(buffer, sizeof(buffer));
|
2021-01-13 11:14:18 +00:00
|
|
|
TEST_CHECK(checksum == 1070237893);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const uint8_t buffer[] = {};
|
2021-01-18 14:41:35 +00:00
|
|
|
const auto checksum = Utils::Crc32(buffer, sizeof(buffer));
|
2021-01-13 11:14:18 +00:00
|
|
|
TEST_CHECK(checksum == 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestNetUtilsGetMacAddress()
|
|
|
|
{
|
2021-01-18 14:41:35 +00:00
|
|
|
const auto mac = Utils::GetMacAddress();
|
|
|
|
const auto expected = Utils::MacAddress{0x00, 0x10, 0x20, 0x30, 0x40, 0x50};
|
2021-01-13 11:14:18 +00:00
|
|
|
TEST_CHECK(mac == expected);
|
|
|
|
}
|