diff options
Diffstat (limited to 'libnm-glib/tests')
| -rw-r--r-- | libnm-glib/tests/Makefile.am | 13 | ||||
| -rw-r--r-- | libnm-glib/tests/Makefile.in | 60 | ||||
| -rw-r--r-- | libnm-glib/tests/common.c | 121 | ||||
| -rw-r--r-- | libnm-glib/tests/common.h | 31 | ||||
| -rw-r--r-- | libnm-glib/tests/test-nm-client.c | 366 | ||||
| -rw-r--r-- | libnm-glib/tests/test-remote-settings-client.c | 35 |
6 files changed, 372 insertions, 254 deletions
diff --git a/libnm-glib/tests/Makefile.am b/libnm-glib/tests/Makefile.am index aeaaa6b6..a1b25f62 100644 --- a/libnm-glib/tests/Makefile.am +++ b/libnm-glib/tests/Makefile.am @@ -1,11 +1,12 @@ if ENABLE_TESTS AM_CPPFLAGS = \ - -I$(top_srcdir)/include \ - -I$(top_builddir)/include \ + -I$(top_srcdir)/shared \ + -I$(top_builddir)/shared \ -I$(top_srcdir)/libnm-util \ -I$(top_builddir)/libnm-util \ -I$(top_srcdir)/libnm-glib \ + -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_LIB_LEGACY \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ -DTEST_NM_SERVICE=\"$(abs_top_srcdir)/tools/test-networkmanager-service.py\" \ $(GLIB_CFLAGS) \ @@ -23,8 +24,8 @@ TESTS = test-nm-client test-remote-settings-client ####### NMClient and non-settings tests ####### test_nm_client_SOURCES = \ - common.c \ - common.h \ + $(top_builddir)/shared/nm-test-utils-impl.c \ + $(top_builddir)/shared/nm-test-libnm-utils.h \ test-nm-client.c test_nm_client_LDADD = \ @@ -36,8 +37,8 @@ test_nm_client_LDADD = \ ####### remote settings client test ####### test_remote_settings_client_SOURCES = \ - common.c \ - common.h \ + $(top_builddir)/shared/nm-test-utils-impl.c \ + $(top_builddir)/shared/nm-test-libnm-utils.h \ test-remote-settings-client.c test_remote_settings_client_LDADD = \ diff --git a/libnm-glib/tests/Makefile.in b/libnm-glib/tests/Makefile.in index ab088a30..8d7e6dea 100644 --- a/libnm-glib/tests/Makefile.in +++ b/libnm-glib/tests/Makefile.in @@ -116,8 +116,11 @@ CONFIG_CLEAN_VPATH_FILES = @ENABLE_TESTS_TRUE@am__EXEEXT_1 = test-nm-client$(EXEEXT) \ @ENABLE_TESTS_TRUE@ test-remote-settings-client$(EXEEXT) PROGRAMS = $(noinst_PROGRAMS) -am__test_nm_client_SOURCES_DIST = common.c common.h test-nm-client.c -@ENABLE_TESTS_TRUE@am_test_nm_client_OBJECTS = common.$(OBJEXT) \ +am__test_nm_client_SOURCES_DIST = \ + $(top_builddir)/shared/nm-test-utils-impl.c \ + $(top_builddir)/shared/nm-test-libnm-utils.h test-nm-client.c +@ENABLE_TESTS_TRUE@am_test_nm_client_OBJECTS = \ +@ENABLE_TESTS_TRUE@ nm-test-utils-impl.$(OBJEXT) \ @ENABLE_TESTS_TRUE@ test-nm-client.$(OBJEXT) test_nm_client_OBJECTS = $(am_test_nm_client_OBJECTS) am__DEPENDENCIES_1 = @@ -129,10 +132,12 @@ AM_V_lt = $(am__v_lt_@AM_V@) am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) am__v_lt_0 = --silent am__v_lt_1 = -am__test_remote_settings_client_SOURCES_DIST = common.c common.h \ +am__test_remote_settings_client_SOURCES_DIST = \ + $(top_builddir)/shared/nm-test-utils-impl.c \ + $(top_builddir)/shared/nm-test-libnm-utils.h \ test-remote-settings-client.c @ENABLE_TESTS_TRUE@am_test_remote_settings_client_OBJECTS = \ -@ENABLE_TESTS_TRUE@ common.$(OBJEXT) \ +@ENABLE_TESTS_TRUE@ nm-test-utils-impl.$(OBJEXT) \ @ENABLE_TESTS_TRUE@ test-remote-settings-client.$(OBJEXT) test_remote_settings_client_OBJECTS = \ $(am_test_remote_settings_client_OBJECTS) @@ -424,7 +429,6 @@ BLUEZ5_LIBS = @BLUEZ5_LIBS@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ -CKDB_PATH = @CKDB_PATH@ CODE_COVERAGE_CFLAGS = @CODE_COVERAGE_CFLAGS@ CODE_COVERAGE_ENABLED = @CODE_COVERAGE_ENABLED@ CODE_COVERAGE_LDFLAGS = @CODE_COVERAGE_LDFLAGS@ @@ -436,8 +440,6 @@ CXXDEPMODE = @CXXDEPMODE@ CXXFLAGS = @CXXFLAGS@ CYGPATH_W = @CYGPATH_W@ DBUS_CFLAGS = @DBUS_CFLAGS@ -DBUS_GLIB_100_CFLAGS = @DBUS_GLIB_100_CFLAGS@ -DBUS_GLIB_100_LIBS = @DBUS_GLIB_100_LIBS@ DBUS_LIBS = @DBUS_LIBS@ DBUS_SYS_DIR = @DBUS_SYS_DIR@ DEFS = @DEFS@ @@ -447,6 +449,7 @@ DHCPCD_PATH = @DHCPCD_PATH@ DISTRO_NETWORK_SERVICE = @DISTRO_NETWORK_SERVICE@ DLLTOOL = @DLLTOOL@ DNSMASQ_PATH = @DNSMASQ_PATH@ +DNSSEC_TRIGGER_SCRIPT = @DNSSEC_TRIGGER_SCRIPT@ DSYMUTIL = @DSYMUTIL@ DUMPBIN = @DUMPBIN@ ECHO_C = @ECHO_C@ @@ -501,16 +504,13 @@ INTROSPECTION_MAKEFILE = @INTROSPECTION_MAKEFILE@ INTROSPECTION_SCANNER = @INTROSPECTION_SCANNER@ INTROSPECTION_TYPELIBDIR = @INTROSPECTION_TYPELIBDIR@ IPTABLES_PATH = @IPTABLES_PATH@ -IWMX_SDK_CFLAGS = @IWMX_SDK_CFLAGS@ -IWMX_SDK_LIBS = @IWMX_SDK_LIBS@ KERNEL_FIRMWARE_DIR = @KERNEL_FIRMWARE_DIR@ LCOV = @LCOV@ LD = @LD@ LDFLAGS = @LDFLAGS@ +LIBAUDIT_CFLAGS = @LIBAUDIT_CFLAGS@ +LIBAUDIT_LIBS = @LIBAUDIT_LIBS@ LIBDL = @LIBDL@ -LIBGCRYPT_CFLAGS = @LIBGCRYPT_CFLAGS@ -LIBGCRYPT_CONFIG = @LIBGCRYPT_CONFIG@ -LIBGCRYPT_LIBS = @LIBGCRYPT_LIBS@ LIBICONV = @LIBICONV@ LIBINTL = @LIBINTL@ LIBM = @LIBM@ @@ -547,6 +547,8 @@ NEWT_LIBS = @NEWT_LIBS@ NM = @NM@ NMEDIT = @NMEDIT@ NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT = @NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT@ +NM_CONFIG_DEFAULT_LOGGING_AUDIT_TEXT = @NM_CONFIG_DEFAULT_LOGGING_AUDIT_TEXT@ +NM_CONFIG_LOGGING_BACKEND_DEFAULT_TEXT = @NM_CONFIG_LOGGING_BACKEND_DEFAULT_TEXT@ NM_MAJOR_VERSION = @NM_MAJOR_VERSION@ NM_MICRO_VERSION = @NM_MICRO_VERSION@ NM_MINOR_VERSION = @NM_MINOR_VERSION@ @@ -575,7 +577,6 @@ POLKIT_LIBS = @POLKIT_LIBS@ POSUB = @POSUB@ PPPD_PATH = @PPPD_PATH@ PPPD_PLUGIN_DIR = @PPPD_PLUGIN_DIR@ -PPPOE_PATH = @PPPOE_PATH@ QT_CFLAGS = @QT_CFLAGS@ QT_LIBS = @QT_LIBS@ RANLIB = @RANLIB@ @@ -590,6 +591,8 @@ SYSTEMD_200_CFLAGS = @SYSTEMD_200_CFLAGS@ SYSTEMD_200_LIBS = @SYSTEMD_200_LIBS@ SYSTEMD_INHIBIT_CFLAGS = @SYSTEMD_INHIBIT_CFLAGS@ SYSTEMD_INHIBIT_LIBS = @SYSTEMD_INHIBIT_LIBS@ +SYSTEMD_JOURNAL_CFLAGS = @SYSTEMD_JOURNAL_CFLAGS@ +SYSTEMD_JOURNAL_LIBS = @SYSTEMD_JOURNAL_LIBS@ SYSTEMD_LOGIN_CFLAGS = @SYSTEMD_LOGIN_CFLAGS@ SYSTEMD_LOGIN_LIBS = @SYSTEMD_LOGIN_LIBS@ SYSTEM_CA_PATH = @SYSTEM_CA_PATH@ @@ -650,6 +653,7 @@ mkdir_p = @mkdir_p@ nmbinary = @nmbinary@ nmconfdir = @nmconfdir@ nmdatadir = @nmdatadir@ +nmlibdir = @nmlibdir@ nmrundir = @nmrundir@ nmstatedir = @nmstatedir@ oldincludedir = @oldincludedir@ @@ -657,6 +661,7 @@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ +runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ @@ -673,11 +678,12 @@ with_netconfig = @with_netconfig@ with_resolvconf = @with_resolvconf@ with_valgrind = @with_valgrind@ @ENABLE_TESTS_TRUE@AM_CPPFLAGS = \ -@ENABLE_TESTS_TRUE@ -I$(top_srcdir)/include \ -@ENABLE_TESTS_TRUE@ -I$(top_builddir)/include \ +@ENABLE_TESTS_TRUE@ -I$(top_srcdir)/shared \ +@ENABLE_TESTS_TRUE@ -I$(top_builddir)/shared \ @ENABLE_TESTS_TRUE@ -I$(top_srcdir)/libnm-util \ @ENABLE_TESTS_TRUE@ -I$(top_builddir)/libnm-util \ @ENABLE_TESTS_TRUE@ -I$(top_srcdir)/libnm-glib \ +@ENABLE_TESTS_TRUE@ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_LIB_LEGACY \ @ENABLE_TESTS_TRUE@ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ @ENABLE_TESTS_TRUE@ -DTEST_NM_SERVICE=\"$(abs_top_srcdir)/tools/test-networkmanager-service.py\" \ @ENABLE_TESTS_TRUE@ $(GLIB_CFLAGS) \ @@ -687,8 +693,8 @@ with_valgrind = @with_valgrind@ ####### NMClient and non-settings tests ####### @ENABLE_TESTS_TRUE@test_nm_client_SOURCES = \ -@ENABLE_TESTS_TRUE@ common.c \ -@ENABLE_TESTS_TRUE@ common.h \ +@ENABLE_TESTS_TRUE@ $(top_builddir)/shared/nm-test-utils-impl.c \ +@ENABLE_TESTS_TRUE@ $(top_builddir)/shared/nm-test-libnm-utils.h \ @ENABLE_TESTS_TRUE@ test-nm-client.c @ENABLE_TESTS_TRUE@test_nm_client_LDADD = \ @@ -700,8 +706,8 @@ with_valgrind = @with_valgrind@ ####### remote settings client test ####### @ENABLE_TESTS_TRUE@test_remote_settings_client_SOURCES = \ -@ENABLE_TESTS_TRUE@ common.c \ -@ENABLE_TESTS_TRUE@ common.h \ +@ENABLE_TESTS_TRUE@ $(top_builddir)/shared/nm-test-utils-impl.c \ +@ENABLE_TESTS_TRUE@ $(top_builddir)/shared/nm-test-libnm-utils.h \ @ENABLE_TESTS_TRUE@ test-remote-settings-client.c @ENABLE_TESTS_TRUE@test_remote_settings_client_LDADD = \ @@ -770,7 +776,7 @@ mostlyclean-compile: distclean-compile: -rm -f *.tab.c -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/common.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nm-test-utils-impl.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test-nm-client.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test-remote-settings-client.Po@am__quote@ @@ -795,6 +801,20 @@ distclean-compile: @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $< +nm-test-utils-impl.o: $(top_builddir)/shared/nm-test-utils-impl.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT nm-test-utils-impl.o -MD -MP -MF $(DEPDIR)/nm-test-utils-impl.Tpo -c -o nm-test-utils-impl.o `test -f '$(top_builddir)/shared/nm-test-utils-impl.c' || echo '$(srcdir)/'`$(top_builddir)/shared/nm-test-utils-impl.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/nm-test-utils-impl.Tpo $(DEPDIR)/nm-test-utils-impl.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$(top_builddir)/shared/nm-test-utils-impl.c' object='nm-test-utils-impl.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o nm-test-utils-impl.o `test -f '$(top_builddir)/shared/nm-test-utils-impl.c' || echo '$(srcdir)/'`$(top_builddir)/shared/nm-test-utils-impl.c + +nm-test-utils-impl.obj: $(top_builddir)/shared/nm-test-utils-impl.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT nm-test-utils-impl.obj -MD -MP -MF $(DEPDIR)/nm-test-utils-impl.Tpo -c -o nm-test-utils-impl.obj `if test -f '$(top_builddir)/shared/nm-test-utils-impl.c'; then $(CYGPATH_W) '$(top_builddir)/shared/nm-test-utils-impl.c'; else $(CYGPATH_W) '$(srcdir)/$(top_builddir)/shared/nm-test-utils-impl.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/nm-test-utils-impl.Tpo $(DEPDIR)/nm-test-utils-impl.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$(top_builddir)/shared/nm-test-utils-impl.c' object='nm-test-utils-impl.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o nm-test-utils-impl.obj `if test -f '$(top_builddir)/shared/nm-test-utils-impl.c'; then $(CYGPATH_W) '$(top_builddir)/shared/nm-test-utils-impl.c'; else $(CYGPATH_W) '$(srcdir)/$(top_builddir)/shared/nm-test-utils-impl.c'; fi` + mostlyclean-libtool: -rm -f *.lo diff --git a/libnm-glib/tests/common.c b/libnm-glib/tests/common.c deleted file mode 100644 index f071fb5b..00000000 --- a/libnm-glib/tests/common.c +++ /dev/null @@ -1,121 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; 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, 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. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Copyright 2010 - 2014 Red Hat, Inc. - * - */ - -#include "config.h" - -#include <dbus/dbus.h> -#include <glib.h> -#include <string.h> - -#include "NetworkManager.h" - -#include "common.h" - -static gboolean -name_exists (GDBusConnection *c, const char *name) -{ - GVariant *reply; - gboolean exists = FALSE; - - reply = g_dbus_connection_call_sync (c, - DBUS_SERVICE_DBUS, - DBUS_PATH_DBUS, - DBUS_INTERFACE_DBUS, - "GetNameOwner", - g_variant_new ("(s)", name), - NULL, - G_DBUS_CALL_FLAGS_NO_AUTO_START, - -1, - NULL, - NULL); - if (reply != NULL) { - exists = TRUE; - g_variant_unref (reply); - } - - return exists; -} - -NMTestServiceInfo * -nm_test_service_init (void) -{ - NMTestServiceInfo *info; - const char *args[2] = { TEST_NM_SERVICE, NULL }; - GError *error = NULL; - int i; - - info = g_malloc0 (sizeof (*info)); - - info->bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error); - g_assert_no_error (error); - - /* Spawn the test service. info->keepalive_fd will be a pipe to the service's - * stdin; if it closes, the service will exit immediately. We use this to - * make sure the service exits if the test program crashes. - */ - g_spawn_async_with_pipes (NULL, (char **) args, NULL, 0, NULL, NULL, - &info->pid, &info->keepalive_fd, NULL, NULL, &error); - g_assert_no_error (error); - - /* Wait until the service is registered on the bus */ - for (i = 1000; i > 0; i--) { - if (name_exists (info->bus, "org.freedesktop.NetworkManager")) - break; - g_usleep (G_USEC_PER_SEC / 50); - } - g_assert (i > 0); - - /* Grab a proxy to our fake NM service to trigger tests */ - info->proxy = g_dbus_proxy_new_sync (info->bus, - G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | - G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS | - G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, - NULL, - NM_DBUS_SERVICE, - NM_DBUS_PATH, - "org.freedesktop.NetworkManager.LibnmGlibTest", - NULL, &error); - g_assert_no_error (error); - - return info; -} - -void -nm_test_service_cleanup (NMTestServiceInfo *info) -{ - int i; - - g_object_unref (info->proxy); - kill (info->pid, SIGTERM); - - /* Wait until the bus notices the service is gone */ - for (i = 100; i > 0; i--) { - if (!name_exists (info->bus, "org.freedesktop.NetworkManager")) - break; - g_usleep (G_USEC_PER_SEC / 50); - } - g_assert (i > 0); - - g_object_unref (info->bus); - close (info->keepalive_fd); - - memset (info, 0, sizeof (*info)); - g_free (info); -} diff --git a/libnm-glib/tests/common.h b/libnm-glib/tests/common.h deleted file mode 100644 index 7c49d253..00000000 --- a/libnm-glib/tests/common.h +++ /dev/null @@ -1,31 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2014 Red Hat, Inc. - */ - -#include <gio/gio.h> - -typedef struct { - GDBusConnection *bus; - GDBusProxy *proxy; - GPid pid; - int keepalive_fd; -} NMTestServiceInfo; - -NMTestServiceInfo *nm_test_service_init (void); -void nm_test_service_cleanup (NMTestServiceInfo *info); diff --git a/libnm-glib/tests/test-nm-client.c b/libnm-glib/tests/test-nm-client.c index af3722eb..f528bc26 100644 --- a/libnm-glib/tests/test-nm-client.c +++ b/libnm-glib/tests/test-nm-client.c @@ -23,50 +23,22 @@ #include <dbus/dbus.h> #include <dbus/dbus-glib.h> #include <dbus/dbus-glib-lowlevel.h> -#include <glib.h> #include <string.h> #include <sys/types.h> #include <signal.h> -#include <NetworkManager.h> +#include "nm-default.h" #include "nm-client.h" #include "nm-device-wifi.h" #include "nm-device-ethernet.h" #include "nm-device-wimax.h" -#include "nm-glib-compat.h" +#include "nm-connection.h" +#include "nm-setting.h" -#include "common.h" +#include "nm-test-libnm-utils.h" static GMainLoop *loop = NULL; -static NMTestServiceInfo *sinfo; - -/*******************************************************************/ - -static NMClient * -test_client_new (void) -{ - NMClient *client; - DBusGConnection *bus; - GError *error = NULL; - gboolean success; - - bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error); - g_assert_no_error (error); - - client = g_object_new (NM_TYPE_CLIENT, - NM_OBJECT_DBUS_CONNECTION, bus, - NM_OBJECT_DBUS_PATH, NM_DBUS_PATH, - NULL); - g_assert (client != NULL); - - dbus_g_connection_unref (bus); - - success = g_initable_init (G_INITABLE (client), NULL, &error); - g_assert_no_error (error); - g_assert (success == TRUE); - - return client; -} +static NMTstcServiceInfo *sinfo; /*******************************************************************/ @@ -99,6 +71,29 @@ add_device (const char *method, const char *ifname, char **out_path) return TRUE; } +static gboolean +add_wired_device (const char *method, const char *ifname, char **out_path) +{ + const char *empty[] = { NULL }; + GError *error = NULL; + GVariant *ret; + + ret = g_dbus_proxy_call_sync (sinfo->proxy, + method, + g_variant_new ("(ss^as)", ifname, "/", empty), + G_DBUS_CALL_FLAGS_NO_AUTO_START, + 3000, + NULL, + &error); + g_assert_no_error (error); + g_assert (ret); + g_assert_cmpstr (g_variant_get_type_string (ret), ==, "(o)"); + if (out_path) + g_variant_get (ret, "(o)", out_path); + g_variant_unref (ret); + return TRUE; +} + /*******************************************************************/ typedef struct { @@ -160,14 +155,14 @@ test_device_added (void) NMDevice *device; DeviceAddedInfo info = { loop, FALSE, FALSE, 0, 0 }; - sinfo = nm_test_service_init (); - client = test_client_new (); + sinfo = nmtstc_service_init (); + client = nmtstc_nm_client_new (); devices = nm_client_get_devices (client); g_assert (devices == NULL); /* Tell the test service to add a new device */ - add_device ("AddWiredDevice", "eth0", NULL); + add_wired_device ("AddWiredDevice", "eth0", NULL); g_signal_connect (client, "device-added", @@ -200,7 +195,7 @@ test_device_added (void) g_assert_cmpstr (nm_device_get_iface (device), ==, "eth0"); g_object_unref (client); - g_clear_pointer (&sinfo, nm_test_service_cleanup); + g_clear_pointer (&sinfo, nmtstc_service_cleanup); } /*******************************************************************/ @@ -317,8 +312,8 @@ test_wifi_ap_added_removed (void) GError *error = NULL; char *expected_path = NULL; - sinfo = nm_test_service_init (); - client = test_client_new (); + sinfo = nmtstc_service_init (); + client = nmtstc_nm_client_new (); /*************************************/ /* Add the wifi device */ @@ -423,7 +418,7 @@ test_wifi_ap_added_removed (void) g_free (expected_path); g_object_unref (client); - g_clear_pointer (&sinfo, nm_test_service_cleanup); + g_clear_pointer (&sinfo, nmtstc_service_cleanup); } /*******************************************************************/ @@ -540,8 +535,8 @@ test_wimax_nsp_added_removed (void) GError *error = NULL; char *expected_path = NULL; - sinfo = nm_test_service_init (); - client = test_client_new (); + sinfo = nmtstc_service_init (); + client = nmtstc_nm_client_new (); /*************************************/ /* Add the wimax device */ @@ -646,7 +641,7 @@ test_wimax_nsp_added_removed (void) g_free (expected_path); g_object_unref (client); - g_clear_pointer (&sinfo, nm_test_service_cleanup); + g_clear_pointer (&sinfo, nmtstc_service_cleanup); } /*******************************************************************/ @@ -662,6 +657,7 @@ typedef struct { static void da_check_quit (DaInfo *info) { + g_assert (info->quit_count > 0); info->quit_count--; if (info->quit_count == 0) { g_source_remove (info->quit_id); @@ -724,14 +720,14 @@ test_devices_array (void) GError *error = NULL; GVariant *ret; - sinfo = nm_test_service_init (); - client = test_client_new (); + sinfo = nmtstc_service_init (); + client = nmtstc_nm_client_new (); /*************************************/ /* Add some devices */ add_device ("AddWifiDevice", "wlan0", &paths[0]); - add_device ("AddWiredDevice", "eth0", &paths[1]); - add_device ("AddWiredDevice", "eth1", &paths[2]); + add_wired_device ("AddWiredDevice", "eth0", &paths[1]); + add_wired_device ("AddWiredDevice", "eth1", &paths[2]); info.quit_count = 3; g_signal_connect (client, @@ -808,7 +804,7 @@ test_devices_array (void) g_free (paths[2]); g_object_unref (client); - g_clear_pointer (&sinfo, nm_test_service_cleanup); + g_clear_pointer (&sinfo, nmtstc_service_cleanup); } static void @@ -830,7 +826,7 @@ test_client_manager_running (void) int running_changed = 0; GError *error = NULL; - client1 = test_client_new (); + client1 = nmtstc_nm_client_new (); g_assert (!nm_client_get_manager_running (client1)); g_assert_cmpstr (nm_client_get_version (client1), ==, NULL); @@ -846,8 +842,8 @@ test_client_manager_running (void) g_clear_error (&error); /* Now start the test service. */ - sinfo = nm_test_service_init (); - client2 = test_client_new (); + sinfo = nmtstc_service_init (); + client2 = nmtstc_nm_client_new (); /* client2 should know that NM is running, but the previously-created * client1 hasn't gotten the news yet. @@ -864,7 +860,7 @@ test_client_manager_running (void) g_source_remove (quit_id); /* And kill it */ - g_clear_pointer (&sinfo, nm_test_service_cleanup); + g_clear_pointer (&sinfo, nmtstc_service_cleanup); g_assert (nm_client_get_manager_running (client1)); @@ -880,14 +876,269 @@ test_client_manager_running (void) /*******************************************************************/ +static GPtrArray * +_slist_to_array (GPtrArray **connections, GSList *list) +{ + GPtrArray *array; + const GSList *iter; + + if (!*connections) + *connections = array = g_ptr_array_new (); + else { + array = *connections; + g_ptr_array_set_size (array, 0); + } + for (iter = list; iter; iter = iter->next) + g_ptr_array_add (array, iter->data); + g_slist_free (list); + return array; +} + +static gboolean +_test_connection_invalid_find_connections (gpointer element, gpointer needle, gpointer user_data) +{ + NMRemoteConnection *con = NM_REMOTE_CONNECTION (element); + const char *path = needle; + + g_assert (NM_IS_REMOTE_CONNECTION (con)); + g_assert (path && *path); + + return strcmp (path, nm_connection_get_path ((NMConnection *) con)) == 0; +} + +#define ASSERT_IDX(i) \ + g_assert_cmpint (idx[i], >=, 0); \ + g_assert (path##i && *path##i); \ + g_assert (NM_IS_REMOTE_CONNECTION (connections->pdata[idx[i]])); \ + g_assert_cmpstr (nm_connection_get_path (connections->pdata[idx[i]]), ==, path##i); + +static void +test_connection_invalid (void) +{ + NMTSTC_SERVICE_INFO_SETUP (my_sinfo) + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection *s_con; + gs_unref_object NMRemoteSettings *settings = NULL; + gs_unref_ptrarray GPtrArray *connections = NULL; + gs_free char *path0 = NULL; + gs_free char *path1 = NULL; + gs_free char *path2 = NULL; + gs_free char *uuid2 = NULL; + gsize n_found; + gssize idx[3]; + + /************************************************************************** + * Add two connection before starting libnm. One valid, one invalid. + *************************************************************************/ + + connection = nmtst_create_minimal_connection ("test-connection-invalid-0", NULL, NM_SETTING_WIRED_SETTING_NAME, &s_con); + nmtst_connection_normalize (connection); + g_object_set (s_con, + NM_SETTING_CONNECTION_UUID, nmtst_uuid_generate (), + NULL); + nmtstc_service_add_connection (my_sinfo, + connection, + TRUE, + &path0); + + nm_connection_remove_setting (connection, NM_TYPE_SETTING_WIRED); + g_object_set (s_con, + NM_SETTING_CONNECTION_ID, "test-connection-invalid-1", + NM_SETTING_CONNECTION_TYPE, "invalid-type-1", + NM_SETTING_CONNECTION_UUID, nmtst_uuid_generate (), + NULL); + nmtstc_service_add_connection (my_sinfo, + connection, + FALSE, + &path1); + + nmtst_main_loop_run (loop, 100); + + settings = nmtstc_nm_remote_settings_new (); + + g_test_expect_message ("libnm-glib", G_LOG_LEVEL_WARNING, "*replace_settings: error updating connection*"); + + nmtst_main_loop_run (loop, 100); + + g_test_assert_expected_messages (); + + _slist_to_array (&connections, nm_remote_settings_list_connections (settings)); + + g_assert_cmpint (connections->len, ==, 2); + n_found = nmtst_find_all_indexes (connections->pdata, + connections->len, + (gpointer *) ((const char *[]) { path0, path1 }), + 2, + _test_connection_invalid_find_connections, + NULL, + idx); + g_assert_cmpint (n_found, ==, 2); + ASSERT_IDX (0); + ASSERT_IDX (1); + nmtst_assert_connection_verifies_without_normalization (connections->pdata[idx[0]]); + nmtst_assert_connection_unnormalizable (connections->pdata[idx[1]], 0, 0); + + /************************************************************************** + * After having the client up and running, add another invalid connection + *************************************************************************/ + + g_object_set (s_con, + NM_SETTING_CONNECTION_ID, "test-connection-invalid-2", + NM_SETTING_CONNECTION_TYPE, "invalid-type-2", + NM_SETTING_CONNECTION_UUID, (uuid2 = g_strdup (nmtst_uuid_generate ())), + NULL); + nmtstc_service_add_connection (my_sinfo, + connection, + FALSE, + &path2); + + g_test_expect_message ("libnm-glib", G_LOG_LEVEL_WARNING, "*replace_settings: error updating connection*"); + + nmtst_main_loop_run (loop, 100); + + g_test_assert_expected_messages (); + + _slist_to_array (&connections, nm_remote_settings_list_connections (settings)); + + g_assert_cmpint (connections->len, ==, 3); + n_found = nmtst_find_all_indexes (connections->pdata, + connections->len, + (gpointer *) ((const char *[]) { path0, path1, path2 }), + 3, + _test_connection_invalid_find_connections, + NULL, + idx); + g_assert_cmpint (n_found, ==, 3); + ASSERT_IDX (0); + ASSERT_IDX (1); + ASSERT_IDX (2); + nmtst_assert_connection_verifies_without_normalization (connections->pdata[idx[0]]); + nmtst_assert_connection_unnormalizable (connections->pdata[idx[1]], 0, 0); + nmtst_assert_connection_unnormalizable (connections->pdata[idx[2]], 0, 0); + + /************************************************************************** + * Modify the invalid connection. Connection disappears + *************************************************************************/ + + g_object_set (s_con, + NM_SETTING_CONNECTION_ID, "test-connection-invalid-2x", + NULL); + nmtstc_service_update_connection (my_sinfo, + path2, + connection, + FALSE); + + g_test_expect_message ("libnm-glib", G_LOG_LEVEL_WARNING, "*replace_settings: error updating connection*"); + + nmtst_main_loop_run (loop, 100); + + g_test_assert_expected_messages (); + + _slist_to_array (&connections, nm_remote_settings_list_connections (settings)); + + g_assert_cmpint (connections->len, ==, 2); + n_found = nmtst_find_all_indexes (connections->pdata, + connections->len, + (gpointer *) ((const char *[]) { path0, path1, path2 }), + 3, + _test_connection_invalid_find_connections, + NULL, + idx); + g_assert_cmpint (n_found, ==, 2); + ASSERT_IDX (0); + ASSERT_IDX (1); + g_assert_cmpint (idx[2], ==, -1); + nmtst_assert_connection_verifies_without_normalization (connections->pdata[idx[0]]); + nmtst_assert_connection_unnormalizable (connections->pdata[idx[1]], 0, 0); + + /************************************************************************** + * Modify the invalid connection again. Note that the connection stays + * invisible (although it exists, and is valid). + *************************************************************************/ + + g_clear_object (&connection); + connection = nmtst_create_minimal_connection ("test-connection-invalid-2", NULL, NM_SETTING_WIRED_SETTING_NAME, &s_con); + nmtst_connection_normalize (connection); + g_object_set (s_con, + NM_SETTING_CONNECTION_ID, "test-connection-invalid-2z", + NM_SETTING_CONNECTION_TYPE, "802-3-ethernet", + NM_SETTING_CONNECTION_UUID, uuid2, + NULL); + + nmtstc_service_update_connection (my_sinfo, + path2, + connection, + FALSE); + + nmtst_main_loop_run (loop, 100); + + _slist_to_array (&connections, nm_remote_settings_list_connections (settings)); + + g_assert_cmpint (connections->len, ==, 2); + n_found = nmtst_find_all_indexes (connections->pdata, + connections->len, + (gpointer *) ((const char *[]) { path0, path1, path2 }), + 3, + _test_connection_invalid_find_connections, + NULL, + idx); + g_assert_cmpint (n_found, ==, 2); + ASSERT_IDX (0); + ASSERT_IDX (1); + g_assert_cmpint (idx[2], ==, -1); + nmtst_assert_connection_verifies_without_normalization (connections->pdata[idx[0]]); + nmtst_assert_connection_unnormalizable (connections->pdata[idx[1]], 0, 0); + + + /************************************************************************** + * Modify the invalid connection and make it valid + *************************************************************************/ + + g_clear_object (&connection); + connection = nmtst_create_minimal_connection ("test-connection-invalid-1", NULL, NM_SETTING_WIRED_SETTING_NAME, &s_con); + nmtst_connection_normalize (connection); + g_object_set (s_con, + NM_SETTING_CONNECTION_ID, "test-connection-invalid-1x", + NM_SETTING_CONNECTION_TYPE, "802-3-ethernet", + NM_SETTING_CONNECTION_UUID, nm_connection_get_uuid (connections->pdata[idx[1]]), + NULL); + + nmtstc_service_update_connection (my_sinfo, + path1, + connection, + FALSE); + + nmtst_main_loop_run (loop, 100); + + _slist_to_array (&connections, nm_remote_settings_list_connections (settings)); + + g_assert_cmpint (connections->len, ==, 2); + n_found = nmtst_find_all_indexes (connections->pdata, + connections->len, + (gpointer *) ((const char *[]) { path0, path1, path2 }), + 3, + _test_connection_invalid_find_connections, + NULL, + idx); + g_assert_cmpint (n_found, ==, 2); + ASSERT_IDX (0); + ASSERT_IDX (1); + g_assert_cmpint (idx[2], ==, -1); + nmtst_assert_connection_verifies_without_normalization (connections->pdata[idx[0]]); + nmtst_assert_connection_verifies_without_normalization (connections->pdata[idx[1]]); + g_assert_cmpstr ("test-connection-invalid-1x", ==, nm_connection_get_id (connections->pdata[idx[1]])); + +#undef ASSERT_IDX +} + +/*******************************************************************/ + +NMTST_DEFINE (); + int main (int argc, char **argv) { -#if !GLIB_CHECK_VERSION (2, 35, 0) - g_type_init (); -#endif - - g_test_init (&argc, &argv, NULL); + nmtst_init (&argc, &argv, TRUE); loop = g_main_loop_new (NULL, FALSE); @@ -896,6 +1147,7 @@ main (int argc, char **argv) g_test_add_func ("/libnm-glib/wimax-nsp-added-removed", test_wimax_nsp_added_removed); g_test_add_func ("/libnm-glib/devices-array", test_devices_array); g_test_add_func ("/libnm-glib/client-manager-running", test_client_manager_running); + g_test_add_func ("/libnm/connection/invalid", test_connection_invalid); return g_test_run (); } diff --git a/libnm-glib/tests/test-remote-settings-client.c b/libnm-glib/tests/test-remote-settings-client.c index a109f8df..83227d4b 100644 --- a/libnm-glib/tests/test-remote-settings-client.c +++ b/libnm-glib/tests/test-remote-settings-client.c @@ -23,22 +23,22 @@ #include <dbus/dbus.h> #include <dbus/dbus-glib.h> #include <dbus/dbus-glib-lowlevel.h> -#include <glib.h> #include <string.h> #include <sys/types.h> #include <signal.h> -#include <NetworkManager.h> +#include "NetworkManager.h" -#include <nm-setting-connection.h> -#include <nm-setting-wired.h> -#include <nm-utils.h> +#include "nm-setting-connection.h" +#include "nm-setting-wired.h" +#include "nm-utils.h" +#include "nm-default.h" #include "nm-remote-settings.h" -#include "common.h" -#include "gsystem-local-alloc.h" -static NMTestServiceInfo *sinfo; +#include "nm-test-libnm-utils.h" + +static NMTstcServiceInfo *sinfo; static NMRemoteSettings *settings = NULL; DBusGConnection *bus = NULL; NMRemoteConnection *remote = NULL; @@ -376,7 +376,7 @@ test_service_running (void) g_assert (running == TRUE); /* Now kill the test service. */ - nm_test_service_cleanup (sinfo); + nmtstc_service_cleanup (sinfo); settings2 = nm_remote_settings_new (bus); @@ -405,7 +405,7 @@ test_service_running (void) g_assert (running == FALSE); /* Now restart it */ - sinfo = nm_test_service_init (); + sinfo = nmtstc_service_init (); quit_id = g_timeout_add_seconds (5, loop_quit, loop); g_main_loop_run (loop); @@ -422,25 +422,22 @@ test_service_running (void) /*******************************************************************/ +NMTST_DEFINE (); + int main (int argc, char **argv) { int ret; GError *error = NULL; -#if !GLIB_CHECK_VERSION (2, 35, 0) - g_type_init (); -#endif - - g_test_init (&argc, &argv, NULL); + nmtst_init (&argc, &argv, TRUE); bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error); g_assert_no_error (error); - sinfo = nm_test_service_init (); + sinfo = nmtstc_service_init (); - settings = nm_remote_settings_new (bus); - g_assert (settings != NULL); + settings = nmtstc_nm_remote_settings_new (); /* FIXME: these tests assume that they get run in order, but g_test_run() * does not actually guarantee that! @@ -453,7 +450,7 @@ main (int argc, char **argv) ret = g_test_run (); - nm_test_service_cleanup (sinfo); + nmtstc_service_cleanup (sinfo); g_object_unref (settings); dbus_g_connection_unref (bus); |