mirror of git://git.sysmocom.de/ofono
test-sms: Unify some copy-pasted code
This commit is contained in:
parent
e38064a66d
commit
96ef528b27
144
unit/test-sms.c
144
unit/test-sms.c
|
@ -92,6 +92,57 @@ 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");
|
||||||
|
else
|
||||||
|
g_print("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");
|
||||||
|
|
||||||
|
g_print("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);
|
||||||
|
|
||||||
|
print_scts(&sms->deliver.scts, "Timestamp");
|
||||||
|
|
||||||
|
break;
|
||||||
|
case SMS_TYPE_SUBMIT:
|
||||||
|
g_print("Type: Submit\n");
|
||||||
|
|
||||||
|
g_print("Message Reference: %u\n", (int)sms->submit.mr);
|
||||||
|
|
||||||
|
g_print("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);
|
||||||
|
|
||||||
|
print_vpf(sms->submit.vpf, &sms->submit.vp);
|
||||||
|
|
||||||
|
break;
|
||||||
|
case SMS_TYPE_STATUS_REPORT:
|
||||||
|
break;
|
||||||
|
case SMS_TYPE_COMMAND:
|
||||||
|
case SMS_TYPE_DELIVER_REPORT_ACK:
|
||||||
|
case SMS_TYPE_DELIVER_REPORT_ERROR:
|
||||||
|
case SMS_TYPE_SUBMIT_REPORT_ACK:
|
||||||
|
case SMS_TYPE_SUBMIT_REPORT_ERROR:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void test_simple_deliver()
|
static void test_simple_deliver()
|
||||||
{
|
{
|
||||||
struct sms sms;
|
struct sms sms;
|
||||||
|
@ -114,23 +165,8 @@ static void test_simple_deliver()
|
||||||
g_assert(ret);
|
g_assert(ret);
|
||||||
g_assert(sms.type == SMS_TYPE_DELIVER);
|
g_assert(sms.type == SMS_TYPE_DELIVER);
|
||||||
|
|
||||||
if (g_test_verbose()) {
|
if (g_test_verbose())
|
||||||
g_print("SMSC Address number_type: %d, number_plan: %d, %s\n",
|
dump_details(&sms);
|
||||||
(int)sms.sc_addr.number_type,
|
|
||||||
(int)sms.sc_addr.numbering_plan, sms.sc_addr.address);
|
|
||||||
|
|
||||||
g_print("SMS type: %d\n", (int)sms.type);
|
|
||||||
|
|
||||||
g_print("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);
|
|
||||||
|
|
||||||
print_scts(&sms.deliver.scts, "Timezone");
|
|
||||||
}
|
|
||||||
|
|
||||||
g_assert(sms.sc_addr.number_type == SMS_NUMBER_TYPE_INTERNATIONAL);
|
g_assert(sms.sc_addr.number_type == SMS_NUMBER_TYPE_INTERNATIONAL);
|
||||||
g_assert(sms.sc_addr.numbering_plan == SMS_NUMBERING_PLAN_ISDN);
|
g_assert(sms.sc_addr.numbering_plan == SMS_NUMBERING_PLAN_ISDN);
|
||||||
|
@ -200,23 +236,8 @@ static void test_alnum_sender()
|
||||||
g_assert(ret);
|
g_assert(ret);
|
||||||
g_assert(sms.type == SMS_TYPE_DELIVER);
|
g_assert(sms.type == SMS_TYPE_DELIVER);
|
||||||
|
|
||||||
if (g_test_verbose()) {
|
if (g_test_verbose())
|
||||||
g_print("SMSC Address number_type: %d, number_plan: %d, %s\n",
|
dump_details(&sms);
|
||||||
(int)sms.sc_addr.number_type,
|
|
||||||
(int)sms.sc_addr.numbering_plan, sms.sc_addr.address);
|
|
||||||
|
|
||||||
g_print("SMS type: %d\n", (int)sms.type);
|
|
||||||
|
|
||||||
g_print("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);
|
|
||||||
|
|
||||||
print_scts(&sms.deliver.scts, "Timestamp");
|
|
||||||
}
|
|
||||||
|
|
||||||
g_assert(sms.sc_addr.number_type == SMS_NUMBER_TYPE_INTERNATIONAL);
|
g_assert(sms.sc_addr.number_type == SMS_NUMBER_TYPE_INTERNATIONAL);
|
||||||
g_assert(sms.sc_addr.numbering_plan == SMS_NUMBERING_PLAN_ISDN);
|
g_assert(sms.sc_addr.numbering_plan == SMS_NUMBERING_PLAN_ISDN);
|
||||||
|
@ -263,6 +284,7 @@ static void test_alnum_sender()
|
||||||
|
|
||||||
g_free(utf8);
|
g_free(utf8);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_deliver_encode()
|
static void test_deliver_encode()
|
||||||
{
|
{
|
||||||
struct sms sms;
|
struct sms sms;
|
||||||
|
@ -361,30 +383,8 @@ static void test_simple_submit()
|
||||||
g_assert(ret);
|
g_assert(ret);
|
||||||
g_assert(sms.type == SMS_TYPE_SUBMIT);
|
g_assert(sms.type == SMS_TYPE_SUBMIT);
|
||||||
|
|
||||||
if (g_test_verbose()) {
|
if (g_test_verbose())
|
||||||
if (sms.sc_addr.address[0] == '\0')
|
dump_details(&sms);
|
||||||
g_print("SMSC Address absent, default will be used\n");
|
|
||||||
else
|
|
||||||
g_print("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);
|
|
||||||
|
|
||||||
g_print("SMS type: %d\n", (int)sms.type);
|
|
||||||
|
|
||||||
g_print("Message Reference: %u\n", (int)sms.submit.mr);
|
|
||||||
|
|
||||||
g_print("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);
|
|
||||||
|
|
||||||
print_vpf(sms.submit.vpf, &sms.submit.vp);
|
|
||||||
}
|
|
||||||
|
|
||||||
g_assert(strlen(sms.sc_addr.address) == 0);
|
g_assert(strlen(sms.sc_addr.address) == 0);
|
||||||
|
|
||||||
|
@ -623,31 +623,8 @@ static void test_ems_udh(gconstpointer data)
|
||||||
g_assert(ret);
|
g_assert(ret);
|
||||||
g_assert(sms.type == SMS_TYPE_SUBMIT);
|
g_assert(sms.type == SMS_TYPE_SUBMIT);
|
||||||
|
|
||||||
if (g_test_verbose()) {
|
if (g_test_verbose())
|
||||||
if (sms.sc_addr.address[0] == '\0')
|
dump_details(&sms);
|
||||||
g_print("SMSC Address absent, default will be used\n");
|
|
||||||
else
|
|
||||||
g_print("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);
|
|
||||||
|
|
||||||
g_print("SMS type: %d\n", (int)sms.type);
|
|
||||||
|
|
||||||
g_print("Message Reference: %u\n", (int)sms.submit.mr);
|
|
||||||
|
|
||||||
g_print("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);
|
|
||||||
|
|
||||||
print_vpf(sms.submit.vpf, &sms.submit.vp);
|
|
||||||
}
|
|
||||||
|
|
||||||
udhl = sms.submit.ud[0];
|
udhl = sms.submit.ud[0];
|
||||||
|
|
||||||
g_assert(sms.submit.udl == test->udl);
|
g_assert(sms.submit.udl == test->udl);
|
||||||
|
@ -890,7 +867,6 @@ struct sms_concat_data {
|
||||||
unsigned int segments;
|
unsigned int segments;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static struct sms_concat_data shakespeare_test = {
|
static struct sms_concat_data shakespeare_test = {
|
||||||
.str = "Shakespeare divided his time between London and Str"
|
.str = "Shakespeare divided his time between London and Str"
|
||||||
"atford during his career. In 1596, the year before he bought New Plac"
|
"atford during his career. In 1596, the year before he bought New Plac"
|
||||||
|
|
Loading…
Reference in New Issue