Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tests/lib/libppath Add tests for ppath(3).
details: https://anonhg.NetBSD.org/src/rev/2c322380d67e
branches: trunk
changeset: 768743:2c322380d67e
user: dyoung <dyoung%NetBSD.org@localhost>
date: Thu Aug 25 19:09:46 2011 +0000
description:
Add tests for ppath(3).
TBD: hook into build and update set lists.
diffstat:
tests/lib/libppath/Makefile | 26 +
tests/lib/libppath/personnel.plist | 26 +
tests/lib/libppath/plist_to_c | 20 +
tests/lib/libppath/t_ppath.c | 1548 ++++++++++++++++++++++++++++++++++++
4 files changed, 1620 insertions(+), 0 deletions(-)
diffs (truncated from 1636 to 300 lines):
diff -r 4b4b1a26edf1 -r 2c322380d67e tests/lib/libppath/Makefile
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/lib/libppath/Makefile Thu Aug 25 19:09:46 2011 +0000
@@ -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"
diff -r 4b4b1a26edf1 -r 2c322380d67e tests/lib/libppath/personnel.plist
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/lib/libppath/personnel.plist Thu Aug 25 19:09:46 2011 +0000
@@ -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>
+ <key>John Doe</key>
+ <dict>
+ <key>children</key>
+ <array>
+ <string>Jane Doe</string>
+ <string>John Doe, Jr.</string>
+ </array>
+
+ <key>pets</key>
+ <array>
+ <string>Fido</string>
+ <string>Spot</string>
+ </array>
+
+ <key>job title</key>
+ <string>computer programmer</string>
+
+ <key>u.s. citizen</key>
+ <true/>
+ </dict>
+</dict>
+</plist>
diff -r 4b4b1a26edf1 -r 2c322380d67e tests/lib/libppath/plist_to_c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/lib/libppath/plist_to_c Thu Aug 25 19:09:46 2011 +0000
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+prog=$(basename $0)
+usage()
+{
+ echo "usage: ${prog} symbol" 1>&2
+ 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
diff -r 4b4b1a26edf1 -r 2c322380d67e tests/lib/libppath/t_ppath.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/lib/libppath/t_ppath.c Thu Aug 25 19:09:46 2011 +0000
@@ -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();
+ assert_no_ppath_component_extant();
+
+ if ((p = ppath_create()) == NULL)
+ atf_tc_fail("ppath_create failed");
+
+ if ((pc = ppath_idx(0)) == NULL)
+ atf_tc_fail("ppath_idx failed");
+
+ for (i = 0; i < PPATH_MAX_COMPONENTS; i++) {
+ rp = ppath_push(p, pc);
+ ATF_CHECK_EQ(rp, p);
+ }
+
+ rp = ppath_push(p, pc);
+ ATF_CHECK_EQ(rp, NULL);
+
+ rp = ppath_push(p, pc);
+ ATF_CHECK_EQ(rp, NULL);
+
+ ppath_component_release(pc);
+ ppath_release(p);
+
+ assert_no_ppath_extant();
+ assert_no_ppath_component_extant();
+}
+
+ATF_TC(pop_until_empty);
+ATF_TC_HEAD(pop_until_empty, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "check ppath_pop() returns error "
+ "after ppath_t is empty");
+}
+
+ATF_TC_BODY(pop_until_empty, tc)
+{
+ ppath_t *p, *rp;
+ ppath_component_t *pc, *rpc;
+ int i;
+
+ assert_no_ppath_extant();
+ assert_no_ppath_component_extant();
+
+ if ((p = ppath_create()) == NULL)
+ atf_tc_fail("ppath_create failed");
+
+ if ((pc = ppath_idx(0)) == NULL)
+ atf_tc_fail("ppath_idx failed");
+
+ for (i = 0; i < PPATH_MAX_COMPONENTS; i++) {
+ rp = ppath_push(p, pc);
+ ATF_CHECK_EQ(rp, p);
+ }
+
+ for (i = 0; i < PPATH_MAX_COMPONENTS; i++) {
+ rp = ppath_pop(p, &rpc);
+ ATF_CHECK_EQ(rp, p);
+ ATF_CHECK_EQ(rpc, pc);
+ ppath_component_release(rpc);
+ }
+
+ rp = ppath_pop(p, &rpc);
+ ATF_CHECK_EQ(rp, NULL);
+ rp = ppath_pop(p, &rpc);
+ ATF_CHECK_EQ(rp, NULL);
+
+ ppath_component_release(pc);
+ ppath_release(p);
+
+ assert_no_ppath_extant();
+ assert_no_ppath_component_extant();
+}
+
+ATF_TC(length);
+
+ATF_TC_HEAD(length, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "check that ppath_push() "
+ "and ppath_pop() affect ppath_length() correctly");
+}
+
+ATF_TC_BODY(length, tc)
+{
+ ppath_t *p, *rp;
+ ppath_component_t *pc;
+ unsigned int i, len;
+
+ assert_no_ppath_extant();
+ assert_no_ppath_component_extant();
+
+ if ((p = ppath_create()) == NULL)
+ atf_tc_fail("ppath_create failed");
+
+ if ((pc = ppath_idx(0)) == NULL)
+ atf_tc_fail("ppath_idx failed");
+
+ for (i = 0; i < PPATH_MAX_COMPONENTS; i++) {
+ len = ppath_length(p);
+ ATF_CHECK_EQ(len, i);
+ rp = ppath_push(p, pc);
+ ATF_CHECK_EQ(rp, p);
+ }
+
+ for (i = 0; i < PPATH_MAX_COMPONENTS; i++) {
+ len = ppath_length(p);
+ ATF_CHECK_EQ(len, PPATH_MAX_COMPONENTS - i);
+ rp = ppath_pop(p, NULL);
+ ATF_CHECK_EQ(rp, p);
+ }
+ ppath_component_release(pc);
+ ppath_release(p);
Home |
Main Index |
Thread Index |
Old Index