modem-helpers: make cpms test parser return error on failure
This commit is contained in:
@@ -6298,13 +6298,10 @@ cpms_format_check_ready (MMBroadbandModem *self,
|
|||||||
if (!mm_3gpp_parse_cpms_test_response (response,
|
if (!mm_3gpp_parse_cpms_test_response (response,
|
||||||
&result->mem1,
|
&result->mem1,
|
||||||
&result->mem2,
|
&result->mem2,
|
||||||
&result->mem3)) {
|
&result->mem3,
|
||||||
|
&error)) {
|
||||||
supported_storages_result_free (result);
|
supported_storages_result_free (result);
|
||||||
g_task_return_new_error (task,
|
g_task_return_error (task, error);
|
||||||
MM_CORE_ERROR,
|
|
||||||
MM_CORE_ERROR_FAILED,
|
|
||||||
"Couldn't parse supported storages reply: '%s'",
|
|
||||||
response);
|
|
||||||
g_object_unref (task);
|
g_object_unref (task);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@@ -2942,17 +2942,18 @@ storage_from_str (const gchar *str)
|
|||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
mm_3gpp_parse_cpms_test_response (const gchar *reply,
|
mm_3gpp_parse_cpms_test_response (const gchar *reply,
|
||||||
GArray **mem1,
|
GArray **mem1,
|
||||||
GArray **mem2,
|
GArray **mem2,
|
||||||
GArray **mem3)
|
GArray **mem3,
|
||||||
|
GError **error)
|
||||||
{
|
{
|
||||||
GRegex *r;
|
|
||||||
gchar **split;
|
|
||||||
guint i;
|
guint i;
|
||||||
GArray *tmp1 = NULL;
|
g_autoptr(GRegex) r = NULL;
|
||||||
GArray *tmp2 = NULL;
|
g_autoptr(GArray) tmp1 = NULL;
|
||||||
GArray *tmp3 = NULL;
|
g_autoptr(GArray) tmp2 = NULL;
|
||||||
|
g_autoptr(GArray) tmp3 = NULL;
|
||||||
|
g_auto(GStrv) split = NULL;
|
||||||
|
|
||||||
g_assert (mem1 != NULL);
|
g_assert (mem1 != NULL);
|
||||||
g_assert (mem2 != NULL);
|
g_assert (mem2 != NULL);
|
||||||
@@ -2965,9 +2966,9 @@ mm_3gpp_parse_cpms_test_response (const gchar *reply,
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (g_strv_length (split) != N_EXPECTED_GROUPS) {
|
if (g_strv_length (split) != N_EXPECTED_GROUPS) {
|
||||||
mm_warn ("Cannot parse +CPMS test response: invalid number of groups (%u != %u)",
|
g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
|
||||||
g_strv_length (split), N_EXPECTED_GROUPS);
|
"Cannot parse +CPMS test response: invalid number of groups (%u != %u)",
|
||||||
g_strfreev (split);
|
g_strv_length (split), N_EXPECTED_GROUPS);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3010,29 +3011,20 @@ mm_3gpp_parse_cpms_test_response (const gchar *reply,
|
|||||||
g_assert_not_reached ();
|
g_assert_not_reached ();
|
||||||
}
|
}
|
||||||
|
|
||||||
g_strfreev (split);
|
|
||||||
g_regex_unref (r);
|
|
||||||
|
|
||||||
g_warn_if_fail (tmp1 != NULL);
|
|
||||||
g_warn_if_fail (tmp2 != NULL);
|
|
||||||
g_warn_if_fail (tmp3 != NULL);
|
|
||||||
|
|
||||||
/* Only return TRUE if all sets have been parsed correctly
|
/* Only return TRUE if all sets have been parsed correctly
|
||||||
* (even if the arrays may be empty) */
|
* (even if the arrays may be empty) */
|
||||||
if (tmp1 && tmp2 && tmp3) {
|
if (tmp1 && tmp2 && tmp3) {
|
||||||
*mem1 = tmp1;
|
*mem1 = g_steal_pointer (&tmp1);
|
||||||
*mem2 = tmp2;
|
*mem2 = g_steal_pointer (&tmp2);
|
||||||
*mem3 = tmp3;
|
*mem3 = g_steal_pointer (&tmp3);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Otherwise, cleanup and return FALSE */
|
g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
|
||||||
if (tmp1)
|
"Cannot parse +CPMS test response: mem1 %s, mem2 %s, mem3 %s",
|
||||||
g_array_unref (tmp1);
|
tmp1 ? "yes" : "no",
|
||||||
if (tmp2)
|
tmp2 ? "yes" : "no",
|
||||||
g_array_unref (tmp2);
|
tmp3 ? "yes" : "no");
|
||||||
if (tmp3)
|
|
||||||
g_array_unref (tmp3);
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -234,10 +234,11 @@ gboolean mm_3gpp_parse_cmgf_test_response (const gchar *reply,
|
|||||||
GError **error);
|
GError **error);
|
||||||
|
|
||||||
/* AT+CPMS=? (Preferred SMS storage) response parser */
|
/* AT+CPMS=? (Preferred SMS storage) response parser */
|
||||||
gboolean mm_3gpp_parse_cpms_test_response (const gchar *reply,
|
gboolean mm_3gpp_parse_cpms_test_response (const gchar *reply,
|
||||||
GArray **mem1,
|
GArray **mem1,
|
||||||
GArray **mem2,
|
GArray **mem2,
|
||||||
GArray **mem3);
|
GArray **mem3,
|
||||||
|
GError **error);
|
||||||
|
|
||||||
/* AT+CPMS? (Current SMS storage) response parser */
|
/* AT+CPMS? (Current SMS storage) response parser */
|
||||||
gboolean mm_3gpp_parse_cpms_query_response (const gchar *reply,
|
gboolean mm_3gpp_parse_cpms_query_response (const gchar *reply,
|
||||||
|
@@ -2901,10 +2901,12 @@ test_cpms_response_cinterion (void *f, gpointer d)
|
|||||||
GArray *mem1 = NULL;
|
GArray *mem1 = NULL;
|
||||||
GArray *mem2 = NULL;
|
GArray *mem2 = NULL;
|
||||||
GArray *mem3 = NULL;
|
GArray *mem3 = NULL;
|
||||||
|
GError *error = NULL;
|
||||||
|
|
||||||
g_debug ("Testing Cinterion +CPMS=? response...");
|
g_debug ("Testing Cinterion +CPMS=? response...");
|
||||||
|
|
||||||
g_assert (mm_3gpp_parse_cpms_test_response (reply, &mem1, &mem2, &mem3));
|
g_assert (mm_3gpp_parse_cpms_test_response (reply, &mem1, &mem2, &mem3, &error));
|
||||||
|
g_assert_no_error (error);
|
||||||
g_assert_cmpuint (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_ME));
|
||||||
g_assert (is_storage_supported (mem1, MM_SMS_STORAGE_MT));
|
g_assert (is_storage_supported (mem1, MM_SMS_STORAGE_MT));
|
||||||
@@ -2929,10 +2931,12 @@ test_cpms_response_huawei_mu609 (void *f, gpointer d)
|
|||||||
GArray *mem1 = NULL;
|
GArray *mem1 = NULL;
|
||||||
GArray *mem2 = NULL;
|
GArray *mem2 = NULL;
|
||||||
GArray *mem3 = NULL;
|
GArray *mem3 = NULL;
|
||||||
|
GError *error = NULL;
|
||||||
|
|
||||||
g_debug ("Testing Huawei MU609 +CPMS=? response...");
|
g_debug ("Testing Huawei MU609 +CPMS=? response...");
|
||||||
|
|
||||||
g_assert (mm_3gpp_parse_cpms_test_response (reply, &mem1, &mem2, &mem3));
|
g_assert (mm_3gpp_parse_cpms_test_response (reply, &mem1, &mem2, &mem3, &error));
|
||||||
|
g_assert_no_error (error);
|
||||||
g_assert_cmpuint (mem1->len, ==, 1);
|
g_assert_cmpuint (mem1->len, ==, 1);
|
||||||
g_assert (is_storage_supported (mem1, MM_SMS_STORAGE_ME));
|
g_assert (is_storage_supported (mem1, MM_SMS_STORAGE_ME));
|
||||||
g_assert_cmpuint (mem2->len, ==, 1);
|
g_assert_cmpuint (mem2->len, ==, 1);
|
||||||
@@ -2953,10 +2957,12 @@ test_cpms_response_nokia_c6 (void *f, gpointer d)
|
|||||||
GArray *mem1 = NULL;
|
GArray *mem1 = NULL;
|
||||||
GArray *mem2 = NULL;
|
GArray *mem2 = NULL;
|
||||||
GArray *mem3 = NULL;
|
GArray *mem3 = NULL;
|
||||||
|
GError *error = NULL;
|
||||||
|
|
||||||
g_debug ("Testing Nokia C6 response...");
|
g_debug ("Testing Nokia C6 response...");
|
||||||
|
|
||||||
g_assert (mm_3gpp_parse_cpms_test_response (reply, &mem1, &mem2, &mem3));
|
g_assert (mm_3gpp_parse_cpms_test_response (reply, &mem1, &mem2, &mem3, &error));
|
||||||
|
g_assert_no_error (error);
|
||||||
g_assert_cmpuint (mem1->len, ==, 0);
|
g_assert_cmpuint (mem1->len, ==, 0);
|
||||||
g_assert_cmpuint (mem2->len, ==, 0);
|
g_assert_cmpuint (mem2->len, ==, 0);
|
||||||
g_assert_cmpuint (mem3->len, ==, 0);
|
g_assert_cmpuint (mem3->len, ==, 0);
|
||||||
@@ -2978,10 +2984,12 @@ test_cpms_response_mixed (void *f, gpointer d)
|
|||||||
GArray *mem1 = NULL;
|
GArray *mem1 = NULL;
|
||||||
GArray *mem2 = NULL;
|
GArray *mem2 = NULL;
|
||||||
GArray *mem3 = NULL;
|
GArray *mem3 = NULL;
|
||||||
|
GError *error = NULL;
|
||||||
|
|
||||||
g_debug ("Testing mixed +CPMS=? response...");
|
g_debug ("Testing mixed +CPMS=? response...");
|
||||||
|
|
||||||
g_assert (mm_3gpp_parse_cpms_test_response (reply, &mem1, &mem2, &mem3));
|
g_assert (mm_3gpp_parse_cpms_test_response (reply, &mem1, &mem2, &mem3, &error));
|
||||||
|
g_assert_no_error (error);
|
||||||
g_assert_cmpuint (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_ME));
|
||||||
g_assert (is_storage_supported (mem1, MM_SMS_STORAGE_MT));
|
g_assert (is_storage_supported (mem1, MM_SMS_STORAGE_MT));
|
||||||
@@ -3003,10 +3011,12 @@ test_cpms_response_mixed_spaces (void *f, gpointer d)
|
|||||||
GArray *mem1 = NULL;
|
GArray *mem1 = NULL;
|
||||||
GArray *mem2 = NULL;
|
GArray *mem2 = NULL;
|
||||||
GArray *mem3 = NULL;
|
GArray *mem3 = NULL;
|
||||||
|
GError *error = NULL;
|
||||||
|
|
||||||
g_debug ("Testing mixed +CPMS=? response with spaces...");
|
g_debug ("Testing mixed +CPMS=? response with spaces...");
|
||||||
|
|
||||||
g_assert (mm_3gpp_parse_cpms_test_response (reply, &mem1, &mem2, &mem3));
|
g_assert (mm_3gpp_parse_cpms_test_response (reply, &mem1, &mem2, &mem3, &error));
|
||||||
|
g_assert_no_error (error);
|
||||||
g_assert_cmpuint (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_ME));
|
||||||
g_assert (is_storage_supported (mem1, MM_SMS_STORAGE_MT));
|
g_assert (is_storage_supported (mem1, MM_SMS_STORAGE_MT));
|
||||||
@@ -3032,10 +3042,12 @@ test_cpms_response_empty_fields (void *f, gpointer d)
|
|||||||
GArray *mem1 = NULL;
|
GArray *mem1 = NULL;
|
||||||
GArray *mem2 = NULL;
|
GArray *mem2 = NULL;
|
||||||
GArray *mem3 = NULL;
|
GArray *mem3 = NULL;
|
||||||
|
GError *error = NULL;
|
||||||
|
|
||||||
g_debug ("Testing mixed +CPMS=? response...");
|
g_debug ("Testing mixed +CPMS=? response...");
|
||||||
|
|
||||||
g_assert (mm_3gpp_parse_cpms_test_response (reply, &mem1, &mem2, &mem3));
|
g_assert (mm_3gpp_parse_cpms_test_response (reply, &mem1, &mem2, &mem3, &error));
|
||||||
|
g_assert_no_error (error);
|
||||||
g_assert_cmpuint (mem1->len, ==, 0);
|
g_assert_cmpuint (mem1->len, ==, 0);
|
||||||
g_assert_cmpuint (mem2->len, ==, 0);
|
g_assert_cmpuint (mem2->len, ==, 0);
|
||||||
g_assert_cmpuint (mem3->len, ==, 0);
|
g_assert_cmpuint (mem3->len, ==, 0);
|
||||||
|
Reference in New Issue
Block a user