diff options
author | Vadim Yanitskiy <axilirator@gmail.com> | 2019-05-25 23:14:00 +0700 |
---|---|---|
committer | Vadim Yanitskiy <axilirator@gmail.com> | 2019-05-28 06:50:41 +0700 |
commit | aa0683d9f8290515fb9c6681727beeba39a72c1e (patch) | |
tree | 90990138a9b42e97d034662e91230028f12ca8e2 /tests/gsm0408/gsm0408_test.ok | |
parent | 581a34da60abb4d1b5c32907961d7863a0ff3b8c (diff) |
gsm0408/gsm0408_test.c: introduce BCD number encoding / decoding test
So far, both gsm48_encode_bcd_number() and gsm48_decode_bcd_number2()
did not have any unit test coverage. Let's fill this gap by testing
the following scenarios:
- encoding / decoding of a regular 9-digit MSISDN;
- encoding / decoding of a MSISDN with optional LHV;
- encoding / decoding of a long 15-digit MSISDN;
- encoding / decoding of a MSISDN to a buffer:
- with exactly matching size,
- with lower size (truncation);
- decoding LV buffer with incorrect length,
- encoding / decoding an empty input buffer.
As it turns out, gsm48_decode_bcd_number2() does not properly
handle encoded LV if the output buffer size is equal to the
original MSISDN length + 1 (\0-terminator): one digit is lost.
For example, decoding of 15-digit long MSISDN to a buffer of size
16 (15 digits + 1 for \0) would give us only 14 digits. This is
reflected in the unit test output:
Decoding HEX (buffer limit=16) '0821436587092143f5'...
Expected: (rc=0) '123456789012345'
Actual: (rc=0) '12345678901234'
Moreover, if the output buffer is shorter than decoded number,
gsm48_decode_bcd_number2() silently truncates it and returns 0,
while its description states, that the rc should reflect this.
To be fixed in the follow-up patches.
Change-Id: I4b2c330cf8ffe4427c0bee7d5f3b74be56ecd85d
Related: OS#4025
Diffstat (limited to 'tests/gsm0408/gsm0408_test.ok')
-rw-r--r-- | tests/gsm0408/gsm0408_test.ok | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/gsm0408/gsm0408_test.ok b/tests/gsm0408/gsm0408_test.ok index 0bd101de..2441b2b4 100644 --- a/tests/gsm0408/gsm0408_test.ok +++ b/tests/gsm0408/gsm0408_test.ok @@ -139,6 +139,54 @@ Decoding zero length Mobile Identities rc=1 returned empty string +BSD number encoding / decoding test +- Running test: regular 9-digit MSISDN + - Encoding ASCII (buffer limit=0) '123456789'... + - Expected: (rc=6) '0521436587f9' + - Actual: (rc=6) '0521436587f9' + - Decoding HEX (buffer limit=0) '0521436587f9'... + - Expected: (rc=0) '123456789' + - Actual: (rc=0) '123456789' +- Running test: regular 6-digit MSISDN with optional header (LHV) + - Encoding ASCII (buffer limit=0) '123456'... + - Expected: (rc=8) '0700000000214365' + - Actual: (rc=8) '0721436587214365' + - Decoding HEX (buffer limit=0) '07deadbeef214365'... + - Expected: (rc=0) '123456' + - Actual: (rc=0) '123456' +- Running test: long 15-digit (maximum) MSISDN + - Encoding ASCII (buffer limit=0) '123456789012345'... + - Expected: (rc=9) '0821436587092143f5' + - Actual: (rc=9) '0821436587092143f5' + - Decoding HEX (buffer limit=0) '0821436587092143f5'... + - Expected: (rc=0) '123456789012345' + - Actual: (rc=0) '123456789012345' +- Running test: long 15-digit (maximum) MSISDN, limited buffer + - Encoding ASCII (buffer limit=9) '123456789012345'... + - Expected: (rc=9) '0821436587092143f5' + - Actual: (rc=9) '0821436587092143f5' + - Decoding HEX (buffer limit=16) '0821436587092143f5'... + - Expected: (rc=0) '123456789012345' + - Actual: (rc=0) '12345678901234' +- Running test: to be truncated 20-digit MSISDN + - Encoding ASCII (buffer limit=9) '12345678901234567890'... + - Expected: (rc=-5) '' + - Actual: (rc=-5) '' + - Decoding HEX (buffer limit=16) '0a21436587092143658709'... + - Expected: (rc=0) '123456789012345' + - Actual: (rc=0) '12345678901234' +- Running test: LV incorrect length + - Decoding HEX (buffer limit=0) '05214365'... + - Expected: (rc=-5) '(none)' + - Actual: (rc=-5) '(none)' +- Running test: empty input buffer + - Encoding ASCII (buffer limit=0) ''... + - Expected: (rc=1) '00' + - Actual: (rc=1) '00' + - Decoding HEX (buffer limit=0) ''... + - Expected: (rc=-5) '(none)' + - Actual: (rc=-5) '(none)' + Constructed RA: 077-121-666-5 MCC+MNC in BCD: 70 17 21 |