summary refs log tree commit diff
path: root/src/tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/Makefile.am49
-rw-r--r--src/tests/Makefile.in628
-rw-r--r--src/tests/test-dhcp-options.c715
-rw-r--r--src/tests/test-policy-hosts.c394
4 files changed, 1786 insertions, 0 deletions
diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am
new file mode 100644
index 00000000..62612a0e
--- /dev/null
+++ b/src/tests/Makefile.am
@@ -0,0 +1,49 @@
+INCLUDES = \
+	-I$(top_srcdir)/include \
+	-I$(top_srcdir)/libnm-util \
+	-I$(top_srcdir)/src/dhcp-manager \
+	-I$(top_builddir)/marshallers \
+	-I$(top_srcdir)/src \
+	-I$(top_builddir)/src
+
+noinst_PROGRAMS = test-dhcp-options test-policy-hosts
+
+####### DHCP options test #######
+
+test_dhcp_options_SOURCES = \
+	test-dhcp-options.c
+
+test_dhcp_options_CPPFLAGS = \
+	$(GLIB_CFLAGS) \
+	$(DBUS_CFLAGS) \
+	-DDHCLIENT_PATH=\"$(DHCLIENT_PATH)\" \
+	-DDHCPCD_PATH=\"$(DHCPCD_PATH)\"
+
+test_dhcp_options_LDADD = \
+	$(top_builddir)/libnm-util/libnm-util.la \
+	$(top_builddir)/src/dhcp-manager/libdhcp-manager.la \
+	$(top_builddir)/src/libtest-dhcp.la \
+	$(GLIB_LIBS) \
+	$(DBUS_LIBS)
+
+####### policy /etc/hosts test #######
+
+test_policy_hosts_SOURCES = \
+	test-policy-hosts.c
+
+test_policy_hosts_CPPFLAGS = \
+	$(GLIB_CFLAGS)
+
+test_policy_hosts_LDADD = \
+	-ldl \
+	$(top_builddir)/src/libtest-policy-hosts.la \
+	$(GLIB_LIBS)
+
+if WITH_TESTS
+
+check-local: test-dhcp-options
+	$(abs_builddir)/test-dhcp-options
+	$(abs_builddir)/test-policy-hosts
+
+endif
+
diff --git a/src/tests/Makefile.in b/src/tests/Makefile.in
new file mode 100644
index 00000000..75fb715d
--- /dev/null
+++ b/src/tests/Makefile.in
@@ -0,0 +1,628 @@
+# Makefile.in generated by automake 1.11.1 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009  Free Software Foundation,
+# Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+@SET_MAKE@
+
+VPATH = @srcdir@
+pkgdatadir = $(datadir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkglibexecdir = $(libexecdir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
+noinst_PROGRAMS = test-dhcp-options$(EXEEXT) \
+	test-policy-hosts$(EXEEXT)
+subdir = src/tests
+DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/m4/compiler_warnings.m4 \
+	$(top_srcdir)/m4/gtk-doc.m4 $(top_srcdir)/m4/intltool.m4 \
+	$(top_srcdir)/m4/libnl-check.m4 $(top_srcdir)/m4/libtool.m4 \
+	$(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
+	$(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
+	$(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+	$(ACLOCAL_M4)
+mkinstalldirs = $(install_sh) -d
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES =
+CONFIG_CLEAN_VPATH_FILES =
+PROGRAMS = $(noinst_PROGRAMS)
+am_test_dhcp_options_OBJECTS =  \
+	test_dhcp_options-test-dhcp-options.$(OBJEXT)
+test_dhcp_options_OBJECTS = $(am_test_dhcp_options_OBJECTS)
+am__DEPENDENCIES_1 =
+test_dhcp_options_DEPENDENCIES =  \
+	$(top_builddir)/libnm-util/libnm-util.la \
+	$(top_builddir)/src/dhcp-manager/libdhcp-manager.la \
+	$(top_builddir)/src/libtest-dhcp.la $(am__DEPENDENCIES_1) \
+	$(am__DEPENDENCIES_1)
+am_test_policy_hosts_OBJECTS =  \
+	test_policy_hosts-test-policy-hosts.$(OBJEXT)
+test_policy_hosts_OBJECTS = $(am_test_policy_hosts_OBJECTS)
+test_policy_hosts_DEPENDENCIES =  \
+	$(top_builddir)/src/libtest-policy-hosts.la \
+	$(am__DEPENDENCIES_1)
+DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
+depcomp = $(SHELL) $(top_srcdir)/depcomp
+am__depfiles_maybe = depfiles
+am__mv = mv -f
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+	--mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
+	$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+CCLD = $(CC)
+LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+	--mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
+	$(LDFLAGS) -o $@
+SOURCES = $(test_dhcp_options_SOURCES) $(test_policy_hosts_SOURCES)
+DIST_SOURCES = $(test_dhcp_options_SOURCES) \
+	$(test_policy_hosts_SOURCES)
+ETAGS = etags
+CTAGS = ctags
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+ACLOCAL = @ACLOCAL@
+ACLOCAL_AMFLAGS = @ACLOCAL_AMFLAGS@
+ALL_LINGUAS = @ALL_LINGUAS@
+AMTAR = @AMTAR@
+AR = @AR@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+CATALOGS = @CATALOGS@
+CATOBJEXT = @CATOBJEXT@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DATADIRNAME = @DATADIRNAME@
+DBUS_CFLAGS = @DBUS_CFLAGS@
+DBUS_LIBS = @DBUS_LIBS@
+DBUS_SYS_DIR = @DBUS_SYS_DIR@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+DHCLIENT_PATH = @DHCLIENT_PATH@
+DHCPCD_PATH = @DHCPCD_PATH@
+DISABLE_DEPRECATED = @DISABLE_DEPRECATED@
+DSYMUTIL = @DSYMUTIL@
+DUMPBIN = @DUMPBIN@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+EXEEXT = @EXEEXT@
+FGREP = @FGREP@
+GETTEXT_PACKAGE = @GETTEXT_PACKAGE@
+GIO_CFLAGS = @GIO_CFLAGS@
+GIO_LIBS = @GIO_LIBS@
+GLIB_CFLAGS = @GLIB_CFLAGS@
+GLIB_GENMARSHAL = @GLIB_GENMARSHAL@
+GLIB_LIBS = @GLIB_LIBS@
+GMODULE_CFLAGS = @GMODULE_CFLAGS@
+GMODULE_LIBS = @GMODULE_LIBS@
+GMOFILES = @GMOFILES@
+GMSGFMT = @GMSGFMT@
+GNUTLS_CFLAGS = @GNUTLS_CFLAGS@
+GNUTLS_LIBS = @GNUTLS_LIBS@
+GREP = @GREP@
+GTKDOC_CHECK = @GTKDOC_CHECK@
+GTKDOC_MKPDF = @GTKDOC_MKPDF@
+GTKDOC_REBASE = @GTKDOC_REBASE@
+GUDEV_CFLAGS = @GUDEV_CFLAGS@
+GUDEV_LIBS = @GUDEV_LIBS@
+HTML_DIR = @HTML_DIR@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+INSTOBJEXT = @INSTOBJEXT@
+INTLLIBS = @INTLLIBS@
+INTLTOOL_EXTRACT = @INTLTOOL_EXTRACT@
+INTLTOOL_MERGE = @INTLTOOL_MERGE@
+INTLTOOL_PERL = @INTLTOOL_PERL@
+INTLTOOL_UPDATE = @INTLTOOL_UPDATE@
+IPTABLES_PATH = @IPTABLES_PATH@
+LD = @LD@
+LDFLAGS = @LDFLAGS@
+LIBDL = @LIBDL@
+LIBGCRYPT_CFLAGS = @LIBGCRYPT_CFLAGS@
+LIBGCRYPT_CONFIG = @LIBGCRYPT_CONFIG@
+LIBGCRYPT_LIBS = @LIBGCRYPT_LIBS@
+LIBM = @LIBM@
+LIBNL_CFLAGS = @LIBNL_CFLAGS@
+LIBNL_LIBS = @LIBNL_LIBS@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LIBTOOL = @LIBTOOL@
+LIPO = @LIPO@
+LN_S = @LN_S@
+LTLIBOBJS = @LTLIBOBJS@
+MAINT = @MAINT@
+MAKEINFO = @MAKEINFO@
+MKDIR_P = @MKDIR_P@
+MKINSTALLDIRS = @MKINSTALLDIRS@
+MSGFMT = @MSGFMT@
+MSGFMT_OPTS = @MSGFMT_OPTS@
+MSGMERGE = @MSGMERGE@
+NM = @NM@
+NMEDIT = @NMEDIT@
+NSS_CFLAGS = @NSS_CFLAGS@
+NSS_LIBS = @NSS_LIBS@
+OBJDUMP = @OBJDUMP@
+OBJEXT = @OBJEXT@
+OTOOL = @OTOOL@
+OTOOL64 = @OTOOL64@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_URL = @PACKAGE_URL@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+PKG_CONFIG = @PKG_CONFIG@
+POFILES = @POFILES@
+POLKIT_CFLAGS = @POLKIT_CFLAGS@
+POLKIT_LIBS = @POLKIT_LIBS@
+POSUB = @POSUB@
+PO_IN_DATADIR_FALSE = @PO_IN_DATADIR_FALSE@
+PO_IN_DATADIR_TRUE = @PO_IN_DATADIR_TRUE@
+PPPD_PLUGIN_DIR = @PPPD_PLUGIN_DIR@
+RANLIB = @RANLIB@
+RESOLVCONF_PATH = @RESOLVCONF_PATH@
+SED = @SED@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+STRIP = @STRIP@
+SYSTEM_CA_PATH = @SYSTEM_CA_PATH@
+UDEV_BASE_DIR = @UDEV_BASE_DIR@
+USE_NLS = @USE_NLS@
+UUID_CFLAGS = @UUID_CFLAGS@
+UUID_LIBS = @UUID_LIBS@
+VERSION = @VERSION@
+XGETTEXT = @XGETTEXT@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build = @build@
+build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
+builddir = @builddir@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+exec_prefix = @exec_prefix@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+lt_ECHO = @lt_ECHO@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+INCLUDES = \
+	-I$(top_srcdir)/include \
+	-I$(top_srcdir)/libnm-util \
+	-I$(top_srcdir)/src/dhcp-manager \
+	-I$(top_builddir)/marshallers \
+	-I$(top_srcdir)/src \
+	-I$(top_builddir)/src
+
+
+####### DHCP options test #######
+test_dhcp_options_SOURCES = \
+	test-dhcp-options.c
+
+test_dhcp_options_CPPFLAGS = \
+	$(GLIB_CFLAGS) \
+	$(DBUS_CFLAGS) \
+	-DDHCLIENT_PATH=\"$(DHCLIENT_PATH)\" \
+	-DDHCPCD_PATH=\"$(DHCPCD_PATH)\"
+
+test_dhcp_options_LDADD = \
+	$(top_builddir)/libnm-util/libnm-util.la \
+	$(top_builddir)/src/dhcp-manager/libdhcp-manager.la \
+	$(top_builddir)/src/libtest-dhcp.la \
+	$(GLIB_LIBS) \
+	$(DBUS_LIBS)
+
+
+####### policy /etc/hosts test #######
+test_policy_hosts_SOURCES = \
+	test-policy-hosts.c
+
+test_policy_hosts_CPPFLAGS = \
+	$(GLIB_CFLAGS)
+
+test_policy_hosts_LDADD = \
+	-ldl \
+	$(top_builddir)/src/libtest-policy-hosts.la \
+	$(GLIB_LIBS)
+
+all: all-am
+
+.SUFFIXES:
+.SUFFIXES: .c .lo .o .obj
+$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am  $(am__configure_deps)
+	@for dep in $?; do \
+	  case '$(am__configure_deps)' in \
+	    *$$dep*) \
+	      ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+	        && { if test -f $@; then exit 0; else break; fi; }; \
+	      exit 1;; \
+	  esac; \
+	done; \
+	echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/tests/Makefile'; \
+	$(am__cd) $(top_srcdir) && \
+	  $(AUTOMAKE) --gnu src/tests/Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+	@case '$?' in \
+	  *config.status*) \
+	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+	  *) \
+	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
+	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+	esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(am__aclocal_m4_deps):
+
+clean-noinstPROGRAMS:
+	@list='$(noinst_PROGRAMS)'; test -n "$$list" || exit 0; \
+	echo " rm -f" $$list; \
+	rm -f $$list || exit $$?; \
+	test -n "$(EXEEXT)" || exit 0; \
+	list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \
+	echo " rm -f" $$list; \
+	rm -f $$list
+test-dhcp-options$(EXEEXT): $(test_dhcp_options_OBJECTS) $(test_dhcp_options_DEPENDENCIES) 
+	@rm -f test-dhcp-options$(EXEEXT)
+	$(LINK) $(test_dhcp_options_OBJECTS) $(test_dhcp_options_LDADD) $(LIBS)
+test-policy-hosts$(EXEEXT): $(test_policy_hosts_OBJECTS) $(test_policy_hosts_DEPENDENCIES) 
+	@rm -f test-policy-hosts$(EXEEXT)
+	$(LINK) $(test_policy_hosts_OBJECTS) $(test_policy_hosts_LDADD) $(LIBS)
+
+mostlyclean-compile:
+	-rm -f *.$(OBJEXT)
+
+distclean-compile:
+	-rm -f *.tab.c
+
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_dhcp_options-test-dhcp-options.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_policy_hosts-test-policy-hosts.Po@am__quote@
+
+.c.o:
+@am__fastdepCC_TRUE@	depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\
+@am__fastdepCC_TRUE@	$(COMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\
+@am__fastdepCC_TRUE@	$(am__mv) $$depbase.Tpo $$depbase.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(COMPILE) -c -o $@ $<
+
+.c.obj:
+@am__fastdepCC_TRUE@	depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.obj$$||'`;\
+@am__fastdepCC_TRUE@	$(COMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ `$(CYGPATH_W) '$<'` &&\
+@am__fastdepCC_TRUE@	$(am__mv) $$depbase.Tpo $$depbase.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
+
+.c.lo:
+@am__fastdepCC_TRUE@	depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.lo$$||'`;\
+@am__fastdepCC_TRUE@	$(LTCOMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\
+@am__fastdepCC_TRUE@	$(am__mv) $$depbase.Tpo $$depbase.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(LTCOMPILE) -c -o $@ $<
+
+test_dhcp_options-test-dhcp-options.o: test-dhcp-options.c
+@am__fastdepCC_TRUE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(test_dhcp_options_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_dhcp_options-test-dhcp-options.o -MD -MP -MF $(DEPDIR)/test_dhcp_options-test-dhcp-options.Tpo -c -o test_dhcp_options-test-dhcp-options.o `test -f 'test-dhcp-options.c' || echo '$(srcdir)/'`test-dhcp-options.c
+@am__fastdepCC_TRUE@	$(am__mv) $(DEPDIR)/test_dhcp_options-test-dhcp-options.Tpo $(DEPDIR)/test_dhcp_options-test-dhcp-options.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='test-dhcp-options.c' object='test_dhcp_options-test-dhcp-options.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(test_dhcp_options_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_dhcp_options-test-dhcp-options.o `test -f 'test-dhcp-options.c' || echo '$(srcdir)/'`test-dhcp-options.c
+
+test_dhcp_options-test-dhcp-options.obj: test-dhcp-options.c
+@am__fastdepCC_TRUE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(test_dhcp_options_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_dhcp_options-test-dhcp-options.obj -MD -MP -MF $(DEPDIR)/test_dhcp_options-test-dhcp-options.Tpo -c -o test_dhcp_options-test-dhcp-options.obj `if test -f 'test-dhcp-options.c'; then $(CYGPATH_W) 'test-dhcp-options.c'; else $(CYGPATH_W) '$(srcdir)/test-dhcp-options.c'; fi`
+@am__fastdepCC_TRUE@	$(am__mv) $(DEPDIR)/test_dhcp_options-test-dhcp-options.Tpo $(DEPDIR)/test_dhcp_options-test-dhcp-options.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='test-dhcp-options.c' object='test_dhcp_options-test-dhcp-options.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(test_dhcp_options_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_dhcp_options-test-dhcp-options.obj `if test -f 'test-dhcp-options.c'; then $(CYGPATH_W) 'test-dhcp-options.c'; else $(CYGPATH_W) '$(srcdir)/test-dhcp-options.c'; fi`
+
+test_policy_hosts-test-policy-hosts.o: test-policy-hosts.c
+@am__fastdepCC_TRUE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(test_policy_hosts_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_policy_hosts-test-policy-hosts.o -MD -MP -MF $(DEPDIR)/test_policy_hosts-test-policy-hosts.Tpo -c -o test_policy_hosts-test-policy-hosts.o `test -f 'test-policy-hosts.c' || echo '$(srcdir)/'`test-policy-hosts.c
+@am__fastdepCC_TRUE@	$(am__mv) $(DEPDIR)/test_policy_hosts-test-policy-hosts.Tpo $(DEPDIR)/test_policy_hosts-test-policy-hosts.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='test-policy-hosts.c' object='test_policy_hosts-test-policy-hosts.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(test_policy_hosts_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_policy_hosts-test-policy-hosts.o `test -f 'test-policy-hosts.c' || echo '$(srcdir)/'`test-policy-hosts.c
+
+test_policy_hosts-test-policy-hosts.obj: test-policy-hosts.c
+@am__fastdepCC_TRUE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(test_policy_hosts_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_policy_hosts-test-policy-hosts.obj -MD -MP -MF $(DEPDIR)/test_policy_hosts-test-policy-hosts.Tpo -c -o test_policy_hosts-test-policy-hosts.obj `if test -f 'test-policy-hosts.c'; then $(CYGPATH_W) 'test-policy-hosts.c'; else $(CYGPATH_W) '$(srcdir)/test-policy-hosts.c'; fi`
+@am__fastdepCC_TRUE@	$(am__mv) $(DEPDIR)/test_policy_hosts-test-policy-hosts.Tpo $(DEPDIR)/test_policy_hosts-test-policy-hosts.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='test-policy-hosts.c' object='test_policy_hosts-test-policy-hosts.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(test_policy_hosts_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_policy_hosts-test-policy-hosts.obj `if test -f 'test-policy-hosts.c'; then $(CYGPATH_W) 'test-policy-hosts.c'; else $(CYGPATH_W) '$(srcdir)/test-policy-hosts.c'; fi`
+
+mostlyclean-libtool:
+	-rm -f *.lo
+
+clean-libtool:
+	-rm -rf .libs _libs
+
+ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
+	list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	mkid -fID $$unique
+tags: TAGS
+
+TAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
+		$(TAGS_FILES) $(LISP)
+	set x; \
+	here=`pwd`; \
+	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	shift; \
+	if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
+	  test -n "$$unique" || unique=$$empty_fix; \
+	  if test $$# -gt 0; then \
+	    $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+	      "$$@" $$unique; \
+	  else \
+	    $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+	      $$unique; \
+	  fi; \
+	fi
+ctags: CTAGS
+CTAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
+		$(TAGS_FILES) $(LISP)
+	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	test -z "$(CTAGS_ARGS)$$unique" \
+	  || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+	     $$unique
+
+GTAGS:
+	here=`$(am__cd) $(top_builddir) && pwd` \
+	  && $(am__cd) $(top_srcdir) \
+	  && gtags -i $(GTAGS_ARGS) "$$here"
+
+distclean-tags:
+	-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+
+distdir: $(DISTFILES)
+	@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+	list='$(DISTFILES)'; \
+	  dist_files=`for file in $$list; do echo $$file; done | \
+	  sed -e "s|^$$srcdirstrip/||;t" \
+	      -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+	case $$dist_files in \
+	  */*) $(MKDIR_P) `echo "$$dist_files" | \
+			   sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+			   sort -u` ;; \
+	esac; \
+	for file in $$dist_files; do \
+	  if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+	  if test -d $$d/$$file; then \
+	    dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+	    if test -d "$(distdir)/$$file"; then \
+	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+	    fi; \
+	    if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+	      cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
+	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+	    fi; \
+	    cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
+	  else \
+	    test -f "$(distdir)/$$file" \
+	    || cp -p $$d/$$file "$(distdir)/$$file" \
+	    || exit 1; \
+	  fi; \
+	done
+@WITH_TESTS_FALSE@check-local:
+check-am: all-am
+	$(MAKE) $(AM_MAKEFLAGS) check-local
+check: check-am
+all-am: Makefile $(PROGRAMS)
+installdirs:
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+	@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+	$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+	  install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+	  `test -z '$(STRIP)' || \
+	    echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+	-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+	-test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
+
+maintainer-clean-generic:
+	@echo "This command is intended for maintainers to use"
+	@echo "it deletes files that may require special tools to rebuild."
+clean: clean-am
+
+clean-am: clean-generic clean-libtool clean-noinstPROGRAMS \
+	mostlyclean-am
+
+distclean: distclean-am
+	-rm -rf ./$(DEPDIR)
+	-rm -f Makefile
+distclean-am: clean-am distclean-compile distclean-generic \
+	distclean-tags
+
+dvi: dvi-am
+
+dvi-am:
+
+html: html-am
+
+html-am:
+
+info: info-am
+
+info-am:
+
+install-data-am:
+
+install-dvi: install-dvi-am
+
+install-dvi-am:
+
+install-exec-am:
+
+install-html: install-html-am
+
+install-html-am:
+
+install-info: install-info-am
+
+install-info-am:
+
+install-man:
+
+install-pdf: install-pdf-am
+
+install-pdf-am:
+
+install-ps: install-ps-am
+
+install-ps-am:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+	-rm -rf ./$(DEPDIR)
+	-rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-compile mostlyclean-generic \
+	mostlyclean-libtool
+
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
+uninstall-am:
+
+.MAKE: check-am install-am install-strip
+
+.PHONY: CTAGS GTAGS all all-am check check-am check-local clean \
+	clean-generic clean-libtool clean-noinstPROGRAMS ctags \
+	distclean distclean-compile distclean-generic \
+	distclean-libtool distclean-tags distdir dvi dvi-am html \
+	html-am info info-am install install-am install-data \
+	install-data-am install-dvi install-dvi-am install-exec \
+	install-exec-am install-html install-html-am install-info \
+	install-info-am install-man install-pdf install-pdf-am \
+	install-ps install-ps-am install-strip installcheck \
+	installcheck-am installdirs maintainer-clean \
+	maintainer-clean-generic mostlyclean mostlyclean-compile \
+	mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
+	tags uninstall uninstall-am
+
+
+@WITH_TESTS_TRUE@check-local: test-dhcp-options
+@WITH_TESTS_TRUE@	$(abs_builddir)/test-dhcp-options
+@WITH_TESTS_TRUE@	$(abs_builddir)/test-policy-hosts
+
+# 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/src/tests/test-dhcp-options.c b/src/tests/test-dhcp-options.c
new file mode 100644
index 00000000..dd1f9149
--- /dev/null
+++ b/src/tests/test-dhcp-options.c
@@ -0,0 +1,715 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* nm-dhcp-manager.c - Handle the DHCP daemon for NetworkManager
+ *
+ * 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 (C) 2008 - 2010 Red Hat, Inc.
+ *
+ */
+
+#include <glib.h>
+#include <dbus/dbus-glib.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <string.h>
+
+#include "nm-test-helpers.h"
+#include <nm-utils.h>
+
+#include "nm-dhcp-manager.h"
+
+typedef struct {
+	const char *name;
+	const char *value;
+} Option;
+
+static void
+destroy_gvalue (gpointer data)
+{
+	GValue *value = (GValue *) data;
+
+	g_value_unset (value);
+	g_slice_free (GValue, value);
+}
+
+static GValue *
+string_to_byte_array_gvalue (const char *str)
+{
+	GByteArray *array;
+	GValue *val;
+
+	array = g_byte_array_sized_new (strlen (str));
+	g_byte_array_append (array, (const guint8 *) str, strlen (str));
+
+	val = g_slice_new0 (GValue);
+	g_value_init (val, DBUS_TYPE_G_UCHAR_ARRAY);
+	g_value_take_boxed (val, array);
+
+	return val;
+}
+
+static GHashTable *
+fill_table (Option *test_options, GHashTable *table)
+{
+	Option *opt;
+
+	if (!table)
+		table = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, destroy_gvalue);
+	for (opt = test_options; opt->name; opt++) {
+		g_hash_table_insert (table,
+		                     (gpointer) opt->name,
+		                     string_to_byte_array_gvalue (opt->value));
+	}
+	return table;
+}
+
+static Option generic_options[] = {
+	{ "new_subnet_mask",            "255.255.255.0" },
+	{ "new_ip_address",             "192.168.1.106" },
+	{ "new_network_number",         "192.168.1.0" },
+	{ "interface",                  "eth0" },
+	{ "reason",                     "BOUND" },
+	{ "new_expiry",                 "1232324877" },
+	{ "new_dhcp_lease_time",        "3600" },
+	{ "new_dhcp_server_identifier", "192.168.1.1" },
+	{ "new_routers",                "192.168.1.1" },
+	{ "new_domain_name_servers",    "216.254.95.2 216.231.41.2" },
+	{ "new_dhcp_message_type",      "5" },
+	{ "new_broadcast_address",      "192.168.1.255" },
+	{ "new_domain_search",          "foobar.com blah.foobar.com" },
+	{ "new_host_name",              "nmreallywhipsthe" },
+	{ "new_domain_name",            "lamasass.com" },
+	{ "new_interface_mtu",          "987" },
+	{ "new_static_routes",          "10.1.1.5 10.1.1.1 100.99.88.56 10.1.1.1" },
+	{ NULL, NULL }
+};
+
+static void
+test_generic_options (const char *client)
+{
+	GHashTable *options;
+	NMIP4Config *ip4_config;
+	NMIP4Address *addr;
+	NMIP4Route *route;
+	struct in_addr tmp;
+	const char *expected_addr = "192.168.1.106";
+	const char *expected_gw = "192.168.1.1";
+	const char *expected_dns1 = "216.254.95.2";
+	const char *expected_dns2 = "216.231.41.2";
+	const char *expected_search1 = "foobar.com";
+	const char *expected_search2 = "blah.foobar.com";
+	const char *expected_route1_dest = "10.1.1.5";
+	const char *expected_route1_gw = "10.1.1.1";
+	const char *expected_route2_dest = "100.99.88.56";
+	const char *expected_route2_gw = "10.1.1.1";
+
+	options = fill_table (generic_options, NULL);
+	ip4_config = nm_dhcp_manager_test_ip4_options_to_config (client, "eth0", options, "rebind");
+	ASSERT (ip4_config != NULL,
+	        "dhcp-generic", "failed to parse DHCP4 options");
+
+	/* IP4 address */
+	ASSERT (nm_ip4_config_get_num_addresses (ip4_config) == 1,
+	        "dhcp-generic", "unexpected number of IP addresses");
+	addr = nm_ip4_config_get_address (ip4_config, 0);
+
+	ASSERT (inet_pton (AF_INET, expected_addr, &tmp) > 0,
+	        "dhcp-generic", "couldn't convert expected IP address");
+	ASSERT (nm_ip4_address_get_address (addr) == tmp.s_addr,
+	        "dhcp-generic", "unexpected IP address");
+
+	ASSERT (nm_ip4_address_get_prefix (addr) == 24,
+	        "dhcp-generic", "unexpected IP address prefix length");
+
+	/* Gateway */
+	ASSERT (inet_pton (AF_INET, expected_gw, &tmp) > 0,
+	        "dhcp-generic", "couldn't convert expected IP gateway");
+	ASSERT (nm_ip4_address_get_gateway (addr) == tmp.s_addr,
+	        "dhcp-generic", "unexpected IP gateway");
+
+	ASSERT (nm_ip4_config_get_ptp_address (ip4_config) == 0,
+	        "dhcp-generic", "unexpected PTP address");
+
+	ASSERT (nm_ip4_config_get_num_wins (ip4_config) == 0,
+	        "dhcp-generic", "unexpected number of WINS servers");
+
+	ASSERT (nm_ip4_config_get_mtu (ip4_config) == 987,
+	        "dhcp-generic", "unexpected MTU");
+
+	/* Domain searches */
+	ASSERT (nm_ip4_config_get_num_searches (ip4_config) == 2,
+	        "dhcp-generic", "unexpected number of domain searches");
+	ASSERT (strcmp (nm_ip4_config_get_search (ip4_config, 0), expected_search1) == 0,
+	        "dhcp-generic", "unexpected domain search #1");
+	ASSERT (strcmp (nm_ip4_config_get_search (ip4_config, 1), expected_search2) == 0,
+	        "dhcp-generic", "unexpected domain search #2");
+
+	/* DNS servers */
+	ASSERT (nm_ip4_config_get_num_nameservers (ip4_config) == 2,
+	        "dhcp-generic", "unexpected number of domain name servers");
+	ASSERT (inet_pton (AF_INET, expected_dns1, &tmp) > 0,
+	        "dhcp-generic", "couldn't convert expected DNS server address #1");
+	ASSERT (nm_ip4_config_get_nameserver (ip4_config, 0) == tmp.s_addr,
+	        "dhcp-generic", "unexpected domain name server #1");
+	ASSERT (inet_pton (AF_INET, expected_dns2, &tmp) > 0,
+	        "dhcp-generic", "couldn't convert expected DNS server address #2");
+	ASSERT (nm_ip4_config_get_nameserver (ip4_config, 1) == tmp.s_addr,
+	        "dhcp-generic", "unexpected domain name server #2");
+
+	/* Routes */
+	ASSERT (nm_ip4_config_get_num_routes (ip4_config) == 2,
+	        "dhcp-generic", "unexpected number of routes");
+
+	/* Route #1 */
+	route = nm_ip4_config_get_route (ip4_config, 0);
+	ASSERT (inet_pton (AF_INET, expected_route1_dest, &tmp) > 0,
+	        "dhcp-generic", "couldn't convert expected route destination #1");
+	ASSERT (nm_ip4_route_get_dest (route) == tmp.s_addr,
+	        "dhcp-generic", "unexpected route #1 destination");
+
+	ASSERT (inet_pton (AF_INET, expected_route1_gw, &tmp) > 0,
+	        "dhcp-generic", "couldn't convert expected route next hop #1");
+	ASSERT (nm_ip4_route_get_next_hop (route) == tmp.s_addr,
+	        "dhcp-generic", "unexpected route #1 next hop");
+
+	ASSERT (nm_ip4_route_get_prefix (route) == 32,
+	        "dhcp-generic", "unexpected route #1 prefix");
+	ASSERT (nm_ip4_route_get_metric (route) == 0,
+	        "dhcp-generic", "unexpected route #1 metric");
+
+	/* Route #2 */
+	route = nm_ip4_config_get_route (ip4_config, 1);
+	ASSERT (inet_pton (AF_INET, expected_route2_dest, &tmp) > 0,
+	        "dhcp-generic", "couldn't convert expected route destination #2");
+	ASSERT (nm_ip4_route_get_dest (route) == tmp.s_addr,
+	        "dhcp-generic", "unexpected route #2 destination");
+
+	ASSERT (inet_pton (AF_INET, expected_route2_gw, &tmp) > 0,
+	        "dhcp-generic", "couldn't convert expected route next hop #2");
+	ASSERT (nm_ip4_route_get_next_hop (route) == tmp.s_addr,
+	        "dhcp-generic", "unexpected route #2 next hop");
+
+	ASSERT (nm_ip4_route_get_prefix (route) == 32,
+	        "dhcp-generic", "unexpected route #2 prefix");
+	ASSERT (nm_ip4_route_get_metric (route) == 0,
+	        "dhcp-generic", "unexpected route #2 metric");
+
+	g_hash_table_destroy (options);
+}
+
+static Option wins_options[] = {
+	{ "new_netbios_name_servers", "63.12.199.5 150.4.88.120" },
+	{ NULL, NULL }
+};
+
+static void
+test_wins_options (const char *client)
+{
+	GHashTable *options;
+	NMIP4Config *ip4_config;
+	NMIP4Address *addr;
+	struct in_addr tmp;
+	const char *expected_wins1 = "63.12.199.5";
+	const char *expected_wins2 = "150.4.88.120";
+
+	options = fill_table (generic_options, NULL);
+	options = fill_table (wins_options, options);
+
+	ip4_config = nm_dhcp_manager_test_ip4_options_to_config (client, "eth0", options, "rebind");
+	ASSERT (ip4_config != NULL,
+	        "dhcp-wins", "failed to parse DHCP4 options");
+
+	/* IP4 address */
+	ASSERT (nm_ip4_config_get_num_addresses (ip4_config) == 1,
+	        "dhcp-wins", "unexpected number of IP addresses");
+	addr = nm_ip4_config_get_address (ip4_config, 0);
+
+	ASSERT (nm_ip4_config_get_num_wins (ip4_config) == 2,
+	        "dhcp-wins", "unexpected number of WINS servers");
+	ASSERT (inet_pton (AF_INET, expected_wins1, &tmp) > 0,
+	        "dhcp-wins", "couldn't convert expected WINS server address #1");
+	ASSERT (nm_ip4_config_get_wins (ip4_config, 0) == tmp.s_addr,
+	        "dhcp-wins", "unexpected WINS server #1");
+	ASSERT (inet_pton (AF_INET, expected_wins2, &tmp) > 0,
+	        "dhcp-wins", "couldn't convert expected WINS server address #1");
+	ASSERT (nm_ip4_config_get_wins (ip4_config, 1) == tmp.s_addr,
+	        "dhcp-wins", "unexpected WINS server #1");
+
+	g_hash_table_destroy (options);
+}
+
+static Option classless_routes_options[] = {
+	/* For dhclient */
+	{ "new_rfc3442_classless_static_routes", "24 192 168 10 192 168 1 1 8 10 10 17 66 41" },
+	/* For dhcpcd */
+	{ "new_classless_static_routes", "192.168.10.0/24 192.168.1.1 10.0.0.0/8 10.17.66.41" },
+	{ NULL, NULL }
+};
+
+static void
+test_classless_static_routes (const char *client)
+{
+	GHashTable *options;
+	NMIP4Config *ip4_config;
+	NMIP4Route *route;
+	struct in_addr tmp;
+	const char *expected_route1_dest = "192.168.10.0";
+	const char *expected_route1_gw = "192.168.1.1";
+	const char *expected_route2_dest = "10.0.0.0";
+	const char *expected_route2_gw = "10.17.66.41";
+
+	options = fill_table (generic_options, NULL);
+	options = fill_table (classless_routes_options, options);
+
+	ip4_config = nm_dhcp_manager_test_ip4_options_to_config (client, "eth0", options, "rebind");
+	ASSERT (ip4_config != NULL,
+	        "dhcp-rfc3442", "failed to parse DHCP4 options");
+
+	/* IP4 routes */
+	ASSERT (nm_ip4_config_get_num_routes (ip4_config) == 2,
+	        "dhcp-rfc3442", "unexpected number of IP routes");
+
+	/* Route #1 */
+	route = nm_ip4_config_get_route (ip4_config, 0);
+	ASSERT (inet_pton (AF_INET, expected_route1_dest, &tmp) > 0,
+	        "dhcp-rfc3442", "couldn't convert expected route destination #1");
+	ASSERT (nm_ip4_route_get_dest (route) == tmp.s_addr,
+	        "dhcp-rfc3442", "unexpected route #1 destination");
+
+	ASSERT (inet_pton (AF_INET, expected_route1_gw, &tmp) > 0,
+	        "dhcp-rfc3442", "couldn't convert expected route next hop #1");
+	ASSERT (nm_ip4_route_get_next_hop (route) == tmp.s_addr,
+	        "dhcp-rfc3442", "unexpected route #1 next hop");
+
+	ASSERT (nm_ip4_route_get_prefix (route) == 24,
+	        "dhcp-rfc3442", "unexpected route #1 prefix");
+	ASSERT (nm_ip4_route_get_metric (route) == 0,
+	        "dhcp-rfc3442", "unexpected route #1 metric");
+
+	/* Route #2 */
+	route = nm_ip4_config_get_route (ip4_config, 1);
+	ASSERT (inet_pton (AF_INET, expected_route2_dest, &tmp) > 0,
+	        "dhcp-rfc3442", "couldn't convert expected route destination #2");
+	ASSERT (nm_ip4_route_get_dest (route) == tmp.s_addr,
+	        "dhcp-rfc3442", "unexpected route #2 destination");
+
+	ASSERT (inet_pton (AF_INET, expected_route2_gw, &tmp) > 0,
+	        "dhcp-rfc3442", "couldn't convert expected route next hop #2");
+	ASSERT (nm_ip4_route_get_next_hop (route) == tmp.s_addr,
+	        "dhcp-rfc3442", "unexpected route #2 next hop");
+
+	ASSERT (nm_ip4_route_get_prefix (route) == 8,
+	        "dhcp-rfc3442", "unexpected route #2 prefix");
+	ASSERT (nm_ip4_route_get_metric (route) == 0,
+	        "dhcp-rfc3442", "unexpected route #2 metric");
+
+	g_hash_table_destroy (options);
+}
+
+static Option invalid_classless_routes1[] = {
+	/* For dhclient */
+	{ "new_rfc3442_classless_static_routes", "24 192 168 10 192 168 1 1 45 10 17 66 41" },
+	/* For dhcpcd */
+	{ "new_classless_static_routes", "192.168.10.0/24 192.168.1.1 10.0.adfadf/44 10.17.66.41" },
+	{ NULL, NULL }
+};
+
+static void
+test_invalid_classless_routes1 (const char *client)
+{
+	GHashTable *options;
+	NMIP4Config *ip4_config;
+	NMIP4Route *route;
+	struct in_addr tmp;
+	const char *expected_route1_dest = "192.168.10.0";
+	const char *expected_route1_gw = "192.168.1.1";
+
+	options = fill_table (generic_options, NULL);
+	options = fill_table (invalid_classless_routes1, options);
+
+	ip4_config = nm_dhcp_manager_test_ip4_options_to_config (client, "eth0", options, "rebind");
+	ASSERT (ip4_config != NULL,
+	        "dhcp-rfc3442-invalid-1", "failed to parse DHCP4 options");
+
+	/* IP4 routes */
+	ASSERT (nm_ip4_config_get_num_routes (ip4_config) == 1,
+	        "dhcp-rfc3442-invalid-1", "unexpected number of IP routes");
+
+	/* Route #1 */
+	route = nm_ip4_config_get_route (ip4_config, 0);
+	ASSERT (inet_pton (AF_INET, expected_route1_dest, &tmp) > 0,
+	        "dhcp-rfc3442-invalid-1", "couldn't convert expected route destination #1");
+	ASSERT (nm_ip4_route_get_dest (route) == tmp.s_addr,
+	        "dhcp-rfc3442-invalid-1", "unexpected route #1 destination");
+
+	ASSERT (inet_pton (AF_INET, expected_route1_gw, &tmp) > 0,
+	        "dhcp-rfc3442-invalid-1", "couldn't convert expected route next hop #1");
+	ASSERT (nm_ip4_route_get_next_hop (route) == tmp.s_addr,
+	        "dhcp-rfc3442-invalid-1", "unexpected route #1 next hop");
+
+	ASSERT (nm_ip4_route_get_prefix (route) == 24,
+	        "dhcp-rfc3442-invalid-1", "unexpected route #1 prefix");
+	ASSERT (nm_ip4_route_get_metric (route) == 0,
+	        "dhcp-rfc3442-invalid-1", "unexpected route #1 metric");
+
+	g_hash_table_destroy (options);
+}
+
+static Option invalid_classless_routes2[] = {
+	/* For dhclient */
+	{ "new_rfc3442_classless_static_routes", "45 10 17 66 41 24 192 168 10 192 168 1 1" },
+	/* For dhcpcd */
+	{ "new_classless_static_routes", "10.0.adfadf/44 10.17.66.41 192.168.10.0/24 192.168.1.1" },
+	{ NULL, NULL }
+};
+
+static void
+test_invalid_classless_routes2 (const char *client)
+{
+	GHashTable *options;
+	NMIP4Config *ip4_config;
+	NMIP4Route *route;
+	struct in_addr tmp;
+	const char *expected_route1_dest = "10.1.1.5";
+	const char *expected_route1_gw = "10.1.1.1";
+	const char *expected_route2_dest = "100.99.88.56";
+	const char *expected_route2_gw = "10.1.1.1";
+
+	options = fill_table (generic_options, NULL);
+	options = fill_table (invalid_classless_routes2, options);
+
+	ip4_config = nm_dhcp_manager_test_ip4_options_to_config (client, "eth0", options, "rebind");
+	ASSERT (ip4_config != NULL,
+	        "dhcp-rfc3442-invalid-2", "failed to parse DHCP4 options");
+
+	/* Test falling back to old-style static routes if the classless static
+	 * routes are invalid.
+	 */
+
+	/* Routes */
+	ASSERT (nm_ip4_config_get_num_routes (ip4_config) == 2,
+	        "dhcp-rfc3442-invalid-2", "unexpected number of routes");
+
+	/* Route #1 */
+	route = nm_ip4_config_get_route (ip4_config, 0);
+	ASSERT (inet_pton (AF_INET, expected_route1_dest, &tmp) > 0,
+	        "dhcp-rfc3442-invalid-2", "couldn't convert expected route destination #1");
+	ASSERT (nm_ip4_route_get_dest (route) == tmp.s_addr,
+	        "dhcp-rfc3442-invalid-2", "unexpected route #1 destination");
+
+	ASSERT (inet_pton (AF_INET, expected_route1_gw, &tmp) > 0,
+	        "dhcp-rfc3442-invalid-2", "couldn't convert expected route next hop #1");
+	ASSERT (nm_ip4_route_get_next_hop (route) == tmp.s_addr,
+	        "dhcp-rfc3442-invalid-2", "unexpected route #1 next hop");
+
+	ASSERT (nm_ip4_route_get_prefix (route) == 32,
+	        "dhcp-rfc3442-invalid-2", "unexpected route #1 prefix");
+	ASSERT (nm_ip4_route_get_metric (route) == 0,
+	        "dhcp-rfc3442-invalid-2", "unexpected route #1 metric");
+
+	/* Route #2 */
+	route = nm_ip4_config_get_route (ip4_config, 1);
+	ASSERT (inet_pton (AF_INET, expected_route2_dest, &tmp) > 0,
+	        "dhcp-rfc3442-invalid-2", "couldn't convert expected route destination #2");
+	ASSERT (nm_ip4_route_get_dest (route) == tmp.s_addr,
+	        "dhcp-rfc3442-invalid-2", "unexpected route #2 destination");
+
+	ASSERT (inet_pton (AF_INET, expected_route2_gw, &tmp) > 0,
+	        "dhcp-rfc3442-invalid-2", "couldn't convert expected route next hop #2");
+	ASSERT (nm_ip4_route_get_next_hop (route) == tmp.s_addr,
+	        "dhcp-rfc3442-invalid-2", "unexpected route #2 next hop");
+
+	ASSERT (nm_ip4_route_get_prefix (route) == 32,
+	        "dhcp-rfc3442-invalid-2", "unexpected route #2 prefix");
+	ASSERT (nm_ip4_route_get_metric (route) == 0,
+	        "dhcp-rfc3442-invalid-2", "unexpected route #2 metric");
+
+	g_hash_table_destroy (options);
+}
+
+static Option invalid_classless_routes3[] = {
+	/* For dhclient */
+	{ "new_rfc3442_classless_static_routes", "24 192 168 10 192 168 1 1 32 128 10 17 66 41" },
+	/* For dhcpcd */
+	{ "new_classless_static_routes", "192.168.10.0/24 192.168.1.1 128/32 10.17.66.41" },
+	{ NULL, NULL }
+};
+
+static void
+test_invalid_classless_routes3 (const char *client)
+{
+	GHashTable *options;
+	NMIP4Config *ip4_config;
+	NMIP4Route *route;
+	struct in_addr tmp;
+	const char *expected_route1_dest = "192.168.10.0";
+	const char *expected_route1_gw = "192.168.1.1";
+
+	options = fill_table (generic_options, NULL);
+	options = fill_table (invalid_classless_routes3, options);
+
+	ip4_config = nm_dhcp_manager_test_ip4_options_to_config (client, "eth0", options, "rebind");
+	ASSERT (ip4_config != NULL,
+	        "dhcp-rfc3442-invalid-3", "failed to parse DHCP4 options");
+
+	/* IP4 routes */
+	ASSERT (nm_ip4_config_get_num_routes (ip4_config) == 1,
+	        "dhcp-rfc3442-invalid-3", "unexpected number of IP routes");
+
+	/* Route #1 */
+	route = nm_ip4_config_get_route (ip4_config, 0);
+	ASSERT (inet_pton (AF_INET, expected_route1_dest, &tmp) > 0,
+	        "dhcp-rfc3442-invalid-3", "couldn't convert expected route destination #1");
+	ASSERT (nm_ip4_route_get_dest (route) == tmp.s_addr,
+	        "dhcp-rfc3442-invalid-3", "unexpected route #1 destination");
+
+	ASSERT (inet_pton (AF_INET, expected_route1_gw, &tmp) > 0,
+	        "dhcp-rfc3442-invalid-3", "couldn't convert expected route next hop #1");
+	ASSERT (nm_ip4_route_get_next_hop (route) == tmp.s_addr,
+	        "dhcp-rfc3442-invalid-3", "unexpected route #1 next hop");
+
+	ASSERT (nm_ip4_route_get_prefix (route) == 24,
+	        "dhcp-rfc3442-invalid-3", "unexpected route #1 prefix");
+	ASSERT (nm_ip4_route_get_metric (route) == 0,
+	        "dhcp-rfc3442-invalid-3", "unexpected route #1 metric");
+
+	g_hash_table_destroy (options);
+}
+
+static Option gw_in_classless_routes[] = {
+	/* For dhclient */
+	{ "new_rfc3442_classless_static_routes", "24 192 168 10 192 168 1 1 0 192 2 3 4" },
+	/* For dhcpcd */
+	{ "new_classless_static_routes", "192.168.10.0/24 192.168.1.1 0.0.0.0/0 192.2.3.4" },
+	{ NULL, NULL }
+};
+
+static void
+test_gateway_in_classless_routes (const char *client)
+{
+	GHashTable *options;
+	NMIP4Config *ip4_config;
+	NMIP4Address *addr;
+	NMIP4Route *route;
+	struct in_addr tmp;
+	const char *expected_route1_dest = "192.168.10.0";
+	const char *expected_route1_gw = "192.168.1.1";
+	const char *expected_gateway = "192.2.3.4";
+
+	options = fill_table (generic_options, NULL);
+	options = fill_table (gw_in_classless_routes, options);
+
+	ip4_config = nm_dhcp_manager_test_ip4_options_to_config (client, "eth0", options, "rebind");
+	ASSERT (ip4_config != NULL,
+	        "dhcp-rfc3442-gateway", "failed to parse DHCP4 options");
+
+	/* IP4 routes */
+	ASSERT (nm_ip4_config_get_num_routes (ip4_config) == 1,
+	        "dhcp-rfc3442-gateway", "unexpected number of IP routes");
+
+	/* Route #1 */
+	route = nm_ip4_config_get_route (ip4_config, 0);
+	ASSERT (inet_pton (AF_INET, expected_route1_dest, &tmp) > 0,
+	        "dhcp-rfc3442-gateway", "couldn't convert expected route destination #1");
+	ASSERT (nm_ip4_route_get_dest (route) == tmp.s_addr,
+	        "dhcp-rfc3442-gateway", "unexpected route #1 destination");
+
+	ASSERT (inet_pton (AF_INET, expected_route1_gw, &tmp) > 0,
+	        "dhcp-rfc3442-gateway", "couldn't convert expected route next hop #1");
+	ASSERT (nm_ip4_route_get_next_hop (route) == tmp.s_addr,
+	        "dhcp-rfc3442-gateway", "unexpected route #1 next hop");
+
+	ASSERT (nm_ip4_route_get_prefix (route) == 24,
+	        "dhcp-rfc3442-gateway", "unexpected route #1 prefix");
+	ASSERT (nm_ip4_route_get_metric (route) == 0,
+	        "dhcp-rfc3442-gateway", "unexpected route #1 metric");
+
+	/* Address */
+	ASSERT (nm_ip4_config_get_num_addresses (ip4_config) == 1,
+	        "dhcp-rfc3442-gateway", "unexpected number of IP addresses");
+	addr = nm_ip4_config_get_address (ip4_config, 0);
+	ASSERT (inet_pton (AF_INET, expected_gateway, &tmp) > 0,
+	        "dhcp-rfc3442-gateway", "couldn't convert expected IP gateway");
+	ASSERT (nm_ip4_address_get_gateway (addr) == tmp.s_addr,
+	        "dhcp-rfc3442-gateway", "unexpected IP gateway");
+
+	g_hash_table_destroy (options);
+}
+
+static Option escaped_searches_options[] = {
+	{ "new_domain_search", "host1\\032host2\\032host3" },
+	{ NULL, NULL }
+};
+
+static void
+test_escaped_domain_searches (const char *client)
+{
+	GHashTable *options;
+	NMIP4Config *ip4_config;
+	const char *expected_search0 = "host1";
+	const char *expected_search1 = "host2";
+	const char *expected_search2 = "host3";
+
+	options = fill_table (generic_options, NULL);
+	options = fill_table (escaped_searches_options, options);
+
+	ip4_config = nm_dhcp_manager_test_ip4_options_to_config (client, "eth0", options, "rebind");
+	ASSERT (ip4_config != NULL,
+	        "dhcp-escaped-domain-searches", "failed to parse DHCP4 options");
+
+	/* domain searches */
+	ASSERT (nm_ip4_config_get_num_searches (ip4_config) == 3,
+	        "dhcp-escaped-domain-searches", "unexpected number of searches");
+	ASSERT (!strcmp (nm_ip4_config_get_search (ip4_config, 0), expected_search0),
+	        "dhcp-escaped-domain-searches", "unexpected domain search #1");
+	ASSERT (!strcmp (nm_ip4_config_get_search (ip4_config, 1), expected_search1),
+	        "dhcp-escaped-domain-searches", "unexpected domain search #1");
+	ASSERT (!strcmp (nm_ip4_config_get_search (ip4_config, 2), expected_search2),
+	        "dhcp-escaped-domain-searches", "unexpected domain search #1");
+
+	g_hash_table_destroy (options);
+}
+
+static Option invalid_escaped_searches_options[] = {
+	{ "new_domain_search", "host1\\aahost2\\032host3" },
+	{ NULL, NULL }
+};
+
+static void
+test_invalid_escaped_domain_searches (const char *client)
+{
+	GHashTable *options;
+	NMIP4Config *ip4_config;
+
+	options = fill_table (generic_options, NULL);
+	options = fill_table (invalid_escaped_searches_options, options);
+
+	ip4_config = nm_dhcp_manager_test_ip4_options_to_config (client, "eth0", options, "rebind");
+	ASSERT (ip4_config != NULL,
+	        "dhcp-invalid-escaped-domain-searches", "failed to parse DHCP4 options");
+
+	/* domain searches */
+	ASSERT (nm_ip4_config_get_num_searches (ip4_config) == 0,
+	        "dhcp-invalid-escaped-domain-searches", "unexpected domain searches");
+
+	g_hash_table_destroy (options);
+}
+
+static void
+test_ip4_missing_prefix (const char *client, const char *ip, guint32 expected_prefix)
+{
+	GHashTable *options;
+	NMIP4Config *ip4_config;
+	NMIP4Address *addr;
+
+	options = fill_table (generic_options, NULL);
+	g_hash_table_insert (options, "new_ip_address", string_to_byte_array_gvalue (ip));
+	g_hash_table_remove (options, "new_subnet_mask");
+
+	ip4_config = nm_dhcp_manager_test_ip4_options_to_config (client, "eth0", options, "rebind");
+	ASSERT (ip4_config != NULL,
+	        "dhcp-ip4-missing-prefix", "failed to parse DHCP4 options");
+
+	ASSERT (nm_ip4_config_get_num_addresses (ip4_config) == 1,
+	        "dhcp-ip4-missing-prefix", "unexpected number of IP4 addresses (not 1)");
+
+	addr = nm_ip4_config_get_address (ip4_config, 0);
+	ASSERT (addr != NULL,
+	        "dhcp-ip4-missing-prefix", "missing IP4 address #1");
+
+	ASSERT (nm_ip4_address_get_prefix (addr) == expected_prefix,
+	        "dhcp-ip4-missing-prefix", "unexpected IP4 address prefix %d (expected %d)",
+	        nm_ip4_address_get_prefix (addr), expected_prefix);
+
+	g_hash_table_destroy (options);
+}
+
+static void
+test_ip4_prefix_classless (const char *client)
+{
+	GHashTable *options;
+	NMIP4Config *ip4_config;
+	NMIP4Address *addr;
+
+	/* Ensure that the missing-subnet-mask handler doesn't mangle classless
+	 * subnet masks at all.  The handler should trigger only if the server
+	 * doesn't send the subnet mask.
+	 */
+
+	options = fill_table (generic_options, NULL);
+	g_hash_table_insert (options, "new_ip_address", string_to_byte_array_gvalue ("172.16.54.22"));
+	g_hash_table_insert (options, "new_subnet_mask", string_to_byte_array_gvalue ("255.255.252.0"));
+
+	ip4_config = nm_dhcp_manager_test_ip4_options_to_config (client, "eth0", options, "rebind");
+	ASSERT (ip4_config != NULL,
+	        "dhcp-ip4-prefix-classless", "failed to parse DHCP4 options");
+
+	ASSERT (nm_ip4_config_get_num_addresses (ip4_config) == 1,
+	        "dhcp-ip4-prefix-classless", "unexpected number of IP4 addresses (not 1)");
+
+	addr = nm_ip4_config_get_address (ip4_config, 0);
+	ASSERT (addr != NULL,
+	        "dhcp-ip4-prefix-classless", "missing IP4 address #1");
+
+	ASSERT (nm_ip4_address_get_prefix (addr) == 22,
+	        "dhcp-ip4-prefix-classless", "unexpected IP4 address prefix %d (expected 22)",
+	        nm_ip4_address_get_prefix (addr));
+
+	g_hash_table_destroy (options);
+}
+
+int main (int argc, char **argv)
+{
+	GError *error = NULL;
+	DBusGConnection *bus;
+	char *base;
+	const char *clients[2][2] = { {DHCLIENT_PATH, "dhclient"}, {DHCPCD_PATH, "dhcpcd"} };
+	guint32 i;
+
+	g_type_init ();
+	bus = dbus_g_bus_get (DBUS_BUS_SESSION, NULL);
+
+	if (!nm_utils_init (&error))
+		FAIL ("nm-utils-init", "failed to initialize libnm-util: %s", error->message);
+
+	/* The tests */
+	for (i = 0; i < 2; i++) {
+		const char *client_path = clients[i][0];
+		const char *client = clients[i][1];
+
+		if (!client_path || !strlen (client_path))
+			continue;
+
+		test_generic_options (client);
+		test_wins_options (client);
+		test_classless_static_routes (client);
+		test_invalid_classless_routes1 (client);
+		test_invalid_classless_routes2 (client);
+		test_invalid_classless_routes3 (client);
+		test_gateway_in_classless_routes (client);
+		test_escaped_domain_searches (client);
+		test_invalid_escaped_domain_searches (client);
+		test_ip4_missing_prefix (client, "192.168.1.10", 24);
+		test_ip4_missing_prefix (client, "172.16.54.50", 16);
+		test_ip4_missing_prefix (client, "10.1.2.3", 8);
+		test_ip4_prefix_classless (client);
+	}
+
+	base = g_path_get_basename (argv[0]);
+	fprintf (stdout, "%s: SUCCESS\n", base);
+	g_free (base);
+	return 0;
+}
+
diff --git a/src/tests/test-policy-hosts.c b/src/tests/test-policy-hosts.c
new file mode 100644
index 00000000..e14f15e5
--- /dev/null
+++ b/src/tests/test-policy-hosts.c
@@ -0,0 +1,394 @@
+/* -*- 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 (C) 2010 Red Hat, Inc.
+ *
+ */
+
+#include <glib.h>
+#include <string.h>
+
+#include "nm-policy-hosts.h"
+
+#define FALLBACK_HOSTNAME "localhost.localdomain"
+
+static void
+test_generic (const char *before,
+              const char *after,
+              const char *hostname,
+              gboolean expect_error)
+{
+	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,
+	                                FALLBACK_HOSTNAME,
+	                                &error);
+	g_strfreev (lines);
+
+	if (expect_error) {
+		g_assert (newc == NULL);
+		g_assert (error != NULL);
+		g_clear_error (&error);
+	} else if (after == NULL) {
+		/* No change to /etc/hosts required */
+		g_assert (newc == NULL);
+		g_assert (error == NULL);
+	} else {
+		g_assert (newc != NULL);
+		g_assert (error == NULL);
+
+#if 0
+		g_message ("\n--------------------------------------\n"
+		           "%s"
+		           "--------------------------------------",
+		           newc->str);
+#endif
+		g_assert (strlen (newc->str) == strlen (after));
+		g_assert (strcmp (newc->str, after) == 0);
+		g_string_free (newc, TRUE);
+	}
+}
+
+/*******************************************/
+
+static const char *generic_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"
+	"127.0.0.1	lcmd.us.intellitxt.com\n";
+
+static void
+test_hosts_generic (void)
+{
+	test_generic (generic_before, NULL, "localhost.localdomain", FALSE);
+}
+
+/*******************************************/
+
+static const char *generic_no_boilerplate_before = \
+	"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 (void)
+{
+	test_generic (generic_no_boilerplate_before, NULL, "localhost.localdomain", 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\n"
+	"127.0.0.1	localhost.localdomain\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",
+	              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		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",
+	              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 void
+test_hosts_named_generic (void)
+{
+	test_generic (named_generic_before, NULL, "playboy", FALSE);
+}
+
+/*******************************************/
+
+static const char *named_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"
+	"127.0.0.1	lcmd.us.intellitxt.com\n"
+	"192.168.1.2	tomcat\n";
+
+static void
+test_hosts_named_non127 (void)
+{
+	test_generic (named_non127_before, NULL, "tomcat", FALSE);
+}
+
+/*******************************************/
+
+static const char *named2_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"
+	"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_named2_non127 (void)
+{
+	test_generic (named2_non127_before, NULL, "tomcat", 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 = \
+	"# 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"
+	"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", 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	localhost.localdomain	localhost\n"
+	"127.0.0.1	tomcat\n"
+	"::1		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", 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", FALSE);
+}
+
+/*******************************************/
+
+static const char *no_host_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_host_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		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_host (void)
+{
+	test_generic (no_host_before, no_host_after, "comet", 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"
+	"127.0.0.1	ads.as4x.tmcs.net\n"
+	"127.0.0.1	n4403ad.doubleclick.net\n"
+	"127.0.0.1	www.assoc-amazon.com\n"
+	"127.0.0.1	s25.sitemeter.com\n"
+	"127.0.0.1	adlog.com.com\n"
+	"127.0.0.1	ahs.laptopmag.com\n"
+	"127.0.0.1	altfarm.mediaplex.com\n"
+	"127.0.0.1	ads.addynamix.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_long (void)
+{
+	test_generic (long_before, NULL, "comet", 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++;
+	}
+}
+
+typedef void (*TCFunc)(void);
+
+#define TESTCASE(t, d) g_test_create_case (#t, 0, d, NULL, (TCFunc) t, NULL)
+
+int main (int argc, char **argv)
+{
+	GTestSuite *suite;
+
+	g_test_init (&argc, &argv, NULL);
+
+	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_named_non127, NULL));
+	g_test_suite_add (suite, TESTCASE (test_hosts_named2_non127, 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_host, NULL));
+	g_test_suite_add (suite, TESTCASE (test_hosts_long, NULL));
+
+	return g_test_run ();
+}
+