Ejemplo n.º 1
0
 def test_read_chars(self):
     b = ByteStream('adam michael vandenberg')
     
     s = b.chars(8)
     self.assertEquals('adam mic', s)
     
     s = b.chars(8)
     self.assertEquals('hael van', s)
Ejemplo n.º 2
0
 def _read_until(self, until, keep, expected):
     b = ByteStream('adam michael vandenberg')
     
     words = list()
     while not b.eof():
         words.append(b.read_until(until, keep=keep))
     
     self.assertEquals(expected, words)
     self.assert_(b.eof())
Ejemplo n.º 3
0
 def test_word(self):
     "Reading words should behave as expected."
     b = ByteStream(self.sample_bytes)
     
     words = list()
     for i in range(len(self.sample_bytes)/2):
         words.append(b.word())
     
     self.assertEquals([2*256+1, 4*256+3, 6*256+5], words)
     self.assert_(b.eof())
Ejemplo n.º 4
0
 def test_byte(self):
     "Reading bytes should behave as expected."
     b = ByteStream(self.sample_bytes)
     
     bytes = list()
     for i in range(len(self.sample_bytes)):
         bytes.append(b.byte())
         
     self.assertEquals([1,2,3,4,5,6], bytes)
     self.assert_(b.eof())
Ejemplo n.º 5
0
 def test_reset(self):
     b = ByteStream('adam michael vandenberg')
     # Read some data and discard them
     b.chars(10)
     # Then reset and try reading the first 8 chars again
     b.reset()
     s = b.chars(8)
     self.assertEquals('adam mic', s)
     # Reset to an internal position and read the rest
     b.reset(13)
     r = b.rest()
     self.assertEquals('vandenberg', r)
Ejemplo n.º 6
0
    def __init__(self, bytes):
        self.load_address = 0
        self.bank = 0
        self.disk_block = 0
        self.diskname = ''
        self.filename = ''
        self.code_offset = 0
        self.code_address = 0
        self.code = ''

        self.is_valid = bytes.startswith('CBM')
        if self.is_valid:
            s = ByteStream(bytes[3:])
            self.load_address = s.word()
            self.bank = s.byte()
            self.disk_block = s.byte()  # What?
            self.diskname = s.read_until(0, keep=False)
            self.filename = s.read_until(0, keep=False)
            self.code_offset = s.pos
            self.code_address = self.code_offset + RAM_BOOTSECTOR
            self.code = s.rest()
Ejemplo n.º 7
0
    def __init__(self, bytes):
        self.load_address = 0
        self.bank = 0
        self.disk_block = 0
        self.diskname = ''
        self.filename = ''
        self.code_offset = 0
        self.code_address = 0
        self.code = ''

        self.is_valid = bytes.startswith('CBM')
        if self.is_valid:
            s = ByteStream(bytes[3:])
            self.load_address = s.word()
            self.bank = s.byte()
            self.disk_block = s.byte() # What?
            self.diskname = s.read_until(0, keep=False)
            self.filename = s.read_until(0, keep=False)
            self.code_offset = s.pos
            self.code_address = self.code_offset + RAM_BOOTSECTOR
            self.code = s.rest()
Ejemplo n.º 8
0
 def test_init(self):
     "ByteStreams should be created correctly given a string."
     b = ByteStream(self.sample_bytes)
     self.assertEquals(self.sample_bytes, b.rest())