summaryrefslogtreecommitdiff
path: root/unit/test-sms.c
diff options
context:
space:
mode:
authorDenis Kenzior <denkenz@gmail.com>2018-12-20 15:54:40 -0600
committerDenis Kenzior <denkenz@gmail.com>2018-12-27 18:18:51 -0600
commit71544d7fe1a293f829ace3aea327311e0eb17c8a (patch)
tree6e8a207b89597ace2bbcea0b1ff1418cc2134662 /unit/test-sms.c
parent538804e1918accd2f6b286db5cc0e1de40cb83f2 (diff)
downloadofono-71544d7fe1a293f829ace3aea327311e0eb17c8a.tar.gz
unit: convert usage of g_test_verbose
Convert all usages of this function in favor of using a static VERBOSE variable. We almost never use verbose output except while debugging. Additionally this allows us to more easily convert all unit tests to the ell unit test framework
Diffstat (limited to 'unit/test-sms.c')
-rw-r--r--unit/test-sms.c217
1 files changed, 109 insertions, 108 deletions
diff --git a/unit/test-sms.c b/unit/test-sms.c
index 1f563c76..8ff1e038 100644
--- a/unit/test-sms.c
+++ b/unit/test-sms.c
@@ -30,11 +30,12 @@
#include <ell/ell.h>
#include <glib.h>
-#include <glib/gprintf.h>
#include "util.h"
#include "smsutil.h"
+static const bool VERBOSE = false;
+
static const char *simple_deliver = "07911326040000F0"
"040B911346610089F60000208062917314480CC8F71D14969741F977FD07";
static const char *alnum_sender = "0791447758100650"
@@ -57,13 +58,13 @@ static void print_scts(struct sms_scts *scts, const char *prefix)
struct tm remote;
char buf[128];
- g_print("%s: (YY-MM-DD) %02d-%02d-%02d\n", prefix,
+ printf("%s: (YY-MM-DD) %02d-%02d-%02d\n", prefix,
(int)scts->year, (int)scts->month, (int)scts->day);
- g_print("%s: (HH-MM-SS) %02d:%02d:%02d\n", prefix,
+ printf("%s: (HH-MM-SS) %02d:%02d:%02d\n", prefix,
(int)scts->hour, (int)scts->minute, (int)scts->second);
- g_print("%s: Timezone %d hours %d minutes\n", prefix,
+ printf("%s: Timezone %d hours %d minutes\n", prefix,
(int)scts->timezone / 4,
(int)((abs(scts->timezone) % 4) * 15));
@@ -72,32 +73,32 @@ static void print_scts(struct sms_scts *scts, const char *prefix)
strftime(buf, 127, "%Y-%m-%dT%H:%M:%S%z", localtime(&ts));
buf[127] = '\0';
- g_print("local time: %s\n", buf);
+ printf("local time: %s\n", buf);
strftime(buf, 127, "%Y-%m-%dT%H:%M:%S%z", &remote);
buf[127] = '\0';
- g_print("remote time: %s\n", buf);
+ printf("remote time: %s\n", buf);
}
static void print_vpf(enum sms_validity_period_format vpf,
struct sms_validity_period *vp)
{
- g_print("Validity Period Format: %d\n", (int)vpf);
+ printf("Validity Period Format: %d\n", (int)vpf);
switch (vpf) {
case SMS_VALIDITY_PERIOD_FORMAT_ABSENT:
- g_print("Validity-Period: Absent\n");
+ printf("Validity-Period: Absent\n");
break;
case SMS_VALIDITY_PERIOD_FORMAT_RELATIVE:
- g_print("Validity-Period: %d\n",
+ printf("Validity-Period: %d\n",
(int)vp->relative);
break;
case SMS_VALIDITY_PERIOD_FORMAT_ABSOLUTE:
print_scts(&vp->absolute, "Validity-Period:");
break;
case SMS_VALIDITY_PERIOD_FORMAT_ENHANCED:
- g_print("Validity-Period: Enhanced");
+ printf("Validity-Period: Enhanced");
break;
}
}
@@ -105,39 +106,39 @@ static void print_vpf(enum sms_validity_period_format vpf,
static void dump_details(struct sms *sms)
{
if (sms->sc_addr.address[0] == '\0')
- g_print("SMSC Address absent, default will be used\n");
+ printf("SMSC Address absent, default will be used\n");
else
- g_print("SMSC Address number_type: %d, number_plan: %d, %s\n",
+ printf("SMSC Address number_type: %d, number_plan: %d, %s\n",
(int)sms->sc_addr.number_type,
(int)sms->sc_addr.numbering_plan, sms->sc_addr.address);
switch (sms->type) {
case SMS_TYPE_DELIVER:
- g_print("Type: Deliver\n");
+ printf("Type: Deliver\n");
- g_print("Originator-Address: %d, %d, %s\n",
+ printf("Originator-Address: %d, %d, %s\n",
(int)sms->deliver.oaddr.number_type,
(int)sms->deliver.oaddr.numbering_plan,
sms->deliver.oaddr.address);
- g_print("PID: %d\n", (int)sms->deliver.pid);
- g_print("DCS: %d\n", (int)sms->deliver.dcs);
+ printf("PID: %d\n", (int)sms->deliver.pid);
+ printf("DCS: %d\n", (int)sms->deliver.dcs);
print_scts(&sms->deliver.scts, "Timestamp");
break;
case SMS_TYPE_SUBMIT:
- g_print("Type: Submit\n");
+ printf("Type: Submit\n");
- g_print("Message Reference: %u\n", (int)sms->submit.mr);
+ printf("Message Reference: %u\n", (int)sms->submit.mr);
- g_print("Destination-Address: %d, %d, %s\n",
+ printf("Destination-Address: %d, %d, %s\n",
(int)sms->submit.daddr.number_type,
(int)sms->submit.daddr.numbering_plan,
sms->submit.daddr.address);
- g_print("PID: %d\n", (int)sms->submit.pid);
- g_print("DCS: %d\n", (int)sms->submit.dcs);
+ printf("PID: %d\n", (int)sms->submit.pid);
+ printf("DCS: %d\n", (int)sms->submit.dcs);
print_vpf(sms->submit.vpf, &sms->submit.vp);
@@ -175,7 +176,7 @@ static void test_simple_deliver(void)
g_assert(ret);
g_assert(sms.type == SMS_TYPE_DELIVER);
- if (g_test_verbose())
+ if (VERBOSE)
dump_details(&sms);
g_assert(sms.sc_addr.number_type == SMS_NUMBER_TYPE_INTERNATIONAL);
@@ -216,8 +217,8 @@ static void test_simple_deliver(void)
g_assert(utf8);
- if (g_test_verbose())
- g_print("Decoded user data is: %s\n", utf8);
+ if (VERBOSE)
+ printf("Decoded user data is: %s\n", utf8);
g_assert(strcmp(utf8, "How are you?") == 0);
@@ -246,7 +247,7 @@ static void test_alnum_sender(void)
g_assert(ret);
g_assert(sms.type == SMS_TYPE_DELIVER);
- if (g_test_verbose())
+ if (VERBOSE)
dump_details(&sms);
g_assert(sms.sc_addr.number_type == SMS_NUMBER_TYPE_INTERNATIONAL);
@@ -287,8 +288,8 @@ static void test_alnum_sender(void)
g_assert(utf8);
- if (g_test_verbose())
- g_print("Decoded user data is: %s\n", utf8);
+ if (VERBOSE)
+ printf("Decoded user data is: %s\n", utf8);
g_assert(strcmp(utf8, "Testmail") == 0);
@@ -320,12 +321,12 @@ static void test_deliver_encode(void)
ret = sms_encode(&sms, &encoded_pdu_len, &encoded_tpdu_len, pdu);
- if (g_test_verbose()) {
+ if (VERBOSE) {
int i;
for (i = 0; i < encoded_pdu_len; i++)
- g_print("%02X", pdu[i]);
- g_print("\n");
+ printf("%02X", pdu[i]);
+ printf("\n");
}
g_assert(ret);
@@ -352,12 +353,12 @@ static void test_deliver_encode(void)
ret = sms_encode(&sms, &encoded_pdu_len, &encoded_tpdu_len, pdu);
- if (g_test_verbose()) {
+ if (VERBOSE) {
int i;
for (i = 0; i < encoded_pdu_len; i++)
- g_print("%02X", pdu[i]);
- g_print("\n");
+ printf("%02X", pdu[i]);
+ printf("\n");
}
g_assert(ret);
@@ -384,12 +385,12 @@ static void test_deliver_encode(void)
ret = sms_encode(&sms, &encoded_pdu_len, &encoded_tpdu_len, pdu);
- if (g_test_verbose()) {
+ if (VERBOSE) {
int i;
for (i = 0; i < encoded_pdu_len; i++)
- g_print("%02X", pdu[i]);
- g_print("\n");
+ printf("%02X", pdu[i]);
+ printf("\n");
}
g_assert(ret);
@@ -425,7 +426,7 @@ static void test_simple_submit(void)
g_assert(ret);
g_assert(sms.type == SMS_TYPE_SUBMIT);
- if (g_test_verbose())
+ if (VERBOSE)
dump_details(&sms);
g_assert(strlen(sms.sc_addr.address) == 0);
@@ -461,8 +462,8 @@ static void test_simple_submit(void)
g_assert(utf8);
- if (g_test_verbose())
- g_print("Decoded user data is: %s\n", utf8);
+ if (VERBOSE)
+ printf("Decoded user data is: %s\n", utf8);
g_assert(strcmp(utf8, "hellohello") == 0);
@@ -494,12 +495,12 @@ static void test_submit_encode(void)
ret = sms_encode(&sms, &encoded_pdu_len, &encoded_tpdu_len, pdu);
- if (g_test_verbose()) {
+ if (VERBOSE) {
int i;
for (i = 0; i < encoded_pdu_len; i++)
- g_print("%02X", pdu[i]);
- g_print("\n");
+ printf("%02X", pdu[i]);
+ printf("\n");
}
g_assert(ret);
@@ -535,7 +536,7 @@ static void test_simple_mwi(void)
g_assert(ret);
g_assert(sms.type == SMS_TYPE_DELIVER);
- if (g_test_verbose())
+ if (VERBOSE)
dump_details(&sms);
g_assert(sms.sc_addr.number_type == SMS_NUMBER_TYPE_INTERNATIONAL);
@@ -577,8 +578,8 @@ static void test_simple_mwi(void)
sms_udh_iter_get_ie_data(&iter, evm_iei);
sms_udh_iter_get_ie_length(&iter);
- if (g_test_verbose())
- g_print("Enhanced Voicemail IEI\n");
+ if (VERBOSE)
+ printf("Enhanced Voicemail IEI\n");
break;
}
@@ -589,8 +590,8 @@ static void test_simple_mwi(void)
sms_udh_iter_get_ie_data(&iter, special_iei);
sms_udh_iter_get_ie_length(&iter);
- if (g_test_verbose())
- g_print("Special Voicemail IEI\n");
+ if (VERBOSE)
+ printf("Special Voicemail IEI\n");
break;
}
@@ -607,8 +608,8 @@ static void test_simple_mwi(void)
&discard);
g_assert(ret);
- if (g_test_verbose()) {
- g_print("Type: %d, Active: %d, Discard: %d\n",
+ if (VERBOSE) {
+ printf("Type: %d, Active: %d, Discard: %d\n",
type, active, discard);
}
@@ -979,7 +980,7 @@ static void test_ems_udh(gconstpointer data)
g_assert(ret);
g_assert(sms.type == SMS_TYPE_SUBMIT);
- if (g_test_verbose())
+ if (VERBOSE)
dump_details(&sms);
udhl = sms.submit.ud[0];
@@ -991,17 +992,17 @@ static void test_ems_udh(gconstpointer data)
g_assert(ret);
for (i = 0; test->formats[i].len; i++) {
- if (g_test_verbose()) {
+ if (VERBOSE) {
int j;
unsigned char ie_data[4];
sms_udh_iter_get_ie_data(&iter, ie_data);
- g_print("Header:\n");
+ printf("Header:\n");
for (j = 0; j < sms_udh_iter_get_ie_length(&iter); j++)
- g_print("0x%02x ", ie_data[j]);
+ printf("0x%02x ", ie_data[j]);
- g_print("\n");
+ printf("\n");
}
g_assert(sms_udh_iter_get_ie_type(&iter) ==
@@ -1037,8 +1038,8 @@ static void test_ems_udh(gconstpointer data)
g_assert(utf8);
- if (g_test_verbose())
- g_print("Decoded user data is: %s\n", utf8);
+ if (VERBOSE)
+ printf("Decoded user data is: %s\n", utf8);
g_assert(strcmp(utf8, test->expected) == 0);
@@ -1094,10 +1095,10 @@ static void test_assembly(void)
l = sms_assembly_add_fragment(assembly, &sms, time(NULL),
&sms.deliver.oaddr, ref, max, seq);
- if (g_test_verbose()) {
- g_print("Ref: %u\n", ref);
- g_print("Max: %u\n", max);
- g_print("From: %s\n",
+ if (VERBOSE) {
+ printf("Ref: %u\n", ref);
+ printf("Max: %u\n", max);
+ printf("From: %s\n",
sms_address_to_string(&sms.deliver.oaddr));
}
@@ -1137,8 +1138,8 @@ static void test_assembly(void)
sms_assembly_free(assembly);
- if (g_test_verbose())
- g_printf("Text:\n%s\n", utf8);
+ if (VERBOSE)
+ printf("Text:\n%s\n", utf8);
l = sms_text_prepare("555", utf8, ref, TRUE, FALSE);
g_assert(l);
@@ -1148,8 +1149,8 @@ static void test_assembly(void)
g_slist_free_full(l, g_free);
- if (g_test_verbose())
- g_printf("ReEncoded:\n%s\n", reencoded);
+ if (VERBOSE)
+ printf("ReEncoded:\n%s\n", reencoded);
g_assert(strcmp(utf8, reencoded) == 0);
@@ -1183,8 +1184,8 @@ static void test_prepare_7bit(void)
sms->sc_addr.numbering_plan = SMS_NUMBERING_PLAN_ISDN;
strcpy(sms->sc_addr.address, sc_addr+1);
- if (g_test_verbose())
- g_print("sc_addr: %s\n", sms_address_to_string(&sms->sc_addr));
+ if (VERBOSE)
+ printf("sc_addr: %s\n", sms_address_to_string(&sms->sc_addr));
g_assert(!strcmp(sc_addr, sms_address_to_string(&sms->sc_addr)));
@@ -1192,8 +1193,8 @@ static void test_prepare_7bit(void)
sms->submit.daddr.numbering_plan = SMS_NUMBERING_PLAN_ISDN;
strcpy(sms->submit.daddr.address, da_addr+1);
- if (g_test_verbose())
- g_print("da_addr: %s\n",
+ if (VERBOSE)
+ printf("da_addr: %s\n",
sms_address_to_string(&sms->submit.daddr));
g_assert(!strcmp(da_addr,
@@ -1203,12 +1204,12 @@ static void test_prepare_7bit(void)
g_assert(ret);
- if (g_test_verbose()) {
+ if (VERBOSE) {
int i;
for (i = 0; i < encoded_pdu_len; i++)
- g_print("%02X", pdu[i]);
- g_print("\n");
+ printf("%02X", pdu[i]);
+ printf("\n");
}
encoded_pdu = encode_hex(pdu, encoded_pdu_len, 0);
@@ -1251,8 +1252,8 @@ static void test_prepare_concat(gconstpointer data)
guint8 max;
guint8 seq;
- if (g_test_verbose())
- g_print("strlen: %zd\n", strlen(test->str));
+ if (VERBOSE)
+ printf("strlen: %zd\n", strlen(test->str));
r = sms_text_prepare("+15554449999", test->str, 0, TRUE, FALSE);
g_assert(r);
@@ -1268,8 +1269,8 @@ static void test_prepare_concat(gconstpointer data)
strpdu = encode_hex(pdu, pdu_len, 0);
- if (g_test_verbose())
- g_printf("PDU: %s, len: %d, tlen: %d\n",
+ if (VERBOSE)
+ printf("PDU: %s, len: %d, tlen: %d\n",
strpdu, pdu_len, tpdu_len);
pdus = g_slist_append(pdus, strpdu);
}
@@ -1282,14 +1283,14 @@ static void test_prepare_concat(gconstpointer data)
decode_hex_own_buf((char *)l->data, -1, &len, 0, pdu);
- if (g_test_verbose())
- g_print("PDU Len: %ld\n", len);
+ if (VERBOSE)
+ printf("PDU Len: %ld\n", len);
ok = sms_decode(pdu, len, TRUE, len - 1, &decoded);
g_assert(ok);
- if (g_test_verbose())
- g_print("Pdu udl: %d\n", (int)decoded.submit.udl);
+ if (VERBOSE)
+ printf("Pdu udl: %d\n", (int)decoded.submit.udl);
sms_extract_concatenation(&decoded, &ref, &max, &seq);
r = sms_assembly_add_fragment(assembly, &decoded, time(NULL),
@@ -1301,8 +1302,8 @@ static void test_prepare_concat(gconstpointer data)
decoded_str = sms_decode_text(r);
- if (g_test_verbose())
- g_printf("Decoded String: %s\n", decoded_str);
+ if (VERBOSE)
+ printf("Decoded String: %s\n", decoded_str);
g_assert(decoded_str);
g_assert(strcmp(decoded_str, test->str) == 0);
@@ -1424,12 +1425,12 @@ static void test_cbs_encode_decode(void)
g_assert(utf8);
- if (g_test_verbose()) {
- g_printf("%s\n", utf8);
+ if (VERBOSE) {
+ printf("%s\n", utf8);
if (iso639_lang[0] == '\0')
- g_printf("Lang: Unspecified\n");
+ printf("Lang: Unspecified\n");
else
- g_printf("Lang: %s\n", iso639_lang);
+ printf("Lang: %s\n", iso639_lang);
}
g_assert(strcmp(utf8, "Belconnen") == 0);
@@ -1519,12 +1520,12 @@ static void test_cbs_assembly(void)
g_assert(utf8);
- if (g_test_verbose()) {
- g_printf("%s\n", utf8);
+ if (VERBOSE) {
+ printf("%s\n", utf8);
if (iso639_lang[0] == '\0')
- g_printf("Lang: Unspecified\n");
+ printf("Lang: Unspecified\n");
else
- g_printf("Lang: %s\n", iso639_lang);
+ printf("Lang: %s\n", iso639_lang);
}
g_assert(strcmp(utf8, "BelconnenFraserBelconnen") == 0);
@@ -1570,12 +1571,12 @@ static void test_cbs_padding_character(void)
g_assert(utf8);
- if (g_test_verbose()) {
- g_printf("%s\n", utf8);
+ if (VERBOSE) {
+ printf("%s\n", utf8);
if (iso639_lang[0] == '\0')
- g_printf("Lang: Unspecified\n");
+ printf("Lang: Unspecified\n");
else
- g_printf("Lang: %s\n", iso639_lang);
+ printf("Lang: %s\n", iso639_lang);
}
g_assert(strcmp(utf8, "b£$¥èéùìòÇ\x0AØø\x0DÅåΔ_ΦΓΛΩΠΨΣΘΞÆæßÉ !\"#¤"
@@ -1617,8 +1618,8 @@ static void test_range_minimizer(void)
g_assert(rangestr);
- if (g_test_verbose())
- g_print("range: %s\n", rangestr);
+ if (VERBOSE)
+ printf("range: %s\n", rangestr);
g_free(rangestr);
g_slist_free_full(r, g_free);
@@ -1659,16 +1660,16 @@ static void test_sr_assembly(void)
decode_hex_own_buf(sr_pdu3, -1, &pdu_len, 0, pdu);
g_assert(sms_decode(pdu, pdu_len, FALSE, 24, &sr3) == TRUE);
- if (g_test_verbose()) {
- g_print("sr1 address: %s, mr: %d\n",
+ if (VERBOSE) {
+ printf("sr1 address: %s, mr: %d\n",
sms_address_to_string(&sr1.status_report.raddr),
sr1.status_report.mr);
- g_print("sr2 address: %s, mr: %d\n",
+ printf("sr2 address: %s, mr: %d\n",
sms_address_to_string(&sr2.status_report.raddr),
sr2.status_report.mr);
- g_print("sr3 address: %s, mr: %d\n",
+ printf("sr3 address: %s, mr: %d\n",
sms_address_to_string(&sr3.status_report.raddr),
sr3.status_report.mr);
}
@@ -1763,7 +1764,7 @@ static void test_wap_push(gconstpointer data)
g_assert(ret);
g_assert(sms.type == SMS_TYPE_DELIVER);
- if (g_test_verbose())
+ if (VERBOSE)
dump_details(&sms);
ret = sms_dcs_decode(sms.deliver.dcs, &cls, &charset, NULL, NULL);
@@ -1773,9 +1774,9 @@ static void test_wap_push(gconstpointer data)
g_assert(sms_extract_app_port(&sms, &dst_port, &src_port, &is_8bit));
- if (g_test_verbose()) {
- g_print("8bit: %d\n", is_8bit);
- g_print("src: %d, dst: %d\n", src_port, dst_port);
+ if (VERBOSE) {
+ printf("8bit: %d\n", is_8bit);
+ printf("src: %d, dst: %d\n", src_port, dst_port);
}
g_assert(is_8bit == FALSE);
@@ -1785,19 +1786,19 @@ static void test_wap_push(gconstpointer data)
wap_push = sms_decode_datagram(list, &data_len);
- if (g_test_verbose()) {
+ if (VERBOSE) {
int i;
- g_print("data_len: %ld\n", data_len);
+ printf("data_len: %ld\n", data_len);
for (i = 0; i < data_len; i++) {
- g_print("%02x", wap_push[i]);
+ printf("%02x", wap_push[i]);
if ((i % 16) == 15)
- g_print("\n");
+ printf("\n");
}
- g_print("\n");
+ printf("\n");
}
g_assert(wap_push);