diff options
author | Aleksander Morgado <aleksander@aleksander.es> | 2018-10-09 10:50:03 +0200 |
---|---|---|
committer | Dan Williams <dcbw@redhat.com> | 2018-10-09 14:34:59 +0000 |
commit | fa67a4f9bb014c947a9bb1c5f207ea787c8976b7 (patch) | |
tree | 20df8ae73356c74a6530448bfe549ce27364c802 /plugins/sierra/tests | |
parent | c7d5902c15957d1487c83f13614b155a18b5f2b6 (diff) |
sierra-legacy: implement connection status monitoring with !SCACT?
Devices like the Netgear AC313U require explicit context monitoring,
otherwise the device may end up disconnected internally and MM would
still think that the connection is ongoing.
Diffstat (limited to 'plugins/sierra/tests')
-rw-r--r-- | plugins/sierra/tests/test-modem-helpers-sierra.c | 150 |
1 files changed, 150 insertions, 0 deletions
diff --git a/plugins/sierra/tests/test-modem-helpers-sierra.c b/plugins/sierra/tests/test-modem-helpers-sierra.c new file mode 100644 index 00000000..a53f27e1 --- /dev/null +++ b/plugins/sierra/tests/test-modem-helpers-sierra.c @@ -0,0 +1,150 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details: + * + * Copyright (C) 2018 Aleksander Morgado <aleksander@aleksander.es> + */ + +#include <glib.h> +#include <glib-object.h> +#include <locale.h> +#include <arpa/inet.h> + +#include <ModemManager.h> +#define _LIBMM_INSIDE_MM +#include <libmm-glib.h> + +#include "mm-log.h" +#include "mm-modem-helpers.h" +#include "mm-modem-helpers-sierra.h" + +/*****************************************************************************/ +/* Test !SCACT? responses */ + +static void +test_scact_read_results (const gchar *desc, + const gchar *reply, + MM3gppPdpContextActive *expected_results, + guint32 expected_results_len) +{ + GList *l; + GError *error = NULL; + GList *results; + + g_debug ("\nTesting %s !SCACT response...\n", desc); + + results = mm_sierra_parse_scact_read_response (reply, &error); + g_assert_no_error (error); + if (expected_results_len) { + g_assert (results); + g_assert_cmpuint (g_list_length (results), ==, expected_results_len); + } + + for (l = results; l; l = g_list_next (l)) { + MM3gppPdpContextActive *pdp = l->data; + gboolean found = FALSE; + guint i; + + for (i = 0; !found && i < expected_results_len; i++) { + MM3gppPdpContextActive *expected; + + expected = &expected_results[i]; + if (pdp->cid == expected->cid) { + found = TRUE; + g_assert_cmpuint (pdp->active, ==, expected->active); + } + } + + g_assert (found == TRUE); + } + + mm_3gpp_pdp_context_active_list_free (results); +} + +static void +test_scact_read_response_none (void) +{ + test_scact_read_results ("none", "", NULL, 0); +} + +static void +test_scact_read_response_single_inactive (void) +{ + const gchar *reply = "!SCACT: 1,0\r\n"; + static MM3gppPdpContextActive expected[] = { + { 1, FALSE }, + }; + + test_scact_read_results ("single inactive", reply, &expected[0], G_N_ELEMENTS (expected)); +} + +static void +test_scact_read_response_single_active (void) +{ + const gchar *reply = "!SCACT: 1,1\r\n"; + static MM3gppPdpContextActive expected[] = { + { 1, TRUE }, + }; + + test_scact_read_results ("single active", reply, &expected[0], G_N_ELEMENTS (expected)); +} + +static void +test_scact_read_response_multiple (void) +{ + const gchar *reply = + "!SCACT: 1,0\r\n" + "!SCACT: 4,1\r\n" + "!SCACT: 5,0\r\n"; + static MM3gppPdpContextActive expected[] = { + { 1, FALSE }, + { 4, TRUE }, + { 5, FALSE }, + }; + + test_scact_read_results ("multiple", reply, &expected[0], G_N_ELEMENTS (expected)); +} + +/*****************************************************************************/ + +void +_mm_log (const char *loc, + const char *func, + guint32 level, + const char *fmt, + ...) +{ +#if defined ENABLE_TEST_MESSAGE_TRACES + /* Dummy log function */ + va_list args; + gchar *msg; + + va_start (args, fmt); + msg = g_strdup_vprintf (fmt, args); + va_end (args); + g_print ("%s\n", msg); + g_free (msg); +#endif +} + +int main (int argc, char **argv) +{ + setlocale (LC_ALL, ""); + + g_test_init (&argc, &argv, NULL); + + g_test_add_func ("/MM/sierra/scact/read/none", test_scact_read_response_none); + g_test_add_func ("/MM/sierra/scact/read/single-inactive", test_scact_read_response_single_inactive); + g_test_add_func ("/MM/sierra/scact/read/single-active", test_scact_read_response_single_active); + g_test_add_func ("/MM/sierra/scact/read/multiple", test_scact_read_response_multiple); + + return g_test_run (); +} |