diff options
Diffstat (limited to 'libnm/tests')
| -rw-r--r-- | libnm/tests/Makefile.am | 18 | ||||
| -rw-r--r-- | libnm/tests/Makefile.in | 72 | ||||
| -rw-r--r-- | libnm/tests/common.c | 187 | ||||
| -rw-r--r-- | libnm/tests/common.h | 37 | ||||
| -rw-r--r-- | libnm/tests/test-nm-client.c | 380 | ||||
| -rw-r--r-- | libnm/tests/test-remote-settings-client.c | 21 | ||||
| -rw-r--r-- | libnm/tests/test-secret-agent.c | 34 |
7 files changed, 417 insertions, 332 deletions
diff --git a/libnm/tests/Makefile.am b/libnm/tests/Makefile.am index 0acbae8f..ddcf50be 100644 --- a/libnm/tests/Makefile.am +++ b/libnm/tests/Makefile.am @@ -1,13 +1,13 @@ 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 \ -I$(top_builddir)/libnm \ -I$(top_srcdir)/libnm-core \ -I$(top_builddir)/libnm-core \ - -DNETWORKMANAGER_COMPILATION \ + -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_LIB \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ -DTEST_NM_SERVICE=\"$(abs_top_srcdir)/tools/test-networkmanager-service.py\" \ $(GLIB_CFLAGS) @@ -26,18 +26,18 @@ endif TESTS = test-nm-client test-remote-settings-client test-secret-agent 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_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_secret_agent_SOURCES = \ - common.c \ - common.h \ + $(top_builddir)/shared/nm-test-utils-impl.c \ + $(top_builddir)/shared/nm-test-libnm-utils.h \ test-secret-agent.c endif diff --git a/libnm/tests/Makefile.in b/libnm/tests/Makefile.in index 0ced3864..0b553a78 100644 --- a/libnm/tests/Makefile.in +++ b/libnm/tests/Makefile.in @@ -118,8 +118,11 @@ CONFIG_CLEAN_VPATH_FILES = @ENABLE_TESTS_TRUE@ test-remote-settings-client$(EXEEXT) \ @ENABLE_TESTS_TRUE@ test-secret-agent$(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) test_nm_client_LDADD = $(LDADD) @@ -131,10 +134,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) @@ -142,9 +147,12 @@ test_remote_settings_client_LDADD = $(LDADD) @ENABLE_TESTS_TRUE@test_remote_settings_client_DEPENDENCIES = \ @ENABLE_TESTS_TRUE@ $(top_builddir)/libnm/libnm.la \ @ENABLE_TESTS_TRUE@ $(am__DEPENDENCIES_1) -am__test_secret_agent_SOURCES_DIST = common.c common.h \ +am__test_secret_agent_SOURCES_DIST = \ + $(top_builddir)/shared/nm-test-utils-impl.c \ + $(top_builddir)/shared/nm-test-libnm-utils.h \ test-secret-agent.c -@ENABLE_TESTS_TRUE@am_test_secret_agent_OBJECTS = common.$(OBJEXT) \ +@ENABLE_TESTS_TRUE@am_test_secret_agent_OBJECTS = \ +@ENABLE_TESTS_TRUE@ nm-test-utils-impl.$(OBJEXT) \ @ENABLE_TESTS_TRUE@ test-secret-agent.$(OBJEXT) test_secret_agent_OBJECTS = $(am_test_secret_agent_OBJECTS) test_secret_agent_LDADD = $(LDADD) @@ -437,7 +445,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@ @@ -449,8 +456,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@ @@ -460,6 +465,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@ @@ -514,16 +520,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@ @@ -560,6 +563,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@ @@ -588,7 +593,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@ @@ -603,6 +607,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@ @@ -663,6 +669,7 @@ mkdir_p = @mkdir_p@ nmbinary = @nmbinary@ nmconfdir = @nmconfdir@ nmdatadir = @nmdatadir@ +nmlibdir = @nmlibdir@ nmrundir = @nmrundir@ nmstatedir = @nmstatedir@ oldincludedir = @oldincludedir@ @@ -670,6 +677,7 @@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ +runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ @@ -686,13 +694,13 @@ 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 \ @ENABLE_TESTS_TRUE@ -I$(top_builddir)/libnm \ @ENABLE_TESTS_TRUE@ -I$(top_srcdir)/libnm-core \ @ENABLE_TESTS_TRUE@ -I$(top_builddir)/libnm-core \ -@ENABLE_TESTS_TRUE@ -DNETWORKMANAGER_COMPILATION \ +@ENABLE_TESTS_TRUE@ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_LIB \ @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) @@ -703,18 +711,18 @@ with_valgrind = @with_valgrind@ @ENABLE_TESTS_TRUE@@WITH_VALGRIND_FALSE@LOG_COMPILER = $(srcdir)/libnm-test-launch.sh @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_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_secret_agent_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-secret-agent.c EXTRA_DIST = libnm-test-launch.sh @@ -779,7 +787,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@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test-secret-agent.Po@am__quote@ @@ -805,6 +813,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/tests/common.c b/libnm/tests/common.c deleted file mode 100644 index 8c1b83a8..00000000 --- a/libnm/tests/common.c +++ /dev/null @@ -1,187 +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 <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, - "org.freedesktop.DBus", - "/org/freedesktop/DBus", - "org.freedesktop.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); -} - -typedef struct { - GMainLoop *loop; - const char *ifname; - char *path; - NMDevice *device; -} AddDeviceInfo; - -static void -device_added_cb (NMClient *client, - NMDevice *device, - gpointer user_data) -{ - AddDeviceInfo *info = user_data; - - g_assert (device); - g_assert_cmpstr (nm_object_get_path (NM_OBJECT (device)), ==, info->path); - g_assert_cmpstr (nm_device_get_iface (device), ==, info->ifname); - - info->device = device; - g_main_loop_quit (info->loop); -} - -static gboolean -timeout (gpointer user_data) -{ - g_assert_not_reached (); - return G_SOURCE_REMOVE; -} - -NMDevice * -nm_test_service_add_device (NMTestServiceInfo *sinfo, NMClient *client, - const char *method, const char *ifname) -{ - AddDeviceInfo info; - GError *error = NULL; - GVariant *ret; - guint timeout_id; - - ret = g_dbus_proxy_call_sync (sinfo->proxy, - method, - g_variant_new ("(s)", ifname), - 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)"); - g_variant_get (ret, "(o)", &info.path); - g_variant_unref (ret); - - /* Wait for libnm to find the device */ - info.ifname = ifname; - info.loop = g_main_loop_new (NULL, FALSE); - g_signal_connect (client, "device-added", - G_CALLBACK (device_added_cb), &info); - timeout_id = g_timeout_add_seconds (5, timeout, NULL); - g_main_loop_run (info.loop); - - g_source_remove (timeout_id); - g_signal_handlers_disconnect_by_func (client, device_added_cb, &info); - g_free (info.path); - g_main_loop_unref (info.loop); - - return info.device; -} diff --git a/libnm/tests/common.h b/libnm/tests/common.h deleted file mode 100644 index aa15167b..00000000 --- a/libnm/tests/common.h +++ /dev/null @@ -1,37 +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> -#include <NetworkManager.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); - -NMDevice *nm_test_service_add_device (NMTestServiceInfo *info, - NMClient *client, - const char *method, - const char *ifname); diff --git a/libnm/tests/test-nm-client.c b/libnm/tests/test-nm-client.c index 3541c741..5be69142 100644 --- a/libnm/tests/test-nm-client.c +++ b/libnm/tests/test-nm-client.c @@ -20,20 +20,14 @@ #include "config.h" -#include <glib.h> #include <string.h> #include <sys/types.h> #include <signal.h> -#include <NetworkManager.h> -#include "nm-glib-compat.h" - -#include "common.h" - -#include "nm-test-utils.h" +#include "nm-test-libnm-utils.h" static GMainLoop *loop = NULL; -static NMTestServiceInfo *sinfo; +static NMTstcServiceInfo *sinfo; /*******************************************************************/ @@ -75,7 +69,7 @@ test_device_added (void) gboolean notified = FALSE; GError *error = NULL; - sinfo = nm_test_service_init (); + sinfo = nmtstc_service_init (); client = nm_client_new (NULL, &error); g_assert_no_error (error); @@ -88,7 +82,7 @@ test_device_added (void) ¬ified); /* Tell the test service to add a new device */ - nm_test_service_add_device (sinfo, client, "AddWiredDevice", "eth0"); + nmtstc_service_add_device (sinfo, client, "AddWiredDevice", "eth0"); /* coverity[loop_condition] */ while (!notified) @@ -109,7 +103,7 @@ test_device_added (void) g_assert_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_NOT_SOFTWARE); g_object_unref (client); - g_clear_pointer (&sinfo, nm_test_service_cleanup); + g_clear_pointer (&sinfo, nmtstc_service_cleanup); } /*******************************************************************/ @@ -167,7 +161,7 @@ test_device_added_signal_after_init (void) guint result = 0; GError *error = NULL; - sinfo = nm_test_service_init (); + sinfo = nmtstc_service_init (); client = nm_client_new (NULL, &error); g_assert_no_error (error); @@ -185,7 +179,7 @@ test_device_added_signal_after_init (void) &result); /* Tell the test service to add a new device */ - nm_test_service_add_device (sinfo, client, "AddWiredDevice", "eth0"); + nmtstc_service_add_device (sinfo, client, "AddWiredDevice", "eth0"); /* Ensure the 'device-added' signal doesn't show up before * the 'Devices' property change notification */ @@ -208,7 +202,7 @@ test_device_added_signal_after_init (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); } /*******************************************************************/ @@ -315,13 +309,13 @@ test_wifi_ap_added_removed (void) GError *error = NULL; char *expected_path = NULL; - sinfo = nm_test_service_init (); + sinfo = nmtstc_service_init (); client = nm_client_new (NULL, &error); g_assert_no_error (error); /*************************************/ /* Add the wifi device */ - wifi = (NMDeviceWifi *) nm_test_service_add_device (sinfo, client, "AddWifiDevice", "wlan0"); + wifi = (NMDeviceWifi *) nmtstc_service_add_device (sinfo, client, "AddWifiDevice", "wlan0"); g_assert (NM_IS_DEVICE_WIFI (wifi)); /*************************************/ @@ -407,7 +401,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); } /*******************************************************************/ @@ -514,13 +508,13 @@ test_wimax_nsp_added_removed (void) GError *error = NULL; char *expected_path = NULL; - sinfo = nm_test_service_init (); + sinfo = nmtstc_service_init (); client = nm_client_new (NULL, &error); g_assert_no_error (error); /*************************************/ /* Add the wimax device */ - wimax = (NMDeviceWimax *) nm_test_service_add_device (sinfo, client, "AddWimaxDevice", "wmx0"); + wimax = (NMDeviceWimax *) nmtstc_service_add_device (sinfo, client, "AddWimaxDevice", "wmx0"); g_assert (NM_IS_DEVICE_WIMAX (wimax)); /*************************************/ @@ -606,7 +600,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); } /*******************************************************************/ @@ -690,7 +684,7 @@ test_devices_array (void) GError *error = NULL; GVariant *ret; - sinfo = nm_test_service_init (); + sinfo = nmtstc_service_init (); /* Make sure that we test the async codepath in at least one test... */ nm_client_new_async (NULL, new_client_cb, &client); @@ -699,9 +693,9 @@ test_devices_array (void) /*************************************/ /* Add some devices */ - wlan0 = nm_test_service_add_device (sinfo, client,"AddWifiDevice", "wlan0"); - eth0 = nm_test_service_add_device (sinfo, client, "AddWiredDevice", "eth0"); - eth1 = nm_test_service_add_device (sinfo, client, "AddWiredDevice", "eth1"); + wlan0 = nmtstc_service_add_device (sinfo, client,"AddWifiDevice", "wlan0"); + eth0 = nmtstc_service_add_device (sinfo, client, "AddWiredDevice", "eth0"); + eth1 = nmtstc_service_add_device (sinfo, client, "AddWiredDevice", "eth1"); /* Ensure the devices now exist */ devices = nm_client_get_devices (client); @@ -766,7 +760,7 @@ test_devices_array (void) g_assert (device == eth1); g_object_unref (client); - g_clear_pointer (&sinfo, nm_test_service_cleanup); + g_clear_pointer (&sinfo, nmtstc_service_cleanup); } static void @@ -805,7 +799,7 @@ test_client_nm_running (void) g_clear_error (&error); /* Now start the test service. */ - sinfo = nm_test_service_init (); + sinfo = nmtstc_service_init (); client2 = nm_client_new (NULL, &error); g_assert_no_error (error); @@ -824,7 +818,7 @@ test_client_nm_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_nm_running (client1)); @@ -938,12 +932,12 @@ test_active_connections (void) TestACInfo info = { loop, NULL, 0 }; GError *error = NULL; - sinfo = nm_test_service_init (); + sinfo = nmtstc_service_init (); client = nm_client_new (NULL, &error); g_assert_no_error (error); /* Tell the test service to add a new device */ - device = nm_test_service_add_device (sinfo, client, "AddWiredDevice", "eth0"); + device = nmtstc_service_add_device (sinfo, client, "AddWiredDevice", "eth0"); conn = nmtst_create_minimal_connection ("test-ac", NULL, NM_SETTING_WIRED_SETTING_NAME, NULL); nm_client_add_and_activate_connection_async (client, conn, device, NULL, @@ -980,7 +974,7 @@ test_active_connections (void) assert_ac_and_device (client); g_object_unref (client); - g_clear_pointer (&sinfo, nm_test_service_cleanup); + g_clear_pointer (&sinfo, nmtstc_service_cleanup); } static void @@ -1068,11 +1062,11 @@ test_activate_virtual (void) TestConnectionInfo conn_info = { loop, NULL }; GError *error = NULL; - sinfo = nm_test_service_init (); + sinfo = nmtstc_service_init (); client = nm_client_new (NULL, &error); g_assert_no_error (error); - nm_test_service_add_device (sinfo, client, "AddWiredDevice", "eth0"); + nmtstc_service_add_device (sinfo, client, "AddWiredDevice", "eth0"); conn = nmtst_create_minimal_connection ("test-ac", NULL, NM_SETTING_VLAN_SETTING_NAME, &s_con); g_object_set (s_con, @@ -1113,7 +1107,7 @@ test_activate_virtual (void) g_object_unref (info.ac); g_object_unref (client); - g_clear_pointer (&sinfo, nm_test_service_cleanup); + g_clear_pointer (&sinfo, nmtstc_service_cleanup); } static void @@ -1141,11 +1135,11 @@ test_activate_failed (void) NMConnection *conn; GError *error = NULL; - sinfo = nm_test_service_init (); + sinfo = nmtstc_service_init (); client = nm_client_new (NULL, &error); g_assert_no_error (error); - device = nm_test_service_add_device (sinfo, client, "AddWiredDevice", "eth0"); + device = nmtstc_service_add_device (sinfo, client, "AddWiredDevice", "eth0"); /* Note that test-networkmanager-service.py checks for this exact name */ conn = nmtst_create_minimal_connection ("object-creation-failed-test", NULL, @@ -1158,7 +1152,315 @@ test_activate_failed (void) g_object_unref (conn); g_object_unref (client); - g_clear_pointer (&sinfo, nm_test_service_cleanup); + g_clear_pointer (&sinfo, nmtstc_service_cleanup); +} + +static void +test_device_connection_compatibility (void) +{ + NMClient *client; + NMDevice *device1, *device2; + NMConnection *conn; + NMSettingWired *s_wired; + GError *error = NULL; + const char *subchannels[] = { "0.0.8000", "0.0.8001", "0.0.8002", NULL }; + const char *subchannels_2[] = { "0.0.8000", "0.0.8001", NULL }; + const char *subchannels_x[] = { "0.0.8000", "0.0.8001", "0.0.800X", NULL }; + const char *hw_addr1 = "52:54:00:ab:db:23"; + const char *hw_addr2 = "52:54:00:ab:db:24"; + + sinfo = nmtstc_service_init (); + client = nm_client_new (NULL, &error); + g_assert_no_error (error); + + /* Create two devices */ + device1 = nmtstc_service_add_wired_device (sinfo, client, "eth0", hw_addr1, subchannels); + device2 = nmtstc_service_add_wired_device (sinfo, client, "eth1", hw_addr2, NULL); + + g_assert_cmpstr (nm_device_get_hw_address (device1), ==, hw_addr1); + g_assert_cmpstr (nm_device_get_hw_address (device2), ==, hw_addr2); + + conn = nmtst_create_minimal_connection ("wired-matches", NULL, + NM_SETTING_WIRED_SETTING_NAME, NULL); + s_wired = nm_connection_get_setting_wired (conn); + nm_setting_wired_add_mac_blacklist_item (s_wired, "00:11:22:33:44:55"); + + /* device1 and conn are compatible */ + g_object_set (s_wired, + NM_SETTING_WIRED_MAC_ADDRESS, hw_addr1, + NM_SETTING_WIRED_S390_SUBCHANNELS, subchannels, + NULL); + nm_device_connection_compatible (device1, conn, &error); + g_assert_no_error (error); + + /* device2 and conn differ in subchannels */ + g_object_set (s_wired, NM_SETTING_WIRED_S390_SUBCHANNELS, subchannels_x, NULL); + nm_device_connection_compatible (device2, conn, &error); + g_assert_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION); + g_clear_error (&error); + + /* device1 and conn differ in subchannels - 2 in connection, 3 in device */ + g_object_set (s_wired, NM_SETTING_WIRED_S390_SUBCHANNELS, subchannels_2, NULL); + nm_device_connection_compatible (device1, conn, &error); + g_assert_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION); + g_clear_error (&error); + + g_object_set (s_wired, NM_SETTING_WIRED_S390_SUBCHANNELS, NULL, NULL); + + /* device2 and conn differ in MAC address */ + g_object_set (s_wired, NM_SETTING_WIRED_MAC_ADDRESS, "aa:bb:cc:dd:ee:ee", NULL); + nm_device_connection_compatible (device2, conn, &error); + g_assert_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION); + g_clear_error (&error); + g_object_set (s_wired, NM_SETTING_WIRED_MAC_ADDRESS, NULL, NULL); + + /* device1 is blacklisted in conn */ + nm_setting_wired_add_mac_blacklist_item (s_wired, hw_addr1); + nm_device_connection_compatible (device1, conn, &error); + g_assert_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION); + g_clear_error (&error); + + g_object_unref (conn); + g_object_unref (client); + + g_clear_pointer (&sinfo, nmtstc_service_cleanup); +} + +/*******************************************************************/ + +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 NMClient *client = NULL; + const GPtrArray *connections; + gs_free_error GError *error = 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); + + + client = nm_client_new (NULL, &error); + g_assert_no_error (error); + + connections = nm_client_get_connections (client); + g_assert (connections); + + 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); + + + nmtst_main_loop_run (loop, 100); + + + connections = nm_client_get_connections (client); + g_assert (connections); + + 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 (still invalid) + *************************************************************************/ + + g_object_set (s_con, + NM_SETTING_CONNECTION_ID, "test-connection-invalid-2x", + NULL); + nmtstc_service_update_connection (my_sinfo, + path2, + connection, + FALSE); + + nmtst_main_loop_run (loop, 100); + + connections = nm_client_get_connections (client); + g_assert (connections); + + 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); + g_assert_cmpstr ("test-connection-invalid-2x", ==, nm_connection_get_id (connections->pdata[idx[2]])); + + /************************************************************************** + * Modify the invalid connection (now becomes 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); + + connections = nm_client_get_connections (client); + g_assert (connections); + + 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_verifies_without_normalization (connections->pdata[idx[2]]); + g_assert_cmpstr ("test-connection-invalid-2z", ==, nm_connection_get_id (connections->pdata[idx[2]])); + + /************************************************************************** + * 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); + + connections = nm_client_get_connections (client); + g_assert (connections); + + 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_verifies_without_normalization (connections->pdata[idx[1]]); + nmtst_assert_connection_verifies_without_normalization (connections->pdata[idx[2]]); + g_assert_cmpstr ("test-connection-invalid-1x", ==, nm_connection_get_id (connections->pdata[idx[1]])); + g_assert_cmpstr ("test-connection-invalid-2z", ==, nm_connection_get_id (connections->pdata[idx[2]])); + +#undef ASSERT_IDX } /*******************************************************************/ @@ -1170,10 +1472,6 @@ main (int argc, char **argv) { g_setenv ("LIBNM_USE_SESSION_BUS", "1", TRUE); -#if !GLIB_CHECK_VERSION (2, 35, 0) - g_type_init (); -#endif - nmtst_init (&argc, &argv, TRUE); loop = g_main_loop_new (NULL, FALSE); @@ -1187,6 +1485,8 @@ main (int argc, char **argv) g_test_add_func ("/libnm/active-connections", test_active_connections); g_test_add_func ("/libnm/activate-virtual", test_activate_virtual); g_test_add_func ("/libnm/activate-failed", test_activate_failed); + g_test_add_func ("/libnm/device-connection-compatibility", test_device_connection_compatibility); + g_test_add_func ("/libnm/connection/invalid", test_connection_invalid); return g_test_run (); } diff --git a/libnm/tests/test-remote-settings-client.c b/libnm/tests/test-remote-settings-client.c index 15590fac..1a3c7988 100644 --- a/libnm/tests/test-remote-settings-client.c +++ b/libnm/tests/test-remote-settings-client.c @@ -20,18 +20,13 @@ #include "config.h" -#include <glib.h> #include <string.h> #include <sys/types.h> #include <signal.h> -#include <NetworkManager.h> +#include "nm-test-libnm-utils.h" -#include "common.h" - -#include "nm-test-utils.h" - -static NMTestServiceInfo *sinfo; +static NMTstcServiceInfo *sinfo; static NMClient *client = NULL; GDBusConnection *bus = NULL; NMRemoteConnection *remote = NULL; @@ -502,6 +497,8 @@ test_save_hostname (void) /*******************************************************************/ +NMTST_DEFINE (); + int main (int argc, char **argv) { @@ -510,16 +507,12 @@ main (int argc, char **argv) g_setenv ("LIBNM_USE_SESSION_BUS", "1", TRUE); -#if !GLIB_CHECK_VERSION (2, 35, 0) - g_type_init (); -#endif - - g_test_init (&argc, &argv, NULL); + nmtst_init (&argc, &argv, TRUE); bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error); g_assert_no_error (error); - sinfo = nm_test_service_init (); + sinfo = nmtstc_service_init (); client = nm_client_new (NULL, &error); g_assert_no_error (error); @@ -538,7 +531,7 @@ main (int argc, char **argv) ret = g_test_run (); - nm_test_service_cleanup (sinfo); + nmtstc_service_cleanup (sinfo); g_object_unref (client); g_object_unref (bus); diff --git a/libnm/tests/test-secret-agent.c b/libnm/tests/test-secret-agent.c index 037b5a81..f8aedd23 100644 --- a/libnm/tests/test-secret-agent.c +++ b/libnm/tests/test-secret-agent.c @@ -20,17 +20,13 @@ #include "config.h" -#include <glib.h> #include <string.h> #include <sys/types.h> #include <signal.h> -#include <NetworkManager.h> #include <nm-secret-agent-old.h> -#include "nm-glib-compat.h" -#include "nm-test-utils.h" -#include "common.h" +#include "nm-test-libnm-utils.h" /*******************************************************************/ @@ -183,7 +179,7 @@ test_secret_agent_new (void) /*******************************************************************/ typedef struct { - NMTestServiceInfo *sinfo; + NMTstcServiceInfo *sinfo; NMClient *client; NMSecretAgentOld *agent; @@ -250,7 +246,7 @@ test_setup (TestSecretAgentData *sadata, gconstpointer test_data) NMSetting *s_wsec; GError *error = NULL; - sadata->sinfo = nm_test_service_init (); + sadata->sinfo = nmtstc_service_init (); sadata->client = nm_client_new (NULL, &error); g_assert_no_error (error); @@ -262,8 +258,8 @@ test_setup (TestSecretAgentData *sadata, gconstpointer test_data) counter++; /* Create the device */ - sadata->device = nm_test_service_add_device (sadata->sinfo, sadata->client, - "AddWifiDevice", sadata->ifname); + sadata->device = nmtstc_service_add_device (sadata->sinfo, sadata->client, + "AddWifiDevice", sadata->ifname); /* Create the connection */ connection = nmtst_create_minimal_connection (sadata->con_id, NULL, NM_SETTING_WIRELESS_SETTING_NAME, &s_con); @@ -336,7 +332,7 @@ test_cleanup (TestSecretAgentData *sadata, gconstpointer test_data) g_object_unref (sadata->connection); g_object_unref (sadata->client); - nm_test_service_cleanup (sadata->sinfo); + nmtstc_service_cleanup (sadata->sinfo); g_source_remove (sadata->timeout_id); g_main_loop_unref (sadata->loop); @@ -583,12 +579,12 @@ registered_changed (GObject *object, GParamSpec *pspec, gpointer user_data) static void test_secret_agent_auto_register (void) { - NMTestServiceInfo *sinfo; + NMTstcServiceInfo *sinfo; NMSecretAgentOld *agent; GMainLoop *loop; GError *error = NULL; - sinfo = nm_test_service_init (); + sinfo = nmtstc_service_init (); loop = g_main_loop_new (NULL, FALSE); agent = test_secret_agent_new (); @@ -604,17 +600,17 @@ test_secret_agent_auto_register (void) g_assert (nm_secret_agent_old_get_registered (agent)); /* Shut down test service */ - nm_test_service_cleanup (sinfo); + nmtstc_service_cleanup (sinfo); g_main_loop_run (loop); g_assert (!nm_secret_agent_old_get_registered (agent)); /* Restart test service */ - sinfo = nm_test_service_init (); + sinfo = nmtstc_service_init (); g_main_loop_run (loop); g_assert (nm_secret_agent_old_get_registered (agent)); /* Shut down test service again */ - nm_test_service_cleanup (sinfo); + nmtstc_service_cleanup (sinfo); g_main_loop_run (loop); g_assert (!nm_secret_agent_old_get_registered (agent)); @@ -624,6 +620,8 @@ test_secret_agent_auto_register (void) /*******************************************************************/ +NMTST_DEFINE (); + int main (int argc, char **argv) { @@ -631,11 +629,7 @@ main (int argc, char **argv) g_setenv ("LIBNM_USE_SESSION_BUS", "1", TRUE); -#if !GLIB_CHECK_VERSION (2, 35, 0) - g_type_init (); -#endif - - g_test_init (&argc, &argv, NULL); + nmtst_init (&argc, &argv, TRUE); g_test_add ("/libnm/secret-agent/none", TestSecretAgentData, NULL, test_setup, test_secret_agent_none, test_cleanup); |