Module Name:src
Committed By: dyoung
Date: Thu Aug 25 19:09:46 UTC 2011
Added Files:
src/tests/lib/libppath: Makefile personnel.plist plist_to_c t_ppath.c
Log Message:
Add tests for ppath(3).
TBD: hook into build and update set lists.
To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/tests/lib/libppath/Makefile \
src/tests/lib/libppath/personnel.plist src/tests/lib/libppath/plist_to_c \
src/tests/lib/libppath/t_ppath.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Added files:
Index: src/tests/lib/libppath/Makefile
diff -u /dev/null src/tests/lib/libppath/Makefile:1.1
--- /dev/null Thu Aug 25 19:09:46 2011
+++ src/tests/lib/libppath/Makefile Thu Aug 25 19:09:46 2011
@@ -0,0 +1,26 @@
+# $Id: Makefile,v 1.1 2011/08/25 19:09:46 dyoung Exp $
+
+.include bsd.own.mk
+
+LIBPPATH != make -V .OBJDIR -C $(.CURDIR)/../lib
+
+TESTS_C=t_ppath t_proplib
+SRCS.t_proplib=t_proplib.c personnel.c personnel.h
+SRCS.t_ppath=t_ppath.c personnel.c personnel.h
+CPPFLAGS+=-I$(.OBJDIR)
+
+.SUFFIXES: .plist .h
+
+.plist.h:
+ echo extern const char ${.TARGET:S,.h$,,} []; ${.TARGET}
+
+.plist.c:
+ ${.CURDIR}/plist_to_c ${.TARGET:S,.c$,,} ${.IMPSRC} ${.TARGET}
+
+CLEANFILES+=personnel.c personnel.h
+
+LDADD+=-L$(LIBPPATH) -lppath -lprop
+DPADD+=$(LIBPPATH)/libppath.a
+
+.include bsd.test.mk
+.include ../mk/tags.mk
Index: src/tests/lib/libppath/personnel.plist
diff -u /dev/null src/tests/lib/libppath/personnel.plist:1.1
--- /dev/null Thu Aug 25 19:09:46 2011
+++ src/tests/lib/libppath/personnel.plist Thu Aug 25 19:09:46 2011
@@ -0,0 +1,26 @@
+?xml version=1.0 encoding=UTF-8?
+!DOCTYPE plist PUBLIC -//Apple//DTD PLIST 1.0//EN http://www.apple.com/DTDs/PropertyList-1.0.dtd;
+plist version=1.0
+dict
+ keyJohn Doe/key
+ dict
+ keychildren/key
+ array
+ stringJane Doe/string
+ stringJohn Doe, Jr./string
+ /array
+
+ keypets/key
+ array
+ stringFido/string
+ stringSpot/string
+ /array
+
+ keyjob title/key
+ stringcomputer programmer/string
+
+ keyu.s. citizen/key
+ true/
+ /dict
+/dict
+/plist
Index: src/tests/lib/libppath/plist_to_c
diff -u /dev/null src/tests/lib/libppath/plist_to_c:1.1
--- /dev/null Thu Aug 25 19:09:46 2011
+++ src/tests/lib/libppath/plist_to_c Thu Aug 25 19:09:46 2011
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+prog=$(basename $0)
+usage()
+{
+ echo usage: ${prog} symbol 12
+ exit 1
+}
+
+if [ $# -ne 1 ]; then
+ usage
+fi
+
+sed 's/\([\]\)/\\\1/g' | \
+awk -v sym=$1 '
+BEGIN { printf const char sym [] = \; }
+ { printf $0 \\n; }
+END { print \;; }'
+
+exit 0
Index: src/tests/lib/libppath/t_ppath.c
diff -u /dev/null src/tests/lib/libppath/t_ppath.c:1.1
--- /dev/null Thu Aug 25 19:09:46 2011
+++ src/tests/lib/libppath/t_ppath.c Thu Aug 25 19:09:46 2011
@@ -0,0 +1,1548 @@
+/* $Id: t_ppath.c,v 1.1 2011/08/25 19:09:46 dyoung Exp $ */
+
+/* Copyright (c) 2010 David Young. All rights reserved. */
+
+#include sys/cdefs.h
+__RCSID($Id: t_ppath.c,v 1.1 2011/08/25 19:09:46 dyoung Exp $);
+
+#include assert.h
+#include atf-c.h
+#include errno.h
+#include stdlib.h
+#include string.h
+
+#include ppath/ppath.h
+#include personnel.h
+
+void test_ppath_extant_inc(void);
+void test_ppath_extant_dec(void);
+void test_ppath_component_extant_inc(void);
+void test_ppath_component_extant_dec(void);
+
+__strong_alias(ppath_extant_inc, test_ppath_extant_inc);
+__strong_alias(ppath_extant_dec, test_ppath_extant_dec);
+__strong_alias(ppath_component_extant_inc, test_ppath_component_extant_inc);
+__strong_alias(ppath_component_extant_dec, test_ppath_component_extant_dec);
+
+static uint64_t nppath = 0, nppath_component = 0;
+
+static bool
+dictionary_equals(prop_dictionary_t ld, prop_dictionary_t rd)
+{
+ bool eq;
+ char *lt, *rt;
+
+ lt = prop_dictionary_externalize(ld);
+ rt = prop_dictionary_externalize(rd);
+
+ assert(lt != NULL rt != NULL);
+
+ eq = (strcmp(lt, rt) == 0);
+
+ free(lt);
+ free(rt);
+
+ return eq;
+}
+
+static void
+assert_no_ppath_extant(void)
+{
+ ATF_CHECK_EQ(nppath, 0);
+}
+
+static void
+assert_no_ppath_component_extant(void)
+{
+ ATF_CHECK_EQ(nppath_component, 0);
+}
+
+void
+test_ppath_extant_inc(void)
+{
+ if (++nppath == 0)
+ atf_tc_fail(count of extant paths overflowed);
+}
+
+void
+test_ppath_extant_dec(void)
+{
+ if (nppath-- == 0)
+ atf_tc_fail(count of extant path underflowed);
+}
+
+void
+test_ppath_component_extant_inc(void)
+{
+ if (++nppath_component == 0)
+ atf_tc_fail(count of extant path components overflowed);
+}
+
+void
+test_ppath_component_extant_dec(void)
+{
+ if (nppath_component-- == 0)
+ atf_tc_fail(count of extant path components underflowed);
+}
+
+ATF_TC(push_until_full);
+
+ATF_TC_HEAD(push_until_full, tc)
+{
+ atf_tc_set_md_var(tc, descr, check ppath_push() returns error
+ after ppath_t reaches maximum length);
+}
+
+ATF_TC_BODY(push_until_full, tc)
+{
+ ppath_t *p, *rp;
+ ppath_component_t *pc;
+ int i;
+
+ assert_no_ppath_extant();
+