diff options
author | Aleksander Morgado <aleksander@aleksander.es> | 2016-10-11 17:49:43 +0200 |
---|---|---|
committer | Aleksander Morgado <aleksander@aleksander.es> | 2016-10-12 11:29:52 +0200 |
commit | d7fdda224765e8ea9c1b4713dfa3708f2251b8c3 (patch) | |
tree | 974af01fff06af2cde17d0018d6cce14b112890f /plugins/linktop/tests/test-modem-helpers-linktop.c | |
parent | 74fd7da774c3a4c644106618499d68eb92a95baf (diff) |
linktop: new Linktop specific +CFUN? response parser
We handle all known CFUN? response values in the new parser, and report an error
if an unknown value is found.
Diffstat (limited to 'plugins/linktop/tests/test-modem-helpers-linktop.c')
-rw-r--r-- | plugins/linktop/tests/test-modem-helpers-linktop.c | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/plugins/linktop/tests/test-modem-helpers-linktop.c b/plugins/linktop/tests/test-modem-helpers-linktop.c new file mode 100644 index 00000000..3a5797e7 --- /dev/null +++ b/plugins/linktop/tests/test-modem-helpers-linktop.c @@ -0,0 +1,94 @@ +/* -*- 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) 2016 Aleksander Morgado <aleksander@aleksander.es> + */ + +#include <glib.h> +#include <glib-object.h> +#include <locale.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-linktop.h" + +/* #define ENABLE_TEST_MESSAGE_TRACES */ + +/*****************************************************************************/ + +typedef struct { + const gchar *str; + MMModemMode allowed; +} CfunQueryCurrentModeTest; + +static const CfunQueryCurrentModeTest cfun_query_current_mode_tests[] = { + { "+CFUN: 0", MM_MODEM_MODE_NONE }, + { "+CFUN: 1", MM_MODEM_MODE_2G | MM_MODEM_MODE_3G }, + { "+CFUN: 4", MM_MODEM_MODE_NONE }, + { "+CFUN: 5", MM_MODEM_MODE_2G }, + { "+CFUN: 6", MM_MODEM_MODE_3G }, +}; + +static void +test_cfun_query_current_modes (void) +{ + guint i; + + for (i = 0; i < G_N_ELEMENTS (cfun_query_current_mode_tests); i++) { + GError *error = NULL; + gboolean success; + MMModemMode allowed = MM_MODEM_MODE_NONE; + + success = mm_linktop_parse_cfun_query_current_modes (cfun_query_current_mode_tests[i].str, &allowed, &error); + g_assert_no_error (error); + g_assert (success); + g_assert_cmpuint (cfun_query_current_mode_tests[i].allowed, ==, allowed); + } +} + +/*****************************************************************************/ + +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_type_init (); + g_test_init (&argc, &argv, NULL); + + g_test_add_func ("/MM/linktop/cfun/query/current-modes", test_cfun_query_current_modes); + + return g_test_run (); +} |