[PATCH 3/3] ussd: Changed 7bit test to check spec conformance directly

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/OpenBSC@lists.osmocom.org/.

Jacob Erlbeck jerlbeck at sysmocom.de
Thu Aug 8 10:38:54 UTC 2013


Renamed gsm_7bit_ussd() to test_7bit_ussd() and extended the function
to take the expected binary encoding and eventually added trailing
bytes in the re-decoded text as arguments. These are used to check
assertions of the right behaviour instead of solely relying on
regression data, because the value are determined by the spec and
fixed and it is more obvious this way. Especially concerning the case
with the duplicated \r which can easily be overlooked when it's only
present in the ok file.
---
 tests/ussd/ussd_test.c |   19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/tests/ussd/ussd_test.c b/tests/ussd/ussd_test.c
index d41c141..ffb5440 100644
--- a/tests/ussd/ussd_test.c
+++ b/tests/ussd/ussd_test.c
@@ -69,7 +69,7 @@ static int parse_mangle_ussd(const uint8_t *_data, int len)
 
 struct log_info info = {};
 
-void gsm_7bit_ussd(char *text)
+static void test_7bit_ussd(const char *text, const char *encoded_hex, const char *appended_after_decode)
 {
 	uint8_t coded[256];
 	char decoded[256];
@@ -78,9 +78,15 @@ void gsm_7bit_ussd(char *text)
 	printf("original = %s\n", osmo_hexdump((uint8_t *)text, strlen(text)));
 	gsm_7bit_encode_ussd(coded, text, &y);
 	printf("encoded = %s\n", osmo_hexdump(coded, y));
+
+	OSMO_ASSERT(!strcmp(encoded_hex, osmo_hexdump_nospc(coded, y)));
+
 	gsm_7bit_decode_ussd(decoded, coded, y * 8 / 7);
 	y = strlen(decoded);
 	printf("decoded = %s\n\n", osmo_hexdump((uint8_t *)decoded, y));
+
+	OSMO_ASSERT(!strncmp(text, decoded, strlen (text)));
+	OSMO_ASSERT(!strcmp(appended_after_decode, decoded + strlen (text)));
 }
 
 int main(int argc, char **argv)
@@ -109,11 +115,12 @@ int main(int argc, char **argv)
 	}
 
 	printf("<CR> case test for 7 bit encode\n");
-	gsm_7bit_ussd("01234567");
-	gsm_7bit_ussd("0123456");
-	gsm_7bit_ussd("01234567\r");
-	gsm_7bit_ussd("0123456\r");
-	gsm_7bit_ussd("012345\r");
+	test_7bit_ussd("01234567",   "b0986c46abd96e",   "");
+	test_7bit_ussd("0123456",    "b0986c46abd91a",   "");
+	test_7bit_ussd("01234567\r", "b0986c46abd96e0d", "");
+        /* The appended \r is compliant to GSM 03.38 section 6.1.2.3.1: */
+	test_7bit_ussd("0123456\r",  "b0986c46abd91a0d", "\r");
+	test_7bit_ussd("012345\r",   "b0986c46ab351a",   "");
 
 	return 0;
 }
-- 
1.7.9.5





More information about the OpenBSC mailing list