Beispiel #1
0
    def test_sequence_counter(self):
        seq = stentura._SequenceCounter()
        actual = [seq() for x in range(512)]
        expected = list(range(256)) * 2
        self.assertEqual(actual, expected)

        seq = stentura._SequenceCounter(67)
        actual = [seq() for x in range(512)]
        expected = list(range(67, 256)) + list(range(256)) + list(range(67))
        self.assertEqual(actual, expected)
Beispiel #2
0
    def test_sequence_counter(self):
        seq = stentura._SequenceCounter()
        actual = [seq() for x in range(512)]
        expected = list(range(256)) * 2
        self.assertEqual(actual, expected)

        seq = stentura._SequenceCounter(67)
        actual = [seq() for x in range(512)]
        expected = list(range(67, 256)) + list(range(256)) + list(range(67))
        self.assertEqual(actual, expected)
Beispiel #3
0
def test_sequence_counter():
    seq = stentura._SequenceCounter()
    actual = [seq() for x in range(512)]
    expected = list(range(256)) * 2
    assert actual == expected

    seq = stentura._SequenceCounter(67)
    actual = [seq() for x in range(512)]
    expected = list(range(67, 256)) + list(range(256)) + list(range(67))
    assert actual == expected
Beispiel #4
0
def test_sequence_counter():
    seq = stentura._SequenceCounter()
    actual = [seq() for x in range(512)]
    expected = list(range(256)) * 2
    assert actual == expected

    seq = stentura._SequenceCounter(67)
    actual = [seq() for x in range(512)]
    expected = list(range(67, 256)) + list(range(256)) + list(range(67))
    assert actual == expected
Beispiel #5
0
    def test_read(self):
        request_buf = bytearray(256)
        response_buf = bytearray(256)
        stroke_buf = bytearray(256)
        event = threading.Event()

        tests = ([0b11000001] * (3 * 512 + 28), [0b11010101] * 4,
                 [0b11000010] * 8)

        for data in tests:
            data = bytearray(data)
            requests, responses = make_readc_packets(data)
            port = MockPacketPort(responses, requests)
            seq = stentura._SequenceCounter()
            block, byte = 0, 0
            block, byte, response = stentura._read(port, event, seq, request_buf,
                                      response_buf, stroke_buf, block, byte)
            self.assertEqual(data, bytes(response))
            self.assertEqual(block, len(data) // 512)
            self.assertEqual(byte, len(data) % 512)
Beispiel #6
0
def test_read():
    request_buf = bytearray(256)
    response_buf = bytearray(256)
    stroke_buf = bytearray(256)
    event = threading.Event()

    tests = ([0b11000001] * (3 * 512 + 28), [0b11010101] * 4, [0b11000010] * 8)

    for data in tests:
        data = bytearray(data)
        requests, responses = make_readc_packets(data)
        port = MockPacketPort(responses, requests)
        seq = stentura._SequenceCounter()
        block, byte = 0, 0
        block, byte, response = stentura._read(port, event, seq, request_buf,
                                               response_buf, stroke_buf, block,
                                               byte)
        assert data == bytes(response)
        assert block == len(data) // 512
        assert byte == len(data) % 512
Beispiel #7
0
    def test_read(self):
        request_buf = array.array('B')
        response_buf = array.array('B')
        stroke_buf = array.array('B')
        event = threading.Event()

        tests = ([0b11000001] * (3 * 512 + 28), [0b11010101] * 4,
                 [0b11000010] * 8)

        for data in tests:
            data = str(buffer(array.array('B', data)))
            requests, responses = make_readc_packets(data)
            port = MockPacketPort(responses, requests)
            seq = stentura._SequenceCounter()
            block, byte = 0, 0
            block, byte, response = stentura._read(port, event, seq,
                                                   request_buf, response_buf,
                                                   stroke_buf, block, byte)
            self.assertEqual(data, str(response))
            self.assertEqual(block, len(data) / 512)
            self.assertEqual(byte, len(data) % 512)
Beispiel #8
0
def make_readc_packets(data):
    requests, responses = [], []
    seq = stentura._SequenceCounter()
    buf = bytearray(256)
    block, byte = 0, 0
    while data:
        s = seq()
        chunk = data[0:512]
        data = data[512:]
        q = stentura._make_read(buf, s, block, byte)
        requests.append(bytes(q))
        r = make_read_response(s, chunk)
        responses.append(bytes(r))
        byte += len(chunk)
        if byte >= 512:
            block += 1
            byte -= 512
    s = seq()
    q = stentura._make_read(buf, s, block, byte)
    requests.append(bytes(q))
    r = make_read_response(s)
    responses.append(bytes(r))
    return requests, responses
Beispiel #9
0
def make_readc_packets(data):
    requests, responses = [], []
    seq = stentura._SequenceCounter()
    buf = bytearray(256)
    block, byte = 0, 0
    while data:
        s = seq()
        chunk = data[0:512]
        data = data[512:]
        q = stentura._make_read(buf, s, block, byte)
        requests.append(bytes(q))
        r = make_read_response(s, chunk)
        responses.append(bytes(r))
        byte += len(chunk)
        if byte >= 512:
            block += 1
            byte -= 512
    s = seq()
    q = stentura._make_read(buf, s, block, byte)
    requests.append(bytes(q))
    r = make_read_response(s)
    responses.append(bytes(r))
    return requests, responses
Beispiel #10
0
def make_readc_packets(data):
    requests, responses = [], []
    seq = stentura._SequenceCounter()
    buf = array.array('B')
    block, byte = 0, 0
    while data:
        s = seq()
        chunk = buffer(data, 0, 512)
        data = buffer(data, 512)
        q = stentura._make_read(buf, s, block, byte)
        requests.append(str(q))
        r = make_read_response(s, chunk)
        responses.append(str(r))
        byte += len(chunk)
        if byte >= 512:
            block += 1
            byte -= 512
    s = seq()
    q = stentura._make_read(buf, s, block, byte)
    requests.append(str(q))
    r = make_read_response(s)
    responses.append(str(r))
    return requests, responses
Beispiel #11
0
def make_readc_packets(data):
    requests, responses = [], []
    seq = stentura._SequenceCounter()
    buf = array.array('B')
    block, byte = 0, 0
    while data:
        s = seq()
        chunk = buffer(data, 0, 512)
        data = buffer(data, 512)
        q = stentura._make_read(buf, s, block, byte)
        requests.append(str(q))
        r = make_read_response(s, chunk)
        responses.append(str(r))
        byte += len(chunk)
        if byte >= 512:
            block += 1
            byte -= 512
    s = seq()
    q = stentura._make_read(buf, s, block, byte)
    requests.append(str(q))
    r = make_read_response(s)
    responses.append(str(r))
    return requests, responses