mirror of
https://github.com/sailfishos/ofono
synced 2025-12-01 23:21:04 +08:00
Merge pull request #195 from marttipiirainen/unit
Unit test improvements
This commit is contained in:
@@ -345,12 +345,21 @@ const unsigned char valid_efopl[] = {
|
||||
};
|
||||
|
||||
const unsigned char valid_efpnn[][28] = {
|
||||
{ 0x43, 0x0a, 0x00, 0x54, 0x75, 0x78, 0x20, 0x43, 0x6f, 0x6d,
|
||||
0x6d, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, },
|
||||
{ 0x43, 0x08, 0x00, 0xD4, 0x3A, 0x1E, 0x34, 0x7C, 0xB7, 0xDB,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, },
|
||||
{ 0x43, 0x05, 0x00, 0x4C, 0x6F, 0x6E, 0x67, 0x45, 0x06, 0x00,
|
||||
0x53, 0x68, 0x6F, 0x72, 0x74, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, }
|
||||
};
|
||||
|
||||
const unsigned char valid_efpnn_2[][28] = {
|
||||
/* Solavei */
|
||||
{ 0x43, 0x08, 0x87, 0xD3, 0x37, 0x3B, 0x6C, 0x2F, 0xA7, 0x01 },
|
||||
/* T-Mobile / T-Mobile */
|
||||
{ 0x43, 0x08, 0x80, 0xD4, 0x56, 0xF3, 0x2D, 0x4E, 0xB3, 0xCB,
|
||||
0x45, 0x08, 0x80, 0xD4, 0x56, 0xF3, 0x2D, 0x4E, 0xB3, 0xCB,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }
|
||||
};
|
||||
|
||||
static void test_eons(void)
|
||||
{
|
||||
const struct sim_eons_operator_info *op_info;
|
||||
@@ -360,6 +369,7 @@ static void test_eons(void)
|
||||
|
||||
g_assert(sim_eons_pnn_is_empty(eons_info));
|
||||
|
||||
/* 1. a fictious operator */
|
||||
sim_eons_add_pnn_record(eons_info, 1,
|
||||
valid_efpnn[0], sizeof(valid_efpnn[0]));
|
||||
g_assert(!sim_eons_pnn_is_empty(eons_info));
|
||||
@@ -380,6 +390,27 @@ static void test_eons(void)
|
||||
g_assert(!op_info->shortname);
|
||||
g_assert(!op_info->info);
|
||||
|
||||
/* 2. a real-world MVNO */
|
||||
sim_eons_add_pnn_record(eons_info, 1,
|
||||
valid_efpnn_2[0], sizeof(valid_efpnn_2[0]));
|
||||
g_assert(!sim_eons_pnn_is_empty(eons_info));
|
||||
|
||||
sim_eons_add_pnn_record(eons_info, 2,
|
||||
valid_efpnn_2[1], sizeof(valid_efpnn_2[1]));
|
||||
g_assert(!sim_eons_pnn_is_empty(eons_info));
|
||||
|
||||
sim_eons_add_opl_record(eons_info, valid_efopl, sizeof(valid_efopl));
|
||||
sim_eons_optimize(eons_info);
|
||||
|
||||
op_info = sim_eons_lookup(eons_info, "246", "82");
|
||||
g_assert(op_info == NULL);
|
||||
op_info = sim_eons_lookup(eons_info, "246", "81");
|
||||
g_assert(op_info);
|
||||
|
||||
g_assert(!strcmp(op_info->longname, "Solavei"));
|
||||
g_assert(!op_info->shortname);
|
||||
g_assert(!op_info->info);
|
||||
|
||||
sim_eons_free(eons_info);
|
||||
}
|
||||
|
||||
|
||||
@@ -1769,6 +1769,63 @@ static void test_wap_push(gconstpointer data)
|
||||
g_slist_free(list);
|
||||
}
|
||||
|
||||
static const char *simple_deliver_unicode = "0791534850020290"
|
||||
"040c915348608475840008412060610141800e0054006500730074002062116211";
|
||||
|
||||
static const char *simple_deliver_unicode_surrogate = "0791534850020290"
|
||||
"040c915348608475840008412060610141800e00540065007300740020D83DDE3B";
|
||||
|
||||
static void test_decode_unicode(void)
|
||||
{
|
||||
struct sms sms;
|
||||
unsigned char *pdu;
|
||||
long pdu_len;
|
||||
gboolean ret;
|
||||
struct sms_assembly *assembly;
|
||||
GSList *l;
|
||||
char *decoded;
|
||||
|
||||
/* contains UCS-2 (Chinese characters) */
|
||||
pdu = decode_hex(simple_deliver_unicode, -1, &pdu_len, 0);
|
||||
g_assert(pdu);
|
||||
g_assert(pdu_len == (long)strlen(simple_deliver_unicode) / 2);
|
||||
ret = sms_decode(pdu, pdu_len, FALSE, 33, &sms);
|
||||
g_free(pdu);
|
||||
|
||||
g_assert(ret);
|
||||
g_assert(sms.type == SMS_TYPE_DELIVER);
|
||||
g_assert(sms.deliver.udl == 14);
|
||||
|
||||
assembly = sms_assembly_new(NULL);
|
||||
l = sms_assembly_add_fragment(assembly, &sms, time(NULL),
|
||||
&sms.deliver.oaddr, 0, 1, 0);
|
||||
g_assert(l);
|
||||
g_assert(g_slist_length(l) == 1);
|
||||
decoded = sms_decode_text(l);
|
||||
sms_assembly_free(assembly);
|
||||
g_assert(strcmp(decoded, "Test 我我") == 0);
|
||||
|
||||
/* contains UTF-16 (a Unicode surrogate pair representing an emoticon) */
|
||||
pdu = decode_hex(simple_deliver_unicode_surrogate, -1, &pdu_len, 0);
|
||||
g_assert(pdu);
|
||||
g_assert(pdu_len == (long)strlen(simple_deliver_unicode_surrogate) / 2);
|
||||
ret = sms_decode(pdu, pdu_len, FALSE, 33, &sms);
|
||||
g_free(pdu);
|
||||
|
||||
g_assert(ret);
|
||||
g_assert(sms.type == SMS_TYPE_DELIVER);
|
||||
g_assert(sms.deliver.udl == 14);
|
||||
|
||||
assembly = sms_assembly_new(NULL);
|
||||
l = sms_assembly_add_fragment(assembly, &sms, time(NULL),
|
||||
&sms.deliver.oaddr, 0, 1, 0);
|
||||
g_assert(l);
|
||||
g_assert(g_slist_length(l) == 1);
|
||||
decoded = sms_decode_text(l);
|
||||
sms_assembly_free(assembly);
|
||||
g_assert(strcmp(decoded, "Test 😻") == 0);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char long_string[152*33 + 1];
|
||||
@@ -1850,5 +1907,7 @@ int main(int argc, char **argv)
|
||||
g_test_add_data_func("/testsms/Test WAP Push 1", &wap_push_1,
|
||||
test_wap_push);
|
||||
|
||||
g_test_add_func("/testsms/Test Decode Unicode", test_decode_unicode);
|
||||
|
||||
return g_test_run();
|
||||
}
|
||||
|
||||
@@ -71,6 +71,10 @@ autoreconf --force --install
|
||||
make %{?jobs:-j%jobs}
|
||||
|
||||
|
||||
%check
|
||||
# run unit tests
|
||||
make check
|
||||
|
||||
%install
|
||||
rm -rf %{buildroot}
|
||||
%make_install
|
||||
|
||||
Reference in New Issue
Block a user