Commit faf0f5da authored by Dan Williams's avatar Dan Williams
Browse files

ifnet: fix some builddir != srcdir issues in testcases

parent e98d1869
......@@ -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;
......
......@@ -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);
......
......@@ -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),
......
......@@ -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
......@@ -25,6 +25,7 @@
#include <glib.h>
#include <arpa/inet.h>
#include <stdlib.h>
#include <unistd.h>
#include <nm-utils.h>
#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;
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);
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");
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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment