modem-helpers: fix parsing CPMS=? responses without groups

The CPMS test parser was expecting 3 groups (parenthesis enclosed lists) of
memory IDs, e.g.:

   +CPMS: ("SM","ME"),("SM","ME"),("SM","ME")

But some modems like the Huawei MU609 may just report single elements, not
groups, e.g.:

   +CPMS: "SM","SM","SM"

This patch avoids using g_strsplit() to split the groups, as that is unaware
of the possible replies without groups. Instead, a new helper method is
implemented which does the group/item split itself, considering also the
possibility of a reply with mixed groups and non-groups, like e.g.:

   +CPMS: ("SM","ME"),"SM","SM"

Additionally, we also now support the case where the groups are empty, e.g.:

   +CPMS: (),(),()

https://bugs.freedesktop.org/show_bug.cgi?id=92243
This commit is contained in:
Aleksander Morgado
2015-12-02 21:38:06 +01:00
parent ffde429843
commit 508a37a891
2 changed files with 220 additions and 25 deletions

View File

@@ -1897,14 +1897,14 @@ test_cpms_response_cinterion (void *f, gpointer d)
trace ("\nTesting Cinterion +CPMS=? response...\n");
g_assert (mm_3gpp_parse_cpms_test_response (reply, &mem1, &mem2, &mem3));
g_assert (mem1->len == 2);
g_assert_cmpuint (mem1->len, ==, 2);
g_assert (is_storage_supported (mem1, MM_SMS_STORAGE_ME));
g_assert (is_storage_supported (mem1, MM_SMS_STORAGE_MT));
g_assert (mem2->len == 3);
g_assert_cmpuint (mem2->len, ==, 3);
g_assert (is_storage_supported (mem2, MM_SMS_STORAGE_ME));
g_assert (is_storage_supported (mem2, MM_SMS_STORAGE_SM));
g_assert (is_storage_supported (mem2, MM_SMS_STORAGE_MT));
g_assert (mem3->len == 2);
g_assert_cmpuint (mem3->len, ==, 2);
g_assert (is_storage_supported (mem3, MM_SMS_STORAGE_SM));
g_assert (is_storage_supported (mem3, MM_SMS_STORAGE_MT));
@@ -1913,6 +1913,130 @@ test_cpms_response_cinterion (void *f, gpointer d)
g_array_unref (mem3);
}
static void
test_cpms_response_huawei_mu609 (void *f, gpointer d)
{
/* Use different sets for each on purpose, even if weird */
const gchar *reply = "+CPMS: \"ME\",\"MT\",\"SM\"";
GArray *mem1 = NULL;
GArray *mem2 = NULL;
GArray *mem3 = NULL;
trace ("\nTesting Huawei MU609 +CPMS=? response...\n");
g_assert (mm_3gpp_parse_cpms_test_response (reply, &mem1, &mem2, &mem3));
g_assert_cmpuint (mem1->len, ==, 1);
g_assert (is_storage_supported (mem1, MM_SMS_STORAGE_ME));
g_assert_cmpuint (mem2->len, ==, 1);
g_assert (is_storage_supported (mem2, MM_SMS_STORAGE_MT));
g_assert_cmpuint (mem3->len, ==, 1);
g_assert (is_storage_supported (mem3, MM_SMS_STORAGE_SM));
g_array_unref (mem1);
g_array_unref (mem2);
g_array_unref (mem3);
}
static void
test_cpms_response_nokia_c6 (void *f, gpointer d)
{
/* Use different sets for each on purpose, even if weird */
const gchar *reply = "+CPMS: (),(),()";
GArray *mem1 = NULL;
GArray *mem2 = NULL;
GArray *mem3 = NULL;
trace ("\nTesting Nokia C6 response...\n");
g_assert (mm_3gpp_parse_cpms_test_response (reply, &mem1, &mem2, &mem3));
g_assert_cmpuint (mem1->len, ==, 0);
g_assert_cmpuint (mem2->len, ==, 0);
g_assert_cmpuint (mem3->len, ==, 0);
g_array_unref (mem1);
g_array_unref (mem2);
g_array_unref (mem3);
}
static void
test_cpms_response_mixed (void *f, gpointer d)
{
/*
* First: ("ME","MT") 2-item group
* Second: "ME" 1 item
* Third: ("SM") 1-item group
*/
const gchar *reply = "+CPMS: (\"ME\",\"MT\"),\"ME\",(\"SM\")";
GArray *mem1 = NULL;
GArray *mem2 = NULL;
GArray *mem3 = NULL;
trace ("\nTesting mixed +CPMS=? response...\n");
g_assert (mm_3gpp_parse_cpms_test_response (reply, &mem1, &mem2, &mem3));
g_assert_cmpuint (mem1->len, ==, 2);
g_assert (is_storage_supported (mem1, MM_SMS_STORAGE_ME));
g_assert (is_storage_supported (mem1, MM_SMS_STORAGE_MT));
g_assert_cmpuint (mem2->len, ==, 1);
g_assert (is_storage_supported (mem2, MM_SMS_STORAGE_ME));
g_assert_cmpuint (mem3->len, ==, 1);
g_assert (is_storage_supported (mem3, MM_SMS_STORAGE_SM));
g_array_unref (mem1);
g_array_unref (mem2);
g_array_unref (mem3);
}
static void
test_cpms_response_mixed_spaces (void *f, gpointer d)
{
/* Test with whitespaces here and there */
const gchar *reply = "+CPMS: ( \"ME\" , \"MT\" ) , \"ME\" , ( \"SM\" )";
GArray *mem1 = NULL;
GArray *mem2 = NULL;
GArray *mem3 = NULL;
trace ("\nTesting mixed +CPMS=? response with spaces...\n");
g_assert (mm_3gpp_parse_cpms_test_response (reply, &mem1, &mem2, &mem3));
g_assert_cmpuint (mem1->len, ==, 2);
g_assert (is_storage_supported (mem1, MM_SMS_STORAGE_ME));
g_assert (is_storage_supported (mem1, MM_SMS_STORAGE_MT));
g_assert_cmpuint (mem2->len, ==, 1);
g_assert (is_storage_supported (mem2, MM_SMS_STORAGE_ME));
g_assert_cmpuint (mem3->len, ==, 1);
g_assert (is_storage_supported (mem3, MM_SMS_STORAGE_SM));
g_array_unref (mem1);
g_array_unref (mem2);
g_array_unref (mem3);
}
static void
test_cpms_response_empty_fields (void *f, gpointer d)
{
/*
* First: () Empty group
* Second: Empty item
* Third: ( ) Empty group with spaces
*/
const gchar *reply = "+CPMS: (),,( )";
GArray *mem1 = NULL;
GArray *mem2 = NULL;
GArray *mem3 = NULL;
trace ("\nTesting mixed +CPMS=? response...\n");
g_assert (mm_3gpp_parse_cpms_test_response (reply, &mem1, &mem2, &mem3));
g_assert_cmpuint (mem1->len, ==, 0);
g_assert_cmpuint (mem2->len, ==, 0);
g_assert_cmpuint (mem3->len, ==, 0);
g_array_unref (mem1);
g_array_unref (mem2);
g_array_unref (mem3);
}
/*****************************************************************************/
/* Test CNUM responses */
@@ -2604,7 +2728,12 @@ int main (int argc, char **argv)
item++;
}
g_test_suite_add (suite, TESTCASE (test_cpms_response_cinterion, NULL));
g_test_suite_add (suite, TESTCASE (test_cpms_response_cinterion, NULL));
g_test_suite_add (suite, TESTCASE (test_cpms_response_huawei_mu609, NULL));
g_test_suite_add (suite, TESTCASE (test_cpms_response_nokia_c6, NULL));
g_test_suite_add (suite, TESTCASE (test_cpms_response_mixed, NULL));
g_test_suite_add (suite, TESTCASE (test_cpms_response_mixed_spaces, NULL));
g_test_suite_add (suite, TESTCASE (test_cpms_response_empty_fields, NULL));
g_test_suite_add (suite, TESTCASE (test_cgdcont_test_response_single, NULL));
g_test_suite_add (suite, TESTCASE (test_cgdcont_test_response_multiple, NULL));