From 9a23eab1634e8feb6c0cf4d4980a8a27c9b438bf Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Tue, 16 Dec 2025 02:55:24 +0100 Subject: [PATCH] unittests/test_files: Pass to-be-encoded length to encoder functions Some of the encoders can only generate valid output if they are told the expected output size. This is due to variable-length fields that depend on the size of the total record (or file). Let's always pass the expected length to the encoder methods. Change-Id: I88f957e49b0c88a121a266d3582e79822fa0e214 --- tests/unittests/test_files.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/unittests/test_files.py b/tests/unittests/test_files.py index ab707717..5bbbdddd 100755 --- a/tests/unittests/test_files.py +++ b/tests/unittests/test_files.py @@ -96,7 +96,7 @@ class LinFixed_Test(unittest.TestCase): inst = c() encoded, rec_num, decoded = self._parse_t(t) logging.debug("Testing encode of %s", name) - re_enc = inst.encode_record_hex(decoded, rec_num) + re_enc = inst.encode_record_hex(decoded, rec_num, len(encoded)//2) self.assertEqual(encoded.upper(), re_enc.upper()) def test_de_encode_record(self): @@ -122,7 +122,7 @@ class LinFixed_Test(unittest.TestCase): self.assertEqual(decoded, re_dec) # re-encode the decoded data logging.debug("Testing re-encode of %s", name) - re_enc = inst.encode_record_hex(re_dec, rec_num) + re_enc = inst.encode_record_hex(re_dec, rec_num, len(encoded)//2) self.assertEqual(encoded.upper(), re_enc.upper()) if hasattr(c, '_test_no_pad') and c._test_no_pad: continue @@ -196,7 +196,7 @@ class TransRecEF_Test(unittest.TestCase): self.assertEqual(decoded, re_dec) # re-encode the decoded data logging.debug("Testing re-encode of %s", name) - re_enc = inst.encode_record_hex(re_dec) + re_enc = inst.encode_record_hex(re_dec, len(encoded)//2) self.assertEqual(encoded.upper(), re_enc.upper()) # there's no point in testing padded input, as TransRecEF have a fixed record # size and we cannot ever receive more input data than that size. @@ -256,7 +256,7 @@ class TransparentEF_Test(unittest.TestCase): encoded = t[0] decoded = t[1] logging.debug("Testing encode of %s", name) - re_enc = inst.encode_hex(decoded) + re_enc = inst.encode_hex(decoded, len(encoded)//2) self.assertEqual(encoded, re_enc) def test_de_encode_file(self): @@ -280,7 +280,7 @@ class TransparentEF_Test(unittest.TestCase): self.assertEqual(decoded, re_dec) logging.debug("Testing re-encode of %s", name) re_dec = inst.decode_hex(encoded) - re_enc = inst.encode_hex(re_dec) + re_enc = inst.encode_hex(re_dec, len(encoded)//2) self.assertEqual(encoded.upper(), re_enc.upper()) if hasattr(c, '_test_no_pad') and c._test_no_pad: continue