aboutsummaryrefslogtreecommitdiff
path: root/tests/test_rom.py
blob: d980dad3ca8149871adfdf7df064a16862967706 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python3

import unittest
import struct
from os import path, environ


class TestRom(unittest.TestCase):
    """Test that the generated game ROM is correct."""

    ROM_SIZE = int(environ.get("ROM_MAX", 0), 16)

    @classmethod
    def setUpClass(cls):
        with open(path.join("..", "bin", "game.rom"), "rb") as fd:
            cls.data = fd.read()

        with open(path.join("..", "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()