64 lines
2.8 KiB
Python
64 lines
2.8 KiB
Python
"""Compare the complete baked tables and codec registry before and after the Stave port."""
|
|
import argparse
|
|
from itertools import zip_longest
|
|
from pathlib import Path
|
|
import subprocess
|
|
|
|
from provider import read_registry
|
|
|
|
ITEM = 33883
|
|
TABLES = {"Item": (0x50238EC2, 7), "ItemSparse": (0x919BE54E, 313)}
|
|
|
|
|
|
def table_test(baker, definitions, parent, child, table):
|
|
def dump(directory):
|
|
return subprocess.run([*baker, "dump", directory, definitions, table],
|
|
stdout=subprocess.PIPE, check=True).stdout.splitlines()
|
|
|
|
changes = 0
|
|
found = False
|
|
for old, new in zip_longest(dump(parent), dump(child)):
|
|
assert old is not None and new is not None, f"{table} row/text count changed"
|
|
if old.startswith(b"33883\t"):
|
|
assert not found
|
|
found = True
|
|
assert b"\tSheatheType=1\t" in old
|
|
assert new == old.replace(b"\tSheatheType=1\t", b"\tSheatheType=2\t", 1), (
|
|
f"{table} 33883 must change only SheatheType from 1 to 2")
|
|
changes += 1
|
|
else:
|
|
assert old == new, f"Unexpected {table} change outside item {ITEM}"
|
|
assert found and changes == 1
|
|
|
|
|
|
def registry_test(parent, child):
|
|
_, old, records, root, pages = read_registry(parent.read_bytes())
|
|
_, new, new_records, new_root, new_pages = read_registry(child.read_bytes())
|
|
expected = bytearray(old)
|
|
changed = set()
|
|
for idx, (table, rid, at, size, status) in enumerate(records):
|
|
for table_hash, offset in TABLES.values():
|
|
if (rid, table) == (ITEM, table_hash):
|
|
assert status == 1 and offset < size and old[at + offset] == 1
|
|
expected[at + offset] = 2
|
|
changed.add(idx)
|
|
assert len(changed) == 2 and new == expected and records == new_records and root != new_root
|
|
for idx, (_, _, at, size, _) in enumerate(records):
|
|
if idx not in changed:
|
|
assert old[at:at + size] == new[at:at + size], "A different row shares a modified byte"
|
|
for (before, first, size), (after, new_first, new_size) in zip(pages, new_pages, strict=True):
|
|
assert (first, size) == (new_first, new_size)
|
|
assert (before != after) == any(first <= i < first + size for i in changed)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
for name in ("baker", "definitions", "parent_db2", "child_db2", "parent_header", "child_header"):
|
|
parser.add_argument(name, type=Path)
|
|
args = parser.parse_args()
|
|
baker = ["dotnet", args.baker] if args.baker.suffix == ".dll" else [args.baker]
|
|
for name in TABLES:
|
|
table_test(baker, args.definitions, args.parent_db2, args.child_db2, name)
|
|
registry_test(args.parent_header, args.child_header)
|
|
print("PASS: both complete DB2 tables and the 230674-record codec registry change only the two Stave sheath fields.")
|