Files
ModemManager/plugins/huawei/tests/test-modem-helpers-huawei.c
T
Aleksander Morgado 663d496968 huawei: improve ^NDISSTATQRY parser for newer firmware
Newer firmware for Huawei devices will not split the IPv4 and IPv6 info in
different lines for the ^NDISSTATQRY reply; instead they will be included in the
same line. E.g. instead of

     ^NDISSTATQRY: 1,,,IPV4
     ^NDISSTATQRY: 0,33,,IPV6
     OK

We may have:

     ^NDISSTATQRY:0,,,"IPV4",0,33,,"IPV6"

Also note the optional spaces after the ':', and that in the new version the
strings are enclosed in double quotes.

https://bugzilla.gnome.org/show_bug.cgi?id=705339
2013-08-15 19:09:51 +02:00

112 lines
4.4 KiB
C

/* -*- 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) 2013 Aleksander Morgado <aleksander@gnu.org>
*/
#include <glib.h>
#include <glib-object.h>
#include <locale.h>
#include "mm-modem-helpers-huawei.h"
/*****************************************************************************/
/* Test ^NDISSTATQRY responses */
typedef struct {
const gchar *str;
gboolean expected_ipv4_available;
gboolean expected_ipv4_connected;
gboolean expected_ipv6_available;
gboolean expected_ipv6_connected;
} NdisstatqryTest;
static const NdisstatqryTest ndisstatqry_tests[] = {
{ "^NDISSTATQRY: 1,,,IPV4\r\n", TRUE, TRUE, FALSE, FALSE },
{ "^NDISSTATQRY: 0,,,IPV4\r\n", TRUE, FALSE, FALSE, FALSE },
{ "^NDISSTATQRY: 1,,,IPV6\r\n", FALSE, FALSE, TRUE, TRUE },
{ "^NDISSTATQRY: 0,,,IPV6\r\n", FALSE, FALSE, TRUE, FALSE },
{ "^NDISSTATQRY: 1,,,IPV4\r\n"
"^NDISSTATQRY: 1,,,IPV6\r\n", TRUE, TRUE, TRUE, TRUE },
{ "^NDISSTATQRY: 1,,,IPV4\r\n"
"^NDISSTATQRY: 0,,,IPV6\r\n", TRUE, TRUE, TRUE, FALSE },
{ "^NDISSTATQRY: 0,,,IPV4\r\n"
"^NDISSTATQRY: 1,,,IPV6\r\n", TRUE, FALSE, TRUE, TRUE },
{ "^NDISSTATQRY: 0,,,IPV4\r\n"
"^NDISSTATQRY: 0,,,IPV6\r\n", TRUE, FALSE, TRUE, FALSE },
{ "^NDISSTATQRY: 1,,,IPV4", TRUE, TRUE, FALSE, FALSE },
{ "^NDISSTATQRY: 0,,,IPV4", TRUE, FALSE, FALSE, FALSE },
{ "^NDISSTATQRY: 1,,,IPV6", FALSE, FALSE, TRUE, TRUE },
{ "^NDISSTATQRY: 0,,,IPV6", FALSE, FALSE, TRUE, FALSE },
{ "^NDISSTATQRY: 1,,,IPV4\r\n"
"^NDISSTATQRY: 1,,,IPV6", TRUE, TRUE, TRUE, TRUE },
{ "^NDISSTATQRY: 1,,,IPV4\r\n"
"^NDISSTATQRY: 0,,,IPV6", TRUE, TRUE, TRUE, FALSE },
{ "^NDISSTATQRY: 0,,,IPV4\r\n"
"^NDISSTATQRY: 1,,,IPV6", TRUE, FALSE, TRUE, TRUE },
{ "^NDISSTATQRY: 0,,,IPV4\r\n"
"^NDISSTATQRY: 0,,,IPV6", TRUE, FALSE, TRUE, FALSE },
{ "^NDISSTATQRY: 1,,,\"IPV4\",1,,,\"IPV6\"", TRUE, TRUE, TRUE, TRUE },
{ "^NDISSTATQRY: 1,,,\"IPV4\",0,,,\"IPV6\"", TRUE, TRUE, TRUE, FALSE },
{ "^NDISSTATQRY: 0,,,\"IPV4\",1,,,\"IPV6\"", TRUE, FALSE, TRUE, TRUE },
{ "^NDISSTATQRY: 0,,,\"IPV4\",0,,,\"IPV6\"", TRUE, FALSE, TRUE, FALSE },
{ "^NDISSTATQRY: 1,,,\"IPV4\",1,,,\"IPV6\"\r\n", TRUE, TRUE, TRUE, TRUE },
{ "^NDISSTATQRY: 1,,,\"IPV4\",0,,,\"IPV6\"\r\n", TRUE, TRUE, TRUE, FALSE },
{ "^NDISSTATQRY: 0,,,\"IPV4\",1,,,\"IPV6\"\r\n", TRUE, FALSE, TRUE, TRUE },
{ "^NDISSTATQRY: 0,,,\"IPV4\",0,,,\"IPV6\"\r\n", TRUE, FALSE, TRUE, FALSE },
{ NULL, FALSE, FALSE, FALSE, FALSE }
};
static void
test_ndisstatqry (void)
{
guint i;
for (i = 0; ndisstatqry_tests[i].str; i++) {
GError *error = NULL;
gboolean ipv4_available;
gboolean ipv4_connected;
gboolean ipv6_available;
gboolean ipv6_connected;
g_assert (mm_huawei_parse_ndisstatqry_response (
ndisstatqry_tests[i].str,
&ipv4_available,
&ipv4_connected,
&ipv6_available,
&ipv6_connected,
&error) == TRUE);
g_assert_no_error (error);
g_assert (ipv4_available == ndisstatqry_tests[i].expected_ipv4_available);
if (ipv4_available)
g_assert (ipv4_connected == ndisstatqry_tests[i].expected_ipv4_connected);
g_assert (ipv6_available == ndisstatqry_tests[i].expected_ipv6_available);
if (ipv6_available)
g_assert (ipv6_connected == ndisstatqry_tests[i].expected_ipv6_connected);
}
}
/*****************************************************************************/
int main (int argc, char **argv)
{
setlocale (LC_ALL, "");
g_type_init ();
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/MM/huawei/ndisstatqry", test_ndisstatqry);
return g_test_run ();
}