filesystem: add unit tests for encoder/decoder methods

Lets add test vectors for the per-record/per-file encode/decode of
our various classes for the Elementary Files.

We keep the test vectors as class variables of the respective EF-classes
to ensure implementation and test vectors are next to each other.

The test classes then iterate over all EF subclasses and execute the
decode/encode functions using the test vectors from the class variables.

Change-Id: I02d884547f4982e0b8ed7ef21b8cda75237942e2
Related: OS#4963
This commit is contained in:
Harald Welte
2023-01-27 19:26:12 +01:00
parent d2edd414a8
commit 865eea68c3
7 changed files with 523 additions and 13 deletions

View File

@@ -80,6 +80,11 @@ EF_ISIM_ADF_map = {
# TS 31.103 Section 4.2.2
class EF_IMPI(TransparentEF):
# FIXME: re-encode fails with "string encoding failed, expected unicode string"
_test_decode = [
( '803137333830303630303030303031303140696d732e6d6e633030302e6d63633733382e336770706e6574776f726b2e6f7267',
{ "nai": "738006000000101@ims.mnc000.mcc738.3gppnetwork.org" } ),
]
class nai(BER_TLV_IE, tag=0x80):
_construct = GreedyString("utf8")
@@ -89,6 +94,11 @@ class EF_IMPI(TransparentEF):
# TS 31.103 Section 4.2.3
class EF_DOMAIN(TransparentEF):
# FIXME: re-encode fails with "string encoding failed, expected unicode string"
_test_decode = [
( '8021696d732e6d6e633030302e6d63633733382e336770706e6574776f726b2e6f7267',
{ "domain": "ims.mnc000.mcc738.3gppnetwork.org" } ),
]
class domain(BER_TLV_IE, tag=0x80):
_construct = GreedyString("utf8")
@@ -98,6 +108,11 @@ class EF_DOMAIN(TransparentEF):
# TS 31.103 Section 4.2.4
class EF_IMPU(LinFixedEF):
# FIXME: re-encode fails with "string encoding failed, expected unicode string"
_test_decode = [
( '80357369703a37333830303630303030303031303140696d732e6d6e633030302e6d63633733382e336770706e6574776f726b2e6f7267',
{ "impu": "sip:738006000000101@ims.mnc000.mcc738.3gppnetwork.org" } ),
]
class impu(BER_TLV_IE, tag=0x80):
_construct = GreedyString("utf8")
@@ -139,6 +154,10 @@ class EF_IST(EF_UServiceTable):
# TS 31.103 Section 4.2.8
class EF_PCSCF(LinFixedEF):
_test_de_encode = [
( '802c0070637363662e696d732e6d6e633030302e6d63633733382e7075622e336770706e6574776f726b2e6f7267',
{ "addr": "pcscf.ims.mnc000.mcc738.pub.3gppnetwork.org", "addr_type": "00" } ),
]
def __init__(self, fid='6f09', sfid=None, name='EF.P-CSCF', desc='P-CSCF Address', **kwargs):
super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, **kwargs)
@@ -163,6 +182,8 @@ class EF_GBANL(LinFixedEF):
# TS 31.103 Section 4.2.11
class EF_NAFKCA(LinFixedEF):
# TODO: 80296273662e696d732e6d6e633030302e6d63633733382e7075622e336770706e6574776f726b2e6f7267ffffffffffffff
# TODO: 8030656e65746e61667830312e696d732e6d6e633030302e6d63633733382e7075622e336770706e6574776f726b2e6f7267
def __init__(self, fid='6fdd', sfid=None, name='EF.NAFKCA', desc='NAF Key Centre Address', **kwargs):
super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, **kwargs)