Files
WoW-Hybrid-gateway/tests/server_cast_identity_test.cpp
praxisandClaude Fable 5.2 7f2139d8d0 Offline test fixtures
883 files, from working commit b1a079a.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-19 01:32:48 +02:00

68 lines
3.0 KiB
C++

#include "gateway/server_cast_identity.hpp"
#include <iostream>
using namespace gateway;
static void check(bool value, const char* message) {
if (!value) throw Error(message);
}
static uint64_t word(const Guid128& guid, unsigned offset) {
uint64_t value = 0;
for (unsigned byte = 0; byte < 8; ++byte)
value |= uint64_t(guid[offset + byte]) << (byte * 8);
return value;
}
template<class Operation> static void rejects(Operation operation) {
try { operation(); }
catch (const Error&) { return; }
throw Error("invalid server cast identity accepted");
}
int main() {
// Source-derived factory vector: Cast47, NORMAL3, realm70, map1,
// genuine Talisman spell21991, serverId0, counter0x123456789a.
// Native raw representation is low64 followed by high64, little-endian.
const Guid128 golden{0x9a,0x78,0x56,0x34,0x12,0,0,0,
0xc3,0x79,0x15,0x20,0,0x18,0x01,0xbc};
const auto actual = forever_server_cast_guid(70, 1, 21991, 0x123456789aULL);
check(actual == golden, "original Cast factory golden vector differs");
const auto high = word(actual, 8), low = word(actual, 0);
check(high >> 58 == 47, "wrong Cast type");
check((high & 0x3f) == 3, "wrong NORMAL cast source");
check(((high >> 42) & 0x1fff) == 70, "wrong realm");
check(((high >> 29) & 0x1fff) == 1, "wrong map");
check(((high >> 6) & 0x7fffff) == 21991, "wrong genuine spell");
check(low == 0x123456789aULL && low >> 40 == 0, "wrong counter/server ID");
const auto minimum = forever_server_cast_guid(1, 0, 1, 1);
check(word(minimum, 0) == 1 && word(minimum, 8) == 0xbc00040000000043ULL,
"minimum bounds or valid map0 rejected");
const auto maximum = forever_server_cast_guid(8191, 8191, 0x7fffff,
0xffffffffffULL);
check(word(maximum, 0) == 0xffffffffffULL &&
word(maximum, 8) == 0xbc7fffffffffffc3ULL,
"maximum factory bounds differ");
check(forever_server_cast_guid(70, 1, 21991, 1) !=
forever_server_cast_guid(70, 1, 21991, 2), "counter alias");
check(actual != forever_server_cast_guid(71, 1, 21991, 0x123456789aULL),
"realm alias");
check(actual != forever_server_cast_guid(70, 2, 21991, 0x123456789aULL),
"map alias");
check(actual != forever_server_cast_guid(70, 1, 21992, 0x123456789aULL),
"spell alias");
for (auto realm : {0u, 8192u, 0xffffffffu})
rejects([&] { forever_server_cast_guid(realm, 0, 1, 1); });
for (auto map : {8192u, 0xffffffffu})
rejects([&] { forever_server_cast_guid(1, map, 1, 1); });
for (auto spell : {0u, 0x800000u, 0xffffffffu})
rejects([&] { forever_server_cast_guid(1, 0, spell, 1); });
for (auto counter : {0ULL, 0x10000000000ULL, 0xffffffffffffffffULL})
rejects([&] { forever_server_cast_guid(1, 0, 1, counter); });
std::cout << "Original Cast factory golden/bounds/identity fields passed; "
"no engine call or gameplay execution asserted.\n";
}