fixeria has submitted this change. ( 
https://gerrit.osmocom.org/c/pysim/+/42597?usp=email )

Change subject: tests: fix TransRecEF _test_de_encode to operate at file level
......................................................................

tests: fix TransRecEF _test_de_encode to operate at file level

Previously, _test_de_encode vectors for TransRecEF subclasses were tested
via decode_record_hex()/encode_record_hex(), i.e. one record at a time,
with the decoded value being a scalar.

Switch test_de_encode_record() in TransRecEF_Test to use decode_hex() /
encode_hex() instead, so that vectors represent whole-file content
(decoded value is a list of records) -- consistent with how LinFixedEF
handles _test_de_encode.  Update all existing vectors accordingly.

Change-Id: I4a9610f9ee39833cd0c90f64f89f5fbdd6f0846d
---
M pySim/ts_51_011.py
M tests/unittests/test_files.py
2 files changed, 15 insertions(+), 18 deletions(-)

Approvals:
  Jenkins Builder: Verified
  dexter: Looks good to me, approved




diff --git a/pySim/ts_51_011.py b/pySim/ts_51_011.py
index 44eccfa..51676c3 100644
--- a/pySim/ts_51_011.py
+++ b/pySim/ts_51_011.py
@@ -420,7 +420,7 @@
 # TS 51.011 Section 10.3.1
 class EF_LP(TransRecEF):
     _test_de_encode = [
-            ( "24", "24"),
+            ( "24", ["24"] ),
         ]
     def __init__(self, fid='6f05', sfid=None, name='EF.LP', size=(1, None), 
rec_len=1,
                  desc='Language Preference'):
@@ -477,8 +477,8 @@
 # TS 51.011 Section 10.3.4
 class EF_PLMNsel(TransRecEF):
     _test_de_encode = [
-            ( "22F860",  { "mcc": "228", "mnc": "06" } ),
-            ( "330420",  { "mcc": "334", "mnc": "020" } ),
+            ( "22F860",  [{ "mcc": "228", "mnc": "06" }] ),
+            ( "330420",  [{ "mcc": "334", "mnc": "020" }] ),
         ]
     def __init__(self, fid='6f30', sfid=None, name='EF.PLMNsel', desc='PLMN 
selector',
                  size=(24, None), rec_len=3, **kwargs):
@@ -692,7 +692,7 @@
 # TS 51.011 Section 10.3.20 / 10.3.22
 class EF_VGCS(TransRecEF):
     _test_de_encode = [
-            ( "92f9ffff", "299" ),
+            ( "92f9ffff", ["299"] ),
         ]
     def __init__(self, fid='6fb1', sfid=None, name='EF.VGCS', size=(4, 200), 
rec_len=4,
                  desc='Voice Group Call Service', **kwargs):
@@ -828,9 +828,9 @@
 # TS 51.011 Section 10.3.35..37
 class EF_xPLMNwAcT(TransRecEF):
     _test_de_encode = [
-        ( '62F2104000', { "mcc": "262", "mnc": "01", "act": [ "E-UTRAN NB-S1", 
"E-UTRAN WB-S1" ] } ),
-        ( '62F2108000', { "mcc": "262", "mnc": "01", "act": [ "UTRAN" ] } ),
-        ( '62F220488C', { "mcc": "262", "mnc": "02", "act": ['E-UTRAN NB-S1', 
'E-UTRAN WB-S1', 'EC-GSM-IoT', 'GSM', 'NG-RAN'] } ),
+        ( '62F2104000', [{ "mcc": "262", "mnc": "01", "act": [ "E-UTRAN 
NB-S1", "E-UTRAN WB-S1" ] }] ),
+        ( '62F2108000', [{ "mcc": "262", "mnc": "01", "act": [ "UTRAN" ] }] ),
+        ( '62F220488C', [{ "mcc": "262", "mnc": "02", "act": ['E-UTRAN NB-S1', 
'E-UTRAN WB-S1', 'EC-GSM-IoT', 'GSM', 'NG-RAN'] }] ),
     ]
     def __init__(self, fid='1234', sfid=None, name=None, desc=None, size=(40, 
None), rec_len=5, **kwargs):
         super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, 
rec_len=rec_len, **kwargs)
@@ -1065,9 +1065,9 @@
 # TS 102 221 Section 13.3 / TS 31.101 Section 13 / TS 51.011 Section 10.1.2
 class EF_PL(TransRecEF):
     _test_de_encode = [
-        ( '6465', "de" ),
-        ( '656e', "en" ),
-        ( 'ffff', None ),
+        ( '6465', ["de"] ),
+        ( '656e', ["en"] ),
+        ( 'ffff', [None] ),
     ]

     def __init__(self, fid='2f05', sfid=0x05, name='EF.PL', desc='Preferred 
Languages'):
diff --git a/tests/unittests/test_files.py b/tests/unittests/test_files.py
index 5bbbddd..e7c50dc 100755
--- a/tests/unittests/test_files.py
+++ b/tests/unittests/test_files.py
@@ -176,12 +176,11 @@

 
     def test_de_encode_record(self):
-        """Test the decoder and encoder for a transparent record-oriented EF.  
Performs first a decoder
-        test, and then re-encodes the decoded data, comparing the re-encoded 
data with the
-        initial input data.
+        """Test the decoder and encoder for a transparent record-oriented EF 
at the whole-file
+        level.  Performs first a decode test, then re-encodes and compares 
with the input.

         Requires the given TransRecEF subclass to have a '_test_de_encode' 
attribute,
-        containing a list of tuples. Each tuple has to be a 2-tuple 
(hexstring, decoded_dict).
+        containing a list of 2-tuples (hexstring, decoded_list).
         """
         for c in self.classes:
             name = get_qualified_name(c)
@@ -192,14 +191,12 @@
                         encoded = t[0]
                         decoded = t[1]
                         logging.debug("Testing decode of %s", name)
-                        re_dec = inst.decode_record_hex(encoded)
+                        re_dec = inst.decode_hex(encoded)
                         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, 
len(encoded)//2)
+                        re_enc = inst.encode_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.


 class TransparentEF_Test(unittest.TestCase):

-- 
To view, visit https://gerrit.osmocom.org/c/pysim/+/42597?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I4a9610f9ee39833cd0c90f64f89f5fbdd6f0846d
Gerrit-Change-Number: 42597
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: dexter <[email protected]>
Gerrit-Reviewer: fixeria <[email protected]>

Reply via email to