summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJacob Erlbeck <jerlbeck@sysmocom.de>2013-08-08 12:38:54 +0200
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2013-08-08 14:29:17 +0200
commit8a1666b1bf630f62f635028edcf49b0f069b9e7a (patch)
tree6eba7ac78e95c92be70223adba6637bd34795430 /tests
parent9597555a362cd28c02e9bbfe4f55c4b90ecdfa34 (diff)
ussd: Changed 7bit test to check spec conformance directly
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.
Diffstat (limited to 'tests')
-rw-r--r--tests/ussd/ussd_test.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/tests/ussd/ussd_test.c b/tests/ussd/ussd_test.c
index d41c141d..e3e8e08a 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)) == 0);
+
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)) == 0);
+ OSMO_ASSERT(strcmp(appended_after_decode, decoded + strlen(text)) == 0);
}
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;
}