diff options
| author | Dave Hibberd <hibby@debian.org> | 2024-08-27 23:18:08 +0100 |
|---|---|---|
| committer | Dave Hibberd <hibby@debian.org> | 2024-08-27 23:18:08 +0100 |
| commit | ddbe8d4b718c0d61a83c48c0b8e45f994254798b (patch) | |
| tree | f12d25b28cc3c0695a28c75a1ff9512a59544dab /tests/unit/test_icf.py | |
| parent | 12882a24180aa2deb5f091b7890ed9e2ae01a9c1 (diff) | |
| parent | ea5898c0bff9b0b52c87408027880f5d7049bdec (diff) | |
Update upstream source from tag 'upstream/20240827'
Update to upstream version '20240827'
with Debian dir f9522178f68ff440c5c82cf36271e1e1235ba8d4
Diffstat (limited to 'tests/unit/test_icf.py')
| -rw-r--r-- | tests/unit/test_icf.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/unit/test_icf.py b/tests/unit/test_icf.py index 08bd74d..cc30ee2 100644 --- a/tests/unit/test_icf.py +++ b/tests/unit/test_icf.py @@ -159,3 +159,32 @@ class TestCloneICF(unittest.TestCase): f = icf.IcfFrame(icf.ADDR_PC, icf.ADDR_RADIO, icf.CMD_CLONE_ID) f.payload = b'\x01\x02' self.assertEqual(b'\xfe\xfe\xee\xef\xe0\x01\x02\xfd', f.pack()) + + +class TestICFUtil(unittest.TestCase): + def test_warp_byte_size(self): + # 4-bit chars to 8-bit bytes + input = bytes([0x12, 0x34]) + output = bytes(icf.warp_byte_size(input, obw=4)) + self.assertEqual(b'\x01\x02\x03\x04', output) + + def test_warp_byte_size_skip(self): + # 4-bit chars to 8-bit bytes with 4 bits of padding ignored + input = bytes([0x12, 0x34]) + output = bytes(icf.warp_byte_size(input, obw=4, iskip=4)) + self.assertEqual(b'\x02\x03\x04', output) + + def test_warp_byte_size_pad(self): + # 8-bit bytes to 4-bit chars, with 4 bits of padding added + input = bytes([2, 3, 4]) + output = bytes(icf.warp_byte_size(input, ibw=4, opad=4)) + self.assertEqual(b'\x02\x34', output) + + def test_warp_byte_size_symmetric_padded(self): + # Make sure we can go from 8->4-> with padding and get back what we + # put in + ref = bytes([1, 2, 3, 4, 5, 6]) + stored = bytes(icf.warp_byte_size(bytes(ref), ibw=6, opad=4)) + self.assertEqual(5, len(bytes(stored))) + self.assertEqual(ref, + bytes(icf.warp_byte_size(stored, obw=6, iskip=4))) |
