diff options
author | Lubomir Rintel <lkundrak@v3.sk> | 2019-08-12 12:42:10 +0200 |
---|---|---|
committer | Lubomir Rintel <lkundrak@v3.sk> | 2019-09-11 14:32:05 +0200 |
commit | 6e5385a4ebba29d17446239030a1ca1d0dd51898 (patch) | |
tree | 78ba8cb9f84bd9dad12612141f37a4519fa8ba21 | |
parent | 6632c7709492182c795895c7d32ce2542a8d9e9a (diff) | |
download | NetworkManager-6e5385a4ebba29d17446239030a1ca1d0dd51898.tar.gz |
wwan/tests: test service-providers.xml parser
Just a handful of unit tests.
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile.am | 26 | ||||
-rw-r--r-- | src/devices/wwan/meson.build | 8 | ||||
-rw-r--r-- | src/devices/wwan/tests/meson.build | 13 | ||||
-rw-r--r-- | src/devices/wwan/tests/test-service-providers.c | 124 | ||||
-rw-r--r-- | src/devices/wwan/tests/test-service-providers.xml | 73 |
6 files changed, 243 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore index d74b40c08d..55e8317e31 100644 --- a/.gitignore +++ b/.gitignore @@ -209,6 +209,7 @@ test-*.trs /src/devices/tests/test-acd /src/devices/tests/test-lldp /src/devices/wifi/tests/test-devices-wifi +/src/devices/wwan/tests/test-service-providers /src/dhcp/nm-dhcp-helper /src/dhcp/tests/test-dhcp-dhclient /src/dhcp/tests/test-dhcp-options diff --git a/Makefile.am b/Makefile.am index aea13af505..7eb6a82674 100644 --- a/Makefile.am +++ b/Makefile.am @@ -3367,11 +3367,35 @@ check-local-devices-wwan: src/devices/wwan/libnm-device-plugin-wwan.la src/devic check_local += check-local-devices-wwan +src_devices_wwan_tests_test_service_providers_SOURCES = \ + src/devices/wwan/tests/test-service-providers.c \ + src/devices/wwan/nm-service-providers.c \ + src/devices/wwan/nm-service-providers.h \ + $(NULL) + +src_devices_wwan_tests_test_service_providers_CPPFLAGS = \ + $(src_cppflags_base_test) \ + -I$(srcdir)/src/devices/wwan \ + $(NULL) + +src_devices_wwan_tests_test_service_providers_LDFLAGS = \ + $(SANITIZER_EXEC_LDFLAGS) \ + $(NULL) + +src_devices_wwan_tests_test_service_providers_LDADD = \ + src/libNetworkManagerTest.la \ + $(GLIB_LIBS) \ + $(NULL) + +check_programs += src/devices/wwan/tests/test-service-providers + endif EXTRA_DIST += \ src/devices/wwan/libnm-wwan.ver \ - src/devices/wwan/meson.build + src/devices/wwan/meson.build \ + src/devices/wwan/tests/test-service-providers.xml \ + $(NULL) ############################################################################### # src/devices/bluetooth diff --git a/src/devices/wwan/meson.build b/src/devices/wwan/meson.build index 7f28265f81..363e522bf1 100644 --- a/src/devices/wwan/meson.build +++ b/src/devices/wwan/meson.build @@ -29,8 +29,10 @@ libnm_wwan = shared_module( install_dir: nm_plugindir, ) +wwan_inc = include_directories('.') + libnm_wwan_dep = declare_dependency( - include_directories: include_directories('.'), + include_directories: wwan_inc, link_with: libnm_wwan, ) @@ -75,3 +77,7 @@ check-local-devices-wwan: src/devices/wwan/libnm-device-plugin-wwan.la src/devic $(srcdir)/tools/check-exports.sh $(builddir)/src/devices/wwan/.libs/libnm-wwan.so "$(srcdir)/src/devices/wwan/libnm-wwan.ver" $(call check_so_symbols,$(builddir)/src/devices/wwan/.libs/libnm-wwan.so) ''' + +if enable_tests + subdir('tests') +endif diff --git a/src/devices/wwan/tests/meson.build b/src/devices/wwan/tests/meson.build new file mode 100644 index 0000000000..64dd76742a --- /dev/null +++ b/src/devices/wwan/tests/meson.build @@ -0,0 +1,13 @@ +exe = executable( + 'test-service-providers', + sources: files('test-service-providers.c', + '../nm-service-providers.c'), + dependencies: test_nm_dep, + include_directories: wwan_inc, +) +test( + 'wwan/test-service-providers', + test_script, + timeout: default_test_timeout, + args: test_args + [exe.full_path()], +) diff --git a/src/devices/wwan/tests/test-service-providers.c b/src/devices/wwan/tests/test-service-providers.c new file mode 100644 index 0000000000..33402cd52c --- /dev/null +++ b/src/devices/wwan/tests/test-service-providers.c @@ -0,0 +1,124 @@ +// SPDX-License-Identifier: LGPL-2.1+ +/* + * Copyright (C) 2019 Red Hat + */ + +#include "nm-default.h" + +#include "nm-service-providers.h" + +#include "nm-test-utils-core.h" + +static void +test_positive_cb (const char *apn, + const char *username, + const char *password, + const char *gateway, + const char *auth_method, + const GSList *dns, + GError *error, + gpointer user_data) +{ + GMainLoop *loop = user_data; + + g_main_loop_quit (loop); + g_assert_no_error (error); + g_assert_cmpstr (apn, ==, "gprs.example.com"); + g_assert_cmpstr (username, ==, "praise"); + g_assert_cmpstr (password, ==, "santa"); + g_assert_cmpstr (gateway, ==, "192.0.2.3"); + g_assert_cmpstr (auth_method, ==, "pap"); + + g_assert_nonnull (dns); + g_assert_cmpstr (dns->data, ==, "192.0.2.2"); + dns = dns->next; + g_assert_nonnull (dns); + g_assert_cmpstr (dns->data, ==, "192.0.2.1"); + g_assert_null (dns->next); +} + +static void +test_positive (void) +{ + GMainLoop *loop = g_main_loop_new (NULL, FALSE); + + nm_service_providers_find_gsm_apn (NM_BUILD_SRCDIR"/src/devices/wwan/tests/test-service-providers.xml", + "13337", NULL, test_positive_cb, loop); + g_main_loop_run (loop); + g_main_loop_unref (loop); +} + +/*****************************************************************************/ + +static void +test_negative_cb (const char *apn, + const char *username, + const char *password, + const char *gateway, + const char *auth_method, + const GSList *dns, + GError *error, + gpointer user_data) +{ + GMainLoop *loop = user_data; + + g_main_loop_quit (loop); + g_assert_error (error, NM_UTILS_ERROR, NM_UTILS_ERROR_UNKNOWN); +} + +static void +test_negative (void) +{ + GMainLoop *loop = g_main_loop_new (NULL, FALSE); + + nm_service_providers_find_gsm_apn (NM_BUILD_SRCDIR"/src/devices/wwan/tests/test-service-providers.xml", + "78130", NULL, test_negative_cb, loop); + g_main_loop_run (loop); + g_main_loop_unref (loop); +} + +/*****************************************************************************/ + +static void +test_nonexistent_cb (const char *apn, + const char *username, + const char *password, + const char *gateway, + const char *auth_method, + const GSList *dns, + GError *error, + gpointer user_data) +{ + GMainLoop *loop = user_data; + + g_main_loop_quit (loop); + g_assert_error (error, G_IO_ERROR, G_IO_ERROR_AGAIN); +} + +static void +test_nonexistent (void) +{ + GMainLoop *loop = g_main_loop_new (NULL, FALSE); + + nm_service_providers_find_gsm_apn ("nonexistent.xml", "13337", NULL, + test_nonexistent_cb, loop); + g_main_loop_run (loop); + g_main_loop_unref (loop); +} + +/*****************************************************************************/ + +NMTST_DEFINE (); + +int +main (int argc, char **argv) +{ + nmtst_init_assert_logging (&argc, &argv, "INFO", "DEFAULT"); + + g_test_add_func ("/service-providers/positive", test_positive); + g_test_add_func ("/service-providers/negative", test_negative); + g_test_add_func ("/service-providers/nonexistent", test_nonexistent); + + return g_test_run (); +} + diff --git a/src/devices/wwan/tests/test-service-providers.xml b/src/devices/wwan/tests/test-service-providers.xml new file mode 100644 index 0000000000..f0ca2debce --- /dev/null +++ b/src/devices/wwan/tests/test-service-providers.xml @@ -0,0 +1,73 @@ +<?xml version="1.0" encoding='utf-8'?> +<!DOCTYPE serviceproviders SYSTEM "serviceproviders.2.dtd"> + +<serviceproviders format="2.0"> + +<country code="feh"> + <provider> + <name>Sophia</name> + <gsm> + <network-id mcc="666" mnc="999"/> + <apn value="access.example.com"> + <plan type="postpaid"/> + <usage type="internet"/> + <name>APN</name> + <dns>192.0.2.1</dns> + <dns>192.0.2.2</dns> + </apn> + </gsm> + </provider> +</country> + +<country code="meh"> + <provider> + <name>Demiurge</name> + <gsm> + <network-id mcc="133" mnc="37"/> + <network-id mcc="133" mnc="666"/> + <apn value="mms"> + <usage type="mms"/> + <name>Unsolicited Nudes MMS</name> + <username>mms</username> + <password>mms</password> + <mmsc>http://mms.example.com/</mmsc> + <mmsproxy>192.0.2.1:8080</mmsproxy> + </apn> + <apn value="gprs.example.com"> + <plan type="postpaid"/> + <usage type="internet"/> + <name>GPRS</name> + <username>praise</username> + <password>santa</password> + <dns>192.0.2.1</dns> + <dns>192.0.2.2</dns> + <gateway>192.0.2.3</gateway> + <authentication method="pap"/> + </apn> + <apn value="second.example.com"> + <plan type="postpaid"/> + <usage type="internet"/> + <name>Second</name> + <username>worship</username> + <password>doom</password> + </apn> + </gsm> + </provider> + + <provider> + <name>Personal</name> + <gsm> + <network-id mcc="666" mnc="999"/> + <apn value="access.example.com"> + <plan type="postpaid"/> + <usage type="internet"/> + <name>APN</name> + <dns>192.0.2.1</dns> + <dns>192.0.2.2</dns> + </apn> + </gsm> + </provider> +</country> + +</serviceproviders> + |