diff --git a/src/settings/plugins/ifnet/net_utils.c b/src/settings/plugins/ifnet/net_utils.c index 71949ddabb..40e9c100dc 100644 --- a/src/settings/plugins/ifnet/net_utils.c +++ b/src/settings/plugins/ifnet/net_utils.c @@ -253,7 +253,7 @@ read_hostname (const char *path) } gboolean -write_hostname (const gchar *hostname, const char *path) +write_hostname (const char *path, const gchar *hostname) { gboolean result; char *contents; diff --git a/src/settings/plugins/ifnet/net_utils.h b/src/settings/plugins/ifnet/net_utils.h index dee4914398..925ad61532 100644 --- a/src/settings/plugins/ifnet/net_utils.h +++ b/src/settings/plugins/ifnet/net_utils.h @@ -45,7 +45,7 @@ typedef struct _ip6_block { } ip6_block; gchar *read_hostname (const char *path); -gboolean write_hostname (const char *hostname, const char *path); +gboolean write_hostname (const char *path, const char *hostname); gboolean is_static_ip4 (const char *conn_name); gboolean is_static_ip6 (const char *conn_name); gboolean is_ip4_address (const char *in_address); diff --git a/src/settings/plugins/ifnet/plugin.c b/src/settings/plugins/ifnet/plugin.c index fff83805fd..c3a8bc7da1 100644 --- a/src/settings/plugins/ifnet/plugin.c +++ b/src/settings/plugins/ifnet/plugin.c @@ -108,7 +108,7 @@ write_system_hostname (NMSystemConfigInterface * config, g_return_if_fail (newhostname); PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Write system hostname: %s", newhostname); - if (write_hostname (newhostname, IFNET_SYSTEM_HOSTNAME_FILE)) { + if (write_hostname (IFNET_SYSTEM_HOSTNAME_FILE, newhostname)) { g_free (priv->hostname); priv->hostname = g_strdup (newhostname); g_object_notify (G_OBJECT (config), diff --git a/src/settings/plugins/ifnet/tests/Makefile.am b/src/settings/plugins/ifnet/tests/Makefile.am index 9df058aa4d..0bccc1893a 100644 --- a/src/settings/plugins/ifnet/tests/Makefile.am +++ b/src/settings/plugins/ifnet/tests/Makefile.am @@ -7,8 +7,8 @@ INCLUDES=-I$(srcdir)/../ \ -I$(top_srcdir)/include \ -I$(top_builddir)/include \ -I$(top_srcdir)/src/settings -TESTS = check_ifnet -check_PROGRAMS = check_ifnet + +noinst_PROGRAMS = check_ifnet check_ifnet_SOURCES = test_all.c check_ifnet_CPPFLAGS = \ @@ -21,10 +21,14 @@ check_ifnet_LDADD = $(top_builddir)/libnm-util/libnm-util.la \ $(CHECK_LIBS) \ $(GLIB_LIBS) \ $(LIBM) -EXTRA_DIST = hostname \ - net \ - net.all \ - nm-system-settings.conf \ - wpa_supplicant.conf +check-local: check_ifnet + $(abs_builddir)/check_ifnet $(abs_srcdir) $(abs_builddir) + +EXTRA_DIST = \ + hostname \ + net \ + net.all \ + nm-system-settings.conf \ + wpa_supplicant.conf endif diff --git a/src/settings/plugins/ifnet/tests/test_all.c b/src/settings/plugins/ifnet/tests/test_all.c index ad0cf2aa7b..461b5ebc4b 100644 --- a/src/settings/plugins/ifnet/tests/test_all.c +++ b/src/settings/plugins/ifnet/tests/test_all.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include "net_parser.h" @@ -62,31 +63,33 @@ test_getdata () } static void -test_read_hostname () +test_read_hostname (const char *base_path) { - gchar *hostname = read_hostname ("hostname"); + char *hostname_path, *hostname; + + hostname_path = g_build_filename (base_path, "hostname", NULL); + hostname = read_hostname (hostname_path); + + g_assert_cmpstr (hostname, ==, "gentoo"); - ASSERT (hostname != NULL, "get hostname", "hostname is NULL"); - ASSERT (strcmp ("gentoo", hostname) == 0, - "get hostname", - "hostname is not correctly read, read:%s, expected: gentoo", - hostname); g_free (hostname); + g_free (hostname_path); } static void -test_write_hostname () +test_write_hostname (const char *temp_path) { - gchar *hostname = read_hostname ("hostname"); - gchar *tmp; + char *hostname_path, *hostname; + + hostname_path = g_build_filename (temp_path, "hostname-test", NULL); + write_hostname (hostname_path, "gentoo-nm"); + hostname = read_hostname (hostname_path); + + g_assert_cmpstr (hostname, ==, "gentoo-nm"); - write_hostname ("gentoo-nm", "hostname"); - tmp = read_hostname ("hostname"); - ASSERT (strcmp (tmp, "gentoo-nm") == 0, - "write hostname", "write hostname error"); - write_hostname (hostname, "hostname"); - g_free (tmp); g_free (hostname); + unlink (hostname_path); + g_free (hostname_path); } static void @@ -402,43 +405,46 @@ test_missing_config () } static void -run_all (gboolean run) +run_all (const char *testdir_path, const char *temp_path) { - if (run) { - test_strip_string (); - test_is_static (); - test_has_ip6_address (); - test_has_default_route (); - test_getdata (); - test_read_hostname (); - test_write_hostname (); - test_is_ip4_address (); - test_is_ip6_address (); - test_convert_ipv4_config_block (); - test_convert_ipv4_routes_block (); - test_is_unmanaged (); - test_wpa_parser (); - test_convert_ipv4_routes_block (); - test_new_connection (); - test_update_connection (); - test_add_connection (); - test_delete_connection (); - test_missing_config (); - } + test_strip_string (); + test_is_static (); + test_has_ip6_address (); + test_has_default_route (); + test_getdata (); + test_read_hostname (testdir_path); + test_write_hostname (temp_path); + test_is_ip4_address (); + test_is_ip6_address (); + test_convert_ipv4_config_block (); + test_convert_ipv4_routes_block (); + test_is_unmanaged (); + test_wpa_parser (); + test_convert_ipv4_routes_block (); + test_new_connection (); + test_update_connection (); + test_add_connection (); + test_delete_connection (); + test_missing_config (); } int -main (void) +main (int argc, char **argv) { -// g_mem_set_vtable(glib_mem_profiler_table); -// g_atexit(g_mem_profile); + char *f; + g_type_init (); - ifnet_destroy (); - wpa_parser_destroy (); - ifnet_init ("net"); - wpa_parser_init (TEST_WPA_SUPPLICANT_CONF); - printf ("Initialization complete\n"); - run_all (TRUE); + + f = g_build_filename (argv[1], "net", NULL); + ifnet_init (f); + g_free (f); + + f = g_build_filename (argv[1], "wpa_supplicant.conf", NULL); + wpa_parser_init (f); + g_free (f); + + run_all (argv[1], argv[2]); + ifnet_destroy (); wpa_parser_destroy (); return 0;