Files
WoW-Hybrid-gateway/tests/tortoise_pdump_empty_text_test.py
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

51 lines
2.2 KiB
Python

#!/usr/bin/env python3
"""Compile the actual local pdump GUID helper; no database/server execution."""
import hashlib
from pathlib import Path
import subprocess
import sys
import tempfile
source = Path(sys.argv[1]) if len(sys.argv) > 1 else Path.home() / 'Servers/tortoise-wow/src/game/PlayerDump.cpp'
if not source.is_file():
print('Local Tortoise source unavailable')
raise SystemExit(77)
raw = source.read_text()
call = 'changeGuid(line, 8, itemTexts, sObjectMgr.GenerateItemTextID(), true)'
if raw.count(call) != 2 or 'changeGuid(line, 8, itemTexts, sObjectMgr.GenerateItemTextID())' in raw:
raise AssertionError('Both native pdump entry points must preserve empty text IDs')
helpers = raw[raw.index('static bool findtoknth('):raw.index('std::string CreateDumpString(')]
program = r'''
#include <string>
#include <map>
#include <cstdint>
#include <cstdio>
using uint32 = uint32_t;
#define _TABLE_SIM_ "`"
''' + helpers + r'''
int main() {
std::map<uint32,uint32> ids;
auto row=[](const char* text) {
return std::string("INSERT INTO `mail` VALUES ('1', '0', '0', '0', '5', '6', 'subject', '")+text+"');";
};
auto empty=row("0");
if(!changeGuid(empty,8,ids,700,true) || getnth(empty,8)!="0" || !ids.empty())return 1;
auto letter=row("42");
if(!changeGuid(letter,8,ids,701,true) || getnth(letter,8)!="701" || ids.at(42)!=701)return 2;
auto shared=row("42");
if(!changeGuid(shared,8,ids,702,true) || getnth(shared,8)!="701" || ids.size()!=1)return 3;
// Prove this fixture detects the previous regression.
auto old=row("0");std::map<uint32,uint32> oldIds;
if(!changeGuid(old,8,oldIds,703) || getnth(old,8)!="703" || oldIds.at(0)!=703)return 4;
return 0;
}
'''
with tempfile.TemporaryDirectory(prefix='pdump-empty-text-') as directory:
path = Path(directory)
(path / 'test.cpp').write_text(program)
subprocess.run(['c++', '-std=c++17', '-Wall', '-Wextra', '-Werror',
str(path / 'test.cpp'), '-o', str(path / 'test')], check=True)
subprocess.run([str(path / 'test')], check=True)
print('Actual Tortoise GUID helper PASS: zero preserved, nonzero shared mapping preserved, old regression reproduced')
print('Source SHA256:', hashlib.sha256(source.read_bytes()).hexdigest())