コード例 #1
0
class TestRom(TestAllocatableBlock):
    def setup(self):
        self.block = Rom()

    def test_detect_rom_type(self):
        self.block.from_file(os.path.join(TEST_DATA_DIR, "roms", "EB_fake_noheader.smc"))
        assert_equal(self.block.type, "Earthbound")
        self.block.from_file(os.path.join(TEST_DATA_DIR, "roms", "EB_fake_header.smc"))
        assert_equal(self.block.type, "Earthbound")
        self.block.from_file(os.path.join(TEST_DATA_DIR, "binaries", "empty.bin"))
        assert_equal(self.block.type, ROM_TYPE_NAME_UNKNOWN)
        self.block.from_file(os.path.join(TEST_DATA_DIR, "binaries", "1kb_null.bin"))
        assert_equal(self.block.type, ROM_TYPE_NAME_UNKNOWN)
        self.block.from_file(os.path.join(TEST_DATA_DIR, "roms", "EB_fake_header.smc"))
        assert_equal(self.block.type, "Earthbound")
        self.block.from_file(os.path.join(TEST_DATA_DIR, "roms", "real_EarthBound.smc"))
        assert_equal(self.block.type, "Earthbound")

    @raises(NotImplementedError)
    def test_add_header_unknown(self):
        self.block.from_list([0])
        self.block.add_header()

    def test_add_header_eb(self):
        self.block.from_file(os.path.join(TEST_DATA_DIR, "roms", "real_EarthBound.smc"))
        assert_equal(self.block.size, 0x300000)
        self.block.add_header()
        assert_equal(self.block.size, 0x300200)
        assert_equal(len(self.block.data), 0x300200)
        assert_equal(self.block[0:0x200].to_list(), [0] * 0x200)

    @raises(NotImplementedError)
    def test_expand_unknown(self):
        self.block.from_list([0])
        self.block.expand(0x123456)

    def test_expand_eb(self):
        self.block.from_file(os.path.join(TEST_DATA_DIR, "roms", "real_EarthBound.smc"))
        assert_raises(InvalidArgumentError, self.block.expand, 0x400200)
        assert_raises(InvalidArgumentError, self.block.expand, 0x300000)
        self.block.expand(0x400000)
        assert_equal(self.block.size, 0x400000)
        assert_equal(len(self.block.data), 0x400000)
        assert_list_equal(self.block[0x300000:0x400000].to_list(), [0] * 0x100000)
        self.block.expand(0x600000)
        assert_equal(self.block.size, 0x600000)
        assert_equal(len(self.block.data), 0x600000)
        assert_equal(self.block[0xffd5], 0x25)
        assert_equal(self.block[0xffd7], 0x0d)

        self.block.from_file(os.path.join(TEST_DATA_DIR, "roms", "real_EarthBound.smc"))
        self.block.expand(0x600000)
        assert_equal(self.block.size, 0x600000)
        assert_equal(len(self.block.data), 0x600000)
        assert_equal(self.block[0xffd5], 0x25)
        assert_equal(self.block[0xffd7], 0x0d)