aboutsummaryrefslogtreecommitdiff
path: root/tests/test_rom.py
diff options
context:
space:
mode:
authorJuan J. Martínez <jjm@usebox.net>2021-10-02 12:33:04 +0000
committerJuan J. Martínez <jjm@usebox.net>2021-10-02 12:33:04 +0000
commitcaa22e5bbd158fd8d563588293aa763ca5801bed (patch)
tree0789e731afeb7844fd68976fc0b1ea53ec4517d7 /tests/test_rom.py
parentc14900274f20d119c6704f910eec420bf2998866 (diff)
downloadubox-msx-lib-caa22e5bbd158fd8d563588293aa763ca5801bed.tar.gz
ubox-msx-lib-caa22e5bbd158fd8d563588293aa763ca5801bed.zip
Start the test suite
Diffstat (limited to 'tests/test_rom.py')
-rwxr-xr-xtests/test_rom.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/test_rom.py b/tests/test_rom.py
new file mode 100755
index 0000000..7ba6992
--- /dev/null
+++ b/tests/test_rom.py
@@ -0,0 +1,37 @@
+#!/usr/bin/env python3
+
+import unittest
+import struct
+
+
+class TestRom(unittest.TestCase):
+ """Test that the generated game ROM is correct."""
+
+ ROM_SIZE = 0x8000
+
+ @classmethod
+ def setUpClass(cls):
+ with open("../bin/game.rom", "rb") as fd:
+ cls.data = fd.read(cls.ROM_SIZE)
+
+ with open("../game/build/game.map", "rb") as fd:
+ game_map = fd.readlines()
+
+ cls.main_init = 0
+ for line in game_map:
+ if b"_main_init" in line:
+ cls.main_init = int(line.split()[0], 16)
+ break
+
+ def test_header_magic(self):
+ self.assertEqual(self.data[:2], b"AB")
+
+ def test_size(self):
+ self.assertEqual(len(self.data), self.ROM_SIZE)
+
+ def test_header_main_init_address(self):
+ self.assertEqual(struct.unpack("H", self.data[2:4]), (self.main_init,))
+
+
+if __name__ == '__main__':
+ unittest.main()