diff options
| author | Michael Biebl <biebl@debian.org> | 2015-01-22 00:29:39 +0100 |
|---|---|---|
| committer | Michael Biebl <biebl@debian.org> | 2015-01-22 00:29:39 +0100 |
| commit | 2c032d8f1c6292c1338a615e6ec40252889ba85c (patch) | |
| tree | 1f77182220b2b0264288ba4a476ab47e5bc48716 /callouts/tests | |
| parent | 33491bc4279481db8ae47213e34a6d695a0e8830 (diff) | |
Imported Upstream version 1.0.0 upstream/1.0.0
Diffstat (limited to 'callouts/tests')
| -rw-r--r-- | callouts/tests/Makefile.am | 17 | ||||
| -rw-r--r-- | callouts/tests/Makefile.in | 154 | ||||
| -rw-r--r-- | callouts/tests/dispatcher-old-up | 1 | ||||
| -rw-r--r-- | callouts/tests/dispatcher-old-vpn-down | 1 | ||||
| -rw-r--r-- | callouts/tests/dispatcher-old-vpn-up | 1 | ||||
| -rw-r--r-- | callouts/tests/test-dispatcher-envp.c | 374 |
6 files changed, 297 insertions, 251 deletions
diff --git a/callouts/tests/Makefile.am b/callouts/tests/Makefile.am index de4b5f52..f8fd82b7 100644 --- a/callouts/tests/Makefile.am +++ b/callouts/tests/Makefile.am @@ -2,11 +2,13 @@ if ENABLE_TESTS AM_CPPFLAGS = \ -I$(top_srcdir)/include \ - -I${top_builddir}/include \ - -I$(top_srcdir)/libnm-util \ - -I$(top_builddir)/libnm-util \ + -I$(top_srcdir)/libnm-core \ + -I$(top_builddir)/libnm-core \ -I$(top_srcdir)/callouts \ + -I$(top_builddir)/callouts \ + -DNETWORKMANAGER_COMPILATION \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ + -DSRCDIR=\"$(abs_srcdir)\" \ $(GLIB_CFLAGS) \ $(DBUS_CFLAGS) @@ -19,20 +21,19 @@ test_dispatcher_envp_SOURCES = \ test-dispatcher-envp.c test_dispatcher_envp_LDADD = \ - $(top_builddir)/libnm-util/libnm-util.la \ + $(top_builddir)/libnm/libnm.la \ $(top_builddir)/callouts/libtest-dispatcher-envp.la \ $(GLIB_LIBS) \ $(DBUS_LIBS) ########################################### -check-local: test-dispatcher-envp - $(abs_builddir)/test-dispatcher-envp $(abs_srcdir) +TESTS = test-dispatcher-envp + +endif EXTRA_DIST= \ dispatcher-old-down \ dispatcher-old-up \ dispatcher-old-vpn-down \ dispatcher-old-vpn-up - -endif diff --git a/callouts/tests/Makefile.in b/callouts/tests/Makefile.in index 25255b59..5372e352 100644 --- a/callouts/tests/Makefile.in +++ b/callouts/tests/Makefile.in @@ -79,6 +79,7 @@ POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ @ENABLE_TESTS_TRUE@noinst_PROGRAMS = test-dispatcher-envp$(EXEEXT) +@ENABLE_TESTS_TRUE@TESTS = test-dispatcher-envp$(EXEEXT) subdir = callouts/tests DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \ $(top_srcdir)/build-aux/depcomp @@ -109,7 +110,7 @@ am__test_dispatcher_envp_SOURCES_DIST = test-dispatcher-envp.c test_dispatcher_envp_OBJECTS = $(am_test_dispatcher_envp_OBJECTS) am__DEPENDENCIES_1 = @ENABLE_TESTS_TRUE@test_dispatcher_envp_DEPENDENCIES = \ -@ENABLE_TESTS_TRUE@ $(top_builddir)/libnm-util/libnm-util.la \ +@ENABLE_TESTS_TRUE@ $(top_builddir)/libnm/libnm.la \ @ENABLE_TESTS_TRUE@ $(top_builddir)/callouts/libtest-dispatcher-envp.la \ @ENABLE_TESTS_TRUE@ $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) AM_V_lt = $(am__v_lt_@AM_V@) @@ -176,6 +177,28 @@ am__define_uniq_tagged_files = \ done | $(am__uniquify_input)` ETAGS = etags CTAGS = ctags +am__tty_colors_dummy = \ + mgn= red= grn= lgn= blu= brg= std=; \ + am__color_tests=no +am__tty_colors = { \ + $(am__tty_colors_dummy); \ + if test "X$(AM_COLOR_TESTS)" = Xno; then \ + am__color_tests=no; \ + elif test "X$(AM_COLOR_TESTS)" = Xalways; then \ + am__color_tests=yes; \ + elif test "X$$TERM" != Xdumb && { test -t 1; } 2>/dev/null; then \ + am__color_tests=yes; \ + fi; \ + if test $$am__color_tests = yes; then \ + red='[0;31m'; \ + grn='[0;32m'; \ + lgn='[1;32m'; \ + blu='[1;34m'; \ + mgn='[0;35m'; \ + brg='[1m'; \ + std='[m'; \ + fi; \ +} DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) ACLOCAL = @ACLOCAL@ ALL_LINGUAS = @ALL_LINGUAS@ @@ -186,6 +209,8 @@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ +BLUEZ5_CFLAGS = @BLUEZ5_CFLAGS@ +BLUEZ5_LIBS = @BLUEZ5_LIBS@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ @@ -309,6 +334,7 @@ NEWT_CFLAGS = @NEWT_CFLAGS@ NEWT_LIBS = @NEWT_LIBS@ NM = @NM@ NMEDIT = @NMEDIT@ +NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT = @NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT@ NM_MAJOR_VERSION = @NM_MAJOR_VERSION@ NM_MICRO_VERSION = @NM_MICRO_VERSION@ NM_MINOR_VERSION = @NM_MINOR_VERSION@ @@ -328,6 +354,7 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ +PERL = @PERL@ PKG_CONFIG = @PKG_CONFIG@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ @@ -354,7 +381,7 @@ SYSTEMD_INHIBIT_LIBS = @SYSTEMD_INHIBIT_LIBS@ SYSTEMD_LOGIN_CFLAGS = @SYSTEMD_LOGIN_CFLAGS@ SYSTEMD_LOGIN_LIBS = @SYSTEMD_LOGIN_LIBS@ SYSTEM_CA_PATH = @SYSTEM_CA_PATH@ -UDEV_BASE_DIR = @UDEV_BASE_DIR@ +UDEV_DIR = @UDEV_DIR@ USE_NLS = @USE_NLS@ UUID_CFLAGS = @UUID_CFLAGS@ UUID_LIBS = @UUID_LIBS@ @@ -435,11 +462,13 @@ with_resolvconf = @with_resolvconf@ with_valgrind = @with_valgrind@ @ENABLE_TESTS_TRUE@AM_CPPFLAGS = \ @ENABLE_TESTS_TRUE@ -I$(top_srcdir)/include \ -@ENABLE_TESTS_TRUE@ -I${top_builddir}/include \ -@ENABLE_TESTS_TRUE@ -I$(top_srcdir)/libnm-util \ -@ENABLE_TESTS_TRUE@ -I$(top_builddir)/libnm-util \ +@ENABLE_TESTS_TRUE@ -I$(top_srcdir)/libnm-core \ +@ENABLE_TESTS_TRUE@ -I$(top_builddir)/libnm-core \ @ENABLE_TESTS_TRUE@ -I$(top_srcdir)/callouts \ +@ENABLE_TESTS_TRUE@ -I$(top_builddir)/callouts \ +@ENABLE_TESTS_TRUE@ -DNETWORKMANAGER_COMPILATION \ @ENABLE_TESTS_TRUE@ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ +@ENABLE_TESTS_TRUE@ -DSRCDIR=\"$(abs_srcdir)\" \ @ENABLE_TESTS_TRUE@ $(GLIB_CFLAGS) \ @ENABLE_TESTS_TRUE@ $(DBUS_CFLAGS) @@ -449,16 +478,16 @@ with_valgrind = @with_valgrind@ @ENABLE_TESTS_TRUE@ test-dispatcher-envp.c @ENABLE_TESTS_TRUE@test_dispatcher_envp_LDADD = \ -@ENABLE_TESTS_TRUE@ $(top_builddir)/libnm-util/libnm-util.la \ +@ENABLE_TESTS_TRUE@ $(top_builddir)/libnm/libnm.la \ @ENABLE_TESTS_TRUE@ $(top_builddir)/callouts/libtest-dispatcher-envp.la \ @ENABLE_TESTS_TRUE@ $(GLIB_LIBS) \ @ENABLE_TESTS_TRUE@ $(DBUS_LIBS) -@ENABLE_TESTS_TRUE@EXTRA_DIST = \ -@ENABLE_TESTS_TRUE@ dispatcher-old-down \ -@ENABLE_TESTS_TRUE@ dispatcher-old-up \ -@ENABLE_TESTS_TRUE@ dispatcher-old-vpn-down \ -@ENABLE_TESTS_TRUE@ dispatcher-old-vpn-up +EXTRA_DIST = \ + dispatcher-old-down \ + dispatcher-old-up \ + dispatcher-old-vpn-down \ + dispatcher-old-vpn-up all: all-am @@ -595,6 +624,99 @@ cscopelist-am: $(am__tagged_files) distclean-tags: -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags +check-TESTS: $(TESTS) + @failed=0; all=0; xfail=0; xpass=0; skip=0; \ + srcdir=$(srcdir); export srcdir; \ + list=' $(TESTS) '; \ + $(am__tty_colors); \ + if test -n "$$list"; then \ + for tst in $$list; do \ + if test -f ./$$tst; then dir=./; \ + elif test -f $$tst; then dir=; \ + else dir="$(srcdir)/"; fi; \ + if $(TESTS_ENVIRONMENT) $${dir}$$tst $(AM_TESTS_FD_REDIRECT); then \ + all=`expr $$all + 1`; \ + case " $(XFAIL_TESTS) " in \ + *[\ \ ]$$tst[\ \ ]*) \ + xpass=`expr $$xpass + 1`; \ + failed=`expr $$failed + 1`; \ + col=$$red; res=XPASS; \ + ;; \ + *) \ + col=$$grn; res=PASS; \ + ;; \ + esac; \ + elif test $$? -ne 77; then \ + all=`expr $$all + 1`; \ + case " $(XFAIL_TESTS) " in \ + *[\ \ ]$$tst[\ \ ]*) \ + xfail=`expr $$xfail + 1`; \ + col=$$lgn; res=XFAIL; \ + ;; \ + *) \ + failed=`expr $$failed + 1`; \ + col=$$red; res=FAIL; \ + ;; \ + esac; \ + else \ + skip=`expr $$skip + 1`; \ + col=$$blu; res=SKIP; \ + fi; \ + echo "$${col}$$res$${std}: $$tst"; \ + done; \ + if test "$$all" -eq 1; then \ + tests="test"; \ + All=""; \ + else \ + tests="tests"; \ + All="All "; \ + fi; \ + if test "$$failed" -eq 0; then \ + if test "$$xfail" -eq 0; then \ + banner="$$All$$all $$tests passed"; \ + else \ + if test "$$xfail" -eq 1; then failures=failure; else failures=failures; fi; \ + banner="$$All$$all $$tests behaved as expected ($$xfail expected $$failures)"; \ + fi; \ + else \ + if test "$$xpass" -eq 0; then \ + banner="$$failed of $$all $$tests failed"; \ + else \ + if test "$$xpass" -eq 1; then passes=pass; else passes=passes; fi; \ + banner="$$failed of $$all $$tests did not behave as expected ($$xpass unexpected $$passes)"; \ + fi; \ + fi; \ + dashes="$$banner"; \ + skipped=""; \ + if test "$$skip" -ne 0; then \ + if test "$$skip" -eq 1; then \ + skipped="($$skip test was not run)"; \ + else \ + skipped="($$skip tests were not run)"; \ + fi; \ + test `echo "$$skipped" | wc -c` -le `echo "$$banner" | wc -c` || \ + dashes="$$skipped"; \ + fi; \ + report=""; \ + if test "$$failed" -ne 0 && test -n "$(PACKAGE_BUGREPORT)"; then \ + report="Please report to $(PACKAGE_BUGREPORT)"; \ + test `echo "$$report" | wc -c` -le `echo "$$banner" | wc -c` || \ + dashes="$$report"; \ + fi; \ + dashes=`echo "$$dashes" | sed s/./=/g`; \ + if test "$$failed" -eq 0; then \ + col="$$grn"; \ + else \ + col="$$red"; \ + fi; \ + echo "$${col}$$dashes$${std}"; \ + echo "$${col}$$banner$${std}"; \ + test -z "$$skipped" || echo "$${col}$$skipped$${std}"; \ + test -z "$$report" || echo "$${col}$$report$${std}"; \ + echo "$${col}$$dashes$${std}"; \ + test "$$failed" -eq 0; \ + else :; fi + distdir: $(DISTFILES) @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ @@ -625,9 +747,8 @@ distdir: $(DISTFILES) || exit 1; \ fi; \ done -@ENABLE_TESTS_FALSE@check-local: check-am: all-am - $(MAKE) $(AM_MAKEFLAGS) check-local + $(MAKE) $(AM_MAKEFLAGS) check-TESTS check: check-am all-am: Makefile $(PROGRAMS) installdirs: @@ -734,7 +855,7 @@ uninstall-am: .MAKE: check-am install-am install-strip -.PHONY: CTAGS GTAGS TAGS all all-am check check-am check-local clean \ +.PHONY: CTAGS GTAGS TAGS all all-am check check-TESTS check-am clean \ clean-generic clean-libtool clean-noinstPROGRAMS cscopelist-am \ ctags ctags-am distclean distclean-compile distclean-generic \ distclean-libtool distclean-tags distdir dvi dvi-am html \ @@ -749,11 +870,6 @@ uninstall-am: tags tags-am uninstall uninstall-am -########################################### - -@ENABLE_TESTS_TRUE@check-local: test-dispatcher-envp -@ENABLE_TESTS_TRUE@ $(abs_builddir)/test-dispatcher-envp $(abs_srcdir) - # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: diff --git a/callouts/tests/dispatcher-old-up b/callouts/tests/dispatcher-old-up index a35812ee..53f35ace 100644 --- a/callouts/tests/dispatcher-old-up +++ b/callouts/tests/dispatcher-old-up @@ -39,6 +39,7 @@ DEVICE_IP_IFACE=wlan0 IP4_ADDRESS_0=192.168.1.119/24 192.168.1.1 IP4_NUM_ADDRESSES=1 IP4_NAMESERVERS=68.87.77.134 68.87.72.134 192.168.1.1 +IP4_GATEWAY=192.168.1.1 IP4_DOMAINS=hsd1.mn.comcast.net. IP4_NUM_ROUTES=0 DHCP4_NETBIOS_NAME_SERVERS=0.0.0.0 diff --git a/callouts/tests/dispatcher-old-vpn-down b/callouts/tests/dispatcher-old-vpn-down index 4fab5e95..1f1cf2b6 100644 --- a/callouts/tests/dispatcher-old-vpn-down +++ b/callouts/tests/dispatcher-old-vpn-down @@ -39,6 +39,7 @@ DEVICE_IP_IFACE=tun0 IP4_ADDRESS_0=192.168.1.119/24 192.168.1.1 IP4_NUM_ADDRESSES=1 IP4_NAMESERVERS=68.87.77.134 68.87.72.134 192.168.1.1 +IP4_GATEWAY=192.168.1.1 IP4_DOMAINS=hsd1.mn.comcast.net. IP4_NUM_ROUTES=0 DHCP4_NETBIOS_NAME_SERVERS=0.0.0.0 diff --git a/callouts/tests/dispatcher-old-vpn-up b/callouts/tests/dispatcher-old-vpn-up index 3c350dbf..7cda8a69 100644 --- a/callouts/tests/dispatcher-old-vpn-up +++ b/callouts/tests/dispatcher-old-vpn-up @@ -39,6 +39,7 @@ DEVICE_IP_IFACE=tun0 IP4_ADDRESS_0=192.168.1.119/24 192.168.1.1 IP4_NUM_ADDRESSES=1 IP4_NAMESERVERS=68.87.77.134 68.87.72.134 192.168.1.1 +IP4_GATEWAY=192.168.1.1 IP4_DOMAINS=hsd1.mn.comcast.net. IP4_NUM_ROUTES=0 DHCP4_NETBIOS_NAME_SERVERS=0.0.0.0 diff --git a/callouts/tests/test-dispatcher-envp.c b/callouts/tests/test-dispatcher-envp.c index a91ae2b2..460174b2 100644 --- a/callouts/tests/test-dispatcher-envp.c +++ b/callouts/tests/test-dispatcher-envp.c @@ -18,117 +18,24 @@ * */ -#include <config.h> +#include "config.h" + #include <arpa/inet.h> #include <stdlib.h> #include <string.h> #include <glib.h> #include <glib-object.h> -#include "nm-connection.h" -#include "nm-setting-connection.h" +#include "nm-core-internal.h" #include "nm-dispatcher-utils.h" -#include "nm-dbus-glib-types.h" #include "nm-dispatcher-api.h" -#include "nm-utils.h" /*******************************************/ -static void -value_destroy (gpointer data) -{ - GValue *value = (GValue *) data; - - g_value_unset (value); - g_slice_free (GValue, value); -} - -static GHashTable * -value_hash_create (void) -{ - return g_hash_table_new_full (g_str_hash, g_str_equal, g_free, value_destroy); -} - -static void -value_hash_add (GHashTable *hash, - const char *key, - GValue *value) -{ - g_hash_table_insert (hash, g_strdup (key), value); -} - -static void -value_hash_add_string (GHashTable *hash, - const char *key, - const char *str) -{ - GValue *value; - - value = g_slice_new0 (GValue); - g_value_init (value, G_TYPE_STRING); - g_value_set_string (value, str); - - value_hash_add (hash, key, value); -} - -static void -value_hash_add_object_path (GHashTable *hash, - const char *key, - const char *op) -{ - GValue *value; - - value = g_slice_new0 (GValue); - g_value_init (value, DBUS_TYPE_G_OBJECT_PATH); - g_value_set_boxed (value, op); - - value_hash_add (hash, key, value); -} - -static void -value_hash_add_uint (GHashTable *hash, - const char *key, - guint32 val) -{ - GValue *value; - - value = g_slice_new0 (GValue); - g_value_init (value, G_TYPE_UINT); - g_value_set_uint (value, val); - - value_hash_add (hash, key, value); -} - -static void -value_hash_add_strv (GHashTable *hash, - const char *key, - char **strv) -{ - GValue *value; - - value = g_slice_new0 (GValue); - g_value_init (value, G_TYPE_STRV); - g_value_take_boxed (value, strv); - value_hash_add (hash, key, value); -} - -static void -value_hash_add_uint_array (GHashTable *hash, - const char *key, - GArray *array) -{ - GValue *value; - - value = g_slice_new0 (GValue); - g_value_init (value, DBUS_TYPE_G_UINT_ARRAY); - g_value_take_boxed (value, array); - value_hash_add (hash, key, value); -} - static gboolean parse_main (GKeyFile *kf, - GHashTable **out_con_hash, - GHashTable **out_con_props, + GVariant **out_con_dict, + GVariant **out_con_props, char **out_expected_iface, char **out_action, char **out_vpn_ip_iface, @@ -137,6 +44,7 @@ parse_main (GKeyFile *kf, char *uuid, *id; NMConnection *connection; NMSettingConnection *s_con; + GVariantBuilder props; *out_expected_iface = g_key_file_get_string (kf, "main", "expected-iface", error); if (*out_expected_iface == NULL) @@ -155,7 +63,7 @@ parse_main (GKeyFile *kf, if (id == NULL) return FALSE; - connection = nm_connection_new (); + connection = nm_simple_connection_new (); g_assert (connection); s_con = (NMSettingConnection *) nm_setting_connection_new (); g_assert (s_con); @@ -167,57 +75,72 @@ parse_main (GKeyFile *kf, g_free (id); nm_connection_add_setting (connection, NM_SETTING (s_con)); - *out_con_hash = nm_connection_to_hash (connection, NM_SETTING_HASH_FLAG_ALL); + *out_con_dict = nm_connection_to_dbus (connection, NM_CONNECTION_SERIALIZE_ALL); g_object_unref (connection); - *out_con_props = value_hash_create (); - value_hash_add_object_path (*out_con_props, "connection-path", "/org/freedesktop/NetworkManager/Connections/5"); + g_variant_builder_init (&props, G_VARIANT_TYPE ("a{sv}")); + g_variant_builder_add (&props, "{sv}", + "connection-path", + g_variant_new_object_path ("/org/freedesktop/NetworkManager/Connections/5")); + *out_con_props = g_variant_builder_end (&props); return TRUE; } static gboolean -parse_device (GKeyFile *kf, GHashTable **out_device_props, GError **error) +parse_device (GKeyFile *kf, GVariant **out_device_props, GError **error) { + GVariantBuilder props; char *tmp; gint i; - *out_device_props = value_hash_create (); + g_variant_builder_init (&props, G_VARIANT_TYPE ("a{sv}")); i = g_key_file_get_integer (kf, "device", "state", error); if (i == 0) return FALSE; - value_hash_add_uint (*out_device_props, NMD_DEVICE_PROPS_STATE, (guint) i); + g_variant_builder_add (&props, "{sv}", + NMD_DEVICE_PROPS_STATE, + g_variant_new_uint32 (i)); i = g_key_file_get_integer (kf, "device", "type", error); if (i == 0) return FALSE; - value_hash_add_uint (*out_device_props, NMD_DEVICE_PROPS_TYPE, (guint) i); + g_variant_builder_add (&props, "{sv}", + NMD_DEVICE_PROPS_TYPE, + g_variant_new_uint32 (i)); tmp = g_key_file_get_string (kf, "device", "interface", error); if (tmp == NULL) return FALSE; - value_hash_add_string (*out_device_props, NMD_DEVICE_PROPS_INTERFACE, tmp); + g_variant_builder_add (&props, "{sv}", + NMD_DEVICE_PROPS_INTERFACE, + g_variant_new_string (tmp)); g_free (tmp); tmp = g_key_file_get_string (kf, "device", "ip-interface", error); if (tmp == NULL) return FALSE; - value_hash_add_string (*out_device_props, NMD_DEVICE_PROPS_IP_INTERFACE, tmp); + g_variant_builder_add (&props, "{sv}", + NMD_DEVICE_PROPS_IP_INTERFACE, + g_variant_new_string (tmp)); g_free (tmp); tmp = g_key_file_get_string (kf, "device", "path", error); if (tmp == NULL) return FALSE; - value_hash_add_object_path (*out_device_props, NMD_DEVICE_PROPS_PATH, tmp); + g_variant_builder_add (&props, "{sv}", + NMD_DEVICE_PROPS_PATH, + g_variant_new_object_path (tmp)); g_free (tmp); + *out_device_props = g_variant_builder_end (&props); return TRUE; } static gboolean add_uint_array (GKeyFile *kf, - GHashTable *props, + GVariantBuilder *props, const char *section, const char *key, GError **error) @@ -244,21 +167,26 @@ add_uint_array (GKeyFile *kf, g_array_append_val (items, addr); } } - value_hash_add_uint_array (props, key, items); + g_variant_builder_add (props, "{sv}", key, + g_variant_new_fixed_array (G_VARIANT_TYPE_UINT32, + items->data, items->len, + sizeof (guint32))); + g_array_unref (items); } g_strfreev (split); return TRUE; } static gboolean -parse_ip4 (GKeyFile *kf, GHashTable **out_props, const char *section, GError **error) +parse_ip4 (GKeyFile *kf, GVariant **out_props, const char *section, GError **error) { + GVariantBuilder props; char *tmp; char **split, **iter; - GSList *list; - GValue *val; + GPtrArray *addresses, *routes; + const char *gateway = NULL; - *out_props = value_hash_create (); + g_variant_builder_init (&props, G_VARIANT_TYPE ("a{sv}")); /* search domains */ /* Use char** for domains. (DBUS_TYPE_G_ARRAY_OF_STRING of NMIP4Config @@ -273,14 +201,15 @@ parse_ip4 (GKeyFile *kf, GHashTable **out_props, const char *section, GError **e if (g_strv_length (split) > 0) { for (iter = split; iter && *iter; iter++) g_strstrip (*iter); - value_hash_add_strv (*out_props, "domains", split); + g_variant_builder_add (&props, "{sv}", "domains", g_variant_new_strv ((gpointer) split, -1)); + g_strfreev (split); } /* nameservers */ - if (!add_uint_array (kf, *out_props, "ip4", "nameservers", error)) + if (!add_uint_array (kf, &props, "ip4", "nameservers", error)) return FALSE; /* wins-servers */ - if (!add_uint_array (kf, *out_props, "ip4", "wins-servers", error)) + if (!add_uint_array (kf, &props, "ip4", "wins-servers", error)) return FALSE; /* Addresses */ @@ -291,39 +220,37 @@ parse_ip4 (GKeyFile *kf, GHashTable **out_props, const char *section, GError **e g_free (tmp); if (g_strv_length (split) > 0) { - list = NULL; + addresses = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip_address_unref); for (iter = split; iter && *iter; iter++) { - NMIP4Address *addr; - guint32 a; - char *p; + NMIPAddress *addr; + char *ip, *prefix; if (strlen (g_strstrip (*iter)) == 0) continue; - addr = nm_ip4_address_new (); - - p = strchr (*iter, '/'); - g_assert (p); - *p++ = '\0'; - - g_assert_cmpint (inet_pton (AF_INET, *iter, &a), ==, 1); - nm_ip4_address_set_address (addr, a); - nm_ip4_address_set_prefix (addr, (guint) atoi (p)); + ip = *iter; - p = strchr (p, ' '); - g_assert (p); - p++; + prefix = strchr (ip, '/'); + g_assert (prefix); + *prefix++ = '\0'; - g_assert_cmpint (inet_pton (AF_INET, p, &a), ==, 1); - nm_ip4_address_set_gateway (addr, a); + if (addresses->len == 0) { + gateway = strchr (prefix, ' '); + g_assert (gateway); + gateway++; + } - list = g_slist_append (list, addr); + addr = nm_ip_address_new (AF_INET, ip, (guint) atoi (prefix), error); + if (!addr) { + g_ptr_array_unref (addresses); + return FALSE; + } + g_ptr_array_add (addresses, addr); } - val = g_slice_new0 (GValue); - g_value_init (val, DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UINT); - nm_utils_ip4_addresses_to_gvalue (list, val); - value_hash_add (*out_props, "addresses", val); + g_variant_builder_add (&props, "{sv}", "addresses", + nm_utils_ip4_addresses_to_variant (addresses, gateway)); + g_ptr_array_unref (addresses); } g_strfreev (split); @@ -335,87 +262,88 @@ parse_ip4 (GKeyFile *kf, GHashTable **out_props, const char *section, GError **e g_free (tmp); if (g_strv_length (split) > 0) { - list = NULL; + routes = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip_route_unref); for (iter = split; iter && *iter; iter++) { - NMIP4Route *route; - guint32 a; - char *p; + NMIPRoute *route; + char *dest, *prefix, *next_hop, *metric; if (strlen (g_strstrip (*iter)) == 0) continue; - route = nm_ip4_route_new (); - - p = strchr (*iter, '/'); - g_assert (p); - *p++ = '\0'; - - g_assert_cmpint (inet_pton (AF_INET, *iter, &a), ==, 1); - nm_ip4_route_set_dest (route, a); - nm_ip4_route_set_prefix (route, (guint) atoi (p)); - - p = strchr (p, ' '); - g_assert (p); - p++; - - g_assert_cmpint (inet_pton (AF_INET, p, &a), ==, 1); - nm_ip4_route_set_next_hop (route, a); - - p = strchr (p, ' '); - g_assert (p); - p++; - nm_ip4_route_set_metric (route, (guint) atoi (p)); - - list = g_slist_append (list, route); + dest = *iter; + + prefix = strchr (dest, '/'); + g_assert (prefix); + *prefix++ = '\0'; + + next_hop = strchr (prefix, ' '); + g_assert (next_hop); + next_hop++; + + metric = strchr (next_hop, ' '); + g_assert (metric); + metric++; + + route = nm_ip_route_new (AF_INET, + dest, (guint) atoi (prefix), + next_hop, (guint) atoi (metric), + error); + if (!route) { + g_ptr_array_unref (routes); + return FALSE; + } + g_ptr_array_add (routes, route); } - val = g_slice_new0 (GValue); - g_value_init (val, DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UINT); - nm_utils_ip4_routes_to_gvalue (list, val); - value_hash_add (*out_props, "routes", val); + g_variant_builder_add (&props, "{sv}", "routes", + nm_utils_ip4_routes_to_variant (routes)); + g_ptr_array_unref (routes); } g_strfreev (split); } + *out_props = g_variant_builder_end (&props); return TRUE; } static gboolean parse_dhcp (GKeyFile *kf, const char *group_name, - GHashTable **out_props, + GVariant **out_props, GError **error) { char **keys, **iter, *val; + GVariantBuilder props; keys = g_key_file_get_keys (kf, group_name, NULL, error); if (!keys) return FALSE; - *out_props = value_hash_create (); + g_variant_builder_init (&props, G_VARIANT_TYPE ("a{sv}")); for (iter = keys; iter && *iter; iter++) { val = g_key_file_get_string (kf, group_name, *iter, error); if (!val) return FALSE; - value_hash_add_string (*out_props, *iter, val); + g_variant_builder_add (&props, "{sv}", *iter, g_variant_new_string (val)); g_free (val); } + *out_props = g_variant_builder_end (&props); return TRUE; } static gboolean get_dispatcher_file (const char *file, - GHashTable **out_con_hash, - GHashTable **out_con_props, - GHashTable **out_device_props, - GHashTable **out_device_ip4_props, - GHashTable **out_device_ip6_props, - GHashTable **out_device_dhcp4_props, - GHashTable **out_device_dhcp6_props, + GVariant **out_con_dict, + GVariant **out_con_props, + GVariant **out_device_props, + GVariant **out_device_ip4_props, + GVariant **out_device_ip6_props, + GVariant **out_device_dhcp4_props, + GVariant **out_device_dhcp6_props, char **out_vpn_ip_iface, - GHashTable **out_vpn_ip4_props, - GHashTable **out_vpn_ip6_props, + GVariant **out_vpn_ip4_props, + GVariant **out_vpn_ip6_props, char **out_expected_iface, char **out_action, GHashTable **out_env, @@ -430,7 +358,7 @@ get_dispatcher_file (const char *file, return FALSE; if (!parse_main (kf, - out_con_hash, + out_con_dict, out_con_props, out_expected_iface, out_action, @@ -480,18 +408,18 @@ out: /*******************************************/ static void -test_generic (const char *path, const char *file, const char *override_vpn_ip_iface) +test_generic (const char *file, const char *override_vpn_ip_iface) { - GHashTable *con_hash = NULL; - GHashTable *con_props = NULL; - GHashTable *device_props = NULL; - GHashTable *device_ip4_props = NULL; - GHashTable *device_ip6_props = NULL; - GHashTable *device_dhcp4_props = NULL; - GHashTable *device_dhcp6_props = NULL; + GVariant *con_dict = NULL; + GVariant *con_props = NULL; + GVariant *device_props = NULL; + GVariant *device_ip4_props = NULL; + GVariant *device_ip6_props = NULL; + GVariant *device_dhcp4_props = NULL; + GVariant *device_dhcp6_props = NULL; char *vpn_ip_iface = NULL; - GHashTable *vpn_ip4_props = NULL; - GHashTable *vpn_ip6_props = NULL; + GVariant *vpn_ip4_props = NULL; + GVariant *vpn_ip6_props = NULL; char *expected_iface = NULL; char *action = NULL; char *out_iface = NULL; @@ -502,9 +430,9 @@ test_generic (const char *path, const char *file, const char *override_vpn_ip_if char **denv, **iter; /* Read in the test file */ - p = g_strdup_printf ("%s/%s", path, file); + p = g_build_filename (SRCDIR, file, NULL); success = get_dispatcher_file (p, - &con_hash, + &con_dict, &con_props, &device_props, &device_ip4_props, @@ -524,7 +452,7 @@ test_generic (const char *path, const char *file, const char *override_vpn_ip_if /* Get the environment from the dispatcher code */ denv = nm_dispatcher_utils_construct_envp (action, - con_hash, + con_dict, con_props, device_props, device_ip4_props, @@ -581,57 +509,57 @@ test_generic (const char *path, const char *file, const char *override_vpn_ip_if g_free (vpn_ip_iface); g_free (expected_iface); g_free (action); - g_hash_table_destroy (con_hash); - g_hash_table_destroy (con_props); - g_hash_table_destroy (device_props); + g_variant_unref (con_dict); + g_variant_unref (con_props); + g_variant_unref (device_props); if (device_ip4_props) - g_hash_table_destroy (device_ip4_props); + g_variant_unref (device_ip4_props); if (device_ip6_props) - g_hash_table_destroy (device_ip6_props); + g_variant_unref (device_ip6_props); if (device_dhcp4_props) - g_hash_table_destroy (device_dhcp4_props); + g_variant_unref (device_dhcp4_props); if (device_dhcp6_props) - g_hash_table_destroy (device_dhcp6_props); + g_variant_unref (device_dhcp6_props); if (vpn_ip4_props) - g_hash_table_destroy (vpn_ip4_props); + g_variant_unref (vpn_ip4_props); if (vpn_ip6_props) - g_hash_table_destroy (vpn_ip6_props); + g_variant_unref (vpn_ip6_props); g_hash_table_destroy (expected_env); } /*******************************************/ static void -test_old_up (const char *path) +test_old_up (void) { - test_generic (path, "dispatcher-old-up", NULL); + test_generic ("dispatcher-old-up", NULL); } static void -test_old_down (const char *path) +test_old_down (void) { - test_generic (path, "dispatcher-old-down", NULL); + test_generic ("dispatcher-old-down", NULL); } static void -test_old_vpn_up (const char *path) +test_old_vpn_up (void) { - test_generic (path, "dispatcher-old-vpn-up", NULL); + test_generic ("dispatcher-old-vpn-up", NULL); } static void -test_old_vpn_down (const char *path) +test_old_vpn_down (void) { - test_generic (path, "dispatcher-old-vpn-down", NULL); + test_generic ("dispatcher-old-vpn-down", NULL); } static void -test_up_empty_vpn_iface (const char *path) +test_up_empty_vpn_iface (void) { /* Test that an empty VPN iface variable, like is passed through D-Bus * from NM, is ignored by the dispatcher environment construction code. */ - test_generic (path, "dispatcher-old-up", ""); + test_generic ("dispatcher-old-up", ""); } /*******************************************/ @@ -639,20 +567,18 @@ test_up_empty_vpn_iface (const char *path) int main (int argc, char **argv) { - g_assert (argc > 1); - g_test_init (&argc, &argv, NULL); #if !GLIB_CHECK_VERSION (2, 35, 0) g_type_init (); #endif - g_test_add_data_func ("/dispatcher/old_up", argv[1], (GTestDataFunc) test_old_up); - g_test_add_data_func ("/dispatcher/old_down", argv[1], (GTestDataFunc) test_old_down); - g_test_add_data_func ("/dispatcher/old_vpn_up", argv[1], (GTestDataFunc) test_old_vpn_up); - g_test_add_data_func ("/dispatcher/old_vpn_down", argv[1], (GTestDataFunc) test_old_vpn_down); + g_test_add_func ("/dispatcher/old_up", test_old_up); + g_test_add_func ("/dispatcher/old_down", test_old_down); + g_test_add_func ("/dispatcher/old_vpn_up", test_old_vpn_up); + g_test_add_func ("/dispatcher/old_vpn_down", test_old_vpn_down); - g_test_add_data_func ("/dispatcher/up_empty_vpn_iface", argv[1], (GTestDataFunc) test_up_empty_vpn_iface); + g_test_add_func ("/dispatcher/up_empty_vpn_iface", test_up_empty_vpn_iface); return g_test_run (); } |