def test_first_constraint(): # v U D # 0 0 0 # 1 x 1 # 2 1-2 # 3 2 3 # 4 3 manager = ConstraintManager({RomVariant.USA, RomVariant.DEMO}) constraint = Constraint() constraint.romA = RomVariant.USA constraint.addressA = 1 constraint.romB = RomVariant.DEMO constraint.addressB = 2 manager.add_constraint(constraint) manager.rebuild_relations() assert_same_address(manager, RomVariant.USA, 0) assert_same_address(manager, RomVariant.DEMO, 0) assert_same_address(manager, RomVariant.DEMO, 1) assert_same_address(manager, RomVariant.DEMO, 2) assert_same_address(manager, RomVariant.DEMO, 3) assert_same_address(manager, RomVariant.DEMO, 0xffffff) assert_differing_address(manager, RomVariant.USA, 1, 2) assert_differing_address(manager, RomVariant.USA, 2, 3) assert_differing_address(manager, RomVariant.USA, 0xffffff, 0xffffff + 1) print('---') assert -1 == manager.to_local(RomVariant.USA, 1)
def test_longer_constraint(): # v E J # 0 0 0 # 1 x 1 # ... ... ... # 100 1---100 # 101 2 101 manager = ConstraintManager({RomVariant.EU, RomVariant.JP}) constraint = Constraint() constraint.romA = RomVariant.JP constraint.addressA = 100 constraint.romB = RomVariant.EU constraint.addressB = 1 manager.add_constraint(constraint) manager.rebuild_relations() assert_same_address(manager, RomVariant.EU, 0) assert_same_address(manager, RomVariant.JP, 0) assert_same_address(manager, RomVariant.JP, 100) assert_same_address(manager, RomVariant.JP, 5000) assert -1 == manager.to_local(RomVariant.EU, 1) assert_differing_address(manager, RomVariant.EU, 1, 100) assert_differing_address(manager, RomVariant.EU, 100, 199)
def assert_differing_address(manager: ConstraintManager, rom: RomVariant, local_address: int, virtual_address: int) -> None: if local_address != -1: assert virtual_address == manager.to_virtual(rom, local_address) assert local_address == manager.to_local(rom, virtual_address)
def assert_same_address(manager: ConstraintManager, rom: RomVariant, address: int) -> None: assert address == manager.to_virtual(rom, address) assert address == manager.to_local(rom, address)