Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src Few naive unit tests for the getprotoent(3) family.
details: https://anonhg.NetBSD.org/src/rev/3d627da8099d
branches: trunk
changeset: 767309:3d627da8099d
user: jruoho <jruoho%NetBSD.org@localhost>
date: Fri Jul 15 06:41:29 2011 +0000
description:
Few naive unit tests for the getprotoent(3) family.
diffstat:
distrib/sets/lists/tests/mi | 4 +-
tests/lib/libc/net/Makefile | 4 +-
tests/lib/libc/net/t_getprotoent.c | 233 +++++++++++++++++++++++++++++++++++++
3 files changed, 239 insertions(+), 2 deletions(-)
diffs (280 lines):
diff -r c834fb067d73 -r 3d627da8099d distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi Fri Jul 15 03:35:13 2011 +0000
+++ b/distrib/sets/lists/tests/mi Fri Jul 15 06:41:29 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.373 2011/07/08 06:38:03 jruoho Exp $
+# $NetBSD: mi,v 1.374 2011/07/15 06:41:29 jruoho Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@@ -406,6 +406,7 @@
./usr/libdata/debug/usr/tests/lib/libc/net/h_nsd_recurse.debug tests-lib-debug debug,atf
./usr/libdata/debug/usr/tests/lib/libc/net/h_protoent.debug tests-lib-debug debug,atf
./usr/libdata/debug/usr/tests/lib/libc/net/h_servent.debug tests-lib-debug debug,atf
+./usr/libdata/debug/usr/tests/lib/libc/net/t_getprotoent.debug tests-lib-debug debug,atf
./usr/libdata/debug/usr/tests/lib/libc/regex tests-lib-debug
./usr/libdata/debug/usr/tests/lib/libc/regex/h_regex.debug tests-lib-debug debug,atf
./usr/libdata/debug/usr/tests/lib/libc/rpc tests-lib-debug
@@ -1952,6 +1953,7 @@
./usr/tests/lib/libc/net/h_nsd_recurse tests-lib-tests atf
./usr/tests/lib/libc/net/h_protoent tests-lib-tests atf
./usr/tests/lib/libc/net/h_servent tests-lib-tests atf
+./usr/tests/lib/libc/net/t_getprotoent tests-lib-tests atf
./usr/tests/lib/libc/net/t_nsdispatch tests-lib-tests atf
./usr/tests/lib/libc/net/t_protoent tests-lib-tests atf
./usr/tests/lib/libc/net/t_servent tests-lib-tests atf
diff -r c834fb067d73 -r 3d627da8099d tests/lib/libc/net/Makefile
--- a/tests/lib/libc/net/Makefile Fri Jul 15 03:35:13 2011 +0000
+++ b/tests/lib/libc/net/Makefile Fri Jul 15 06:41:29 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.4 2011/01/13 02:24:51 pgoyette Exp $
+# $NetBSD: Makefile,v 1.5 2011/07/15 06:41:29 jruoho Exp $
.include <bsd.own.mk>
@@ -8,6 +8,8 @@
TESTSDIR= ${TESTSBASE}/lib/libc/net
+TESTS_C+= t_getprotoent
+
TESTS_SH+= t_nsdispatch
TESTS_SH+= t_protoent
TESTS_SH+= t_servent
diff -r c834fb067d73 -r 3d627da8099d tests/lib/libc/net/t_getprotoent.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/lib/libc/net/t_getprotoent.c Fri Jul 15 06:41:29 2011 +0000
@@ -0,0 +1,233 @@
+/* $NetBSD: t_getprotoent.c,v 1.1 2011/07/15 06:41:29 jruoho Exp $ */
+
+/*-
+ * Copyright (c) 2011 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jukka Ruohonen.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: t_getprotoent.c,v 1.1 2011/07/15 06:41:29 jruoho Exp $");
+
+#include <atf-c.h>
+#include <netdb.h>
+#include <limits.h>
+#include <stdio.h>
+#include <string.h>
+
+static const struct {
+ const char *name;
+ int number;
+} protos[] = {
+
+ { "icmp", 1 }, { "tcp", 6 }, { "udp", 17 }, { "gre", 47 },
+ { "esp", 50 }, { "ah", 51 }, { "sctp", 132}, { "ipv6-icmp", 58 }
+};
+
+ATF_TC(endprotoent_rewind);
+ATF_TC_HEAD(endprotoent_rewind, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Check that endprotoent(3) rewinds");
+}
+
+ATF_TC_BODY(endprotoent_rewind, tc)
+{
+ struct protoent *p;
+ int i = 0;
+
+ setprotoent(0);
+
+ while ((p = getprotoent()) != NULL && i <= 10) {
+ ATF_REQUIRE(p->p_proto == i);
+ i++;
+ }
+
+ i = 0;
+ endprotoent();
+
+ while ((p = getprotoent()) != NULL && i <= 10) {
+ ATF_REQUIRE(p->p_proto == i);
+ i++;
+ }
+
+ endprotoent();
+}
+
+ATF_TC(getprotobyname_basic);
+ATF_TC_HEAD(getprotobyname_basic, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "A naive test of getprotobyname(3)");
+}
+
+ATF_TC_BODY(getprotobyname_basic, tc)
+{
+ struct protoent *p;
+ size_t i;
+
+ for (i = 0; i < __arraycount(protos); i++) {
+
+ p = getprotobyname(protos[i].name);
+
+ ATF_REQUIRE(p != NULL);
+ ATF_REQUIRE(p->p_proto == protos[i].number);
+ ATF_REQUIRE(strcmp(p->p_name, protos[i].name) == 0);
+ }
+
+ endprotoent();
+}
+
+ATF_TC(getprotobyname_err);
+ATF_TC_HEAD(getprotobyname_err, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Test EOF from getprotobyname(3)");
+}
+
+ATF_TC_BODY(getprotobyname_err, tc)
+{
+ static const char * name[] =
+ { "xxx", "yyy", "xyz", ".as.d}9x.._?!!#¤,¨^//&%%,",
+ "0", "", "tCp", "uDp", "t c p", "tcp ", " tcp" };
+
+ size_t i;
+
+ for (i = 0; i < __arraycount(name); i++)
+ ATF_REQUIRE(getprotobyname(name[i]) == NULL);
+
+ endprotoent();
+}
+
+ATF_TC(getprotobynumber_basic);
+ATF_TC_HEAD(getprotobynumber_basic, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "A naive test of getprotobynumber(3)");
+}
+
+ATF_TC_BODY(getprotobynumber_basic, tc)
+{
+ struct protoent *p;
+ size_t i;
+
+ /*
+ * No ATF_CHECK() due static storage.
+ */
+ for (i = 0; i < __arraycount(protos); i++) {
+
+ p = getprotobynumber(protos[i].number);
+
+ ATF_REQUIRE(p != NULL);
+ ATF_REQUIRE(p->p_proto == protos[i].number);
+ ATF_REQUIRE(strcmp(p->p_name, protos[i].name) == 0);
+ }
+
+ endprotoent();
+}
+
+ATF_TC(getprotobynumber_err);
+ATF_TC_HEAD(getprotobynumber_err, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Test EOF from getprotobynumber(3)");
+}
+
+ATF_TC_BODY(getprotobynumber_err, tc)
+{
+ static const int number[] = { -1, -99999, INT_MAX, 1000000000 };
+ size_t i;
+
+ for (i = 0; i < __arraycount(number); i++)
+ ATF_REQUIRE(getprotobynumber(number[i]) == NULL);
+
+ endprotoent();
+}
+
+ATF_TC(getprotoent_next);
+ATF_TC_HEAD(getprotoent_next, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "getprotoent(3) returns next line?");
+}
+
+ATF_TC_BODY(getprotoent_next, tc)
+{
+ struct protoent *p;
+ int i = 0;
+
+ /*
+ * The range [0, 60] is already reserved by IANA.
+ */
+ while ((p = getprotoent()) != NULL && i <= 60) {
+ ATF_CHECK(p->p_proto == i);
+ i++;
+ }
+
+ endprotoent();
+}
+
+ATF_TC(setprotoent_rewind);
+ATF_TC_HEAD(setprotoent_rewind, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Check that setprotoent(3) rewinds");
+}
+
+ATF_TC_BODY(setprotoent_rewind, tc)
+{
+ struct protoent *p;
+
+ setprotoent(0);
+
+ p = getprotoent();
+ ATF_REQUIRE(p->p_proto == 0);
+
+ p = getprotoent();
+ ATF_REQUIRE(p->p_proto == 1);
+
+ p = getprotoent();
+ ATF_REQUIRE(p->p_proto == 2);
+
+ setprotoent(0);
+
+ p = getprotoent();
+ ATF_REQUIRE(p->p_proto == 0);
+
+ p = getprotoent();
+ ATF_REQUIRE(p->p_proto == 1);
+
+ p = getprotoent();
+ ATF_REQUIRE(p->p_proto == 2);
+
+ endprotoent();
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, getprotobyname_basic);
+ ATF_TP_ADD_TC(tp, getprotobyname_err);
+ ATF_TP_ADD_TC(tp, getprotobynumber_basic);
+ ATF_TP_ADD_TC(tp, getprotobynumber_err);
+ ATF_TP_ADD_TC(tp, endprotoent_rewind);
+ ATF_TP_ADD_TC(tp, getprotoent_next);
+ ATF_TP_ADD_TC(tp, setprotoent_rewind);
+
+ return atf_no_error();
+}
Home |
Main Index |
Thread Index |
Old Index