tests: added pack and unpack test
[renesas-ra-flasher] / tests / test_parse.py
1 from flasher.flasher import calc_sum, unpack_pkt, pack_pkt
2 import pytest
3
4 def test_calc_sum():
5     assert calc_sum(0x12, ['0x00']) == (0, 0x2, 0xEC)
6     assert calc_sum(0x34, ['0x00']) == (0, 0x2, 0xCA)
7     assert calc_sum(0x00, ['0x00']) == (0, 0x02, 0xFE)
8
9 def test_unpack():
10     assert unpack_pkt(b'\x81\x00\x02\x00\x00\xFE\x03') == ['0x00']
11     assert unpack_pkt(b'\x81\x00\x02\x12\x00\xEC\x03') == ['0x00']
12     assert unpack_pkt(b'\x81\x00\x02\x13\x00\xEB\x03') == ['0x00']
13
14 def test_pack_unpack():
15     assert unpack_pkt(pack_pkt(0x13, ['0x00','0x01','0x02'])) == ['0x00', '0x01', '0x02']
16     assert unpack_pkt(pack_pkt(0x34, ['0x00'])) == ['0x00']
17     assert unpack_pkt(pack_pkt(0x00, ['0x00'])) == ['0x00']
18     assert unpack_pkt(pack_pkt(0x12, ['0x00'])) == ['0x00']