Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tests/lib/libc Moving t_hsearch - belongs in stdlib/
details: https://anonhg.NetBSD.org/src/rev/8bdcadbfbcd1
branches: trunk
changeset: 760817:8bdcadbfbcd1
user: pgoyette <pgoyette%NetBSD.org@localhost>
date: Thu Jan 13 14:32:35 2011 +0000
description:
Moving t_hsearch - belongs in stdlib/
diffstat:
tests/lib/libc/Makefile | 3 +-
tests/lib/libc/stdlib/Makefile | 3 +-
tests/lib/libc/stdlib/t_hsearch.c | 249 ++++++++++++++++++++++++++++++++++++++
tests/lib/libc/t_hsearch.c | 249 --------------------------------------
4 files changed, 252 insertions(+), 252 deletions(-)
diffs (truncated from 539 to 300 lines):
diff -r efcffdf81c08 -r 8bdcadbfbcd1 tests/lib/libc/Makefile
--- a/tests/lib/libc/Makefile Thu Jan 13 14:25:33 2011 +0000
+++ b/tests/lib/libc/Makefile Thu Jan 13 14:32:35 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.36 2011/01/13 13:53:49 pgoyette Exp $
+# $NetBSD: Makefile,v 1.37 2011/01/13 14:32:35 pgoyette Exp $
.include <bsd.own.mk>
.include <bsd.sys.mk>
@@ -14,6 +14,5 @@
TESTS_C+= t_convfp
TESTS_C+= t_gdtoa
-TESTS_C+= t_hsearch
.include <bsd.test.mk>
diff -r efcffdf81c08 -r 8bdcadbfbcd1 tests/lib/libc/stdlib/Makefile
--- a/tests/lib/libc/stdlib/Makefile Thu Jan 13 14:25:33 2011 +0000
+++ b/tests/lib/libc/stdlib/Makefile Thu Jan 13 14:32:35 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.8 2011/01/12 19:44:08 pgoyette Exp $
+# $NetBSD: Makefile,v 1.9 2011/01/13 14:32:35 pgoyette Exp $
.include <bsd.own.mk>
@@ -7,6 +7,7 @@
TESTS_C+= t_div
TESTS_C+= t_environment
TESTS_C+= t_environment_pth
+TESTS_C+= t_hsearch
TESTS_C+= t_mi_vector_hash
TESTS_C+= t_posix_memalign
TESTS_C+= t_strtox
diff -r efcffdf81c08 -r 8bdcadbfbcd1 tests/lib/libc/stdlib/t_hsearch.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/lib/libc/stdlib/t_hsearch.c Thu Jan 13 14:32:35 2011 +0000
@@ -0,0 +1,249 @@
+/* $NetBSD: t_hsearch.c,v 1.1 2011/01/13 14:32:35 pgoyette Exp $ */
+
+/*-
+ * Copyright (c) 2008 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * 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.
+ */
+
+/*
+ * Copyright (c) 2001 Christopher G. Demetriou
+ * All rights reserved.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed for the
+ * NetBSD Project. See http://www.NetBSD.org/ for
+ * information about NetBSD.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ *
+ * <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>>
+ */
+
+#include <sys/cdefs.h>
+__COPYRIGHT("@(#) Copyright (c) 2008\
+ The NetBSD Foundation, inc. All rights reserved.");
+__RCSID("$NetBSD: t_hsearch.c,v 1.1 2011/01/13 14:32:35 pgoyette Exp $");
+
+#include <errno.h>
+#include <search.h>
+#include <string.h>
+#include <stdio.h>
+
+#include <atf-c.h>
+
+#define REQUIRE_ERRNO(x) ATF_REQUIRE_MSG(x, "%s", strerror(errno))
+
+ATF_TC(basic);
+
+ATF_TC_HEAD(basic, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr", "Checks basic insertions and searching");
+}
+
+ATF_TC_BODY(basic, tc)
+{
+ ENTRY e, *ep;
+ char ch[2];
+ int i;
+
+ REQUIRE_ERRNO(hcreate(16) != 0);
+
+ /* ch[1] should be constant from here on down. */
+ ch[1] = '\0';
+
+ /* Basic insertions. Check enough that there'll be collisions. */
+ for (i = 0; i < 26; i++) {
+ ch[0] = 'a' + i;
+ e.key = strdup(ch); /* ptr to provided key is kept! */
+ ATF_REQUIRE(e.key != NULL);
+ e.data = (void *)(long)i;
+
+ ep = hsearch(e, ENTER);
+
+ ATF_REQUIRE(ep != NULL);
+ ATF_REQUIRE_STREQ(ep->key, ch);
+ ATF_REQUIRE_EQ((long)ep->data, i);
+ }
+
+ /* e.key should be constant from here on down. */
+ e.key = ch;
+
+ /* Basic lookups. */
+ for (i = 0; i < 26; i++) {
+ ch[0] = 'a' + i;
+
+ ep = hsearch(e, FIND);
+
+ ATF_REQUIRE(ep != NULL);
+ ATF_REQUIRE_STREQ(ep->key, ch);
+ ATF_REQUIRE_EQ((long)ep->data, i);
+ }
+
+ hdestroy();
+}
+
+ATF_TC(duplicate);
+
+ATF_TC_HEAD(duplicate, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr", "Checks that inserting duplicate "
+ "doesn't overwrite existing data");
+}
+
+ATF_TC_BODY(duplicate, tc)
+{
+ ENTRY e, *ep;
+
+ REQUIRE_ERRNO(hcreate(16));
+
+ e.key = strdup("a");
+ ATF_REQUIRE(e.key != NULL);
+ e.data = (void *)(long) 0;
+
+ ep = hsearch(e, ENTER);
+
+ ATF_REQUIRE(ep != NULL);
+ ATF_REQUIRE_STREQ(ep->key, "a");
+ ATF_REQUIRE_EQ((long)ep->data, 0);
+
+ e.data = (void *)(long)12345;
+
+ ep = hsearch(e, ENTER);
+ ep = hsearch(e, FIND);
+
+ ATF_REQUIRE(ep != NULL);
+ ATF_REQUIRE_STREQ(ep->key, "a");
+ ATF_REQUIRE_EQ((long)ep->data, 0);
+
+ hdestroy();
+}
+
+ATF_TC(nonexistent);
+
+ATF_TC_HEAD(nonexistent, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr",
+ "Checks searching for non-existent entry");
+}
+
+ATF_TC_BODY(nonexistent, tc)
+{
+ ENTRY e, *ep;
+
+ REQUIRE_ERRNO(hcreate(16));
+
+ e.key = strdup("A");
+ ep = hsearch(e, FIND);
+ ATF_REQUIRE_EQ(ep, NULL);
+
+ hdestroy();
+}
+
+ATF_TC(two);
+
+ATF_TC_HEAD(two, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr",
+ "Checks that searching doesn't overwrite previous search results");
+}
+
+ATF_TC_BODY(two, tc)
+{
+ ENTRY e, *ep, *ep2;
+ char *sa, *sb;
+
+ ATF_REQUIRE((sa = strdup("a")) != NULL);
+ ATF_REQUIRE((sb = strdup("b")) != NULL);
+
+ REQUIRE_ERRNO(hcreate(16));
+
+ e.key = sa;
+ e.data = (void*)(long)0;
+
+ ep = hsearch(e, ENTER);
+
+ ATF_REQUIRE(ep != NULL);
+ ATF_REQUIRE_STREQ(ep->key, "a");
+ ATF_REQUIRE_EQ((long)ep->data, 0);
+
+ e.key = sb;
+ e.data = (void*)(long)1;
+
+ ep = hsearch(e, ENTER);
+
+ ATF_REQUIRE(ep != NULL);
+ ATF_REQUIRE_STREQ(ep->key, "b");
+ ATF_REQUIRE_EQ((long)ep->data, 1);
+
+ e.key = sa;
+ ep = hsearch(e, FIND);
+
+ e.key = sb;
+ ep2 = hsearch(e, FIND);
+
+ ATF_REQUIRE(ep != NULL);
+ ATF_REQUIRE_STREQ(ep->key, "a");
+ ATF_REQUIRE_EQ((long)ep->data, 0);
+
+ ATF_REQUIRE(ep2 != NULL);
+ ATF_REQUIRE_STREQ(ep2->key, "b");
+ ATF_REQUIRE_EQ((long)ep2->data, 1);
+
+ hdestroy();
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, basic);
+ ATF_TP_ADD_TC(tp, duplicate);
+ ATF_TP_ADD_TC(tp, nonexistent);
+ ATF_TP_ADD_TC(tp, two);
+
+ return atf_no_error();
+}
diff -r efcffdf81c08 -r 8bdcadbfbcd1 tests/lib/libc/t_hsearch.c
--- a/tests/lib/libc/t_hsearch.c Thu Jan 13 14:25:33 2011 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,249 +0,0 @@
-/* $NetBSD: t_hsearch.c,v 1.1 2010/12/31 14:36:11 pgoyette Exp $ */
-
-/*-
- * Copyright (c) 2008 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * 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
Home |
Main Index |
Thread Index |
Old Index