summaryrefslogtreecommitdiff
path: root/common/tests
diff options
context:
space:
mode:
Diffstat (limited to 'common/tests')
-rw-r--r--common/tests/Makefile.am10
-rw-r--r--common/tests/Makefile.in452
-rw-r--r--common/tests/test_alloc.c496
3 files changed, 958 insertions, 0 deletions
diff --git a/common/tests/Makefile.am b/common/tests/Makefile.am
new file mode 100644
index 00000000..1a2e5582
--- /dev/null
+++ b/common/tests/Makefile.am
@@ -0,0 +1,10 @@
+AM_CPPFLAGS = -I../..
+
+check_PROGRAMS = test_alloc
+
+TESTS = test_alloc
+
+test_alloc_SOURCES = test_alloc.c
+test_alloc_LDADD = ../libdhcp.a ../../tests/libt_api.a \
+ ../../omapip/libomapi.a ../../dst/libdst.a ../../minires/libres.a
+
diff --git a/common/tests/Makefile.in b/common/tests/Makefile.in
new file mode 100644
index 00000000..479dca30
--- /dev/null
+++ b/common/tests/Makefile.in
@@ -0,0 +1,452 @@
+# Makefile.in generated by automake 1.9.6 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005 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@
+srcdir = @srcdir@
+top_srcdir = @top_srcdir@
+VPATH = @srcdir@
+pkgdatadir = $(datadir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+top_builddir = ../..
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+INSTALL = @INSTALL@
+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 = :
+check_PROGRAMS = test_alloc$(EXEEXT)
+subdir = common/tests
+DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+ $(ACLOCAL_M4)
+mkinstalldirs = $(install_sh) -d
+CONFIG_HEADER = $(top_builddir)/includes/config.h
+CONFIG_CLEAN_FILES =
+am_test_alloc_OBJECTS = test_alloc.$(OBJEXT)
+test_alloc_OBJECTS = $(am_test_alloc_OBJECTS)
+test_alloc_DEPENDENCIES = ../libdhcp.a ../../tests/libt_api.a \
+ ../../omapip/libomapi.a ../../dst/libdst.a \
+ ../../minires/libres.a
+DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)/includes
+depcomp = $(SHELL) $(top_srcdir)/depcomp
+am__depfiles_maybe = depfiles
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+CCLD = $(CC)
+LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
+SOURCES = $(test_alloc_SOURCES)
+DIST_SOURCES = $(test_alloc_SOURCES)
+ETAGS = etags
+CTAGS = ctags
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+ACLOCAL = @ACLOCAL@
+AMDEP_FALSE = @AMDEP_FALSE@
+AMDEP_TRUE = @AMDEP_TRUE@
+AMTAR = @AMTAR@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+EXEEXT = @EXEEXT@
+GREP = @GREP@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+LDFLAGS = @LDFLAGS@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LTLIBOBJS = @LTLIBOBJS@
+MAKEINFO = @MAKEINFO@
+OBJEXT = @OBJEXT@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+RANLIB = @RANLIB@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+STRIP = @STRIP@
+VERSION = @VERSION@
+ac_ct_CC = @ac_ct_CC@
+am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
+am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
+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_alias = @build_alias@
+byte_order = @byte_order@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+exec_prefix = @exec_prefix@
+host_alias = @host_alias@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+AM_CPPFLAGS = -I../..
+TESTS = test_alloc
+test_alloc_SOURCES = test_alloc.c
+test_alloc_LDADD = ../libdhcp.a ../../tests/libt_api.a \
+ ../../omapip/libomapi.a ../../dst/libdst.a ../../minires/libres.a
+
+all: all-am
+
+.SUFFIXES:
+.SUFFIXES: .c .o .obj
+$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
+ @for dep in $?; do \
+ case '$(am__configure_deps)' in \
+ *$$dep*) \
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
+ && exit 0; \
+ exit 1;; \
+ esac; \
+ done; \
+ echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign common/tests/Makefile'; \
+ cd $(top_srcdir) && \
+ $(AUTOMAKE) --foreign common/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: $(am__configure_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4): $(am__aclocal_m4_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+clean-checkPROGRAMS:
+ -test -z "$(check_PROGRAMS)" || rm -f $(check_PROGRAMS)
+test_alloc$(EXEEXT): $(test_alloc_OBJECTS) $(test_alloc_DEPENDENCIES)
+ @rm -f test_alloc$(EXEEXT)
+ $(LINK) $(test_alloc_LDFLAGS) $(test_alloc_OBJECTS) $(test_alloc_LDADD) $(LIBS)
+
+mostlyclean-compile:
+ -rm -f *.$(OBJEXT)
+
+distclean-compile:
+ -rm -f *.tab.c
+
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_alloc.Po@am__quote@
+
+.c.o:
+@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
+@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 $<
+
+.c.obj:
+@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ `$(CYGPATH_W) '$<'`; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
+@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 `$(CYGPATH_W) '$<'`
+uninstall-info-am:
+
+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; } \
+ END { for (i in files) print i; }'`; \
+ mkid -fID $$unique
+tags: TAGS
+
+TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
+ $(TAGS_FILES) $(LISP)
+ tags=; \
+ 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; } \
+ END { for (i in files) print i; }'`; \
+ if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \
+ test -n "$$unique" || unique=$$empty_fix; \
+ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+ $$tags $$unique; \
+ fi
+ctags: CTAGS
+CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
+ $(TAGS_FILES) $(LISP)
+ tags=; \
+ 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; } \
+ END { for (i in files) print i; }'`; \
+ test -z "$(CTAGS_ARGS)$$tags$$unique" \
+ || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+ $$tags $$unique
+
+GTAGS:
+ here=`$(am__cd) $(top_builddir) && pwd` \
+ && cd $(top_srcdir) \
+ && gtags -i $(GTAGS_ARGS) $$here
+
+distclean-tags:
+ -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+
+check-TESTS: $(TESTS)
+ @failed=0; all=0; xfail=0; xpass=0; skip=0; \
+ srcdir=$(srcdir); export srcdir; \
+ list='$(TESTS)'; \
+ if test -n "$$list"; then \
+ for tst in $$list; do \
+ if test -f ./$$tst; then dir=./; \
+ elif test -f $$tst; then dir=; \
+ else dir="$(srcdir)/"; fi; \
+ if $(TESTS_ENVIRONMENT) $${dir}$$tst; then \
+ all=`expr $$all + 1`; \
+ case " $(XFAIL_TESTS) " in \
+ *" $$tst "*) \
+ xpass=`expr $$xpass + 1`; \
+ failed=`expr $$failed + 1`; \
+ echo "XPASS: $$tst"; \
+ ;; \
+ *) \
+ echo "PASS: $$tst"; \
+ ;; \
+ esac; \
+ elif test $$? -ne 77; then \
+ all=`expr $$all + 1`; \
+ case " $(XFAIL_TESTS) " in \
+ *" $$tst "*) \
+ xfail=`expr $$xfail + 1`; \
+ echo "XFAIL: $$tst"; \
+ ;; \
+ *) \
+ failed=`expr $$failed + 1`; \
+ echo "FAIL: $$tst"; \
+ ;; \
+ esac; \
+ else \
+ skip=`expr $$skip + 1`; \
+ echo "SKIP: $$tst"; \
+ fi; \
+ done; \
+ if test "$$failed" -eq 0; then \
+ if test "$$xfail" -eq 0; then \
+ banner="All $$all tests passed"; \
+ else \
+ banner="All $$all tests behaved as expected ($$xfail expected failures)"; \
+ fi; \
+ else \
+ if test "$$xpass" -eq 0; then \
+ banner="$$failed of $$all tests failed"; \
+ else \
+ banner="$$failed of $$all tests did not behave as expected ($$xpass unexpected passes)"; \
+ fi; \
+ fi; \
+ dashes="$$banner"; \
+ skipped=""; \
+ if test "$$skip" -ne 0; then \
+ skipped="($$skip tests were not run)"; \
+ test `echo "$$skipped" | wc -c` -le `echo "$$banner" | wc -c` || \
+ dashes="$$skipped"; \
+ fi; \
+ report=""; \
+ if test "$$failed" -ne 0 && test -n "$(PACKAGE_BUGREPORT)"; then \
+ report="Please report to $(PACKAGE_BUGREPORT)"; \
+ test `echo "$$report" | wc -c` -le `echo "$$banner" | wc -c` || \
+ dashes="$$report"; \
+ fi; \
+ dashes=`echo "$$dashes" | sed s/./=/g`; \
+ echo "$$dashes"; \
+ echo "$$banner"; \
+ test -z "$$skipped" || echo "$$skipped"; \
+ test -z "$$report" || echo "$$report"; \
+ echo "$$dashes"; \
+ test "$$failed" -eq 0; \
+ else :; fi
+
+distdir: $(DISTFILES)
+ @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \
+ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \
+ list='$(DISTFILES)'; for file in $$list; do \
+ case $$file in \
+ $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \
+ $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \
+ esac; \
+ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+ dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
+ if test "$$dir" != "$$file" && test "$$dir" != "."; then \
+ dir="/$$dir"; \
+ $(mkdir_p) "$(distdir)$$dir"; \
+ else \
+ dir=''; \
+ fi; \
+ if test -d $$d/$$file; then \
+ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+ cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
+ fi; \
+ cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
+ else \
+ test -f $(distdir)/$$file \
+ || cp -p $$d/$$file $(distdir)/$$file \
+ || exit 1; \
+ fi; \
+ done
+check-am: all-am
+ $(MAKE) $(AM_MAKEFLAGS) $(check_PROGRAMS)
+ $(MAKE) $(AM_MAKEFLAGS) check-TESTS
+check: check-am
+all-am: Makefile
+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)
+
+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-checkPROGRAMS clean-generic 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
+
+info: info-am
+
+info-am:
+
+install-data-am:
+
+install-exec-am:
+
+install-info: install-info-am
+
+install-man:
+
+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
+
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
+uninstall-am: uninstall-info-am
+
+.PHONY: CTAGS GTAGS all all-am check check-TESTS check-am clean \
+ clean-checkPROGRAMS clean-generic ctags distclean \
+ distclean-compile distclean-generic distclean-tags distdir dvi \
+ dvi-am html html-am info info-am install install-am \
+ install-data install-data-am install-exec install-exec-am \
+ install-info install-info-am install-man install-strip \
+ installcheck installcheck-am installdirs maintainer-clean \
+ maintainer-clean-generic mostlyclean mostlyclean-compile \
+ mostlyclean-generic pdf pdf-am ps ps-am tags uninstall \
+ uninstall-am uninstall-info-am
+
+# 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/common/tests/test_alloc.c b/common/tests/test_alloc.c
new file mode 100644
index 00000000..563fe11c
--- /dev/null
+++ b/common/tests/test_alloc.c
@@ -0,0 +1,496 @@
+/*
+ * We test the functions provided in alloc.c here. These are very
+ * basic functions, and it is very important that they work correctly.
+ *
+ * You can see two different styles of testing:
+ *
+ * - In the first, we have a single test for each function that tests
+ * all of the possible ways it can operate. (This is the case for
+ * the buffer tests.)
+ *
+ * - In the second, we have a separate test for each of the ways a
+ * function can operate. (This is the case for the data_string
+ * tests.)
+ *
+ * The advantage of a single test per function is that you have fewer
+ * tests, and less duplicated and extra code. The advantage of having
+ * a separate test is that each test is simpler. Plus if you need to
+ * allow certain tests to fail for some reason (known bugs that are
+ * hard to fix for example), then
+ */
+
+/* TODO: dmalloc() test */
+
+#include "config.h"
+#include "t_api.h"
+
+#include "dhcpd.h"
+
+static void test_buffer_allocate(void);
+static void test_buffer_reference(void);
+static void test_buffer_dereference(void);
+static void test_data_string_forget(void);
+static void test_data_string_forget_nobuf(void);
+static void test_data_string_copy(void);
+static void test_data_string_copy_nobuf(void);
+
+/*
+ * T_testlist is a list of tests that are invoked.
+ */
+testspec_t T_testlist[] = {
+ { test_buffer_allocate,
+ "buffer_allocate()" },
+ { test_buffer_reference,
+ "buffer_reference()" },
+ { test_buffer_dereference,
+ "buffer_dereference()" },
+ { test_data_string_forget,
+ "data_string_forget()" },
+ { test_data_string_forget_nobuf,
+ "data_string_forget(), no buffer" },
+ { test_data_string_copy,
+ "data_string_copy()" },
+ { test_data_string_copy_nobuf,
+ "data_string_copy(), no buffer" },
+ { NULL, NULL }
+};
+
+static void
+test_buffer_allocate(void) {
+ static const char *test_desc =
+ "buffer_allocate basic test";
+
+ struct buffer *buf;
+
+ t_assert("buffer_allocate", 1, T_REQUIRED, test_desc);
+
+ /*
+ * Check a 0-length buffer.
+ */
+ buf = NULL;
+ if (!buffer_allocate(&buf, 0, MDL)) {
+ t_info("failed on 0-len buffer\n");
+ t_result(T_FAIL);
+ return;
+ }
+ if (!buffer_dereference(&buf, MDL)) {
+ t_info("buffer_dereference() failed\n");
+ t_result(T_FAIL);
+ return;
+ }
+ if (buf != NULL) {
+ t_info("buffer_dereference() did not NULL-out buffer\n");
+ t_result(T_FAIL);
+ return;
+ }
+
+ /*
+ * Check an actual buffer.
+ */
+ buf = NULL;
+ if (!buffer_allocate(&buf, 100, MDL)) {
+ t_info("failed on allocate\n");
+ t_result(T_FAIL);
+ return;
+ }
+ if (!buffer_dereference(&buf, MDL)) {
+ t_info("buffer_dereference() failed\n");
+ t_result(T_FAIL);
+ return;
+ }
+ if (buf != NULL) {
+ t_info("buffer_dereference() did not NULL-out buffer\n");
+ t_result(T_FAIL);
+ return;
+ }
+
+ /*
+ * Okay, we're happy.
+ */
+ t_result(T_PASS);
+}
+
+static void
+test_buffer_reference(void) {
+ static const char *test_desc =
+ "buffer_reference basic test";
+ int result = T_PASS;
+
+ struct buffer *a, *b;
+
+ t_assert("buffer_reference", 1, T_REQUIRED, test_desc);
+
+ /*
+ * Create a buffer.
+ */
+ a = NULL;
+ if (!buffer_allocate(&a, 100, MDL)) {
+ t_info("failed on allocate\n");
+ t_result(T_FAIL);
+ return;
+ }
+
+ /*
+ * Confirm buffer_reference() doesn't work if we pass in NULL.
+ *
+ * TODO: we should confirm we get an error message here.
+ */
+ if (buffer_reference(NULL, a, MDL)) {
+ t_info("succeeded on an error input\n");
+ t_result(T_FAIL);
+ return;
+ }
+
+ /*
+ * TODO: we should confirm we get an error message if we pass
+ * a non-NULL target.
+ */
+
+ /*
+ * Confirm we work under normal circumstances.
+ */
+ b = NULL;
+ if (!buffer_reference(&b, a, MDL)) {
+ t_info("buffer_reference() failed\n");
+ t_result(T_FAIL);
+ return;
+ }
+
+ if (b != a) {
+ t_info("incorrect pointer\n");
+ result = T_FAIL;
+ }
+ if (b->refcnt != 2) {
+ t_info("incorrect refcnt\n");
+ result = T_FAIL;
+ }
+
+ /*
+ * Clean up.
+ */
+ if (!buffer_dereference(&b, MDL)) {
+ t_info("buffer_dereference() failed\n");
+ t_result(T_FAIL);
+ return;
+ }
+ if (!buffer_dereference(&a, MDL)) {
+ t_info("buffer_dereference() failed\n");
+ t_result(T_FAIL);
+ return;
+ }
+
+ t_result(result);
+}
+
+static void
+test_buffer_dereference(void) {
+ static const char *test_desc =
+ "buffer_dereference basic test";
+
+ struct buffer *a, *b;
+
+ t_assert("buffer_dereference", 1, T_REQUIRED, test_desc);
+
+ /*
+ * Confirm buffer_dereference() doesn't work if we pass in NULL.
+ *
+ * TODO: we should confirm we get an error message here.
+ */
+ if (buffer_dereference(NULL, MDL)) {
+ t_info("succeeded on an error input\n");
+ t_result(T_FAIL);
+ return;
+ }
+
+ /*
+ * Confirm buffer_dereference() doesn't work if we pass in
+ * a pointer to NULL.
+ *
+ * TODO: we should confirm we get an error message here.
+ */
+ a = NULL;
+ if (buffer_dereference(&a, MDL)) {
+ t_info("succeeded on an error input\n");
+ t_result(T_FAIL);
+ return;
+ }
+
+ /*
+ * Confirm we work under normal circumstances.
+ */
+ a = NULL;
+ if (!buffer_allocate(&a, 100, MDL)) {
+ t_info("failed on allocate\n");
+ t_result(T_FAIL);
+ return;
+ }
+ if (!buffer_dereference(&a, MDL)) {
+ t_info("buffer_dereference() failed\n");
+ t_result(T_FAIL);
+ return;
+ }
+ if (a != NULL) {
+ t_info("non-null buffer after buffer_dereference()\n");
+ t_result(T_FAIL);
+ return;
+ }
+
+ /*
+ * Confirm we get an error from negative refcnt.
+ *
+ * TODO: we should confirm we get an error message here.
+ */
+ a = NULL;
+ if (!buffer_allocate(&a, 100, MDL)) {
+ t_info("failed on allocate\n");
+ t_result(T_FAIL);
+ return;
+ }
+ b = NULL;
+ if (!buffer_reference(&b, a, MDL)) {
+ t_info("buffer_reference() failed\n");
+ t_result(T_FAIL);
+ return;
+ }
+ a->refcnt = 0; /* purposely set to invalid value */
+ if (buffer_dereference(&a, MDL)) {
+ t_info("buffer_dereference() succeeded on error input\n");
+ t_result(T_FAIL);
+ return;
+ }
+ a->refcnt = 2;
+ if (!buffer_dereference(&b, MDL)) {
+ t_info("buffer_dereference() failed\n");
+ t_result(T_FAIL);
+ return;
+ }
+ if (!buffer_dereference(&a, MDL)) {
+ t_info("buffer_dereference() failed\n");
+ t_result(T_FAIL);
+ return;
+ }
+
+ t_result(T_PASS);
+}
+
+static void
+test_data_string_forget(void) {
+ static const char *test_desc =
+ "data_string_forget basic test";
+ int result = T_PASS;
+
+ struct buffer *buf;
+ struct data_string a;
+ const char *str = "Lorem ipsum dolor sit amet turpis duis.";
+
+ t_assert("data_string_forget", 1, T_REQUIRED, test_desc);
+
+ /*
+ * Create the string we want to forget.
+ */
+ memset(&a, 0, sizeof(a));
+ a.len = strlen(str);
+ buf = NULL;
+ if (!buffer_allocate(&buf, a.len, MDL)) {
+ t_info("out of memory\n");
+ t_result(T_FAIL);
+ return;
+ }
+ if (!buffer_reference(&a.buffer, buf, MDL)) {
+ t_info("buffer_reference() failed\n");
+ t_result(T_FAIL);
+ return;
+ }
+ a.data = a.buffer->data;
+ memcpy(a.buffer->data, str, a.len);
+
+ /*
+ * Forget and confirm we've forgotten.
+ */
+ data_string_forget(&a, MDL);
+
+ if (a.len != 0) {
+ t_info("incorrect length\n");
+ result = T_FAIL;
+ }
+ if (a.data != NULL) {
+ t_info("incorrect data\n");
+ result = T_FAIL;
+ }
+ if (a.terminated) {
+ t_info("incorrect terminated\n");
+ result = T_FAIL;
+ }
+ if (a.buffer != NULL) {
+ t_info("incorrect buffer\n");
+ result = T_FAIL;
+ }
+ if (buf->refcnt != 1) {
+ t_info("too many references to buf\n");
+ result = T_FAIL;
+ }
+
+ /*
+ * Clean up buffer.
+ */
+ if (!buffer_dereference(&buf, MDL)) {
+ t_info("buffer_reference() failed\n");
+ t_result(T_FAIL);
+ return;
+ }
+
+ t_result(result);
+}
+
+static void
+test_data_string_forget_nobuf(void) {
+ static const char *test_desc =
+ "data_string_forget test, data_string without buffer";
+ int result = T_PASS;
+
+ struct data_string a;
+ const char *str = "Lorem ipsum dolor sit amet massa nunc.";
+
+ t_assert("data_string_forget, no buffer", 1, T_REQUIRED, test_desc);
+
+ /*
+ * Create the string we want to forget.
+ */
+ memset(&a, 0, sizeof(a));
+ a.len = strlen(str);
+ a.data = (const unsigned char *)str;
+ a.terminated = 1;
+
+ /*
+ * Forget and confirm we've forgotten.
+ */
+ data_string_forget(&a, MDL);
+
+ if (a.len != 0) {
+ t_info("incorrect length\n");
+ result = T_FAIL;
+ }
+ if (a.data != NULL) {
+ t_info("incorrect data\n");
+ result = T_FAIL;
+ }
+ if (a.terminated) {
+ t_info("incorrect terminated\n");
+ result = T_FAIL;
+ }
+ if (a.buffer != NULL) {
+ t_info("incorrect buffer\n");
+ result = T_FAIL;
+ }
+
+ t_result(result);
+}
+
+static void
+test_data_string_copy(void) {
+ static const char *test_desc =
+ "data_string_copy basic test";
+ int result = T_PASS;
+
+ struct data_string a, b;
+ const char *str = "Lorem ipsum dolor sit amet orci aliquam.";
+
+ t_assert("data_string_copy", 1, T_REQUIRED, test_desc);
+
+
+ /*
+ * Create the string we want to copy.
+ */
+ memset(&a, 0, sizeof(a));
+ a.len = strlen(str);
+ if (!buffer_allocate(&a.buffer, a.len, MDL)) {
+ t_info("out of memory\n");
+ t_result(T_FAIL);
+ return;
+ }
+ a.data = a.buffer->data;
+ memcpy(a.buffer->data, str, a.len);
+
+ /*
+ * Copy the string, and confirm it works.
+ */
+ memset(&b, 0, sizeof(b));
+ data_string_copy(&b, &a, MDL);
+
+ if (b.len != a.len) {
+ t_info("incorrect length\n");
+ result = T_FAIL;
+ }
+ if (b.data != a.data) {
+ t_info("incorrect data\n");
+ result = T_FAIL;
+ }
+ if (b.terminated != a.terminated) {
+ t_info("incorrect terminated\n");
+ result = T_FAIL;
+ }
+ if (b.buffer != a.buffer) {
+ t_info("incorrect buffer\n");
+ result = T_FAIL;
+ }
+
+ /*
+ * Clean up.
+ */
+ data_string_forget(&b, MDL);
+ data_string_forget(&a, MDL);
+
+ t_result(result);
+}
+
+static void
+test_data_string_copy_nobuf(void) {
+ static const char *test_desc =
+ "data_string_copy test, data_string without buffer";
+ int result = T_PASS;
+
+ struct data_string a, b;
+ const char *str = "Lorem ipsum dolor sit amet cras amet.";
+
+ t_assert("data_string_copy, no buffer", 1, T_REQUIRED, test_desc);
+
+
+ /*
+ * Create the string we want to copy.
+ */
+ memset(&a, 0, sizeof(a));
+ a.len = strlen(str);
+ a.data = (const unsigned char *)str;
+ a.terminated = 1;
+
+ /*
+ * Copy the string, and confirm it works.
+ */
+ memset(&b, 0, sizeof(b));
+ data_string_copy(&b, &a, MDL);
+
+ if (b.len != a.len) {
+ t_info("incorrect length\n");
+ result = T_FAIL;
+ }
+ if (b.data != a.data) {
+ t_info("incorrect data\n");
+ result = T_FAIL;
+ }
+ if (b.terminated != a.terminated) {
+ t_info("incorrect terminated\n");
+ result = T_FAIL;
+ }
+ if (b.buffer != a.buffer) {
+ t_info("incorrect buffer\n");
+ result = T_FAIL;
+ }
+
+ /*
+ * Clean up.
+ */
+ data_string_forget(&b, MDL);
+ data_string_forget(&a, MDL);
+
+ t_result(result);
+}