2017-05-07 20:28:15 +00:00
|
|
|
from __future__ import print_function
|
2017-05-08 01:58:10 +00:00
|
|
|
from builtins import object
|
2016-06-01 22:37:28 +00:00
|
|
|
from mock import *
|
|
|
|
|
2018-06-24 19:10:59 +00:00
|
|
|
from atrcopy import SegmentData, AtariDosFile, DefaultSegment, XexContainerSegment, errors
|
|
|
|
|
2016-06-01 22:37:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestAtariDosFile(object):
|
|
|
|
def setup(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def test_segment(self):
|
2017-03-21 23:25:59 +00:00
|
|
|
bytes = np.asarray([0xff, 0xff, 0x00, 0x60, 0x01, 0x60, 1, 2], dtype=np.uint8)
|
2016-06-01 22:37:28 +00:00
|
|
|
rawdata = SegmentData(bytes)
|
2017-03-21 23:25:59 +00:00
|
|
|
container = XexContainerSegment(rawdata, 0)
|
|
|
|
image = AtariDosFile(container.rawdata)
|
2016-06-01 22:37:28 +00:00
|
|
|
image.parse_segments()
|
2017-05-07 20:28:15 +00:00
|
|
|
print(image.segments)
|
2016-06-01 22:37:28 +00:00
|
|
|
assert len(image.segments) == 1
|
|
|
|
assert len(image.segments[0]) == 2
|
2017-03-21 23:25:59 +00:00
|
|
|
assert np.all(image.segments[0] == bytes[6:8])
|
|
|
|
container.resize(16)
|
|
|
|
for s in image.segments:
|
|
|
|
s.replace_data(container)
|
|
|
|
new_segment = DefaultSegment(rawdata[8:16])
|
|
|
|
new_segment[:] = 99
|
|
|
|
assert np.all(image.segments[0] == bytes[6:8])
|
2017-05-07 20:28:15 +00:00
|
|
|
print(new_segment[:])
|
2017-03-21 23:25:59 +00:00
|
|
|
assert np.all(new_segment[:] == 99)
|
|
|
|
|
2016-06-01 22:37:28 +00:00
|
|
|
|
|
|
|
def test_short_segment(self):
|
|
|
|
bytes = [0xff, 0xff, 0x00, 0x60, 0xff, 0x60, 1, 2]
|
|
|
|
rawdata = SegmentData(bytes)
|
|
|
|
image = AtariDosFile(rawdata)
|
|
|
|
image.parse_segments()
|
|
|
|
assert len(image.segments) == 1
|
|
|
|
assert len(image.segments[0]) == 2
|
|
|
|
|
|
|
|
def test_err_segment(self):
|
|
|
|
bytes = [0xff, 0xff, 0x00, 0x60, 0x00, 0x00, 1, 2]
|
|
|
|
rawdata = SegmentData(bytes)
|
|
|
|
image = AtariDosFile(rawdata)
|
2018-06-24 19:10:59 +00:00
|
|
|
with pytest.raises(errors.InvalidBinaryFile):
|
2016-06-01 22:37:28 +00:00
|
|
|
image.parse_segments()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
t = TestAtariDosFile()
|
|
|
|
t.setup()
|
|
|
|
t.test_segment()
|