Files
cpputils/tests/test_uuid.cpp
2026-01-27 14:33:19 +01:00

44 lines
1.3 KiB
C++

#include "catch.hpp"
#include <cpputils/uuid.h>
#include <array>
TEST_CASE("uuidToString formats UUIDs correctly") {
struct TestVector {
std::array<uint8_t, 16> uuid;
char const* expected;
};
constexpr TestVector tests[] = {
{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00},
"00000000-0000-0000-0000-000000000000"},
{{0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01, 0x23, 0x45, 0x67,
0x89, 0xab, 0xcd, 0xef},
"01234567-89ab-cdef-0123-456789abcdef"},
{{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff},
"ffffffff-ffff-ffff-ffff-ffffffffffff"},
{{0x55, 0x0e, 0x84, 0x00, 0xe2, 0x9b, 0x41, 0xd4, 0xa7, 0x16, 0x44, 0x66,
0x55, 0x44, 0x00, 0x00},
"550e8400-e29b-41d4-a716-446655440000"},
{{0xde, 0xad, 0xbe, 0xef, 0xca, 0xfe, 0xba, 0xbe, 0x80, 0x00, 0x01, 0x23,
0x45, 0x67, 0x89, 0xab},
"deadbeef-cafe-babe-8000-0123456789ab"},
{{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
0x0c, 0x0d, 0x0e, 0x0f},
"00010203-0405-0607-0809-0a0b0c0d0e0f"},
};
for (auto const& t : tests) {
REQUIRE(cpputils::uuid::uuidToString(t.uuid) == t.expected);
}
}