summaryrefslogtreecommitdiff
path: root/src/tests/test-policy-hosts.c
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2011-03-18 20:17:47 +0100
committerMichael Biebl <biebl@debian.org>2011-03-18 20:17:47 +0100
commite22c6e05e9ebc6cce941762020c5710b8014677b (patch)
tree7e9fd7f8ae24a94b03f683e0cef9a346968e1e8b /src/tests/test-policy-hosts.c
parenta6b89d35fabd9f5934b84d7cde22e9268f92c3d3 (diff)
Imported Upstream version 0.8.3.998upstream/0.8.3.998
Diffstat (limited to 'src/tests/test-policy-hosts.c')
-rw-r--r--src/tests/test-policy-hosts.c761
1 files changed, 24 insertions, 737 deletions
diff --git a/src/tests/test-policy-hosts.c b/src/tests/test-policy-hosts.c
index 8865c4264..62862e756 100644
--- a/src/tests/test-policy-hosts.c
+++ b/src/tests/test-policy-hosts.c
@@ -23,41 +23,17 @@
#include "nm-policy-hosts.h"
-#define FALLBACK_HOSTNAME4 "localhost.localdomain"
-#define FALLBACK_HOSTNAME6 "localhost6.localdomain6"
-
-#define DEBUG 0
+#define DEBUG 1
static void
-test_generic (const char *before,
- const char *after,
- const char *hostname,
- const char *ip4_addr,
- const char *ip6_addr,
- gboolean expect_error)
+test_generic (const char *before, const char *after)
{
- char **lines;
GString *newc;
- GError *error = NULL;
/* Get the new /etc/hosts contents */
- lines = g_strsplit_set (before, "\n\r", 0);
- newc = nm_policy_get_etc_hosts ((const char **) lines,
- strlen (before),
- hostname,
- NULL,
- FALLBACK_HOSTNAME4,
- FALLBACK_HOSTNAME6,
- ip4_addr,
- ip6_addr,
- &error);
- g_strfreev (lines);
+ newc = nm_policy_get_etc_hosts (before, strlen (before));
- if (expect_error) {
- g_assert (newc == NULL);
- g_assert (error != NULL);
- g_clear_error (&error);
- } else if (after == NULL) {
+ if (after == NULL) {
/* No change to /etc/hosts required */
#if DEBUG
if (newc != NULL) {
@@ -68,10 +44,8 @@ test_generic (const char *before,
}
#endif
g_assert (newc == NULL);
- g_assert (error == NULL);
} else {
g_assert (newc != NULL);
- g_assert (error == NULL);
#if DEBUG
g_message ("\n- NEW ---------------------------------\n"
@@ -81,7 +55,6 @@ test_generic (const char *before,
"^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
newc->str, after);
#endif
- g_assert (strlen (newc->str) == strlen (after));
g_assert (strcmp (newc->str, after) == 0);
g_string_free (newc, TRUE);
}
@@ -99,7 +72,7 @@ static const char *generic_before = \
static void
test_hosts_generic (void)
{
- test_generic (generic_before, NULL, "localhost.localdomain", NULL, NULL, FALSE);
+ test_generic (generic_before, NULL);
}
/*******************************************/
@@ -112,311 +85,25 @@ static const char *generic_no_boilerplate_before = \
static void
test_hosts_generic_no_boilerplate (void)
{
- test_generic (generic_no_boilerplate_before, NULL, "localhost.localdomain", NULL, NULL, FALSE);
-}
-
-/*******************************************/
-
-static const char *generic_no_boilerplate_no_lh_before = \
- "127.0.0.1 localhost.localdomain\n"
- "::1 localhost6.localdomain6 localhost6\n"
- "127.0.0.1 lcmd.us.intellitxt.com\n";
-
-static const char *generic_no_boilerplate_no_lh_after = \
- "127.0.0.1 localhost.localdomain localhost\n"
- "::1 localhost6.localdomain6 localhost6\n"
- "127.0.0.1 lcmd.us.intellitxt.com\n";
-
-static void
-test_hosts_generic_no_boilerplate_no_lh (void)
-{
- test_generic (generic_no_boilerplate_no_lh_before,
- generic_no_boilerplate_no_lh_after,
- "localhost.localdomain",
- NULL,
- NULL,
- FALSE);
-}
-
-/*******************************************/
-
-
-static const char *generic_no_boilerplate_no_lh_no_host_before = \
- "127.0.0.1 localhost.localdomain\n"
- "::1 localhost6.localdomain6 localhost6\n"
- "127.0.0.1 lcmd.us.intellitxt.com\n";
-
-static const char *generic_no_boilerplate_no_lh_no_host_after = \
- "127.0.0.1 comet localhost.localdomain localhost\n"
- "::1 comet localhost6.localdomain6 localhost6\n"
- "127.0.0.1 lcmd.us.intellitxt.com\n";
-
-static void
-test_hosts_generic_no_boilerplate_no_lh_no_host (void)
-{
- test_generic (generic_no_boilerplate_no_lh_no_host_before,
- generic_no_boilerplate_no_lh_no_host_after,
- "comet",
- NULL,
- NULL,
- FALSE);
-}
-
-/*******************************************/
-static const char *named_generic_before = \
- "# Do not remove the following line, or various programs\n"
- "# that require network functionality will fail.\n"
- "127.0.0.1 playboy localhost\n"
- "::1 localhost6.localdomain6 localhost6\n"
- "127.0.0.1 lcmd.us.intellitxt.com\n";
-
-static const char *named_generic_after = \
- "# Do not remove the following line, or various programs\n"
- "# that require network functionality will fail.\n"
- "127.0.0.1 playboy localhost.localdomain localhost\n"
- "::1 playboy localhost6.localdomain6 localhost6\n"
- "127.0.0.1 lcmd.us.intellitxt.com\n";
-
-static void
-test_hosts_named_generic (void)
-{
- test_generic (named_generic_before, named_generic_after, "playboy", NULL, NULL, FALSE);
+ test_generic (generic_no_boilerplate_before, NULL);
}
/*******************************************/
-static const char *named4_non127_before = \
- "# Do not remove the following line, or various programs\n"
- "# that require network functionality will fail.\n"
- "127.0.0.1 localhost.localdomain localhost\n"
- "::1 tomcat localhost6.localdomain6 localhost6\n"
- "127.0.0.1 lcmd.us.intellitxt.com\n"
- "192.168.1.2 tomcat\n";
-
-static void
-test_hosts_named4_non127 (void)
-{
- test_generic (named4_non127_before, NULL, "tomcat", "192.168.1.2", NULL, FALSE);
-}
-
-/*******************************************/
-
-static const char *named6_non127_before = \
- "# Do not remove the following line, or various programs\n"
- "# that require network functionality will fail.\n"
- "127.0.0.1 tomcat localhost.localdomain localhost\n"
- "::1 localhost6.localdomain6 localhost6\n"
- "127.0.0.1 lcmd.us.intellitxt.com\n"
- "3001:abba::3234 tomcat\n";
-
-static void
-test_hosts_named6_non127 (void)
-{
- test_generic (named6_non127_before, NULL, "tomcat", NULL, "3001:abba::3234", FALSE);
-}
-
-/*******************************************/
-
-static const char *named4_non127_more_before = \
- "# Do not remove the following line, or various programs\n"
- "# that require network functionality will fail.\n"
- "127.0.0.1 localhost.localdomain localhost\n"
- "::1 tomcat localhost6.localdomain6 localhost6\n"
- "127.0.0.1 lcmd.us.intellitxt.com\n"
- "192.168.1.2 tomcat\n"
- "127.0.0.1 lcmd.us.intellitxt.com\n"
- "127.0.0.1 srx.main.ebayrtm.com\n"
- "127.0.0.1 cdn5.tribalfusion.com\n";
-
-static void
-test_hosts_named4_non127_more (void)
-{
- test_generic (named4_non127_more_before, NULL, "tomcat", "192.168.1.2", NULL, FALSE);
-}
-
-/*******************************************/
-
-static const char *named6_non127_more_before = \
- "# Do not remove the following line, or various programs\n"
- "# that require network functionality will fail.\n"
- "127.0.0.1 tomcat localhost.localdomain localhost\n"
- "::1 localhost6.localdomain6 localhost6\n"
- "127.0.0.1 lcmd.us.intellitxt.com\n"
- "3001:abba::3234 tomcat\n"
- "127.0.0.1 lcmd.us.intellitxt.com\n"
- "127.0.0.1 srx.main.ebayrtm.com\n"
- "127.0.0.1 cdn5.tribalfusion.com\n";
-
-static void
-test_hosts_named6_non127_more (void)
-{
- test_generic (named6_non127_more_before, NULL, "tomcat", NULL, "3001:abba::3234", FALSE);
-}
-
-/*******************************************/
-
-static const char *named_no_lh_before = \
- "# Do not remove the following line, or various programs\n"
- "# that require network functionality will fail.\n"
- "127.0.0.1 localhost.localdomain\n"
- "::1 localhost6.localdomain6 localhost6\n"
- "127.0.0.1 lcmd.us.intellitxt.com\n"
- "192.168.1.2 tomcat\n";
-
-static const char *named_no_lh_after = \
+static const char *leftover_before = \
"# Do not remove the following line, or various programs\n"
"# that require network functionality will fail.\n"
+ "192.168.1.2 comet # Added by NetworkManager\n"
"127.0.0.1 localhost.localdomain localhost\n"
- "::1 tomcat localhost6.localdomain6 localhost6\n"
- "127.0.0.1 lcmd.us.intellitxt.com\n"
- "192.168.1.2 tomcat\n";
-
-static void
-test_hosts_named_no_localhost (void)
-{
- test_generic (named_no_lh_before, named_no_lh_after, "tomcat", "192.168.1.2", NULL, FALSE);
-}
-
-/*******************************************/
-
-static const char *no_lh_before = \
- "# Do not remove the following line, or various programs\n"
- "# that require network functionality will fail.\n"
- "127.0.0.1 tomcat\n"
- "::1 localhost6.localdomain6 localhost6\n"
- "127.0.0.1 lcmd.us.intellitxt.com\n";
-
-static const char *no_lh_after = \
- "# Do not remove the following line, or various programs\n"
- "# that require network functionality will fail.\n"
- "127.0.0.1 tomcat localhost.localdomain localhost\n"
- "::1 tomcat localhost6.localdomain6 localhost6\n"
- "127.0.0.1 lcmd.us.intellitxt.com\n";
-
-static void
-test_hosts_no_localhost (void)
-{
- test_generic (no_lh_before, no_lh_after, "tomcat", NULL, NULL, FALSE);
-}
-
-/*******************************************/
-
-static const char *named_last_before = \
- "# Do not remove the following line, or various programs\n"
- "# that require network functionality will fail.\n"
- "127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 sparcbook.ausil.us\n"
- "::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 sparcbook.ausil.us\n";
-
-static void
-test_hosts_named_last (void)
-{
- test_generic (named_last_before, NULL, "sparcbook.ausil.us", NULL, NULL, FALSE);
-}
-
-/*******************************************/
-
-static const char *no_host4_before = \
- "# Do not remove the following line, or various programs\n"
- "# that require network functionality will fail.\n"
- "::1 localhost6.localdomain6 localhost6\n"
- "\n"
- "127.0.0.1 lcmd.us.intellitxt.com\n"
- "127.0.0.1 srx.main.ebayrtm.com\n"
- "127.0.0.1 cdn5.tribalfusion.com\n"
- "127.0.0.1 a.tribalfusion.com\n";
-
-static const char *no_host4_after = \
- "# Do not remove the following line, or various programs\n"
- "# that require network functionality will fail.\n"
- "127.0.0.1 comet localhost.localdomain localhost\n"
- "::1 comet localhost6.localdomain6 localhost6\n"
- "\n"
- "127.0.0.1 lcmd.us.intellitxt.com\n"
- "127.0.0.1 srx.main.ebayrtm.com\n"
- "127.0.0.1 cdn5.tribalfusion.com\n"
- "127.0.0.1 a.tribalfusion.com\n";
-
-static void
-test_hosts_no_host4 (void)
-{
- test_generic (no_host4_before, no_host4_after, "comet", NULL, NULL, FALSE);
-}
-
-/*******************************************/
-
-static const char *no_host6_before = \
- "# Do not remove the following line, or various programs\n"
- "# that require network functionality will fail.\n"
- "127.0.0.1 localhost.localdomain localhost\n"
- "\n"
- "127.0.0.1 lcmd.us.intellitxt.com\n";
-
-static const char *no_host6_after = \
- "# Do not remove the following line, or various programs\n"
- "# that require network functionality will fail.\n"
- "127.0.0.1 comet localhost.localdomain localhost\n"
- "::1 comet localhost6.localdomain6 localhost6\n"
- "\n"
- "127.0.0.1 lcmd.us.intellitxt.com\n";
-
-static void
-test_hosts_no_host6 (void)
-{
- test_generic (no_host6_before, no_host6_after, "comet", NULL, NULL, FALSE);
-}
-
-/*******************************************/
-
-static const char *named46_non127_before = \
- "# Do not remove the following line, or various programs\n"
- "# that require network functionality will fail.\n"
- "127.0.0.1 localhost.localdomain localhost\n"
- "::1 localhost6.localdomain6 localhost6\n"
- "192.168.1.2 comet\n"
- "3001:abba::3234 comet\n"
- "\n"
- "127.0.0.1 lcmd.us.intellitxt.com\n";
-
-static void
-test_hosts_named46_non127 (void)
-{
- test_generic (named46_non127_before, NULL, "comet", "192.168.1.2", "3001:abba::3234", FALSE);
-}
-
-/*******************************************/
-
-static const char *named46_non127_long_before = \
- "# Do not remove the following line, or various programs\n"
- "# that require network functionality will fail.\n"
- "127.0.0.1 localhost.localdomain localhost\n"
- "::1 localhost6.localdomain6 localhost6\n"
- "192.168.1.2 comet.space comet\n"
- "3001:abba::3234 comet.space comet\n"
- "\n"
- "127.0.0.1 lcmd.us.intellitxt.com\n";
-
-static void
-test_hosts_named46_non127_long (void)
-{
- test_generic (named46_non127_long_before, NULL, "comet.space", "192.168.1.2", "3001:abba::3234", FALSE);
-}
-
-/*******************************************/
-
-static const char *named46_non127_other4_before = \
- "# Do not remove the following line, or various programs\n"
- "# that require network functionality will fail.\n"
- "127.0.0.1 localhost.localdomain localhost\n"
"::1 localhost6.localdomain6 localhost6\n"
"192.168.1.3 comet\n"
"3001:abba::3234 comet\n"
"\n"
"127.0.0.1 lcmd.us.intellitxt.com\n";
-static const char *named46_non127_other4_after = \
+static const char *leftover_after = \
"# Do not remove the following line, or various programs\n"
"# that require network functionality will fail.\n"
- "192.168.1.2 comet # Added by NetworkManager\n"
"127.0.0.1 localhost.localdomain localhost\n"
"::1 localhost6.localdomain6 localhost6\n"
"192.168.1.3 comet\n"
@@ -425,416 +112,44 @@ static const char *named46_non127_other4_after = \
"127.0.0.1 lcmd.us.intellitxt.com\n";
static void
-test_hosts_named46_non127_other4 (void)
+test_hosts_leftover (void)
{
- test_generic (named46_non127_other4_before, named46_non127_other4_after, "comet", "192.168.1.2", "3001:abba::3234", FALSE);
+ test_generic (leftover_before, leftover_after);
}
/*******************************************/
-static const char *named46_non127_other4_long_before = \
- "# Do not remove the following line, or various programs\n"
- "# that require network functionality will fail.\n"
- "127.0.0.1 localhost.localdomain localhost\n"
- "::1 localhost6.localdomain6 localhost6\n"
- "192.168.1.3 comet.space\n"
- "3001:abba::3234 comet.space\n"
- "\n"
- "127.0.0.1 lcmd.us.intellitxt.com\n";
-
-static const char *named46_non127_other4_long_after = \
- "# Do not remove the following line, or various programs\n"
- "# that require network functionality will fail.\n"
- "192.168.1.2 comet.space comet # Added by NetworkManager\n"
- "127.0.0.1 localhost.localdomain localhost\n"
- "::1 localhost6.localdomain6 localhost6\n"
- "192.168.1.3 comet.space\n"
- "3001:abba::3234 comet.space\n"
- "\n"
- "127.0.0.1 lcmd.us.intellitxt.com\n";
-
-static void
-test_hosts_named46_non127_other4_long (void)
-{
- test_generic (named46_non127_other4_long_before, named46_non127_other4_long_after, "comet.space", "192.168.1.2", "3001:abba::3234", FALSE);
-}
-
-/*******************************************/
-
-static const char *named46_non127_other6_before = \
- "# Do not remove the following line, or various programs\n"
- "# that require network functionality will fail.\n"
- "127.0.0.1 localhost.localdomain localhost\n"
- "::1 localhost6.localdomain6 localhost6\n"
- "192.168.1.2 comet\n"
- "3001:abba::9675 comet\n"
- "\n"
- "127.0.0.1 lcmd.us.intellitxt.com\n";
-
-static const char *named46_non127_other6_after = \
- "# Do not remove the following line, or various programs\n"
- "# that require network functionality will fail.\n"
- "3001:abba::3234 comet # Added by NetworkManager\n"
- "127.0.0.1 localhost.localdomain localhost\n"
- "::1 localhost6.localdomain6 localhost6\n"
- "192.168.1.2 comet\n"
- "3001:abba::9675 comet\n"
- "\n"
- "127.0.0.1 lcmd.us.intellitxt.com\n";
-
-static void
-test_hosts_named46_non127_other6 (void)
-{
- test_generic (named46_non127_other6_before, named46_non127_other6_after, "comet", "192.168.1.2", "3001:abba::3234", FALSE);
-}
-
-/*******************************************/
-
-static const char *named46_non127_other6_long_before = \
- "# Do not remove the following line, or various programs\n"
- "# that require network functionality will fail.\n"
- "127.0.0.1 localhost.localdomain localhost\n"
- "::1 localhost6.localdomain6 localhost6\n"
- "192.168.1.2 comet.space\n"
- "3001:abba::9675 comet.space\n"
- "\n"
- "127.0.0.1 lcmd.us.intellitxt.com\n";
-
-static const char *named46_non127_other6_long_after = \
- "# Do not remove the following line, or various programs\n"
- "# that require network functionality will fail.\n"
- "3001:abba::3234 comet.space comet # Added by NetworkManager\n"
- "127.0.0.1 localhost.localdomain localhost\n"
- "::1 localhost6.localdomain6 localhost6\n"
- "192.168.1.2 comet.space\n"
- "3001:abba::9675 comet.space\n"
- "\n"
- "127.0.0.1 lcmd.us.intellitxt.com\n";
-
-static void
-test_hosts_named46_non127_other6_long (void)
-{
- test_generic (named46_non127_other6_long_before, named46_non127_other6_long_after, "comet.space", "192.168.1.2", "3001:abba::3234", FALSE);
-}
-
-/*******************************************/
-
-static const char *unnamed46_non127_before = \
- "# Do not remove the following line, or various programs\n"
- "# that require network functionality will fail.\n"
- "127.0.0.1 localhost.localdomain localhost\n"
- "::1 localhost6.localdomain6 localhost6\n"
- "\n"
- "127.0.0.1 lcmd.us.intellitxt.com\n";
-
-static const char *unnamed46_non127_after = \
+static const char *leftover_double_newline_before = \
"# Do not remove the following line, or various programs\n"
"# that require network functionality will fail.\n"
"192.168.1.2 comet # Added by NetworkManager\n"
- "3001:abba::3234 comet # Added by NetworkManager\n"
- "127.0.0.1 localhost.localdomain localhost\n"
- "::1 localhost6.localdomain6 localhost6\n"
- "\n"
- "127.0.0.1 lcmd.us.intellitxt.com\n";
-
-static void
-test_hosts_unnamed46_non127 (void)
-{
- test_generic (unnamed46_non127_before, unnamed46_non127_after, "comet", "192.168.1.2", "3001:abba::3234", FALSE);
-}
-
-/*******************************************/
-
-static const char *unnamed46_non127_long_before = \
- "# Do not remove the following line, or various programs\n"
- "# that require network functionality will fail.\n"
- "127.0.0.1 localhost.localdomain localhost\n"
- "::1 localhost6.localdomain6 localhost6\n"
- "\n"
- "127.0.0.1 lcmd.us.intellitxt.com\n";
-
-static const char *unnamed46_non127_long_after = \
- "# Do not remove the following line, or various programs\n"
- "# that require network functionality will fail.\n"
- "192.168.1.2 comet.space comet # Added by NetworkManager\n"
- "3001:abba::3234 comet.space comet # Added by NetworkManager\n"
"127.0.0.1 localhost.localdomain localhost\n"
"::1 localhost6.localdomain6 localhost6\n"
+ "192.168.1.3 comet\n"
+ "3001:abba::3234 comet\n"
"\n"
- "127.0.0.1 lcmd.us.intellitxt.com\n";
-
-static void
-test_hosts_unnamed46_non127_long (void)
-{
- test_generic (unnamed46_non127_long_before, unnamed46_non127_long_after, "comet.space", "192.168.1.2", "3001:abba::3234", FALSE);
-}
-
-/*******************************************/
-
-static const char *named46_non127_wrong_before = \
- "# Do not remove the following line, or various programs\n"
- "# that require network functionality will fail.\n"
- "127.0.0.1 localhost.localdomain localhost\n"
- "::1 localhost6.localdomain6 localhost6\n"
- "192.168.1.3 comet # Added by NetworkManager\n"
- "3001:abba::9876 comet # Added by NetworkManager\n"
- "\n"
- "127.0.0.1 lcmd.us.intellitxt.com\n";
+ "127.0.0.1 lcmd.us.intellitxt.com\n"
+ "\n";
-static const char *named46_non127_wrong_after = \
+static const char *leftover_double_newline_after = \
"# Do not remove the following line, or various programs\n"
"# that require network functionality will fail.\n"
- "192.168.1.2 comet # Added by NetworkManager\n"
- "3001:abba::3234 comet # Added by NetworkManager\n"
"127.0.0.1 localhost.localdomain localhost\n"
"::1 localhost6.localdomain6 localhost6\n"
- "\n"
- "127.0.0.1 lcmd.us.intellitxt.com\n";
-
-static void
-test_hosts_named46_non127_wrong (void)
-{
- test_generic (named46_non127_wrong_before, named46_non127_wrong_after, "comet", "192.168.1.2", "3001:abba::3234", FALSE);
-}
-
-/*******************************************/
-
-static const char *long_before = \
- "# Do not remove the following line, or various programs\n"
- "# that require network functionality will fail.\n"
- "127.0.0.1 localhost.localdomain localhost comet\n"
- "::1 localhost6.localdomain6 localhost6\n"
- "\n"
- "127.0.0.1 lcmd.us.intellitxt.com\n"
- "127.0.0.1 adserver.adtech.de\n"
- "127.0.0.1 a.as-us.falkag.net\n"
- "127.0.0.1 a.as-eu.falkag.net\n"
- "127.0.0.1 ads.doubleclick.com\n"
- "\n"
- "# random comment\n"
- "127.0.0.1 m1.2mdn.net\n"
- "127.0.0.1 ds.serving-sys.com\n"
- "127.0.0.1 pagead2.googlesyndication.com\n"
- "127.0.0.1 ad.doubleclick.com\n"
- "127.0.0.1 ad.doubleclick.net\n"
- "127.0.0.1 oascentral.movietickets.com\n"
- "127.0.0.1 view.atdmt.com\n"
- "127.0.0.1 ads.chumcity.com\n";
-
-static const char *long_after = \
- "# Do not remove the following line, or various programs\n"
- "# that require network functionality will fail.\n"
- "127.0.0.1 comet localhost.localdomain localhost\n"
- "::1 comet localhost6.localdomain6 localhost6\n"
+ "192.168.1.3 comet\n"
+ "3001:abba::3234 comet\n"
"\n"
"127.0.0.1 lcmd.us.intellitxt.com\n"
- "127.0.0.1 adserver.adtech.de\n"
- "127.0.0.1 a.as-us.falkag.net\n"
- "127.0.0.1 a.as-eu.falkag.net\n"
- "127.0.0.1 ads.doubleclick.com\n"
- "\n"
- "# random comment\n"
- "127.0.0.1 m1.2mdn.net\n"
- "127.0.0.1 ds.serving-sys.com\n"
- "127.0.0.1 pagead2.googlesyndication.com\n"
- "127.0.0.1 ad.doubleclick.com\n"
- "127.0.0.1 ad.doubleclick.net\n"
- "127.0.0.1 oascentral.movietickets.com\n"
- "127.0.0.1 view.atdmt.com\n"
- "127.0.0.1 ads.chumcity.com\n";
-
-static void
-test_hosts_long (void)
-{
- test_generic (long_before, long_after, "comet", NULL, NULL, FALSE);
-}
-
-/*******************************************/
-
-static const char *custom4_before = \
- "# Do not remove the following line, or various programs\n"
- "# that require network functionality will fail.\n"
- "127.0.0.1 localhost.localdomain localhost pintglass\n"
- "::1 localhost6.localdomain6 localhost6\n";
-
-static const char *custom4_after = \
- "# Do not remove the following line, or various programs\n"
- "# that require network functionality will fail.\n"
- "127.0.0.1 comet localhost.localdomain localhost pintglass\n"
- "::1 comet localhost6.localdomain6 localhost6\n";
-
-static void
-test_hosts_custom4 (void)
-{
- test_generic (custom4_before, custom4_after, "comet", NULL, NULL, FALSE);
-}
-
-/*******************************************/
-
-static const char *custom6_before = \
- "# Do not remove the following line, or various programs\n"
- "# that require network functionality will fail.\n"
- "127.0.0.1 localhost.localdomain localhost\n"
- "::1 localhost6.localdomain6 localhost6 pintglass\n";
-
-static const char *custom6_after = \
- "# Do not remove the following line, or various programs\n"
- "# that require network functionality will fail.\n"
- "127.0.0.1 comet localhost.localdomain localhost\n"
- "::1 comet localhost6.localdomain6 localhost6 pintglass\n";
-
-static void
-test_hosts_custom6 (void)
-{
- test_generic (custom6_before, custom6_after, "comet", NULL, NULL, FALSE);
-}
-
-/*******************************************/
-
-static const char *custom46_before = \
- "# Do not remove the following line, or various programs\n"
- "# that require network functionality will fail.\n"
- "127.0.0.1 localhost.localdomain localhost shotglass\n"
- "::1 localhost6.localdomain6 localhost6 pintglass\n";
-
-static const char *custom46_after = \
- "# Do not remove the following line, or various programs\n"
- "# that require network functionality will fail.\n"
- "127.0.0.1 comet localhost.localdomain localhost shotglass\n"
- "::1 comet localhost6.localdomain6 localhost6 pintglass\n";
-
-static void
-test_hosts_custom46 (void)
-{
- test_generic (custom46_before, custom46_after, "comet", NULL, NULL, FALSE);
-}
-
-/*******************************************/
-
-static const char *custom46_mixed_before = \
- "# Do not remove the following line, or various programs\n"
- "# that require network functionality will fail.\n"
- "127.0.0.1 localhost.localdomain localhost shotglass\n"
- "::1 localhost6.localdomain6 localhost6 pintglass\n";
-
-static const char *custom46_mixed_after = \
- "# Do not remove the following line, or various programs\n"
- "# that require network functionality will fail.\n"
- "127.0.0.1 comet localhost.localdomain localhost shotglass\n"
- "::1 comet localhost6.localdomain6 localhost6 pintglass\n";
-
-static void
-test_hosts_custom46_mixed (void)
-{
- test_generic (custom46_mixed_before, custom46_mixed_after, "comet", NULL, NULL, FALSE);
-}
-
-/*******************************************/
-
-static const char *stale4_removed_before = \
- "# Do not remove the following line, or various programs\n"
- "# that require network functionality will fail.\n"
- "1.2.3.4 comet # Added by NetworkManager\n"
- "127.0.0.1 localhost.localdomain localhost\n"
- "::1 comet localhost6.localdomain6 localhost6\n";
-
-static const char *stale4_removed_after = \
- "# Do not remove the following line, or various programs\n"
- "# that require network functionality will fail.\n"
- "127.0.0.1 comet localhost.localdomain localhost\n"
- "::1 comet localhost6.localdomain6 localhost6\n";
+ "\n";
static void
-test_hosts_stale4_removed (void)
+test_hosts_leftover_double_newline (void)
{
- test_generic (stale4_removed_before, stale4_removed_after, "comet", NULL, NULL, FALSE);
+ test_generic (leftover_double_newline_before, leftover_double_newline_after);
}
/*******************************************/
-static const char *stale6_removed_before = \
- "# Do not remove the following line, or various programs\n"
- "# that require network functionality will fail.\n"
- "3001:abba::3234 comet # Added by NetworkManager\n"
- "127.0.0.1 comet localhost.localdomain localhost\n"
- "::1 localhost6.localdomain6 localhost6\n";
-
-static const char *stale6_removed_after = \
- "# Do not remove the following line, or various programs\n"
- "# that require network functionality will fail.\n"
- "127.0.0.1 comet localhost.localdomain localhost\n"
- "::1 comet localhost6.localdomain6 localhost6\n";
-
-static void
-test_hosts_stale6_removed (void)
-{
- test_generic (stale6_removed_before, stale6_removed_after, "comet", NULL, NULL, FALSE);
-}
-
-/*******************************************/
-
-static const char *stale46_removed_before = \
- "# Do not remove the following line, or various programs\n"
- "# that require network functionality will fail.\n"
- "1.2.3.4 comet # Added by NetworkManager\n"
- "3001:abba::3234 comet # Added by NetworkManager\n"
- "127.0.0.1 localhost.localdomain localhost\n"
- "::1 localhost6.localdomain6 localhost6\n";
-
-static const char *stale46_removed_after = \
- "# Do not remove the following line, or various programs\n"
- "# that require network functionality will fail.\n"
- "127.0.0.1 comet localhost.localdomain localhost\n"
- "::1 comet localhost6.localdomain6 localhost6\n";
-
-static void
-test_hosts_stale46_removed (void)
-{
- test_generic (stale46_removed_before, stale46_removed_after, "comet", NULL, NULL, FALSE);
-}
-
-/*******************************************/
-
-typedef struct {
- const char *line;
- const char *token;
- gboolean expected;
-} Foo;
-
-static Foo foo[] = {
- /* Using \t here to easily differentiate tabs vs. spaces for testing */
- { "127.0.0.1\tfoobar\tblah", "blah", TRUE },
- { "", "blah", FALSE },
- { "1.1.1.1\tbork\tfoo", "blah", FALSE },
- { "127.0.0.1 foobar\tblah", "blah", TRUE },
- { "127.0.0.1 foobar blah", "blah", TRUE },
- { "127.0.0.1 localhost", "localhost.localdomain", FALSE },
- { "192.168.1.1 blah borkbork", "blah", TRUE },
- { "192.168.1.1 foobar\tblah borkbork", "blah", TRUE },
- { "192.168.1.1\tfoobar\tblah\tborkbork", "blah", TRUE },
- { "192.168.1.1 \tfoobar \tblah \tborkbork\t ", "blah", TRUE },
- { "\t\t\t\t \t\t\tasdfadf a\t\t\t\t\t \t\t\t\t\t ", "blah", FALSE },
- { NULL, NULL, FALSE }
-};
-
-static void
-test_find_token (void)
-{
- Foo *iter = &foo[0];
-
- while (iter->line) {
- gboolean found;
-
- found = nm_policy_hosts_find_token (iter->line, iter->token);
- if (found != iter->expected) {
- g_warning ("find-token: unexpected token result %d for '%s' <= '%s' (expected %d)",
- found, iter->line, iter->token, iter->expected);
- }
- g_assert (found == iter->expected);
- iter++;
- }
-}
-
#if GLIB_CHECK_VERSION(2,25,12)
typedef GTestFixtureFunc TCFunc;
#else
@@ -851,38 +166,10 @@ int main (int argc, char **argv)
suite = g_test_get_root ();
- g_test_suite_add (suite, TESTCASE (test_find_token, NULL));
g_test_suite_add (suite, TESTCASE (test_hosts_generic, NULL));
g_test_suite_add (suite, TESTCASE (test_hosts_generic_no_boilerplate, NULL));
- g_test_suite_add (suite, TESTCASE (test_hosts_generic_no_boilerplate_no_lh, NULL));
- g_test_suite_add (suite, TESTCASE (test_hosts_generic_no_boilerplate_no_lh_no_host, NULL));
- g_test_suite_add (suite, TESTCASE (test_hosts_named_generic, NULL));
- g_test_suite_add (suite, TESTCASE (test_hosts_named4_non127, NULL));
- g_test_suite_add (suite, TESTCASE (test_hosts_named6_non127, NULL));
- g_test_suite_add (suite, TESTCASE (test_hosts_named4_non127_more, NULL));
- g_test_suite_add (suite, TESTCASE (test_hosts_named6_non127_more, NULL));
- g_test_suite_add (suite, TESTCASE (test_hosts_named46_non127, NULL));
- g_test_suite_add (suite, TESTCASE (test_hosts_named46_non127_long, NULL));
- g_test_suite_add (suite, TESTCASE (test_hosts_named46_non127_other4, NULL));
- g_test_suite_add (suite, TESTCASE (test_hosts_named46_non127_other4_long, NULL));
- g_test_suite_add (suite, TESTCASE (test_hosts_named46_non127_other6, NULL));
- g_test_suite_add (suite, TESTCASE (test_hosts_named46_non127_other6_long, NULL));
- g_test_suite_add (suite, TESTCASE (test_hosts_named46_non127_wrong, NULL));
- g_test_suite_add (suite, TESTCASE (test_hosts_unnamed46_non127, NULL));
- g_test_suite_add (suite, TESTCASE (test_hosts_unnamed46_non127_long, NULL));
- g_test_suite_add (suite, TESTCASE (test_hosts_named_no_localhost, NULL));
- g_test_suite_add (suite, TESTCASE (test_hosts_no_localhost, NULL));
- g_test_suite_add (suite, TESTCASE (test_hosts_named_last, NULL));
- g_test_suite_add (suite, TESTCASE (test_hosts_no_host4, NULL));
- g_test_suite_add (suite, TESTCASE (test_hosts_no_host6, NULL));
- g_test_suite_add (suite, TESTCASE (test_hosts_long, NULL));
- g_test_suite_add (suite, TESTCASE (test_hosts_custom4, NULL));
- g_test_suite_add (suite, TESTCASE (test_hosts_custom6, NULL));
- g_test_suite_add (suite, TESTCASE (test_hosts_custom46, NULL));
- g_test_suite_add (suite, TESTCASE (test_hosts_custom46_mixed, NULL));
- g_test_suite_add (suite, TESTCASE (test_hosts_stale4_removed, NULL));
- g_test_suite_add (suite, TESTCASE (test_hosts_stale6_removed, NULL));
- g_test_suite_add (suite, TESTCASE (test_hosts_stale46_removed, NULL));
+ g_test_suite_add (suite, TESTCASE (test_hosts_leftover, NULL));
+ g_test_suite_add (suite, TESTCASE (test_hosts_leftover_double_newline, NULL));
return g_test_run ();
}