aboutsummaryrefslogtreecommitdiff
path: root/plugins/huawei/tests
diff options
context:
space:
mode:
authorBen Chan <benchan@chromium.org>2013-10-18 02:56:50 -0700
committerAleksander Morgado <aleksander@lanedo.com>2013-10-20 17:01:51 +0200
commit49d4163a2b1271edc2a1794c4e86a3f01c19a92c (patch)
tree1f82bb0a0019a3f4c6bd4cef5833a1c6e0e32ec5 /plugins/huawei/tests
parente529cd32124618d26ef15a7b8d25597a9634531a (diff)
huawei: fix ^SYSINFO parsing
The original sysinfo_parse() in MMBroadbandModemHuawei incorrectly sets 'out_sys_submode_valid' to TRUE even when <sys_submode> is not present in a ^SYSINFO response. This patch moves the code to mm-modem-helpers-huawei.c, fixes the regex for parsing ^SYSINFO responses, and adds unit tests.
Diffstat (limited to 'plugins/huawei/tests')
-rw-r--r--plugins/huawei/tests/test-modem-helpers-huawei.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/plugins/huawei/tests/test-modem-helpers-huawei.c b/plugins/huawei/tests/test-modem-helpers-huawei.c
index 8d99215e..fa791fee 100644
--- a/plugins/huawei/tests/test-modem-helpers-huawei.c
+++ b/plugins/huawei/tests/test-modem-helpers-huawei.c
@@ -129,6 +129,69 @@ test_ndisstatqry (void)
}
/*****************************************************************************/
+/* Test ^SYSINFO responses */
+
+typedef struct {
+ const gchar *str;
+ guint expected_srv_status;
+ guint expected_srv_domain;
+ guint expected_roam_status;
+ guint expected_sys_mode;
+ guint expected_sim_state;
+ gboolean expected_sys_submode_valid;
+ guint expected_sys_submode;
+} SysinfoTest;
+
+static const SysinfoTest sysinfo_tests[] = {
+ { "^SYSINFO:2,4,5,3,1", 2, 4, 5, 3, 1, FALSE, 0 },
+ { "^SYSINFO:2,4,5,3,1,", 2, 4, 5, 3, 1, FALSE, 0 },
+ { "^SYSINFO:2,4,5,3,1,,", 2, 4, 5, 3, 1, FALSE, 0 },
+ { "^SYSINFO:2,4,5,3,1,6", 2, 4, 5, 3, 1, FALSE, 6 },
+ { "^SYSINFO:2,4,5,3,1,6,", 2, 4, 5, 3, 1, FALSE, 6 },
+ { "^SYSINFO:2,4,5,3,1,,3", 2, 4, 5, 3, 1, TRUE, 3 },
+ { "^SYSINFO:2,4,5,3,1,0,3", 2, 4, 5, 3, 1, TRUE, 3 },
+ { "^SYSINFO: 2,4,5,3,1,0,3", 2, 4, 5, 3, 1, TRUE, 3 },
+ { NULL, 0, 0, 0, 0, 0, FALSE, 0 }
+};
+
+static void
+test_sysinfo (void)
+{
+ guint i;
+
+ for (i = 0; sysinfo_tests[i].str; i++) {
+ GError *error = NULL;
+ guint srv_status = 0;
+ guint srv_domain = 0;
+ guint roam_status = 0;
+ guint sys_mode = 0;
+ guint sim_state = 0;
+ gboolean sys_submode_valid = FALSE;
+ guint sys_submode = 0;
+
+ g_assert (mm_huawei_parse_sysinfo_response (sysinfo_tests[i].str,
+ &srv_status,
+ &srv_domain,
+ &roam_status,
+ &sys_mode,
+ &sim_state,
+ &sys_submode_valid,
+ &sys_submode,
+ &error) == TRUE);
+ g_assert_no_error (error);
+
+ g_assert (srv_status == sysinfo_tests[i].expected_srv_status);
+ g_assert (srv_domain == sysinfo_tests[i].expected_srv_domain);
+ g_assert (roam_status == sysinfo_tests[i].expected_roam_status);
+ g_assert (sys_mode == sysinfo_tests[i].expected_sys_mode);
+ g_assert (sim_state == sysinfo_tests[i].expected_sim_state);
+ g_assert (sys_submode_valid == sysinfo_tests[i].expected_sys_submode_valid);
+ if (sys_submode_valid)
+ g_assert (sys_submode == sysinfo_tests[i].expected_sys_submode);
+ }
+}
+
+/*****************************************************************************/
int main (int argc, char **argv)
{
@@ -138,6 +201,7 @@ int main (int argc, char **argv)
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/MM/huawei/ndisstatqry", test_ndisstatqry);
+ g_test_add_func ("/MM/huawei/sysinfo", test_sysinfo);
return g_test_run ();
}