# SPDX-License-Identifier: GPL-2.0-or-later """Tests for the patcher: python -m pytest test_patcher.py Offline: S-records, the boot loader's LZSS against our packer, the version label guard. With the official update (CDJ900NXS_UPD, or C900NXS.UPD in this folder): the stock file rebuilt byte for byte, the relabelled stock differing in three bytes only, and every tampering with the boot area caught.""" import os import random import struct import sys import pytest HERE = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, HERE) import upd # noqa: E402 import cdj900nxs_patcher as cli # noqa: E402 STOCK = os.environ.get('CDJ900NXS_UPD') or os.path.join(HERE, 'C900NXS.UPD') need_stock = pytest.mark.skipif(not os.path.isfile(STOCK), reason='needs the official C900NXS.UPD') def test_record_round_trip(): rec = upd.Record(2, 0x040020, bytes(range(32))) line = rec.encode() assert line.startswith(b'S2') and line.endswith(b'\r\n') raw = bytes.fromhex(line[2:-2].decode()) assert raw[0] == len(raw) - 1 and sum(raw) & 0xFF == 0xFF def test_lzss_matches_the_boot_loader(): _, lzss = cli.load_repo(cli.DEFAULT_REPO) rnd = random.Random(7) data = bytes(rnd.choice(b' \0ABAB\xff') for _ in range(20000)) + b' ' * 5000 + bytes(4000) assert upd.unpack_lzss(lzss.pack(data)) == data def test_region_checksum_and_padding(): reg = upd.pack_region(b'abc') assert len(reg) % 32 == 0 size = struct.unpack_from('