summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2015-12-26 19:09:30 +0100
committerThomas Haller <thaller@redhat.com>2015-12-26 19:09:30 +0100
commitd1bd8c7132233adeafff4eb19cdcd21a42682fc8 (patch)
tree42bfd0f27b542dbee3fa8cab31b3103b5ef4a4f7
parent2ef3c1047d6b3c044ae6caf1ba7c0d8af6cc6bf9 (diff)
parent92f122525dab49fece51b6b6bda99c762507f7c9 (diff)
downloadNetworkManager-d1bd8c7132233adeafff4eb19cdcd21a42682fc8.tar.gz
libnm: merge branch 'th/libnm-test-invalid-connection'
-rw-r--r--.gitignore2
-rw-r--r--Makefile.am4
-rw-r--r--callouts/Makefile.am4
-rw-r--r--callouts/tests/Makefile.am4
-rw-r--r--clients/Makefile.am4
-rw-r--r--clients/cli/Makefile.am4
-rw-r--r--clients/tui/Makefile.am4
-rw-r--r--clients/tui/newt/Makefile.am4
-rw-r--r--configure.ac4
-rwxr-xr-xcontrib/fedora/rpm/build_clean.sh2
-rw-r--r--docs/libnm-glib/Makefile.am4
-rw-r--r--examples/C/glib/Makefile.am4
-rw-r--r--libnm-core/Makefile.am4
-rw-r--r--libnm-core/Makefile.libnm-core2
-rw-r--r--libnm-core/tests/Makefile.am4
-rw-r--r--libnm-glib/Makefile.am6
-rw-r--r--libnm-glib/nm-remote-connection.c7
-rw-r--r--libnm-glib/tests/Makefile.am13
-rw-r--r--libnm-glib/tests/common.c121
-rw-r--r--libnm-glib/tests/common.h31
-rw-r--r--libnm-glib/tests/test-nm-client.c327
-rw-r--r--libnm-glib/tests/test-remote-settings-client.c24
-rw-r--r--libnm-util/Makefile.am8
-rw-r--r--libnm-util/tests/Makefile.am4
-rw-r--r--libnm/Makefile.am6
-rw-r--r--libnm/tests/Makefile.am18
-rw-r--r--libnm/tests/common.c234
-rw-r--r--libnm/tests/common.h45
-rw-r--r--libnm/tests/test-nm-client.c311
-rw-r--r--libnm/tests/test-remote-settings-client.c13
-rw-r--r--libnm/tests/test-secret-agent.c26
-rw-r--r--shared/Makefile.am (renamed from include/Makefile.am)0
-rw-r--r--shared/gsystem-local-alloc.h (renamed from include/gsystem-local-alloc.h)0
-rw-r--r--shared/nm-dbus-compat.h (renamed from include/nm-dbus-compat.h)0
-rw-r--r--shared/nm-default.h (renamed from include/nm-default.h)5
-rw-r--r--shared/nm-glib.h (renamed from include/nm-glib.h)0
-rw-r--r--shared/nm-macros-internal.h (renamed from include/nm-macros-internal.h)4
-rw-r--r--shared/nm-test-libnm-utils.h101
-rw-r--r--shared/nm-test-utils-impl.c466
-rw-r--r--shared/nm-test-utils.h (renamed from include/nm-test-utils.h)116
-rw-r--r--shared/nm-version-macros.h.in (renamed from include/nm-version-macros.h.in)0
-rw-r--r--src/Makefile.am8
-rw-r--r--src/devices/adsl/Makefile.am4
-rw-r--r--src/devices/bluetooth/Makefile.am4
-rw-r--r--src/devices/team/Makefile.am4
-rw-r--r--src/devices/tests/Makefile.am4
-rw-r--r--src/devices/wifi/Makefile.am4
-rw-r--r--src/devices/wifi/tests/Makefile.am4
-rw-r--r--src/devices/wwan/Makefile.am4
-rw-r--r--src/dhcp-manager/Makefile.am4
-rw-r--r--src/dhcp-manager/tests/Makefile.am4
-rw-r--r--src/dnsmasq-manager/tests/Makefile.am4
-rw-r--r--src/platform/tests/Makefile.am4
-rw-r--r--src/ppp-manager/Makefile.am4
-rw-r--r--src/rdisc/tests/Makefile.am4
-rw-r--r--src/settings/plugins/ibft/Makefile.am4
-rw-r--r--src/settings/plugins/ibft/tests/Makefile.am4
-rw-r--r--src/settings/plugins/ifcfg-rh/Makefile.am4
-rw-r--r--src/settings/plugins/ifcfg-rh/tests/Makefile.am4
-rw-r--r--src/settings/plugins/ifnet/Makefile.am4
-rw-r--r--src/settings/plugins/ifnet/tests/Makefile.am4
-rw-r--r--src/settings/plugins/ifupdown/Makefile.am4
-rw-r--r--src/settings/plugins/ifupdown/tests/Makefile.am4
-rw-r--r--src/settings/plugins/keyfile/Makefile.am4
-rw-r--r--src/settings/plugins/keyfile/tests/Makefile.am4
-rw-r--r--src/supplicant-manager/tests/Makefile.am4
-rw-r--r--src/tests/Makefile.am4
-rw-r--r--src/tests/config/Makefile.am4
-rwxr-xr-xtools/test-networkmanager-service.py90
69 files changed, 1459 insertions, 683 deletions
diff --git a/.gitignore b/.gitignore
index 6629338305..d6c22aebed 100644
--- a/.gitignore
+++ b/.gitignore
@@ -137,7 +137,7 @@ test-*.trs
/examples/C/qt/list-connections
/examples/C/qt/change-ipv4-addresses
-/include/nm-version-macros.h
+/shared/nm-version-macros.h
/introspection/all.xml
/introspection/nmdbus-*.c
diff --git a/Makefile.am b/Makefile.am
index 00e703cc1c..a79bddca3d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -2,7 +2,7 @@ include $(GLIB_MAKEFILE)
SUBDIRS = \
. \
- include \
+ shared \
introspection \
libnm-core \
libnm \
@@ -67,6 +67,6 @@ pkgconfig_DATA = NetworkManager.pc
CLEANFILES = cscope.in.out cscope.out cscope.po.out
cscope:
- cscope -b -q -R -Iinclude -ssrc -slibnm-core -slibnm -slibnm-glib -slibnm-util -sclients;
+ cscope -b -q -R -sshared -ssrc -slibnm-core -slibnm -slibnm-glib -slibnm-util -sclients;
.PHONY: cscope
diff --git a/callouts/Makefile.am b/callouts/Makefile.am
index 3708aebbdf..6440a4de02 100644
--- a/callouts/Makefile.am
+++ b/callouts/Makefile.am
@@ -1,8 +1,8 @@
SUBDIRS = . tests
AM_CPPFLAGS = \
- -I${top_srcdir}/include \
- -I${top_builddir}/include \
+ -I${top_srcdir}/shared \
+ -I${top_builddir}/shared \
-I${top_srcdir}/libnm-core \
-I${top_builddir}/libnm-core \
$(GLIB_CFLAGS) \
diff --git a/callouts/tests/Makefile.am b/callouts/tests/Makefile.am
index 30b73b17ca..ee3f647d37 100644
--- a/callouts/tests/Makefile.am
+++ b/callouts/tests/Makefile.am
@@ -1,8 +1,8 @@
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-core \
-I$(top_builddir)/libnm-core \
-I$(top_srcdir)/callouts \
diff --git a/clients/Makefile.am b/clients/Makefile.am
index 8316dcc0ed..9c30eea1b2 100644
--- a/clients/Makefile.am
+++ b/clients/Makefile.am
@@ -1,8 +1,8 @@
SUBDIRS = cli tui
AM_CPPFLAGS = \
- -I${top_srcdir}/include \
- -I$(top_builddir)/include \
+ -I${top_srcdir}/shared \
+ -I$(top_builddir)/shared \
-I${top_srcdir}/libnm-core \
-I${top_builddir}/libnm-core \
-I${top_srcdir}/libnm \
diff --git a/clients/cli/Makefile.am b/clients/cli/Makefile.am
index 192920e6e5..dfcb1e961a 100644
--- a/clients/cli/Makefile.am
+++ b/clients/cli/Makefile.am
@@ -6,8 +6,8 @@ bin_PROGRAMS = \
AM_CPPFLAGS = \
-I${top_srcdir} \
-I${top_builddir} \
- -I${top_srcdir}/include \
- -I$(top_builddir)/include \
+ -I${top_srcdir}/shared \
+ -I$(top_builddir)/shared \
-I${top_srcdir}/libnm-core \
-I${top_builddir}/libnm-core \
-I${top_srcdir}/libnm \
diff --git a/clients/tui/Makefile.am b/clients/tui/Makefile.am
index 305f08b25d..ba2bbcd135 100644
--- a/clients/tui/Makefile.am
+++ b/clients/tui/Makefile.am
@@ -4,8 +4,8 @@ SUBDIRS = newt .
AM_CPPFLAGS= \
-I$(top_srcdir) \
- -I$(top_srcdir)/include \
- -I$(top_builddir)/include \
+ -I$(top_srcdir)/shared \
+ -I$(top_builddir)/shared \
-I$(top_srcdir)/libnm-core \
-I$(top_builddir)/libnm-core \
-I$(top_srcdir)/libnm \
diff --git a/clients/tui/newt/Makefile.am b/clients/tui/newt/Makefile.am
index 9413e96087..e07f9beff6 100644
--- a/clients/tui/newt/Makefile.am
+++ b/clients/tui/newt/Makefile.am
@@ -1,6 +1,6 @@
AM_CPPFLAGS= \
- -I$(top_srcdir)/include \
- -I$(top_builddir)/include \
+ -I$(top_srcdir)/shared \
+ -I$(top_builddir)/shared \
-I$(top_srcdir)/libnm-core \
-I$(top_builddir)/libnm-core \
-DG_LOG_DOMAIN=\""nmtui"\" \
diff --git a/configure.ac b/configure.ac
index c2c48d2c6d..63f2db1aa0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1007,8 +1007,8 @@ AM_CONDITIONAL(SETTING_DOCS_AVAILABLE, test "$build_setting_docs" = "yes" -o "$h
AC_CONFIG_FILES([
Makefile
-include/Makefile
-include/nm-version-macros.h
+shared/Makefile
+shared/nm-version-macros.h
src/Makefile
src/tests/Makefile
src/tests/config/Makefile
diff --git a/contrib/fedora/rpm/build_clean.sh b/contrib/fedora/rpm/build_clean.sh
index b57b7099e8..8b098681c3 100755
--- a/contrib/fedora/rpm/build_clean.sh
+++ b/contrib/fedora/rpm/build_clean.sh
@@ -76,7 +76,7 @@ fi
./autogen.sh --enable-gtk-doc || die "Error autogen.sh"
if [[ $QUICK == 1 ]]; then
- make -C include || die "Error make -C include"
+ make -C shared || die "Error make -C shared"
make -C introspection || die "Error make -C introspection"
make -C libnm-core || die "Error make -C libnm-core"
make -C libnm || die "Error make -C libnm"
diff --git a/docs/libnm-glib/Makefile.am b/docs/libnm-glib/Makefile.am
index 2d78856103..c38e6e3431 100644
--- a/docs/libnm-glib/Makefile.am
+++ b/docs/libnm-glib/Makefile.am
@@ -53,8 +53,8 @@ extra_files = libnm-glib.png
# CFLAGS and LDFLAGS for compiling scan program. Only needed
# if $(DOC_MODULE).types is non-empty.
GTKDOC_CFLAGS = \
- -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 \
diff --git a/examples/C/glib/Makefile.am b/examples/C/glib/Makefile.am
index 4b03d87f5e..3e442c30b1 100644
--- a/examples/C/glib/Makefile.am
+++ b/examples/C/glib/Makefile.am
@@ -1,6 +1,6 @@
AM_CPPFLAGS = \
- -I${top_srcdir}/include \
- -I$(top_builddir)/include \
+ -I${top_srcdir}/shared \
+ -I$(top_builddir)/shared \
-I${top_srcdir}/libnm-core \
-I${top_builddir}/libnm-core \
-I${top_srcdir}/libnm \
diff --git a/libnm-core/Makefile.am b/libnm-core/Makefile.am
index 55ed2f6ab6..527a1c2482 100644
--- a/libnm-core/Makefile.am
+++ b/libnm-core/Makefile.am
@@ -3,8 +3,8 @@ include $(GLIB_MAKEFILE)
SUBDIRS = . tests
AM_CPPFLAGS = \
- -I${top_srcdir}/include \
- -I${top_builddir}/include \
+ -I${top_srcdir}/shared \
+ -I${top_builddir}/shared \
-DG_LOG_DOMAIN=\""libnm"\" \
-DLOCALEDIR=\"$(datadir)/locale\" \
-DNMCONFDIR=\"$(nmconfdir)\" \
diff --git a/libnm-core/Makefile.libnm-core b/libnm-core/Makefile.libnm-core
index df219295c4..fe8cc8a603 100644
--- a/libnm-core/Makefile.libnm-core
+++ b/libnm-core/Makefile.libnm-core
@@ -6,7 +6,7 @@ core = $(top_srcdir)/libnm-core
core_build = $(top_builddir)/libnm-core
libnm_core_headers = \
- $(top_builddir)/include/nm-version-macros.h \
+ $(top_builddir)/shared/nm-version-macros.h \
$(core_build)/nm-core-enum-types.h \
$(core)/nm-connection.h \
$(core)/nm-core-types.h \
diff --git a/libnm-core/tests/Makefile.am b/libnm-core/tests/Makefile.am
index 9949241abe..92c816fd84 100644
--- a/libnm-core/tests/Makefile.am
+++ b/libnm-core/tests/Makefile.am
@@ -12,8 +12,8 @@ if ENABLE_TESTS
certsdir = $(srcdir)/certs
AM_CPPFLAGS = \
- -I${top_srcdir}/include \
- -I${top_builddir}/include \
+ -I${top_srcdir}/shared \
+ -I${top_builddir}/shared \
-I$(top_srcdir)/libnm-core \
-I$(top_builddir)/libnm-core \
-DNETWORKMANAGER_COMPILATION \
diff --git a/libnm-glib/Makefile.am b/libnm-glib/Makefile.am
index 53d5669e85..676b067116 100644
--- a/libnm-glib/Makefile.am
+++ b/libnm-glib/Makefile.am
@@ -3,12 +3,12 @@ include $(GLIB_MAKEFILE)
SUBDIRS = . 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 \
-DG_LOG_DOMAIN=\""libnm-glib"\" \
- -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_LIB \
+ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_LIB_LEGACY \
-DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \
$(DBUS_CFLAGS) \
$(GLIB_CFLAGS)
diff --git a/libnm-glib/nm-remote-connection.c b/libnm-glib/nm-remote-connection.c
index 1bc545d555..4298129bc0 100644
--- a/libnm-glib/nm-remote-connection.c
+++ b/libnm-glib/nm-remote-connection.c
@@ -496,6 +496,9 @@ updated_get_settings_cb (DBusGProxy *proxy,
priv->visible = FALSE;
g_signal_emit (self, signals[VISIBLE], 0, FALSE);
} else {
+ gs_unref_object NMConnection *self_alive = NULL;
+
+ self_alive = g_object_ref (self);
replace_settings (self, new_settings);
g_hash_table_destroy (new_settings);
@@ -618,6 +621,7 @@ init_sync (GInitable *initable, GCancellable *cancellable, GError **error)
{
NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (initable);
GHashTable *hash;
+ gs_unref_object NMConnection *self_alive = NULL;
if (!dbus_g_proxy_call (priv->proxy, "GetSettings", error,
G_TYPE_INVALID,
@@ -625,6 +629,7 @@ init_sync (GInitable *initable, GCancellable *cancellable, GError **error)
G_TYPE_INVALID))
return FALSE;
priv->visible = TRUE;
+ self_alive = g_object_ref (initable);
replace_settings (NM_REMOTE_CONNECTION (initable), hash);
g_hash_table_destroy (hash);
@@ -688,6 +693,7 @@ init_get_settings_cb (DBusGProxy *proxy,
NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (init_data->connection);
GHashTable *settings;
GError *error = NULL;
+ gs_unref_object NMConnection *self_alive = NULL;
dbus_g_proxy_end_call (proxy, call, &error,
DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, &settings,
@@ -698,6 +704,7 @@ init_get_settings_cb (DBusGProxy *proxy,
}
priv->visible = TRUE;
+ self_alive = g_object_ref (init_data->connection);
replace_settings (init_data->connection, settings);
g_hash_table_destroy (settings);
diff --git a/libnm-glib/tests/Makefile.am b/libnm-glib/tests/Makefile.am
index aeaaa6b67c..a1b25f62f4 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/common.c b/libnm-glib/tests/common.c
deleted file mode 100644
index 9e3b002cfc..0000000000
--- 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 <string.h>
-
-#include "nm-default.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 5ffd955c49..0000000000
--- 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 "nm-default.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 2c721f94df..f528bc26fb 100644
--- a/libnm-glib/tests/test-nm-client.c
+++ b/libnm-glib/tests/test-nm-client.c
@@ -27,47 +27,18 @@
#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-connection.h"
+#include "nm-setting.h"
-#include "nm-test-utils.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;
/*******************************************************************/
@@ -184,8 +155,8 @@ 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);
@@ -224,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);
}
/*******************************************************************/
@@ -341,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 */
@@ -447,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);
}
/*******************************************************************/
@@ -564,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 */
@@ -670,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);
}
/*******************************************************************/
@@ -749,8 +720,8 @@ 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 */
@@ -833,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
@@ -855,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);
@@ -871,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.
@@ -889,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));
@@ -905,6 +876,263 @@ 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
@@ -919,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 831c1beef5..83227d4bbc 100644
--- a/libnm-glib/tests/test-remote-settings-client.c
+++ b/libnm-glib/tests/test-remote-settings-client.c
@@ -27,19 +27,18 @@
#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 "nm-test-utils.h"
+#include "nm-test-libnm-utils.h"
-static NMTestServiceInfo *sinfo;
+static NMTstcServiceInfo *sinfo;
static NMRemoteSettings *settings = NULL;
DBusGConnection *bus = NULL;
NMRemoteConnection *remote = NULL;
@@ -377,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);
@@ -406,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);
@@ -436,10 +435,9 @@ main (int argc, char **argv)
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!
@@ -452,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);
diff --git a/libnm-util/Makefile.am b/libnm-util/Makefile.am
index 29c83f09a1..6e63790817 100644
--- a/libnm-util/Makefile.am
+++ b/libnm-util/Makefile.am
@@ -4,11 +4,11 @@ SUBDIRS = . tests
AM_CPPFLAGS = \
-I${top_srcdir} \
- -I${top_srcdir}/include \
- -I$(top_builddir)/include \
+ -I${top_srcdir}/shared \
+ -I$(top_builddir)/shared \
-DG_LOG_DOMAIN=\""libnm-util"\" \
-DLOCALEDIR=\"$(datadir)/locale\" \
- -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_LIB \
+ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_LIB_LEGACY \
-DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \
$(GLIB_CFLAGS) \
$(DBUS_CFLAGS) \
@@ -25,7 +25,7 @@ endif
lib_LTLIBRARIES=libnm-util.la
libnm_util_include_HEADERS = \
- $(top_builddir)/include/nm-version-macros.h \
+ $(top_builddir)/shared/nm-version-macros.h \
NetworkManager.h \
NetworkManagerVPN.h \
nm-connection.h \
diff --git a/libnm-util/tests/Makefile.am b/libnm-util/tests/Makefile.am
index e580a13486..eda212ed87 100644
--- a/libnm-util/tests/Makefile.am
+++ b/libnm-util/tests/Makefile.am
@@ -1,8 +1,8 @@
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 \
-DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \
diff --git a/libnm/Makefile.am b/libnm/Makefile.am
index 253e109e21..80cdccb066 100644
--- a/libnm/Makefile.am
+++ b/libnm/Makefile.am
@@ -3,8 +3,8 @@ include $(GLIB_MAKEFILE)
SUBDIRS = . tests
AM_CPPFLAGS = \
- -I$(top_srcdir)/include \
- -I$(top_builddir)/include \
+ -I$(top_srcdir)/shared \
+ -I$(top_builddir)/shared \
-I$(top_builddir)/introspection \
-I$(top_srcdir)/libnm-core \
-I$(top_builddir)/libnm-core \
@@ -26,7 +26,7 @@ lib_LTLIBRARIES = libnm.la
libnmincludedir = $(includedir)/libnm
libnminclude_hfiles = \
- $(top_builddir)/include/nm-version-macros.h \
+ $(top_builddir)/shared/nm-version-macros.h \
NetworkManager.h \
nm-access-point.h \
nm-active-connection.h \
diff --git a/libnm/tests/Makefile.am b/libnm/tests/Makefile.am
index 0acbae8fe3..ddcf50be80 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/common.c b/libnm/tests/common.c
deleted file mode 100644
index 5b3f74eb27..0000000000
--- a/libnm/tests/common.c
+++ /dev/null
@@ -1,234 +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 <string.h>
-
-#include "nm-default.h"
-#include "NetworkManager.h"
-#include "nm-dbus-compat.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);
-}
-
-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;
-}
-
-static GVariant *
-call_add_wired_device (GDBusProxy *proxy, const char *ifname, const char *hwaddr,
- const char **subchannels, GError **error)
-{
- const char *empty[] = { NULL };
-
- if (!hwaddr)
- hwaddr = "/";
- if (!subchannels)
- subchannels = empty;
-
- return g_dbus_proxy_call_sync (proxy,
- "AddWiredDevice",
- g_variant_new ("(ss^as)", ifname, hwaddr, subchannels),
- G_DBUS_CALL_FLAGS_NO_AUTO_START,
- 3000,
- NULL,
- error);
-}
-
-static GVariant *
-call_add_device (GDBusProxy *proxy, const char *method, const char *ifname, GError **error)
-{
- return g_dbus_proxy_call_sync (proxy,
- method,
- g_variant_new ("(s)", ifname),
- G_DBUS_CALL_FLAGS_NO_AUTO_START,
- 3000,
- NULL,
- error);
-}
-
-static NMDevice *
-add_device_common (NMTestServiceInfo *sinfo, NMClient *client,
- const char *method, const char *ifname,
- const char *hwaddr, const char **subchannels)
-{
- AddDeviceInfo info;
- GError *error = NULL;
- GVariant *ret;
- guint timeout_id;
-
- if (g_strcmp0 (method, "AddWiredDevice") == 0)
- ret = call_add_wired_device (sinfo->proxy, ifname, hwaddr, subchannels, &error);
- else
- ret = call_add_device (sinfo->proxy, method, ifname, &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;
-}
-
-NMDevice *
-nm_test_service_add_device (NMTestServiceInfo *sinfo, NMClient *client,
- const char *method, const char *ifname)
-{
- return add_device_common (sinfo, client, method, ifname, NULL, NULL);
-}
-
-NMDevice *
-nm_test_service_add_wired_device (NMTestServiceInfo *sinfo, NMClient *client,
- const char *ifname, const char *hwaddr,
- const char **subchannels)
-{
- return add_device_common (sinfo, client, "AddWiredDevice", ifname, hwaddr, subchannels);
-}
diff --git a/libnm/tests/common.h b/libnm/tests/common.h
deleted file mode 100644
index 501ea16c4e..0000000000
--- a/libnm/tests/common.h
+++ /dev/null
@@ -1,45 +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 <NetworkManager.h>
-
-#include "nm-default.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);
-
-NMDevice * nm_test_service_add_wired_device (NMTestServiceInfo *sinfo,
- NMClient *client,
- const char *ifname,
- const char *hwaddr,
- const char **subchannels);
-
diff --git a/libnm/tests/test-nm-client.c b/libnm/tests/test-nm-client.c
index 9da5647147..5be69142e5 100644
--- a/libnm/tests/test-nm-client.c
+++ b/libnm/tests/test-nm-client.c
@@ -24,15 +24,10 @@
#include <sys/types.h>
#include <signal.h>
-#include <NetworkManager.h>
-
-#include "nm-default.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;
/*******************************************************************/
@@ -74,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);
@@ -87,7 +82,7 @@ test_device_added (void)
&notified);
/* 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)
@@ -108,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);
}
/*******************************************************************/
@@ -166,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);
@@ -184,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 */
@@ -207,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);
}
/*******************************************************************/
@@ -314,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));
/*************************************/
@@ -406,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);
}
/*******************************************************************/
@@ -513,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));
/*************************************/
@@ -605,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);
}
/*******************************************************************/
@@ -689,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);
@@ -698,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);
@@ -765,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
@@ -804,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);
@@ -823,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));
@@ -937,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,
@@ -979,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
@@ -1067,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,
@@ -1112,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
@@ -1140,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,
@@ -1157,7 +1152,7 @@ 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
@@ -1174,13 +1169,13 @@ test_device_connection_compatibility (void)
const char *hw_addr1 = "52:54:00:ab:db:23";
const char *hw_addr2 = "52:54:00:ab:db:24";
- sinfo = nm_test_service_init ();
+ sinfo = nmtstc_service_init ();
client = nm_client_new (NULL, &error);
g_assert_no_error (error);
/* Create two devices */
- device1 = nm_test_service_add_wired_device (sinfo, client, "eth0", hw_addr1, subchannels);
- device2 = nm_test_service_add_wired_device (sinfo, client, "eth1", hw_addr2, NULL);
+ 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);
@@ -1228,7 +1223,244 @@ test_device_connection_compatibility (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 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
}
/*******************************************************************/
@@ -1254,6 +1486,7 @@ main (int argc, char **argv)
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 66fbf2bfbc..1a3c7988a2 100644
--- a/libnm/tests/test-remote-settings-client.c
+++ b/libnm/tests/test-remote-settings-client.c
@@ -24,14 +24,9 @@
#include <sys/types.h>
#include <signal.h>
-#include <NetworkManager.h>
+#include "nm-test-libnm-utils.h"
-#include "nm-default.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;
@@ -517,7 +512,7 @@ main (int argc, char **argv)
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);
@@ -536,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 ed2e2dcb50..f8aedd2368 100644
--- a/libnm/tests/test-secret-agent.c
+++ b/libnm/tests/test-secret-agent.c
@@ -24,13 +24,9 @@
#include <sys/types.h>
#include <signal.h>
-#include <NetworkManager.h>
#include <nm-secret-agent-old.h>
-#include "nm-default.h"
-#include "common.h"
-
-#include "nm-test-utils.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));
diff --git a/include/Makefile.am b/shared/Makefile.am
index f0a1dba963..f0a1dba963 100644
--- a/include/Makefile.am
+++ b/shared/Makefile.am
diff --git a/include/gsystem-local-alloc.h b/shared/gsystem-local-alloc.h
index 51b6251974..51b6251974 100644
--- a/include/gsystem-local-alloc.h
+++ b/shared/gsystem-local-alloc.h
diff --git a/include/nm-dbus-compat.h b/shared/nm-dbus-compat.h
index dd97b5fd62..dd97b5fd62 100644
--- a/include/nm-dbus-compat.h
+++ b/shared/nm-dbus-compat.h
diff --git a/include/nm-default.h b/shared/nm-default.h
index 70069a92e8..045ad8db88 100644
--- a/include/nm-default.h
+++ b/shared/nm-default.h
@@ -28,6 +28,7 @@
#define NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON 0x0002
#define NM_NETWORKMANAGER_COMPILATION_LIB 0x0004
#define NM_NETWORKMANAGER_COMPILATION_SYSTEMD 0x0008
+#define NM_NETWORKMANAGER_COMPILATION_LIB_LEGACY 0x0010
#ifndef NETWORKMANAGER_COMPILATION
/* For convenience, we don't require our Makefile.am to define
@@ -46,7 +47,7 @@
/*****************************************************************************/
-#if (NETWORKMANAGER_COMPILATION) == NM_NETWORKMANAGER_COMPILATION_LIB
+#if ((NETWORKMANAGER_COMPILATION) == NM_NETWORKMANAGER_COMPILATION_LIB) || ((NETWORKMANAGER_COMPILATION) == NM_NETWORKMANAGER_COMPILATION_LIB_LEGACY)
#include <glib/gi18n-lib.h>
@@ -54,7 +55,7 @@
#include <glib/gi18n.h>
-#endif /* NM_NETWORKMANAGER_COMPILATION_LIB */
+#endif /* NM_NETWORKMANAGER_COMPILATION_LIB || NM_NETWORKMANAGER_COMPILATION_LIB_LEGACY */
/*****************************************************************************/
diff --git a/include/nm-glib.h b/shared/nm-glib.h
index c75e91ba51..c75e91ba51 100644
--- a/include/nm-glib.h
+++ b/shared/nm-glib.h
diff --git a/include/nm-macros-internal.h b/shared/nm-macros-internal.h
index b4d2d23c91..14430c4277 100644
--- a/include/nm-macros-internal.h
+++ b/shared/nm-macros-internal.h
@@ -84,11 +84,11 @@
#if defined (__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
#define NM_PRAGMA_WARNING_DISABLE(warning) \
- _Pragma("GCC diagnostic push"); \
+ _Pragma("GCC diagnostic push") \
_Pragma(_NM_PRAGMA_WARNING_DO(warning))
#elif defined (__clang__)
#define NM_PRAGMA_WARNING_DISABLE(warning) \
- _Pragma("clang diagnostic push"); \
+ _Pragma("clang diagnostic push") \
_Pragma(_NM_PRAGMA_WARNING_DO(warning))
#else
#define NM_PRAGMA_WARNING_DISABLE(warning)
diff --git a/shared/nm-test-libnm-utils.h b/shared/nm-test-libnm-utils.h
new file mode 100644
index 0000000000..8d111003aa
--- /dev/null
+++ b/shared/nm-test-libnm-utils.h
@@ -0,0 +1,101 @@
+/* -*- 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 - 2015 Red Hat, Inc.
+ */
+
+#include "NetworkManager.h"
+
+#include "nm-test-utils.h"
+
+/*****************************************************************************/
+
+typedef struct {
+ GDBusConnection *bus;
+ GDBusProxy *proxy;
+ GPid pid;
+ int keepalive_fd;
+#if ((NETWORKMANAGER_COMPILATION) == NM_NETWORKMANAGER_COMPILATION_LIB_LEGACY)
+ struct {
+ DBusGConnection *bus;
+ } libdbus;
+#endif
+} NMTstcServiceInfo;
+
+NMTstcServiceInfo *nmtstc_service_init (void);
+void nmtstc_service_cleanup (NMTstcServiceInfo *info);
+
+static inline void _nmtstc_auto_service_cleanup (NMTstcServiceInfo **info)
+{
+ if (info && *info) {
+ nmtstc_service_cleanup (*info);
+ *info = NULL;
+ }
+}
+
+#define NMTSTC_SERVICE_INFO_SETUP(sinfo) \
+ NM_PRAGMA_WARNING_DISABLE ("-Wunused-variable") \
+ __attribute__ ((cleanup(_nmtstc_auto_service_cleanup))) NMTstcServiceInfo *sinfo = nmtstc_service_init (); \
+ NM_PRAGMA_WARNING_REENABLE
+
+/*****************************************************************************/
+
+#if ((NETWORKMANAGER_COMPILATION) == NM_NETWORKMANAGER_COMPILATION_LIB)
+
+NMDevice *nmtstc_service_add_device (NMTstcServiceInfo *info,
+ NMClient *client,
+ const char *method,
+ const char *ifname);
+
+NMDevice * nmtstc_service_add_wired_device (NMTstcServiceInfo *sinfo,
+ NMClient *client,
+ const char *ifname,
+ const char *hwaddr,
+ const char **subchannels);
+
+#endif /* NM_NETWORKMANAGER_COMPILATION_LIB */
+
+#if ((NETWORKMANAGER_COMPILATION) == NM_NETWORKMANAGER_COMPILATION_LIB_LEGACY)
+
+#include "nm-client.h"
+#include "nm-remote-settings.h"
+
+NMClient *nmtstc_nm_client_new (void);
+NMRemoteSettings *nmtstc_nm_remote_settings_new (void);
+
+#endif /* NM_NETWORKMANAGER_COMPILATION_LIB_LEGACY */
+
+void nmtstc_service_add_connection (NMTstcServiceInfo *sinfo,
+ NMConnection *connection,
+ gboolean verify_connection,
+ char **out_path);
+
+void nmtstc_service_add_connection_variant (NMTstcServiceInfo *sinfo,
+ GVariant *connection,
+ gboolean verify_connection,
+ char **out_path);
+
+void nmtstc_service_update_connection (NMTstcServiceInfo *sinfo,
+ const char *path,
+ NMConnection *connection,
+ gboolean verify_connection);
+
+void nmtstc_service_update_connection_variant (NMTstcServiceInfo *sinfo,
+ const char *path,
+ GVariant *connection,
+ gboolean verify_connection);
+
diff --git a/shared/nm-test-utils-impl.c b/shared/nm-test-utils-impl.c
new file mode 100644
index 0000000000..5cdfda3d79
--- /dev/null
+++ b/shared/nm-test-utils-impl.c
@@ -0,0 +1,466 @@
+/* -*- 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 - 2015 Red Hat, Inc.
+ *
+ */
+
+#include "config.h"
+
+#include <string.h>
+
+#include "nm-default.h"
+#include "NetworkManager.h"
+#include "nm-dbus-compat.h"
+
+#if ((NETWORKMANAGER_COMPILATION) == NM_NETWORKMANAGER_COMPILATION_LIB_LEGACY)
+#include "nm-dbus-glib-types.h"
+#endif
+
+#include "nm-test-libnm-utils.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;
+}
+
+#if ((NETWORKMANAGER_COMPILATION) == NM_NETWORKMANAGER_COMPILATION_LIB_LEGACY)
+
+static DBusGProxy *
+_libdbus_create_proxy_test (DBusGConnection *bus)
+{
+ DBusGProxy *proxy;
+
+ proxy = dbus_g_proxy_new_for_name (bus,
+ NM_DBUS_SERVICE,
+ NM_DBUS_PATH,
+ "org.freedesktop.NetworkManager.LibnmGlibTest");
+ g_assert (proxy);
+
+ dbus_g_proxy_set_default_timeout (proxy, G_MAXINT);
+
+ return proxy;
+}
+
+#endif
+
+NMTstcServiceInfo *
+nmtstc_service_init (void)
+{
+ NMTstcServiceInfo *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);
+
+#if ((NETWORKMANAGER_COMPILATION) == NM_NETWORKMANAGER_COMPILATION_LIB_LEGACY)
+ info->libdbus.bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
+ g_assert_no_error (error);
+ g_assert (info->libdbus.bus);
+#endif
+ return info;
+}
+
+void
+nmtstc_service_cleanup (NMTstcServiceInfo *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);
+
+#if ((NETWORKMANAGER_COMPILATION) == NM_NETWORKMANAGER_COMPILATION_LIB_LEGACY)
+ g_clear_pointer (&info->libdbus.bus, dbus_g_connection_unref);
+#endif
+
+ memset (info, 0, sizeof (*info));
+ g_free (info);
+}
+
+#if ((NETWORKMANAGER_COMPILATION) == NM_NETWORKMANAGER_COMPILATION_LIB)
+
+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;
+}
+
+static GVariant *
+call_add_wired_device (GDBusProxy *proxy, const char *ifname, const char *hwaddr,
+ const char **subchannels, GError **error)
+{
+ const char *empty[] = { NULL };
+
+ if (!hwaddr)
+ hwaddr = "/";
+ if (!subchannels)
+ subchannels = empty;
+
+ return g_dbus_proxy_call_sync (proxy,
+ "AddWiredDevice",
+ g_variant_new ("(ss^as)", ifname, hwaddr, subchannels),
+ G_DBUS_CALL_FLAGS_NO_AUTO_START,
+ 3000,
+ NULL,
+ error);
+}
+
+static GVariant *
+call_add_device (GDBusProxy *proxy, const char *method, const char *ifname, GError **error)
+{
+ return g_dbus_proxy_call_sync (proxy,
+ method,
+ g_variant_new ("(s)", ifname),
+ G_DBUS_CALL_FLAGS_NO_AUTO_START,
+ 3000,
+ NULL,
+ error);
+}
+
+static NMDevice *
+add_device_common (NMTstcServiceInfo *sinfo, NMClient *client,
+ const char *method, const char *ifname,
+ const char *hwaddr, const char **subchannels)
+{
+ AddDeviceInfo info;
+ GError *error = NULL;
+ GVariant *ret;
+ guint timeout_id;
+
+ if (g_strcmp0 (method, "AddWiredDevice") == 0)
+ ret = call_add_wired_device (sinfo->proxy, ifname, hwaddr, subchannels, &error);
+ else
+ ret = call_add_device (sinfo->proxy, method, ifname, &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;
+}
+
+NMDevice *
+nmtstc_service_add_device (NMTstcServiceInfo *sinfo, NMClient *client,
+ const char *method, const char *ifname)
+{
+ return add_device_common (sinfo, client, method, ifname, NULL, NULL);
+}
+
+NMDevice *
+nmtstc_service_add_wired_device (NMTstcServiceInfo *sinfo, NMClient *client,
+ const char *ifname, const char *hwaddr,
+ const char **subchannels)
+{
+ return add_device_common (sinfo, client, "AddWiredDevice", ifname, hwaddr, subchannels);
+}
+
+#endif /* NM_NETWORKMANAGER_COMPILATION_LIB */
+
+void
+nmtstc_service_add_connection (NMTstcServiceInfo *sinfo,
+ NMConnection *connection,
+ gboolean verify_connection,
+ char **out_path)
+{
+#if ((NETWORKMANAGER_COMPILATION) == NM_NETWORKMANAGER_COMPILATION_LIB_LEGACY)
+ gs_unref_hashtable GHashTable *new_settings = NULL;
+ gboolean success;
+ gs_free_error GError *error = NULL;
+ gs_free char *path = NULL;
+ gs_unref_object DBusGProxy *proxy = NULL;
+
+ g_assert (sinfo);
+ g_assert (NM_IS_CONNECTION (connection));
+
+ new_settings = nm_connection_to_hash (connection, NM_SETTING_HASH_FLAG_ALL);
+
+ proxy = _libdbus_create_proxy_test (sinfo->libdbus.bus);
+
+ success = dbus_g_proxy_call (proxy,
+ "AddConnection",
+ &error,
+ DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, new_settings,
+ G_TYPE_BOOLEAN, verify_connection,
+ G_TYPE_INVALID,
+ DBUS_TYPE_G_OBJECT_PATH, &path,
+ G_TYPE_INVALID);
+ g_assert_no_error (error);
+ g_assert (success);
+
+ g_assert (path && *path);
+
+ if (out_path)
+ *out_path = g_strdup (path);
+#else
+ nmtstc_service_add_connection_variant (sinfo,
+ nm_connection_to_dbus (connection, NM_CONNECTION_SERIALIZE_ALL),
+ verify_connection,
+ out_path);
+#endif
+}
+
+void
+nmtstc_service_add_connection_variant (NMTstcServiceInfo *sinfo,
+ GVariant *connection,
+ gboolean verify_connection,
+ char **out_path)
+{
+ GVariant *result;
+ GError *error = NULL;
+
+ g_assert (sinfo);
+ g_assert (G_IS_DBUS_PROXY (sinfo->proxy));
+ g_assert (g_variant_is_of_type (connection, G_VARIANT_TYPE ("a{sa{sv}}")));
+
+ result = g_dbus_proxy_call_sync (sinfo->proxy,
+ "AddConnection",
+ g_variant_new ("(vb)", connection, verify_connection),
+ G_DBUS_CALL_FLAGS_NO_AUTO_START,
+ 3000,
+ NULL,
+ &error);
+ g_assert_no_error (error);
+ g_assert (g_variant_is_of_type (result, G_VARIANT_TYPE ("(o)")));
+ if (out_path)
+ g_variant_get (result, "(o)", out_path);
+ g_variant_unref (result);
+}
+
+void
+nmtstc_service_update_connection (NMTstcServiceInfo *sinfo,
+ const char *path,
+ NMConnection *connection,
+ gboolean verify_connection)
+{
+ if (!path)
+ path = nm_connection_get_path (connection);
+ g_assert (path);
+
+#if ((NETWORKMANAGER_COMPILATION) == NM_NETWORKMANAGER_COMPILATION_LIB_LEGACY)
+ {
+ gs_unref_hashtable GHashTable *new_settings = NULL;
+ gboolean success;
+ gs_free_error GError *error = NULL;
+ gs_unref_object DBusGProxy *proxy = NULL;
+
+ g_assert (sinfo);
+ g_assert (NM_IS_CONNECTION (connection));
+
+ new_settings = nm_connection_to_hash (connection, NM_SETTING_HASH_FLAG_ALL);
+
+ proxy = _libdbus_create_proxy_test (sinfo->libdbus.bus);
+
+ success = dbus_g_proxy_call (proxy,
+ "UpdateConnection",
+ &error,
+ DBUS_TYPE_G_OBJECT_PATH, path,
+ DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, new_settings,
+ G_TYPE_BOOLEAN, verify_connection,
+ G_TYPE_INVALID,
+ G_TYPE_INVALID);
+ g_assert_no_error (error);
+ g_assert (success);
+ }
+#else
+ nmtstc_service_update_connection_variant (sinfo,
+ path,
+ nm_connection_to_dbus (connection, NM_CONNECTION_SERIALIZE_ALL),
+ verify_connection);
+#endif
+}
+
+void
+nmtstc_service_update_connection_variant (NMTstcServiceInfo *sinfo,
+ const char *path,
+ GVariant *connection,
+ gboolean verify_connection)
+{
+ GVariant *result;
+ GError *error = NULL;
+
+ g_assert (sinfo);
+ g_assert (G_IS_DBUS_PROXY (sinfo->proxy));
+ g_assert (g_variant_is_of_type (connection, G_VARIANT_TYPE ("a{sa{sv}}")));
+ g_assert (path && path[0] == '/');
+
+ result = g_dbus_proxy_call_sync (sinfo->proxy,
+ "UpdateConnection",
+ g_variant_new ("(ovb)", path, connection, verify_connection),
+ G_DBUS_CALL_FLAGS_NO_AUTO_START,
+ 3000,
+ NULL,
+ &error);
+ g_assert_no_error (error);
+ g_assert (g_variant_is_of_type (result, G_VARIANT_TYPE ("()")));
+ g_variant_unref (result);
+}
+
+/*****************************************************************************/
+
+#if ((NETWORKMANAGER_COMPILATION) == NM_NETWORKMANAGER_COMPILATION_LIB_LEGACY)
+
+NMClient *
+nmtstc_nm_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);
+ g_assert (bus);
+
+ 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;
+}
+
+NMRemoteSettings *
+nmtstc_nm_remote_settings_new (void)
+{
+ NMRemoteSettings *settings;
+ DBusGConnection *bus;
+ GError *error = NULL;
+
+ bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
+ g_assert_no_error (error);
+ g_assert (bus);
+
+ settings = nm_remote_settings_new (bus);
+ g_assert (settings);
+
+ dbus_g_connection_unref (bus);
+
+ return settings;
+}
+
+#endif /* NM_NETWORKMANAGER_COMPILATION_LIB_LEGACY */
+
+/*****************************************************************************/
diff --git a/include/nm-test-utils.h b/shared/nm-test-utils.h
index 28ae56fee7..0402201c28 100644
--- a/include/nm-test-utils.h
+++ b/shared/nm-test-utils.h
@@ -733,6 +733,45 @@ nmtst_rand_perm (GRand *rand, void *dst, const void *src, gsize elmt_size, gsize
return dst;
}
+/*****************************************************************************/
+
+inline static gboolean
+_nmtst_main_loop_run_timeout (gpointer user_data)
+{
+ GMainLoop **p_loop = user_data;
+
+ g_assert (p_loop);
+ g_assert (*p_loop);
+
+ g_main_loop_quit (*p_loop);
+ *p_loop = NULL;
+
+ return G_SOURCE_REMOVE;
+}
+
+inline static gboolean
+nmtst_main_loop_run (GMainLoop *loop, int timeout_ms)
+{
+ GSource *source = NULL;
+ guint id = 0;
+ GMainLoop *loopx = loop;
+
+ if (timeout_ms > 0) {
+ source = g_timeout_source_new (timeout_ms);
+ g_source_set_callback (source, _nmtst_main_loop_run_timeout, &loopx, NULL);
+ id = g_source_attach (source, g_main_loop_get_context (loop));
+ g_assert (id);
+ g_source_unref (source);
+ }
+
+ g_main_loop_run (loop);
+
+ /* if the timeout was reached, return FALSE. */
+ return loopx != NULL;
+}
+
+/*****************************************************************************/
+
inline static const char *
nmtst_get_sudo_cmd (void)
{
@@ -768,6 +807,49 @@ nmtst_reexec_sudo (void)
g_error (">> exec %s failed: %d - %s", __nmtst_internal.sudo_cmd, errsv, strerror (errsv));
}
+/*****************************************************************************/
+
+inline static gsize
+nmtst_find_all_indexes (gpointer *elements,
+ gsize n_elements,
+ gpointer *needles,
+ gsize n_needles,
+ gboolean (*equal_fcn) (gpointer element, gpointer needle, gpointer user_data),
+ gpointer user_data,
+ gssize *out_idx)
+{
+ gsize i, j, k;
+ gsize found = 0;
+
+ for (i = 0; i < n_needles; i++) {
+ gssize idx = -1;
+
+ for (j = 0; j < n_elements; j++) {
+
+ /* no duplicates */
+ for (k = 0; k < i; k++) {
+ if (out_idx[k] == j)
+ goto next;
+ }
+
+ if (equal_fcn (elements[j], needles[i], user_data)) {
+ idx = j;
+ break;
+ }
+next:
+ ;
+ }
+
+ out_idx[i] = idx;
+ if (idx >= 0)
+ found++;
+ }
+
+ return found;
+}
+
+/*****************************************************************************/
+
#define __define_nmtst_static(NUM,SIZE) \
inline static const char * \
nmtst_static_##SIZE##_##NUM (const char *str) \
@@ -786,6 +868,17 @@ __define_nmtst_static(02, 1024)
__define_nmtst_static(03, 1024)
#undef __define_nmtst_static
+inline static const char *
+nmtst_uuid_generate (void)
+{
+ static char u[37];
+ gs_free char *m = NULL;
+
+ m = nm_utils_uuid_generate ();
+ g_assert (m && strlen (m) == sizeof (u) - 1);
+ memcpy (u, m, sizeof (u));
+ return u;
+}
#define NMTST_SWAP(x,y) \
G_STMT_START { \
@@ -1168,7 +1261,7 @@ nmtst_ip6_config_clone (NMIP6Config *config)
#endif
-#if defined(__NM_SIMPLE_CONNECTION_H__) && defined(__NM_SETTING_CONNECTION_H__)
+#if (defined(__NM_SIMPLE_CONNECTION_H__) && defined(__NM_SETTING_CONNECTION_H__)) || (defined(NM_CONNECTION_H))
inline static NMConnection *
nmtst_create_minimal_connection (const char *id, const char *uuid, const char *type, NMSettingConnection **out_s_con)
@@ -1186,7 +1279,13 @@ nmtst_create_minimal_connection (const char *id, const char *uuid, const char *t
uuid = uuid_free = nm_utils_uuid_generate ();
if (type) {
- GType type_g = nm_setting_lookup_type (type);
+ GType type_g;
+
+#if defined(__NM_SIMPLE_CONNECTION_H__)
+ type_g = nm_setting_lookup_type (type);
+#else
+ type_g = nm_connection_lookup_setting_type (type);
+#endif
g_assert (type_g != G_TYPE_INVALID);
@@ -1194,7 +1293,12 @@ nmtst_create_minimal_connection (const char *id, const char *uuid, const char *t
g_assert (NM_IS_SETTING (s_base));
}
+#if defined(__NM_SIMPLE_CONNECTION_H__)
con = nm_simple_connection_new ();
+#else
+ con = nm_connection_new ();
+#endif
+
s_con = NM_SETTING_CONNECTION (nm_setting_connection_new ());
g_object_set (s_con,
@@ -1265,7 +1369,11 @@ _nmtst_connection_duplicate_and_normalize (NMConnection *connection, ...)
g_assert (NM_IS_CONNECTION (connection));
+#if defined(__NM_SIMPLE_CONNECTION_H__)
connection = nm_simple_connection_new_clone (connection);
+#else
+ connection = nm_connection_duplicate (connection);
+#endif
va_start (args, connection);
was_modified = _nmtst_connection_normalize_v (connection, args);
@@ -1347,7 +1455,11 @@ nmtst_assert_connection_verifies_without_normalization (NMConnection *con)
g_assert (NM_IS_CONNECTION (con));
+#if defined(__NM_SIMPLE_CONNECTION_H__)
clone = nm_simple_connection_new_clone (con);
+#else
+ clone = nm_connection_duplicate (con);
+#endif
success = nm_connection_verify (con, &error);
g_assert_no_error (error);
diff --git a/include/nm-version-macros.h.in b/shared/nm-version-macros.h.in
index a8ad5c8d6e..a8ad5c8d6e 100644
--- a/include/nm-version-macros.h.in
+++ b/shared/nm-version-macros.h.in
diff --git a/src/Makefile.am b/src/Makefile.am
index e4b2cb090c..c37b058ac5 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -33,8 +33,8 @@ SUBDIRS += \
endif
AM_CPPFLAGS = \
- -I$(top_srcdir)/include \
- -I$(top_builddir)/include \
+ -I$(top_srcdir)/shared \
+ -I$(top_builddir)/shared \
-I$(top_builddir)/introspection \
-I$(top_srcdir)/libnm-core \
-I$(top_builddir)/libnm-core \
@@ -173,8 +173,8 @@ libsystemd_nm_la_SOURCES = \
systemd/src/systemd/sd-ndisc.h
libsystemd_nm_la_CPPFLAGS = \
- -I$(top_srcdir)/include \
- -I$(top_builddir)/include \
+ -I$(top_srcdir)/shared \
+ -I$(top_builddir)/shared \
-I$(top_srcdir)/libnm-core \
-I$(top_builddir)/libnm-core \
$(SYSTEMD_NM_CFLAGS_PATHS) \
diff --git a/src/devices/adsl/Makefile.am b/src/devices/adsl/Makefile.am
index b082ffc4ff..e7034fa873 100644
--- a/src/devices/adsl/Makefile.am
+++ b/src/devices/adsl/Makefile.am
@@ -8,8 +8,8 @@ AM_CPPFLAGS = \
-I${top_srcdir}/src/devices \
-I${top_srcdir}/src/platform \
-I${top_builddir}/introspection \
- -I${top_srcdir}/include \
- -I$(top_builddir)/include \
+ -I${top_srcdir}/shared \
+ -I$(top_builddir)/shared \
-I${top_builddir}/libnm-core \
-I${top_srcdir}/libnm-core \
-DG_LOG_DOMAIN=\""NetworkManager-adsl"\" \
diff --git a/src/devices/bluetooth/Makefile.am b/src/devices/bluetooth/Makefile.am
index 37217dfac6..2054ea0f59 100644
--- a/src/devices/bluetooth/Makefile.am
+++ b/src/devices/bluetooth/Makefile.am
@@ -10,8 +10,8 @@ AM_CPPFLAGS = \
-I${top_srcdir}/src/platform \
-I${top_srcdir}/src/devices/wwan \
-I${top_builddir}/introspection \
- -I${top_srcdir}/include \
- -I$(top_builddir)/include \
+ -I${top_srcdir}/shared \
+ -I$(top_builddir)/shared \
-I${top_builddir}/libnm-core \
-I${top_srcdir}/libnm-core \
-DG_LOG_DOMAIN=\""NetworkManager-bluetooth"\" \
diff --git a/src/devices/team/Makefile.am b/src/devices/team/Makefile.am
index 3df138609d..a66458337c 100644
--- a/src/devices/team/Makefile.am
+++ b/src/devices/team/Makefile.am
@@ -8,8 +8,8 @@ AM_CPPFLAGS = \
-I${top_srcdir}/src/devices \
-I${top_srcdir}/src/platform \
-I${top_builddir}/introspection \
- -I${top_srcdir}/include \
- -I$(top_builddir)/include \
+ -I${top_srcdir}/shared \
+ -I$(top_builddir)/shared \
-I${top_builddir}/libnm-core \
-I${top_srcdir}/libnm-core \
-DG_LOG_DOMAIN=\""NetworkManager-team"\" \
diff --git a/src/devices/tests/Makefile.am b/src/devices/tests/Makefile.am
index 4b1595e7b4..330377b0b8 100644
--- a/src/devices/tests/Makefile.am
+++ b/src/devices/tests/Makefile.am
@@ -1,6 +1,6 @@
AM_CPPFLAGS = \
- -I$(top_srcdir)/include \
- -I$(top_builddir)/include \
+ -I$(top_srcdir)/shared \
+ -I$(top_builddir)/shared \
-I$(top_srcdir)/libnm-core \
-I$(top_builddir)/libnm-core \
-I$(top_srcdir)/src/platform \
diff --git a/src/devices/wifi/Makefile.am b/src/devices/wifi/Makefile.am
index df21597d38..b0919ef710 100644
--- a/src/devices/wifi/Makefile.am
+++ b/src/devices/wifi/Makefile.am
@@ -14,8 +14,8 @@ AM_CPPFLAGS = \
-I${top_srcdir}/src/platform \
-I${top_srcdir}/src/supplicant-manager \
-I${top_builddir}/introspection \
- -I${top_srcdir}/include \
- -I$(top_builddir)/include \
+ -I${top_srcdir}/shared \
+ -I$(top_builddir)/shared \
-I${top_builddir}/libnm-core \
-I${top_srcdir}/libnm-core \
-DG_LOG_DOMAIN=\""NetworkManager-wifi"\" \
diff --git a/src/devices/wifi/tests/Makefile.am b/src/devices/wifi/tests/Makefile.am
index 2e25dc422a..dee8e799b2 100644
--- a/src/devices/wifi/tests/Makefile.am
+++ b/src/devices/wifi/tests/Makefile.am
@@ -1,7 +1,7 @@
AM_CPPFLAGS = \
-I$(top_builddir)/introspection \
- -I$(top_srcdir)/include \
- -I$(top_builddir)/include \
+ -I$(top_srcdir)/shared \
+ -I$(top_builddir)/shared \
-I$(top_srcdir)/libnm-core \
-I$(top_builddir)/libnm-core \
-I${top_srcdir}/src/platform \
diff --git a/src/devices/wwan/Makefile.am b/src/devices/wwan/Makefile.am
index 1d2dcb680b..107f630b3f 100644
--- a/src/devices/wwan/Makefile.am
+++ b/src/devices/wwan/Makefile.am
@@ -9,8 +9,8 @@ AM_CPPFLAGS = \
-I${top_srcdir}/src/settings \
-I${top_srcdir}/src/platform \
-I${top_builddir}/introspection \
- -I${top_srcdir}/include \
- -I$(top_builddir)/include \
+ -I${top_srcdir}/shared \
+ -I$(top_builddir)/shared \
-I${top_srcdir}/libnm-core \
-I${top_builddir}/libnm-core \
-DG_LOG_DOMAIN=\""NetworkManager-wwan"\" \
diff --git a/src/dhcp-manager/Makefile.am b/src/dhcp-manager/Makefile.am
index b07bbc671f..3199ab0451 100644
--- a/src/dhcp-manager/Makefile.am
+++ b/src/dhcp-manager/Makefile.am
@@ -4,8 +4,8 @@ nm_dhcp_helper_SOURCES = nm-dhcp-helper.c
nm_dhcp_helper_CPPFLAGS = \
$(GLIB_CFLAGS) \
- -I$(top_srcdir)/include \
- -I${top_builddir}/include \
+ -I$(top_srcdir)/shared \
+ -I${top_builddir}/shared \
-I$(top_srcdir)/libnm-core \
-I$(top_builddir)/libnm-core \
-DG_LOG_DOMAIN=\""nm-dhcp-helper"\" \
diff --git a/src/dhcp-manager/tests/Makefile.am b/src/dhcp-manager/tests/Makefile.am
index 578f7144ac..5c7f9ba20e 100644
--- a/src/dhcp-manager/tests/Makefile.am
+++ b/src/dhcp-manager/tests/Makefile.am
@@ -1,6 +1,6 @@
AM_CPPFLAGS = \
- -I$(top_srcdir)/include \
- -I${top_builddir}/include \
+ -I$(top_srcdir)/shared \
+ -I${top_builddir}/shared \
-I${top_srcdir}/libnm-core \
-I${top_builddir}/libnm-core \
-I$(top_srcdir)/src/dhcp-manager \
diff --git a/src/dnsmasq-manager/tests/Makefile.am b/src/dnsmasq-manager/tests/Makefile.am
index 0ddaa381c1..2c5e8e4063 100644
--- a/src/dnsmasq-manager/tests/Makefile.am
+++ b/src/dnsmasq-manager/tests/Makefile.am
@@ -1,6 +1,6 @@
AM_CPPFLAGS = \
- -I$(top_srcdir)/include \
- -I${top_builddir}/include \
+ -I$(top_srcdir)/shared \
+ -I${top_builddir}/shared \
-I${top_srcdir}/libnm-core \
-I${top_builddir}/libnm-core \
-I$(top_srcdir)/src/dnsmasq-manager \
diff --git a/src/platform/tests/Makefile.am b/src/platform/tests/Makefile.am
index 5996f34706..b097fcf6b2 100644
--- a/src/platform/tests/Makefile.am
+++ b/src/platform/tests/Makefile.am
@@ -1,7 +1,7 @@
AM_CPPFLAGS = \
-I${top_srcdir} \
- -I${top_srcdir}/include \
- -I${top_builddir}/include \
+ -I${top_srcdir}/shared \
+ -I${top_builddir}/shared \
-I${top_srcdir}/src \
-I${top_builddir}/src \
-I${top_srcdir}/libnm-core \
diff --git a/src/ppp-manager/Makefile.am b/src/ppp-manager/Makefile.am
index 650c4301f2..5cf908df70 100644
--- a/src/ppp-manager/Makefile.am
+++ b/src/ppp-manager/Makefile.am
@@ -1,8 +1,8 @@
if WITH_PPP
AM_CPPFLAGS = \
- -I${top_srcdir}/include \
- -I${top_builddir}/include \
+ -I${top_srcdir}/shared \
+ -I${top_builddir}/shared \
-I${top_srcdir}/libnm-core \
-I${top_srcdir}/src \
-I${top_builddir}/libnm-core \
diff --git a/src/rdisc/tests/Makefile.am b/src/rdisc/tests/Makefile.am
index cf302ad6c7..d520e4164a 100644
--- a/src/rdisc/tests/Makefile.am
+++ b/src/rdisc/tests/Makefile.am
@@ -1,7 +1,7 @@
AM_CPPFLAGS = \
-I${top_srcdir} \
- -I$(top_srcdir)/include \
- -I$(top_builddir)/include \
+ -I$(top_srcdir)/shared \
+ -I$(top_builddir)/shared \
-I${top_srcdir}/src \
-I${top_srcdir}/src/platform \
-I${top_srcdir}/libnm-core \
diff --git a/src/settings/plugins/ibft/Makefile.am b/src/settings/plugins/ibft/Makefile.am
index 49d78311de..a994808d84 100644
--- a/src/settings/plugins/ibft/Makefile.am
+++ b/src/settings/plugins/ibft/Makefile.am
@@ -14,8 +14,8 @@ AM_CPPFLAGS = \
-I$(top_srcdir)/src/ \
-I$(top_srcdir)/src/platform \
-I$(top_srcdir)/src/settings \
- -I$(top_srcdir)/include \
- -I$(top_builddir)/include \
+ -I$(top_srcdir)/shared \
+ -I$(top_builddir)/shared \
-I$(top_srcdir)/libnm-core \
-I$(top_builddir)/libnm-core \
-DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \
diff --git a/src/settings/plugins/ibft/tests/Makefile.am b/src/settings/plugins/ibft/tests/Makefile.am
index 3c3b5cf577..29881e852d 100644
--- a/src/settings/plugins/ibft/tests/Makefile.am
+++ b/src/settings/plugins/ibft/tests/Makefile.am
@@ -5,8 +5,8 @@ if ENABLE_TESTS
AM_CPPFLAGS = \
$(GLIB_CFLAGS) \
$(CODE_COVERAGE_CFLAGS) \
- -I$(top_srcdir)/include \
- -I$(top_builddir)/include \
+ -I$(top_srcdir)/shared \
+ -I$(top_builddir)/shared \
-I$(top_srcdir)/libnm-core \
-I$(top_builddir)/libnm-core \
-I$(top_srcdir)/src/ \
diff --git a/src/settings/plugins/ifcfg-rh/Makefile.am b/src/settings/plugins/ifcfg-rh/Makefile.am
index ebae6374e5..ab96a32852 100644
--- a/src/settings/plugins/ifcfg-rh/Makefile.am
+++ b/src/settings/plugins/ifcfg-rh/Makefile.am
@@ -43,8 +43,8 @@ AM_CPPFLAGS = \
-I$(top_srcdir)/src/ \
-I$(top_srcdir)/src/platform \
-I$(top_srcdir)/src/settings \
- -I$(top_srcdir)/include \
- -I$(top_builddir)/include \
+ -I$(top_srcdir)/shared \
+ -I$(top_builddir)/shared \
-I$(top_srcdir)/libnm-core \
-I$(top_builddir)/libnm-core \
-DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \
diff --git a/src/settings/plugins/ifcfg-rh/tests/Makefile.am b/src/settings/plugins/ifcfg-rh/tests/Makefile.am
index 4f942d2050..25d271976e 100644
--- a/src/settings/plugins/ifcfg-rh/tests/Makefile.am
+++ b/src/settings/plugins/ifcfg-rh/tests/Makefile.am
@@ -7,8 +7,8 @@ SUBDIRS=network-scripts
AM_CPPFLAGS = \
$(GLIB_CFLAGS) \
$(CODE_COVERAGE_CFLAGS) \
- -I$(top_srcdir)/include \
- -I$(top_builddir)/include \
+ -I$(top_srcdir)/shared \
+ -I$(top_builddir)/shared \
-I$(top_srcdir)/libnm-core \
-I$(top_builddir)/libnm-core \
-I$(top_srcdir)/src/ \
diff --git a/src/settings/plugins/ifnet/Makefile.am b/src/settings/plugins/ifnet/Makefile.am
index 5e1713a147..ffd8ab3caf 100644
--- a/src/settings/plugins/ifnet/Makefile.am
+++ b/src/settings/plugins/ifnet/Makefile.am
@@ -6,8 +6,8 @@ AM_CPPFLAGS = \
-I$(top_srcdir)/src \
-I$(top_srcdir)/src/platform \
-I$(top_srcdir)/src/settings \
- -I$(top_srcdir)/include \
- -I$(top_builddir)/include \
+ -I$(top_srcdir)/shared \
+ -I$(top_builddir)/shared \
-I$(top_srcdir)/libnm-core \
-I$(top_builddir)/libnm-core \
-DG_LOG_DOMAIN=\""NetworkManager-ifnet"\" \
diff --git a/src/settings/plugins/ifnet/tests/Makefile.am b/src/settings/plugins/ifnet/tests/Makefile.am
index 9c1bcbf62e..1919f1410a 100644
--- a/src/settings/plugins/ifnet/tests/Makefile.am
+++ b/src/settings/plugins/ifnet/tests/Makefile.am
@@ -4,8 +4,8 @@ if ENABLE_TESTS
AM_CPPFLAGS= \
-I$(srcdir)/../ \
- -I$(top_srcdir)/include \
- -I$(top_builddir)/include \
+ -I$(top_srcdir)/shared \
+ -I$(top_builddir)/shared \
-I$(top_srcdir)/libnm-core \
-I$(top_builddir)/libnm-core \
-I$(top_srcdir)/src \
diff --git a/src/settings/plugins/ifupdown/Makefile.am b/src/settings/plugins/ifupdown/Makefile.am
index b3ab2efdfc..c5c645d358 100644
--- a/src/settings/plugins/ifupdown/Makefile.am
+++ b/src/settings/plugins/ifupdown/Makefile.am
@@ -5,8 +5,8 @@ SUBDIRS = . tests
AM_CPPFLAGS = \
-I$(top_srcdir)/src \
-I$(top_srcdir)/src/settings \
- -I$(top_srcdir)/include \
- -I$(top_builddir)/include \
+ -I$(top_srcdir)/shared \
+ -I$(top_builddir)/shared \
-I$(top_srcdir)/libnm-core \
-I$(top_builddir)/libnm-core \
-DG_LOG_DOMAIN=\""NetworkManager-ifupdown"\" \
diff --git a/src/settings/plugins/ifupdown/tests/Makefile.am b/src/settings/plugins/ifupdown/tests/Makefile.am
index 55d9f88b2a..29e9a7ed5c 100644
--- a/src/settings/plugins/ifupdown/tests/Makefile.am
+++ b/src/settings/plugins/ifupdown/tests/Makefile.am
@@ -1,8 +1,8 @@
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-core \
-I$(top_builddir)/libnm-core \
-I$(top_srcdir)/src \
diff --git a/src/settings/plugins/keyfile/Makefile.am b/src/settings/plugins/keyfile/Makefile.am
index 1278b2fa3c..ddcd15b292 100644
--- a/src/settings/plugins/keyfile/Makefile.am
+++ b/src/settings/plugins/keyfile/Makefile.am
@@ -5,8 +5,8 @@ SUBDIRS = . tests
AM_CPPFLAGS = \
-I$(top_srcdir)/src \
-I$(top_srcdir)/src/settings \
- -I$(top_srcdir)/include \
- -I$(top_builddir)/include \
+ -I$(top_srcdir)/shared \
+ -I$(top_builddir)/shared \
-I$(top_srcdir)/libnm-core \
-I$(top_builddir)/libnm-core \
-DG_LOG_DOMAIN=\""NetworkManager-keyfile"\" \
diff --git a/src/settings/plugins/keyfile/tests/Makefile.am b/src/settings/plugins/keyfile/tests/Makefile.am
index 34331e15a8..4d85f09a40 100644
--- a/src/settings/plugins/keyfile/tests/Makefile.am
+++ b/src/settings/plugins/keyfile/tests/Makefile.am
@@ -5,8 +5,8 @@ SUBDIRS=keyfiles
@GNOME_CODE_COVERAGE_RULES@
AM_CPPFLAGS = \
- -I$(top_srcdir)/include \
- -I$(top_builddir)/include \
+ -I$(top_srcdir)/shared \
+ -I$(top_builddir)/shared \
-I$(top_srcdir)/libnm-core \
-I$(top_builddir)/libnm-core \
-I$(top_srcdir)/src \
diff --git a/src/supplicant-manager/tests/Makefile.am b/src/supplicant-manager/tests/Makefile.am
index 66bd7d581d..9ac0387c4b 100644
--- a/src/supplicant-manager/tests/Makefile.am
+++ b/src/supplicant-manager/tests/Makefile.am
@@ -1,8 +1,8 @@
SUBDIRS=certs
AM_CPPFLAGS = \
- -I$(top_srcdir)/include \
- -I$(top_builddir)/include \
+ -I$(top_srcdir)/shared \
+ -I$(top_builddir)/shared \
-I$(top_srcdir)/libnm-core \
-I$(top_builddir)/libnm-core \
-I$(top_srcdir)/src \
diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am
index 18fce10088..26c2ed7f55 100644
--- a/src/tests/Makefile.am
+++ b/src/tests/Makefile.am
@@ -1,8 +1,8 @@
SUBDIRS = config
AM_CPPFLAGS = \
- -I$(top_srcdir)/include \
- -I$(top_builddir)/include \
+ -I$(top_srcdir)/shared \
+ -I$(top_builddir)/shared \
-I$(top_srcdir)/libnm-core \
-I$(top_builddir)/libnm-core \
-I$(top_srcdir)/src/platform \
diff --git a/src/tests/config/Makefile.am b/src/tests/config/Makefile.am
index 80f923c46e..5d4aed5c86 100644
--- a/src/tests/config/Makefile.am
+++ b/src/tests/config/Makefile.am
@@ -1,6 +1,6 @@
AM_CPPFLAGS = \
- -I$(top_srcdir)/include \
- -I$(top_builddir)/include \
+ -I$(top_srcdir)/shared \
+ -I$(top_builddir)/shared \
-I$(top_srcdir)/libnm-core \
-I$(top_builddir)/libnm-core \
-I$(top_srcdir)/src/ \
diff --git a/tools/test-networkmanager-service.py b/tools/test-networkmanager-service.py
index ae63eaf745..6335fd8070 100755
--- a/tools/test-networkmanager-service.py
+++ b/tools/test-networkmanager-service.py
@@ -10,6 +10,7 @@ import dbus.service
import dbus.mainloop.glib
import random
import collections
+import uuid
mainloop = GLib.MainLoop()
@@ -918,6 +919,15 @@ class NetworkManager(ExportedObj):
def AutoRemoveNextConnection(self):
settings.auto_remove_next_connection()
+ @dbus.service.method(dbus_interface=IFACE_TEST, in_signature='a{sa{sv}}b', out_signature='o')
+ def AddConnection(self, connection, verify_connection):
+ return settings.add_connection(connection, verify_connection)
+
+ @dbus.service.method(dbus_interface=IFACE_TEST, in_signature='sa{sa{sv}}b', out_signature='')
+ def UpdateConnection(self, path, connection, verify_connection):
+ return settings.update_connection(connection, path, verify_connection)
+
+
###################################################################
IFACE_CONNECTION = 'org.freedesktop.NetworkManager.Settings.Connection'
@@ -934,17 +944,15 @@ class MissingSettingException(dbus.DBusException):
_dbus_error_name = IFACE_CONNECTION + '.MissingSetting'
class Connection(dbus.service.Object):
- def __init__(self, bus, object_path, settings, remove_func):
- dbus.service.Object.__init__(self, bus, object_path)
+ def __init__(self, bus, object_path, settings, remove_func, verify_connection=True):
- if 'connection' not in settings:
- raise MissingSettingException('connection: setting is required')
- s_con = settings['connection']
- if 'type' not in s_con:
- raise MissingPropertyException('connection.type: property is required')
- type = s_con['type']
- if not type in ['802-3-ethernet', '802-11-wireless', 'vlan', 'wimax']:
- raise InvalidPropertyException('connection.type: unsupported connection type')
+ if self.get_uuid(settings) is None:
+ if 'connection' not in settings:
+ settings['connection'] = { }
+ settings['connection']['uuid'] = uuid.uuid4()
+ self.verify(settings, verify_strict=verify_connection)
+
+ dbus.service.Object.__init__(self, bus, object_path)
self.path = object_path
self.settings = settings
@@ -953,6 +961,45 @@ class Connection(dbus.service.Object):
self.props = {}
self.props['Unsaved'] = False
+ def get_uuid(self, settings=None):
+ if settings is None:
+ settings = self.settings
+ if 'connection' in settings:
+ s_con = settings['connection']
+ if 'uuid' in s_con:
+ return s_con['uuid']
+ return None
+
+ def verify(self, settings=None, verify_strict=True):
+ if settings is None:
+ settings = self.settings;
+ if 'connection' not in settings:
+ raise MissingSettingException('connection: setting is required')
+ s_con = settings['connection']
+ if 'type' not in s_con:
+ raise MissingPropertyException('connection.type: property is required')
+ if 'uuid' not in s_con:
+ raise MissingPropertyException('connection.uuid: property is required')
+ if 'id' not in s_con:
+ raise MissingPropertyException('connection.id: property is required')
+
+ if not verify_strict:
+ return;
+ t = s_con['type']
+ if t not in ['802-3-ethernet', '802-11-wireless', 'vlan', 'wimax']:
+ raise InvalidPropertyException('connection.type: unsupported connection type "%s"' % (t))
+
+ def update_connection(self, settings, verify_connection):
+ self.verify(settings, verify_strict=verify_connection)
+
+ old_uuid = self.get_uuid()
+ new_uuid = self.get_uuid(settings)
+ if old_uuid != new_uuid:
+ raise InvalidPropertyException('connection.uuid: cannot change the uuid from %s to %s' % (old_uuid, new_uuid))
+
+ self.settings = settings;
+ self.Updated()
+
# Properties interface
@dbus.service.method(dbus_interface=dbus.PROPERTIES_IFACE, in_signature='s', out_signature='a{sv}')
def GetAll(self, iface):
@@ -986,6 +1033,10 @@ class Connection(dbus.service.Object):
self.Removed()
self.remove_from_connection()
+ @dbus.service.method(dbus_interface=IFACE_CONNECTION, in_signature='a{sa{sv}}', out_signature='')
+ def Update(self, settings):
+ self.update_connection(settings, TRUE)
+
@dbus.service.signal(IFACE_CONNECTION, signature='')
def Removed(self):
pass
@@ -1024,9 +1075,18 @@ class Settings(dbus.service.Object):
@dbus.service.method(dbus_interface=IFACE_SETTINGS, in_signature='a{sa{sv}}', out_signature='o')
def AddConnection(self, settings):
+ return self.add_connection(settings)
+
+ def add_connection(self, settings, verify_connection=True):
path = "/org/freedesktop/NetworkManager/Settings/Connection/{0}".format(self.counter)
+ con = Connection(self.bus, path, settings, self.delete_connection, verify_connection)
+
+ uuid = con.get_uuid()
+ if uuid in [c.get_uuid() for c in self.connections.itervalues()]:
+ raise InvalidSettingException('cannot add duplicate connection with uuid %s' % (uuid))
+
self.counter = self.counter + 1
- self.connections[path] = Connection(self.bus, path, settings, self.delete_connection)
+ self.connections[path] = con
self.props['Connections'] = dbus.Array(self.connections.keys(), 'o')
self.NewConnection(path)
self.PropertiesChanged({ 'connections': self.props['Connections'] })
@@ -1037,6 +1097,14 @@ class Settings(dbus.service.Object):
return path
+ def update_connection(self, connection, path=None, verify_connection=True):
+ if path is None:
+ path = connection.path
+ if path not in self.connections:
+ raise UnknownConnectionException('Connection not found')
+ con = self.connections[path]
+ con.update_connection(connection, verify_connection)
+
def delete_connection(self, connection):
del self.connections[connection.path]
self.props['Connections'] = dbus.Array(self.connections.keys(), 'o')