aboutsummaryrefslogtreecommitdiffstats
path: root/tests/sms
diff options
context:
space:
mode:
authorJacob Erlbeck <jerlbeck@sysmocom.de>2014-01-07 13:39:24 +0100
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2014-01-09 08:22:14 +0100
commit26cbd459fcc7cd7bed8256a5ad078c177a7a7fe2 (patch)
tree0de9217e0d73edd48d3a175680a6824ffd2c77ea /tests/sms
parentd4d87c5427bdf838cbfc3948bcf035e1e4036fd9 (diff)
sms: Fix gsm_7bit legacy functions return value
The legacy 7bit conversion functions (those without the '_n_' in the name) gave wrong return values on 64 bit platforms due to unproper signed/unsigned conversions and the usage of SIZE_MAX. This patch fixes this by using a smaller max size (see GSM_7BIT_LEGACY_MAX_BUFFER_SIZE, currently set to 64k) for the legacy wrappers and by using unsigned int for max_septets. In addition, there are tests now that check the return values of legacy encoding and decoding. Sponsored-by: On-Waves ehf
Diffstat (limited to 'tests/sms')
-rw-r--r--tests/sms/sms_test.c22
-rw-r--r--tests/sms/sms_test.ok8
2 files changed, 30 insertions, 0 deletions
diff --git a/tests/sms/sms_test.c b/tests/sms/sms_test.c
index 2c9d8d8..755b321 100644
--- a/tests/sms/sms_test.c
+++ b/tests/sms/sms_test.c
@@ -280,6 +280,17 @@ int main(int argc, char** argv)
/* test 7-bit encoding */
for (i = 0; i < ARRAY_SIZE(test_encode); ++i) {
+ /* Test legacy function (return value only) */
+ septet_length = gsm_7bit_encode(coded,
+ (const char *) test_encode[i].input);
+ printf("Legacy encode case %d: "
+ "septet length %d (expected %d)\n"
+ , i
+ , septet_length, test_encode[i].expected_septet_length
+ );
+ OSMO_ASSERT (septet_length == test_encode[i].expected_septet_length);
+
+ /* Test new function */
memset(coded, 0x42, sizeof(coded));
septet_length = gsm_7bit_encode_n(coded, sizeof(coded),
(const char *) test_encode[i].input,
@@ -296,6 +307,7 @@ int main(int argc, char** argv)
OSMO_ASSERT (octets_written == test_encode[i].expected_octet_length);
OSMO_ASSERT (octets_written == computed_octet_length);
OSMO_ASSERT (memcmp(coded, test_encode[i].expected, octets_written) == 0);
+ OSMO_ASSERT (septet_length == test_encode[i].expected_septet_length);
/* check buffer limiting */
memset(coded, 0xaa, sizeof(coded));
@@ -357,6 +369,16 @@ int main(int argc, char** argv)
/* test 7-bit decoding */
for (i = 0; i < ARRAY_SIZE(test_decode); ++i) {
+ /* Test legacy function (return value only) */
+ if (!test_decode[i].ud_hdr_ind) {
+ nchars = gsm_7bit_decode(result, test_decode[i].input,
+ test_decode[i].expected_septet_length);
+ printf("Legacy decode case %d: "
+ "return value %d (expected %d)\n",
+ i, nchars, test_decode[i].expected_septet_length);
+ }
+
+ /* Test new function */
memset(result, 0x42, sizeof(result));
nchars = gsm_7bit_decode_n_hdr(result, sizeof(result), test_decode[i].input,
test_decode[i].expected_septet_length, test_decode[i].ud_hdr_ind);
diff --git a/tests/sms/sms_test.ok b/tests/sms/sms_test.ok
index a71567d..fa536ea 100644
--- a/tests/sms/sms_test.ok
+++ b/tests/sms/sms_test.ok
@@ -1,11 +1,19 @@
SMS testing
+Legacy encode case 0: septet length 9 (expected 9)
Encode case 0: Octet length 8 (expected 8, computed 8), septet length 9 (expected 9)
+Legacy encode case 1: septet length 41 (expected 41)
Encode case 1: Octet length 36 (expected 36, computed 36), septet length 41 (expected 41)
+Legacy encode case 2: septet length 39 (expected 39)
Encode case 2: Octet length 35 (expected 35, computed 35), septet length 39 (expected 39)
+Legacy encode case 3: septet length 40 (expected 40)
Encode case 3: Octet length 35 (expected 35, computed 35), septet length 40 (expected 40)
+Legacy decode case 0: return value 9 (expected 9)
Decode case 0: return value 9 (expected 9)
+Legacy decode case 1: return value 41 (expected 41)
Decode case 1: return value 40 (expected 40)
+Legacy decode case 2: return value 39 (expected 39)
Decode case 2: return value 31 (expected 31)
+Legacy decode case 3: return value 40 (expected 40)
Decode case 3: return value 32 (expected 32)
Decode case 4: return value 153 (expected 153)
Decode case 5: return value 40 (expected 40)