58 lines
2.5 KiB
Python
58 lines
2.5 KiB
Python
"""Independent wire fixtures for the pinned native LootPackets writers."""
|
|
import struct
|
|
import subprocess
|
|
import sys
|
|
from native_codec_driver import require_optional_cli
|
|
|
|
P = struct.pack
|
|
codec = sys.argv[1]
|
|
require_optional_cli(codec)
|
|
obj = P('<QQ', 9, (15 << 58) | (70 << 42) | (1 << 29))
|
|
player = P('<QQ', 4510, (2 << 58) | (70 << 42))
|
|
|
|
|
|
def packed(guid):
|
|
return P('<H', sum((v != 0) << i for i, v in enumerate(guid))) + bytes(v for v in guid if v)
|
|
|
|
|
|
def item(ui):
|
|
return bytes([ui << 3]) + P('<IBBI', 2, 0, 0, 25) + bytes(2)
|
|
|
|
|
|
def run(data):
|
|
return subprocess.run([codec, '--loot-event'], input=data, capture_output=True, timeout=15)
|
|
|
|
|
|
base = obj + P('<BIIi', 0, 25, 2, 0)
|
|
start = bytes([6]) + base + P('<IIB', 1, 59800, 3)
|
|
broadcast = bytes([7]) + base + player + P('<iBB', -1, 2, 1)
|
|
won_other = bytes([8]) + base + player + P('<iBB', 42, 2, 0)
|
|
won_self = bytes([8]) + base + player + P('<iBB', 42, 2, 1)
|
|
all_passed = bytes([9]) + base
|
|
cases = [
|
|
(start, packed(obj) + P('<i', 1) + item(1) + P('<IB', 59800, 7) + bytes(20) + bytes([3]) + P('<i', 0)),
|
|
(broadcast, packed(obj) + packed(player) + item(1) + P('<iBiB', -1, 2, 0, 0)),
|
|
(bytes([7]) + base + player + P('<iBB', 69, 1, 0), packed(obj) + packed(player) + item(0) + P('<iBiB', 69, 1, 0, 0)),
|
|
(bytes([7]) + base + player + P('<iBB', 69, 1, 1), packed(obj) + packed(player) + item(1) + P('<iBiB', 69, 1, 0, 0)),
|
|
(won_other, packed(obj) + item(2) + packed(player) + P('<iBiB', 42, 2, 0, 0x80)),
|
|
(won_self, packed(obj) + item(0) + packed(player) + P('<iBiB', 42, 2, 0, 0x80)),
|
|
(all_passed, packed(obj) + item(0) + P('<i', 0)),
|
|
]
|
|
for data, expected in cases:
|
|
result = run(data)
|
|
assert result.returncode == 0 and result.stdout == expected, result.stderr.decode(errors='replace')
|
|
for end in range(len(data)):
|
|
assert run(data[:end]).returncode != 0
|
|
assert run(data + b'\0').returncode != 0
|
|
|
|
for number, vote in [(0, 0), (-1, 1), (101, 2), (1, 0)]:
|
|
assert run(bytes([7]) + base + player + P('<iBB', number, vote, 1)).returncode != 0
|
|
for bad in [bytes([7]) + base + player + P('<iBB', 0, 1, 0),
|
|
bytes([7]) + base + player + P('<iBB', 69, 1, 2),
|
|
bytes([6]) + base + P('<IIB', 1, 0, 3),
|
|
bytes([8]) + base + player + P('<iBB', 42, 2, 2),
|
|
bytes([9]) + obj + P('<BIIi', 16, 25, 2, 0),
|
|
bytes([9]) + obj + P('<BIIi', 0, 25, 0, 0)]:
|
|
assert run(bad).returncode != 0
|
|
print('Native roll writer framing, selection, slot zero and bounded failures PASS')
|