Files
WoW-Hybrid-gateway/tests/editor_client_127_test.py

104 lines
6.5 KiB
Python

import json
import struct
import sys
import unittest
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'ops'))
import editor_client_127 as editor
class EditorClientStageTest(unittest.TestCase):
def test_staged_m2_v264_particle_and_ribbon_bounds(self):
root = Path('/mnt/Games/@project/editor-client-127/Data/common.MPQ')
models = list(root.rglob('*.m2'))
self.assertGreaterEqual(len(models), 140)
for model in models:
raw = model.read_bytes()
with self.subTest(model=str(model.relative_to(root))):
self.assertEqual(raw[:4], b'MD20')
self.assertEqual(struct.unpack_from('<I', raw, 4)[0], 264)
self.assertTrue(model.with_name(model.stem + '00.skin').is_file())
for header_at, width, track_offsets, fake_offsets in (
(288, 176, (36, 56, 76, 96, 132, 152), ()),
(296, 476, (52, 72, 92, 112, 132, 152, 176,
200, 220, 240, 456), (260, 276, 292, 316, 332))):
count, offset = struct.unpack_from('<II', raw, header_at)
self.assertLessEqual(offset + count * width, len(raw))
for i in range(count):
base = offset + i * width
for rel in track_offsets:
n_times, time_at, n_keys, key_at = struct.unpack_from('<4I', raw, base + rel + 4)
self.assertLessEqual(time_at + n_times * 8, len(raw))
self.assertLessEqual(key_at + n_keys * 8, len(raw))
for n, at in ((n_times, time_at), (n_keys, key_at)):
for j in range(n):
nested_n, nested_at = struct.unpack_from('<II', raw, at + j * 8)
self.assertLessEqual(nested_at + nested_n, len(raw))
for rel in fake_offsets:
n_times, time_at, n_keys, key_at = struct.unpack_from('<4I', raw, base + rel)
self.assertLessEqual(time_at + n_times * 2, len(raw))
self.assertLessEqual(key_at + n_keys * 2, len(raw))
def test_elwynn_stage_and_dbc_columns(self):
root = Path('/mnt/Games/@project/editor-client-127')
report = json.loads((root / 'editor-client-127-report.json').read_text())
self.assertEqual(set(report['dbc']), set(editor.DBCS) | {'MapDifficulty'})
for name, detail in report['dbc'].items():
raw = (root / 'Data/patch.MPQ/dbfilesclient' / (name.lower() + '.dbc')).read_bytes()
self.assertEqual(raw[:4], b'WDBC')
rows, columns, width, strings = struct.unpack_from('<4I', raw, 4)
self.assertEqual((rows, columns, width),
(detail['rows'], detail['target_columns'], 4 * detail['target_columns']))
self.assertEqual(len(raw), 20 + rows * width + strings)
wdt = (root / 'Data/patch.MPQ/world/maps/azeroth/azeroth.wdt').read_bytes()
main = next(at for tag, at, size in editor.chunks(wdt) if tag == 'MAIN')
active = [i for i in range(4096) if struct.unpack_from('<I', wdt, main + i * 8)[0] & 1]
self.assertEqual(active, [48 * 64 + 32])
wdl = (root / 'Data/patch.MPQ/world/maps/azeroth/azeroth.wdl').read_bytes()
self.assertEqual(report['wdl']['sha256'], editor.hashlib.sha256(wdl).hexdigest())
self.assertIn('MARE', {tag for tag, _, _ in editor.chunks(wdl)})
difficulty = (root / 'Data/patch.MPQ/dbfilesclient/mapdifficulty.dbc').read_bytes()
self.assertEqual(struct.unpack_from('<I', difficulty, 4)[0], report['dbc']['Map']['rows'])
tile = (root / 'Data/patch.MPQ/world/maps/azeroth/azeroth_32_48.adt').read_bytes()
self.assertEqual(report['tile']['sha256'], editor.hashlib.sha256(tile).hexdigest())
self.assertIn('MH2O', {tag for tag, _, _ in editor.chunks(tile)})
self.assertIn(report['roundtrip']['live_root_equal'], (None, True))
self.assertEqual(report['roundtrip']['root_sha256'],
editor.hashlib.sha256(editor.roundtrip_root(tile)).hexdigest())
if 'tex0_byte_equal' in report['roundtrip']:
self.assertTrue(report['roundtrip']['tex0_byte_equal'])
self.assertTrue(report['roundtrip']['doodad_byte_equal'])
self.assertTrue(report['roundtrip']['source_wmo_byte_equal'])
self.assertEqual(report['roundtrip']['source_wmos'], 7)
self.assertEqual(report['roundtrip']['live_extra_wmos'], 4)
self.assertEqual(report['assets']['missing'], [])
missing = {path.lower() for path in report['helpers']['missing']}
self.assertEqual(missing, {
f'world/scale/{name}.m2' for name in (
'50yardradiusdisc', '50yardradiussphere', '200yardradiusdisc',
'200yardradiussphere', '777yardradiusdisc', '777yardradiussphere')})
self.assertTrue((root / 'Data/common.MPQ/textures/shanecube.blp').is_file())
self.assertTrue((root / 'Data/common.MPQ/tileset/generic/black.blp').is_file())
self.assertTrue((root / 'Data/common.MPQ/environments/stars/stars.m2').is_file())
self.assertTrue((root / 'Data/common.MPQ/world/wmo/azeroth/buildings/human_farm/farm.wmo').is_file())
self.assertTrue((root / 'Data/common.MPQ/world/wmo/azeroth/buildings/human_farm/farm_000.wmo').is_file())
self.assertEqual(report['helpers']['m2_conversion_failures'], [])
self.assertEqual(report['helpers']['legacy_m2_without_skin'], [])
self.assertEqual(report['helpers']['editor_preview_resampled'],
['world/azeroth/elwynn/activedoodads/abbeybell/nsabbeybell.m2'])
self.assertEqual(len(report['helpers']['converted_m2']), 149)
for source_path in editor.names(tile, 'MMDX'):
path = source_path.replace('\\', '/').lower()
model = root / 'Data/common.MPQ' / path
self.assertEqual(model.read_bytes()[:4], b'MD20')
self.assertEqual(struct.unpack_from('<I', model.read_bytes(), 4)[0], 264)
self.assertTrue((root / 'Data/common.MPQ' / (path[:-3] + '00.skin')).is_file())
self.assertTrue((root / 'Data/enUS/realmlist.wtf').is_file())
for archive in (root / 'Data/common.MPQ', root / 'Data/patch.MPQ'):
self.assertTrue(all(path.name == path.name.lower() for path in archive.rglob('*') if path.is_file()))
if __name__ == '__main__':
unittest.main()