Create GBA adventure with walkable map and NPC dialogue
This commit is contained in:
commit
b4017d5c1a
10 files changed
+623
No files matched your search
@@ -0,0 +1,58 @@
|
||||
import importlib.util
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
spec = importlib.util.spec_from_file_location("rom_header", ROOT / "tools/rom_header.py")
|
||||
header = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(header)
|
||||
|
||||
|
||||
class HeaderTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.rom = bytearray((ROOT / "game.gba").read_bytes())
|
||||
|
||||
def test_built_rom_is_valid(self):
|
||||
self.assertEqual(len(header.LOGO), 156)
|
||||
header.verify(self.rom)
|
||||
|
||||
def test_bad_logo_is_rejected(self):
|
||||
self.rom[4] ^= 1
|
||||
with self.assertRaisesRegex(ValueError, "hardware header"):
|
||||
header.verify(self.rom)
|
||||
|
||||
def test_bad_checksum_is_rejected(self):
|
||||
self.rom[160] ^= 1
|
||||
with self.assertRaisesRegex(ValueError, "checksum"):
|
||||
header.verify(self.rom)
|
||||
|
||||
def test_bad_entry_is_rejected(self):
|
||||
self.rom[:4] = bytes.fromhex("ffffffea")
|
||||
with self.assertRaisesRegex(ValueError, "Entry branch"):
|
||||
header.verify(self.rom)
|
||||
|
||||
def test_small_rom_is_rejected(self):
|
||||
with self.assertRaisesRegex(ValueError, "size"):
|
||||
header.verify(b"short")
|
||||
|
||||
def test_header_writer_and_padding(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
path = Path(directory) / "test.gba"
|
||||
raw = bytearray(256)
|
||||
raw[:4] = bytes.fromhex("2e0000ea") # Branch to offset 192.
|
||||
path.write_bytes(raw)
|
||||
subprocess.run(
|
||||
[sys.executable, str(ROOT / "tools/rom_header.py"), str(path)],
|
||||
check=True, capture_output=True, text=True,
|
||||
)
|
||||
result = path.read_bytes()
|
||||
self.assertEqual(len(result), 32768)
|
||||
self.assertEqual(result[160:172], b"FIRSTQUEST\0\0")
|
||||
header.verify(result)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user