From f48456c0d92801af43395dc9e11d1e522e52e352 Mon Sep 17 00:00:00 2001 From: Daniel Willmann Date: Wed, 26 Mar 2014 20:54:34 +0100 Subject: sms_test: Test that gsm340_scts(gsm340_gen_scts(time) == time gsm340_scts() needs to be the inverse of gsm340_gen_scts() Test different timezones and iterate through a whole year (2013) in 30 min steps. Also test that encoding and decoding work if they happen in different timezones. Record the current test result (which is failing some tests) --- tests/sms/sms_test.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++ tests/sms/sms_test.ok | 30 ++++++++++++++++++++ 2 files changed, 107 insertions(+) diff --git a/tests/sms/sms_test.c b/tests/sms/sms_test.c index cdd41585..4b1859a5 100644 --- a/tests/sms/sms_test.c +++ b/tests/sms/sms_test.c @@ -268,6 +268,78 @@ static void test_gen_oa(void) printf("Result: len(%d) data(%s)\n", len, osmo_hexdump(oa, len)); } +const char *tz_list[] = { + "UTC", + "Europe/London", + "Europe/Berlin", + "Europe/Athens", + "Europe/Moscow", + "Canada/Central", + "America/New_York", + "America/Los_Angeles", + NULL +}; + +static int test_scts_id_one_tz(const char *tz1, const char *tz2) +{ + uint8_t scts[7]; + time_t ts, ts_res, start_ts, end_ts; + + /* 2013-01-01 00:00:00 - 2014-01-01 01:00:00 increment in 30min steps */ + start_ts = 1356998400; + end_ts = 1388538000; + for (ts = start_ts; ts <= end_ts; ts += 1800) { + memset(scts, 0, sizeof(scts)); + + setenv("TZ", tz1, 1); + tzset(); + gsm340_gen_scts(scts, ts); + + setenv("TZ", tz2, 1); + tzset(); + ts_res = gsm340_scts(scts); + + if (ts_res != ts) { + printf("%li -> %s -> %li\n", ts, + osmo_hexdump_nospc(scts, sizeof(scts)), ts_res); + return ts; + } + } + return 0; +} + +static void test_scts_id(void) +{ + int i; + time_t ts; + const char *tz; + char *old_tz = getenv("TZ"); + + for (i = 0; ;i++) { + tz = tz_list[i]; + if (!tz) + break; + + printf("Testing gsm340_scts(gsm340_gen_scts(ts)) == ts " + "for TZ %s\n", tz); + + ts = test_scts_id_one_tz(tz, tz); + if (ts) + printf("Timezone %s failed at ts %li\n", tz, ts); + } + setenv("TZ", old_tz, 1); +} + +static void test_scts_across_tz(const char *tz1, const char *tz2) +{ + time_t ts; + + printf("Testing SCTS generation in TZ %s, decoding in TZ %s\n", tz1, tz2); + ts = test_scts_id_one_tz(tz1, tz2); + if (ts) + printf("Timezone %s->%s failed at ts %li\n",tz1, tz2, ts); +} + int main(int argc, char** argv) { printf("SMS testing\n"); @@ -414,6 +486,11 @@ int main(int argc, char** argv) test_octet_return(); test_gen_oa(); + test_scts_id(); + test_scts_across_tz("UTC", "Europe/Berlin"); + test_scts_across_tz("Europe/Berlin", "UTC"); + test_scts_across_tz("Europe/Berlin", "Canada/Central"); + test_scts_across_tz("Canada/Central", "Europe/Berlin"); printf("OK\n"); return 0; diff --git a/tests/sms/sms_test.ok b/tests/sms/sms_test.ok index fa536eaa..331a7779 100644 --- a/tests/sms/sms_test.ok +++ b/tests/sms/sms_test.ok @@ -26,4 +26,34 @@ Result: len(12) data(14 a1 21 43 65 87 09 21 43 65 87 19 ) Result: len(2) data(00 91 ) Result: len(9) data(0e d0 4f 78 d9 2d 9c 0e 01 ) Result: len(12) data(14 d0 4f 78 d9 2d 9c 0e c3 e2 31 19 ) +Testing gsm340_scts(gsm340_gen_scts(ts)) == ts for TZ UTC +Testing gsm340_scts(gsm340_gen_scts(ts)) == ts for TZ Europe/London +1364691600 -> 31301310000000 -> 1364695200 +Timezone Europe/London failed at ts 1364691600 +Testing gsm340_scts(gsm340_gen_scts(ts)) == ts for TZ Europe/Berlin +1364695200 -> 31301320000000 -> 1364698800 +Timezone Europe/Berlin failed at ts 1364695200 +Testing gsm340_scts(gsm340_gen_scts(ts)) == ts for TZ Europe/Athens +1364698800 -> 31301330000000 -> 1364702400 +Timezone Europe/Athens failed at ts 1364698800 +Testing gsm340_scts(gsm340_gen_scts(ts)) == ts for TZ Europe/Moscow +Testing gsm340_scts(gsm340_gen_scts(ts)) == ts for TZ Canada/Central +1362880800 -> 31300120000000 -> 1362884400 +Timezone Canada/Central failed at ts 1362880800 +Testing gsm340_scts(gsm340_gen_scts(ts)) == ts for TZ America/New_York +1362880800 -> 31300120000000 -> 1362884400 +Timezone America/New_York failed at ts 1362880800 +Testing gsm340_scts(gsm340_gen_scts(ts)) == ts for TZ America/Los_Angeles +1362880800 -> 31300120000000 -> 1362884400 +Timezone America/Los_Angeles failed at ts 1362880800 +Testing SCTS generation in TZ UTC, decoding in TZ Europe/Berlin +1364695200 -> 31301320000000 -> 1364698800 +Timezone UTC->Europe/Berlin failed at ts 1364695200 +Testing SCTS generation in TZ Europe/Berlin, decoding in TZ UTC +Testing SCTS generation in TZ Europe/Berlin, decoding in TZ Canada/Central +1362880800 -> 31300120000000 -> 1362884400 +Timezone Europe/Berlin->Canada/Central failed at ts 1362880800 +Testing SCTS generation in TZ Canada/Central, decoding in TZ Europe/Berlin +1364695200 -> 31301320000000 -> 1364698800 +Timezone Canada/Central->Europe/Berlin failed at ts 1364695200 OK -- cgit v1.2.3