diff options
Diffstat (limited to 'plugins/ublox/tests/test-modem-helpers-ublox.c')
-rw-r--r-- | plugins/ublox/tests/test-modem-helpers-ublox.c | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/plugins/ublox/tests/test-modem-helpers-ublox.c b/plugins/ublox/tests/test-modem-helpers-ublox.c new file mode 100644 index 00000000..17b6ba22 --- /dev/null +++ b/plugins/ublox/tests/test-modem-helpers-ublox.c @@ -0,0 +1,101 @@ +/* -*- 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 <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-ublox.h" + +/*****************************************************************************/ +/* Test UUSBCONF? responses */ + +typedef struct { + const gchar *str; + MMUbloxUsbProfile profile; +} UusbconfResponseTest; + +static const UusbconfResponseTest uusbconf_response_tests[] = { + { + .str = "+UUSBCONF: 3,\"RNDIS\",,\"0x1146\"\r\n", + .profile = MM_UBLOX_USB_PROFILE_RNDIS + }, + { + .str = "+UUSBCONF: 2,\"ECM\",,\"0x1143\"\r\n", + .profile = MM_UBLOX_USB_PROFILE_ECM + }, + { + .str = "+UUSBCONF: 0,\"\",,\"0x1141\"\r\n", + .profile = MM_UBLOX_USB_PROFILE_BACK_COMPATIBLE + }, +}; + +static void +test_uusbconf_response (void) +{ + guint i; + + for (i = 0; i < G_N_ELEMENTS (uusbconf_response_tests); i++) { + MMUbloxUsbProfile profile = MM_UBLOX_USB_PROFILE_UNKNOWN; + GError *error = NULL; + gboolean success; + + success = mm_ublox_parse_uusbconf_response (uusbconf_response_tests[i].str, &profile, &error); + g_assert_no_error (error); + g_assert (success); + g_assert_cmpuint (uusbconf_response_tests[i].profile, ==, profile); + } +} + +/*****************************************************************************/ + +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/ublox/uusbconf/response", test_uusbconf_response); + + return g_test_run (); +} |