xref: /netbsd-src/tests/lib/libc/stdlib/t_hsearch.c (revision 6030f04a157fd2c258cc9a89032f25cbfc764783)
1*6030f04aSchristos /* $NetBSD: t_hsearch.c,v 1.4 2014/07/20 20:17:21 christos Exp $ */
27a60df32Spgoyette 
37a60df32Spgoyette /*-
47a60df32Spgoyette  * Copyright (c) 2008 The NetBSD Foundation, Inc.
57a60df32Spgoyette  * All rights reserved.
67a60df32Spgoyette  *
77a60df32Spgoyette  * Redistribution and use in source and binary forms, with or without
87a60df32Spgoyette  * modification, are permitted provided that the following conditions
97a60df32Spgoyette  * are met:
107a60df32Spgoyette  * 1. Redistributions of source code must retain the above copyright
117a60df32Spgoyette  *    notice, this list of conditions and the following disclaimer.
127a60df32Spgoyette  * 2. Redistributions in binary form must reproduce the above copyright
137a60df32Spgoyette  *    notice, this list of conditions and the following disclaimer in the
147a60df32Spgoyette  *    documentation and/or other materials provided with the distribution.
157a60df32Spgoyette  *
167a60df32Spgoyette  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
177a60df32Spgoyette  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
187a60df32Spgoyette  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
197a60df32Spgoyette  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
207a60df32Spgoyette  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
217a60df32Spgoyette  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
227a60df32Spgoyette  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
237a60df32Spgoyette  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
247a60df32Spgoyette  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
257a60df32Spgoyette  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
267a60df32Spgoyette  * POSSIBILITY OF SUCH DAMAGE.
277a60df32Spgoyette  */
287a60df32Spgoyette 
297a60df32Spgoyette /*
307a60df32Spgoyette  * Copyright (c) 2001 Christopher G. Demetriou
317a60df32Spgoyette  * All rights reserved.
327a60df32Spgoyette  *
337a60df32Spgoyette  * Redistribution and use in source and binary forms, with or without
347a60df32Spgoyette  * modification, are permitted provided that the following conditions
357a60df32Spgoyette  * are met:
367a60df32Spgoyette  * 1. Redistributions of source code must retain the above copyright
377a60df32Spgoyette  *    notice, this list of conditions and the following disclaimer.
387a60df32Spgoyette  * 2. Redistributions in binary form must reproduce the above copyright
397a60df32Spgoyette  *    notice, this list of conditions and the following disclaimer in the
407a60df32Spgoyette  *    documentation and/or other materials provided with the distribution.
417a60df32Spgoyette  * 3. All advertising materials mentioning features or use of this software
427a60df32Spgoyette  *    must display the following acknowledgement:
437a60df32Spgoyette  *          This product includes software developed for the
447a60df32Spgoyette  *          NetBSD Project.  See http://www.NetBSD.org/ for
457a60df32Spgoyette  *          information about NetBSD.
467a60df32Spgoyette  * 4. The name of the author may not be used to endorse or promote products
477a60df32Spgoyette  *    derived from this software without specific prior written permission.
487a60df32Spgoyette  *
497a60df32Spgoyette  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
507a60df32Spgoyette  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
517a60df32Spgoyette  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
527a60df32Spgoyette  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
537a60df32Spgoyette  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
547a60df32Spgoyette  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
557a60df32Spgoyette  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
567a60df32Spgoyette  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
577a60df32Spgoyette  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
587a60df32Spgoyette  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
597a60df32Spgoyette  *
607a60df32Spgoyette  * <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>>
617a60df32Spgoyette  */
627a60df32Spgoyette 
637a60df32Spgoyette #include <sys/cdefs.h>
647a60df32Spgoyette __COPYRIGHT("@(#) Copyright (c) 2008\
657a60df32Spgoyette  The NetBSD Foundation, inc. All rights reserved.");
66*6030f04aSchristos __RCSID("$NetBSD: t_hsearch.c,v 1.4 2014/07/20 20:17:21 christos Exp $");
677a60df32Spgoyette 
687a60df32Spgoyette #include <errno.h>
697a60df32Spgoyette #include <search.h>
707a60df32Spgoyette #include <string.h>
717a60df32Spgoyette #include <stdio.h>
72*6030f04aSchristos #include <stdlib.h>
737a60df32Spgoyette 
747a60df32Spgoyette #include <atf-c.h>
757a60df32Spgoyette 
767a60df32Spgoyette #define REQUIRE_ERRNO(x) ATF_REQUIRE_MSG(x, "%s", strerror(errno))
777a60df32Spgoyette 
786836bf78Sjruoho ATF_TC(hsearch_basic);
ATF_TC_HEAD(hsearch_basic,tc)796836bf78Sjruoho ATF_TC_HEAD(hsearch_basic, tc)
807a60df32Spgoyette {
817a60df32Spgoyette 
827a60df32Spgoyette 	atf_tc_set_md_var(tc, "descr", "Checks basic insertions and searching");
837a60df32Spgoyette }
847a60df32Spgoyette 
ATF_TC_BODY(hsearch_basic,tc)856836bf78Sjruoho ATF_TC_BODY(hsearch_basic, tc)
867a60df32Spgoyette {
877a60df32Spgoyette 	ENTRY e, *ep;
887a60df32Spgoyette 	char ch[2];
897a60df32Spgoyette 	int i;
907a60df32Spgoyette 
917a60df32Spgoyette 	REQUIRE_ERRNO(hcreate(16) != 0);
927a60df32Spgoyette 
937a60df32Spgoyette 	/* ch[1] should be constant from here on down. */
947a60df32Spgoyette 	ch[1] = '\0';
957a60df32Spgoyette 
967a60df32Spgoyette 	/* Basic insertions.  Check enough that there'll be collisions. */
977a60df32Spgoyette 	for (i = 0; i < 26; i++) {
987a60df32Spgoyette 		ch[0] = 'a' + i;
997a60df32Spgoyette 		e.key = strdup(ch);	/* ptr to provided key is kept! */
1007a60df32Spgoyette 		ATF_REQUIRE(e.key != NULL);
101*6030f04aSchristos 		e.data = (void *)(intptr_t)i;
1027a60df32Spgoyette 
1037a60df32Spgoyette 		ep = hsearch(e, ENTER);
1047a60df32Spgoyette 
1057a60df32Spgoyette 		ATF_REQUIRE(ep != NULL);
1067a60df32Spgoyette 		ATF_REQUIRE_STREQ(ep->key, ch);
107*6030f04aSchristos 		ATF_REQUIRE_EQ((intptr_t)ep->data, i);
1087a60df32Spgoyette 	}
1097a60df32Spgoyette 
1107a60df32Spgoyette 	/* e.key should be constant from here on down. */
1117a60df32Spgoyette 	e.key = ch;
1127a60df32Spgoyette 
1137a60df32Spgoyette 	/* Basic lookups. */
1147a60df32Spgoyette 	for (i = 0; i < 26; i++) {
1157a60df32Spgoyette 		ch[0] = 'a' + i;
1167a60df32Spgoyette 
1177a60df32Spgoyette 		ep = hsearch(e, FIND);
1187a60df32Spgoyette 
1197a60df32Spgoyette 		ATF_REQUIRE(ep != NULL);
1207a60df32Spgoyette 		ATF_REQUIRE_STREQ(ep->key, ch);
121*6030f04aSchristos 		ATF_REQUIRE_EQ((intptr_t)ep->data, i);
1227a60df32Spgoyette 	}
1237a60df32Spgoyette 
124*6030f04aSchristos 	hdestroy1(free, NULL);
1257a60df32Spgoyette }
1267a60df32Spgoyette 
1276836bf78Sjruoho ATF_TC(hsearch_duplicate);
ATF_TC_HEAD(hsearch_duplicate,tc)1286836bf78Sjruoho ATF_TC_HEAD(hsearch_duplicate, tc)
1297a60df32Spgoyette {
1307a60df32Spgoyette 
1317a60df32Spgoyette 	atf_tc_set_md_var(tc, "descr", "Checks that inserting duplicate "
1327a60df32Spgoyette 	    "doesn't overwrite existing data");
1337a60df32Spgoyette }
1347a60df32Spgoyette 
ATF_TC_BODY(hsearch_duplicate,tc)1356836bf78Sjruoho ATF_TC_BODY(hsearch_duplicate, tc)
1367a60df32Spgoyette {
1377a60df32Spgoyette 	ENTRY e, *ep;
1387a60df32Spgoyette 
1397a60df32Spgoyette 	REQUIRE_ERRNO(hcreate(16));
1407a60df32Spgoyette 
141*6030f04aSchristos 	e.key = __UNCONST("a");
142*6030f04aSchristos 	e.data = (void *)(intptr_t) 0;
1437a60df32Spgoyette 
1447a60df32Spgoyette 	ep = hsearch(e, ENTER);
1457a60df32Spgoyette 
1467a60df32Spgoyette 	ATF_REQUIRE(ep != NULL);
1477a60df32Spgoyette 	ATF_REQUIRE_STREQ(ep->key, "a");
148*6030f04aSchristos 	ATF_REQUIRE_EQ((intptr_t)ep->data, 0);
1497a60df32Spgoyette 
150*6030f04aSchristos 	e.data = (void *)(intptr_t)12345;
1517a60df32Spgoyette 
1527a60df32Spgoyette 	ep = hsearch(e, ENTER);
1537a60df32Spgoyette 	ep = hsearch(e, FIND);
1547a60df32Spgoyette 
1557a60df32Spgoyette 	ATF_REQUIRE(ep != NULL);
1567a60df32Spgoyette 	ATF_REQUIRE_STREQ(ep->key, "a");
157*6030f04aSchristos 	ATF_REQUIRE_EQ((intptr_t)ep->data, 0);
1587a60df32Spgoyette 
1597a60df32Spgoyette 	hdestroy();
1607a60df32Spgoyette }
1617a60df32Spgoyette 
1626836bf78Sjruoho ATF_TC(hsearch_nonexistent);
ATF_TC_HEAD(hsearch_nonexistent,tc)1636836bf78Sjruoho ATF_TC_HEAD(hsearch_nonexistent, tc)
1647a60df32Spgoyette {
1657a60df32Spgoyette 
1667a60df32Spgoyette 	atf_tc_set_md_var(tc, "descr",
1677a60df32Spgoyette 	    "Checks searching for non-existent entry");
1687a60df32Spgoyette }
1697a60df32Spgoyette 
ATF_TC_BODY(hsearch_nonexistent,tc)1706836bf78Sjruoho ATF_TC_BODY(hsearch_nonexistent, tc)
1717a60df32Spgoyette {
1727a60df32Spgoyette 	ENTRY e, *ep;
1737a60df32Spgoyette 
1747a60df32Spgoyette 	REQUIRE_ERRNO(hcreate(16));
1757a60df32Spgoyette 
176*6030f04aSchristos 	e.key = __UNCONST("A");
1777a60df32Spgoyette 	ep = hsearch(e, FIND);
1787a60df32Spgoyette 	ATF_REQUIRE_EQ(ep, NULL);
1797a60df32Spgoyette 
1807a60df32Spgoyette 	hdestroy();
1817a60df32Spgoyette }
1827a60df32Spgoyette 
1836836bf78Sjruoho ATF_TC(hsearch_two);
ATF_TC_HEAD(hsearch_two,tc)1846836bf78Sjruoho ATF_TC_HEAD(hsearch_two, tc)
1857a60df32Spgoyette {
1867a60df32Spgoyette 
1877a60df32Spgoyette 	atf_tc_set_md_var(tc, "descr",
1887a60df32Spgoyette 	    "Checks that searching doesn't overwrite previous search results");
1897a60df32Spgoyette }
1907a60df32Spgoyette 
ATF_TC_BODY(hsearch_two,tc)1916836bf78Sjruoho ATF_TC_BODY(hsearch_two, tc)
1927a60df32Spgoyette {
1937a60df32Spgoyette 	ENTRY e, *ep, *ep2;
1947a60df32Spgoyette 
1957a60df32Spgoyette 	REQUIRE_ERRNO(hcreate(16));
1967a60df32Spgoyette 
197*6030f04aSchristos 	e.key = __UNCONST("a");
198*6030f04aSchristos 	e.data = (void*)(intptr_t)0;
1997a60df32Spgoyette 
2007a60df32Spgoyette 	ep = hsearch(e, ENTER);
2017a60df32Spgoyette 
2027a60df32Spgoyette 	ATF_REQUIRE(ep != NULL);
2037a60df32Spgoyette 	ATF_REQUIRE_STREQ(ep->key, "a");
204*6030f04aSchristos 	ATF_REQUIRE_EQ((intptr_t)ep->data, 0);
2057a60df32Spgoyette 
206*6030f04aSchristos 	e.key = __UNCONST("b");
207*6030f04aSchristos 	e.data = (void*)(intptr_t)1;
2087a60df32Spgoyette 
2097a60df32Spgoyette 	ep = hsearch(e, ENTER);
2107a60df32Spgoyette 
2117a60df32Spgoyette 	ATF_REQUIRE(ep != NULL);
2127a60df32Spgoyette 	ATF_REQUIRE_STREQ(ep->key, "b");
213*6030f04aSchristos 	ATF_REQUIRE_EQ((intptr_t)ep->data, 1);
2147a60df32Spgoyette 
215*6030f04aSchristos 	e.key = __UNCONST("a");
2167a60df32Spgoyette 	ep = hsearch(e, FIND);
2177a60df32Spgoyette 
218*6030f04aSchristos 	e.key = __UNCONST("b");
2197a60df32Spgoyette 	ep2 = hsearch(e, FIND);
2207a60df32Spgoyette 
2217a60df32Spgoyette 	ATF_REQUIRE(ep != NULL);
2227a60df32Spgoyette 	ATF_REQUIRE_STREQ(ep->key, "a");
223*6030f04aSchristos 	ATF_REQUIRE_EQ((intptr_t)ep->data, 0);
2247a60df32Spgoyette 
2257a60df32Spgoyette 	ATF_REQUIRE(ep2 != NULL);
2267a60df32Spgoyette 	ATF_REQUIRE_STREQ(ep2->key, "b");
227*6030f04aSchristos 	ATF_REQUIRE_EQ((intptr_t)ep2->data, 1);
2287a60df32Spgoyette 
2297a60df32Spgoyette 	hdestroy();
2307a60df32Spgoyette }
2317a60df32Spgoyette 
232a2221b9cSchristos ATF_TC(hsearch_r_basic);
ATF_TC_HEAD(hsearch_r_basic,tc)233a2221b9cSchristos ATF_TC_HEAD(hsearch_r_basic, tc)
234a2221b9cSchristos {
235a2221b9cSchristos 
236a2221b9cSchristos 	atf_tc_set_md_var(tc, "descr", "Checks basic insertions and searching");
237a2221b9cSchristos }
238a2221b9cSchristos 
ATF_TC_BODY(hsearch_r_basic,tc)239a2221b9cSchristos ATF_TC_BODY(hsearch_r_basic, tc)
240a2221b9cSchristos {
241a2221b9cSchristos 	ENTRY e, *ep;
242a2221b9cSchristos 	char ch[2];
243a2221b9cSchristos 	int i;
244a2221b9cSchristos 	struct hsearch_data t;
245a2221b9cSchristos 
246a2221b9cSchristos 	REQUIRE_ERRNO(hcreate_r(16, &t) != 0);
247a2221b9cSchristos 
248a2221b9cSchristos 	/* ch[1] should be constant from here on down. */
249a2221b9cSchristos 	ch[1] = '\0';
250a2221b9cSchristos 
251a2221b9cSchristos 	/* Basic insertions.  Check enough that there'll be collisions. */
252a2221b9cSchristos 	for (i = 0; i < 26; i++) {
253a2221b9cSchristos 		ch[0] = 'a' + i;
254a2221b9cSchristos 		e.key = strdup(ch);	/* ptr to provided key is kept! */
255a2221b9cSchristos 		ATF_REQUIRE(e.key != NULL);
256*6030f04aSchristos 		e.data = (void *)(intptr_t)i;
257a2221b9cSchristos 
258a2221b9cSchristos 		ATF_REQUIRE(hsearch_r(e, ENTER, &ep, &t) == 1);
259a2221b9cSchristos 		ATF_REQUIRE(ep != NULL);
260a2221b9cSchristos 		ATF_REQUIRE_STREQ(ep->key, ch);
261*6030f04aSchristos 		ATF_REQUIRE_EQ((intptr_t)ep->data, i);
262a2221b9cSchristos 	}
263a2221b9cSchristos 
264a2221b9cSchristos 	/* e.key should be constant from here on down. */
265a2221b9cSchristos 	e.key = ch;
266a2221b9cSchristos 
267a2221b9cSchristos 	/* Basic lookups. */
268a2221b9cSchristos 	for (i = 0; i < 26; i++) {
269a2221b9cSchristos 		ch[0] = 'a' + i;
270a2221b9cSchristos 
271a2221b9cSchristos 		ATF_REQUIRE(hsearch_r(e, FIND, &ep, &t) == 1);
272a2221b9cSchristos 		ATF_REQUIRE(ep != NULL);
273a2221b9cSchristos 		ATF_REQUIRE_STREQ(ep->key, ch);
274*6030f04aSchristos 		ATF_REQUIRE_EQ((intptr_t)ep->data, i);
275a2221b9cSchristos 	}
276a2221b9cSchristos 
277*6030f04aSchristos 	hdestroy1_r(&t, free, NULL);
278a2221b9cSchristos }
279a2221b9cSchristos 
280a2221b9cSchristos ATF_TC(hsearch_r_duplicate);
ATF_TC_HEAD(hsearch_r_duplicate,tc)281a2221b9cSchristos ATF_TC_HEAD(hsearch_r_duplicate, tc)
282a2221b9cSchristos {
283a2221b9cSchristos 
284a2221b9cSchristos 	atf_tc_set_md_var(tc, "descr", "Checks that inserting duplicate "
285a2221b9cSchristos 	    "doesn't overwrite existing data");
286a2221b9cSchristos }
287a2221b9cSchristos 
ATF_TC_BODY(hsearch_r_duplicate,tc)288a2221b9cSchristos ATF_TC_BODY(hsearch_r_duplicate, tc)
289a2221b9cSchristos {
290a2221b9cSchristos 	ENTRY e, *ep;
291a2221b9cSchristos 	struct hsearch_data t;
292a2221b9cSchristos 
293a2221b9cSchristos 	REQUIRE_ERRNO(hcreate_r(16, &t));
294a2221b9cSchristos 
295*6030f04aSchristos 	e.key = __UNCONST("a");
296*6030f04aSchristos 	e.data = (void *)(intptr_t) 0;
297a2221b9cSchristos 
298a2221b9cSchristos 	ATF_REQUIRE(hsearch_r(e, ENTER, &ep, &t) == 1);
299a2221b9cSchristos 	ATF_REQUIRE(ep != NULL);
300a2221b9cSchristos 	ATF_REQUIRE_STREQ(ep->key, "a");
301*6030f04aSchristos 	ATF_REQUIRE_EQ((intptr_t)ep->data, 0);
302a2221b9cSchristos 
303*6030f04aSchristos 	e.data = (void *)(intptr_t)12345;
304a2221b9cSchristos 
305a2221b9cSchristos 	ATF_REQUIRE(hsearch_r(e, ENTER, &ep, &t) == 1);
306a2221b9cSchristos 	ATF_REQUIRE(hsearch_r(e, FIND, &ep, &t) == 1);
307a2221b9cSchristos 
308a2221b9cSchristos 	ATF_REQUIRE(ep != NULL);
309a2221b9cSchristos 	ATF_REQUIRE_STREQ(ep->key, "a");
310*6030f04aSchristos 	ATF_REQUIRE_EQ((intptr_t)ep->data, 0);
311a2221b9cSchristos 
312a2221b9cSchristos 	hdestroy_r(&t);
313a2221b9cSchristos }
314a2221b9cSchristos 
315a2221b9cSchristos ATF_TC(hsearch_r_nonexistent);
ATF_TC_HEAD(hsearch_r_nonexistent,tc)316a2221b9cSchristos ATF_TC_HEAD(hsearch_r_nonexistent, tc)
317a2221b9cSchristos {
318a2221b9cSchristos 
319a2221b9cSchristos 	atf_tc_set_md_var(tc, "descr",
320a2221b9cSchristos 	    "Checks searching for non-existent entry");
321a2221b9cSchristos }
322a2221b9cSchristos 
ATF_TC_BODY(hsearch_r_nonexistent,tc)323a2221b9cSchristos ATF_TC_BODY(hsearch_r_nonexistent, tc)
324a2221b9cSchristos {
325a2221b9cSchristos 	ENTRY e, *ep;
326a2221b9cSchristos 	struct hsearch_data t;
327a2221b9cSchristos 
328a2221b9cSchristos 	REQUIRE_ERRNO(hcreate_r(16, &t));
329a2221b9cSchristos 
330*6030f04aSchristos 	e.key = __UNCONST("A");
331a2221b9cSchristos 	ATF_REQUIRE(hsearch_r(e, FIND, &ep, &t) == 1);
332a2221b9cSchristos 	ATF_REQUIRE_EQ(ep, NULL);
333a2221b9cSchristos 
334a2221b9cSchristos 	hdestroy_r(&t);
335a2221b9cSchristos }
336a2221b9cSchristos 
337a2221b9cSchristos ATF_TC(hsearch_r_two);
ATF_TC_HEAD(hsearch_r_two,tc)338a2221b9cSchristos ATF_TC_HEAD(hsearch_r_two, tc)
339a2221b9cSchristos {
340a2221b9cSchristos 
341a2221b9cSchristos 	atf_tc_set_md_var(tc, "descr",
342a2221b9cSchristos 	    "Checks that searching doesn't overwrite previous search results");
343a2221b9cSchristos }
344a2221b9cSchristos 
ATF_TC_BODY(hsearch_r_two,tc)345a2221b9cSchristos ATF_TC_BODY(hsearch_r_two, tc)
346a2221b9cSchristos {
347a2221b9cSchristos 	ENTRY e, *ep, *ep2;
348a2221b9cSchristos 	struct hsearch_data t;
349a2221b9cSchristos 
350a2221b9cSchristos 	REQUIRE_ERRNO(hcreate_r(16, &t));
351a2221b9cSchristos 
352*6030f04aSchristos 	e.key = __UNCONST("a");
353*6030f04aSchristos 	e.data = (void*)(intptr_t)0;
354a2221b9cSchristos 
355a2221b9cSchristos 	ATF_REQUIRE(hsearch_r(e, ENTER, &ep, &t) == 1);
356a2221b9cSchristos 	ATF_REQUIRE(ep != NULL);
357a2221b9cSchristos 	ATF_REQUIRE_STREQ(ep->key, "a");
358*6030f04aSchristos 	ATF_REQUIRE_EQ((intptr_t)ep->data, 0);
359a2221b9cSchristos 
360*6030f04aSchristos 	e.key = __UNCONST("b");
361*6030f04aSchristos 	e.data = (void*)(intptr_t)1;
362a2221b9cSchristos 
363a2221b9cSchristos 	ATF_REQUIRE(hsearch_r(e, ENTER, &ep, &t) == 1);
364a2221b9cSchristos 	ATF_REQUIRE(ep != NULL);
365a2221b9cSchristos 	ATF_REQUIRE_STREQ(ep->key, "b");
366*6030f04aSchristos 	ATF_REQUIRE_EQ((intptr_t)ep->data, 1);
367a2221b9cSchristos 
368*6030f04aSchristos 	e.key = __UNCONST("a");
369a2221b9cSchristos 	ATF_REQUIRE(hsearch_r(e, FIND, &ep, &t) == 1);
370a2221b9cSchristos 
371*6030f04aSchristos 	e.key = __UNCONST("b");
372a2221b9cSchristos 	ATF_REQUIRE(hsearch_r(e, FIND, &ep2, &t) == 1);
373a2221b9cSchristos 
374a2221b9cSchristos 	ATF_REQUIRE(ep != NULL);
375a2221b9cSchristos 	ATF_REQUIRE_STREQ(ep->key, "a");
376*6030f04aSchristos 	ATF_REQUIRE_EQ((intptr_t)ep->data, 0);
377a2221b9cSchristos 
378a2221b9cSchristos 	ATF_REQUIRE(ep2 != NULL);
379a2221b9cSchristos 	ATF_REQUIRE_STREQ(ep2->key, "b");
380*6030f04aSchristos 	ATF_REQUIRE_EQ((intptr_t)ep2->data, 1);
381a2221b9cSchristos 
382a2221b9cSchristos 	hdestroy_r(&t);
383a2221b9cSchristos }
384a2221b9cSchristos 
ATF_TP_ADD_TCS(tp)3857a60df32Spgoyette ATF_TP_ADD_TCS(tp)
3867a60df32Spgoyette {
3877a60df32Spgoyette 
3886836bf78Sjruoho 	ATF_TP_ADD_TC(tp, hsearch_basic);
3896836bf78Sjruoho 	ATF_TP_ADD_TC(tp, hsearch_duplicate);
3906836bf78Sjruoho 	ATF_TP_ADD_TC(tp, hsearch_nonexistent);
3916836bf78Sjruoho 	ATF_TP_ADD_TC(tp, hsearch_two);
3927a60df32Spgoyette 
393a2221b9cSchristos 	ATF_TP_ADD_TC(tp, hsearch_r_basic);
394a2221b9cSchristos 	ATF_TP_ADD_TC(tp, hsearch_r_duplicate);
395a2221b9cSchristos 	ATF_TP_ADD_TC(tp, hsearch_r_nonexistent);
396a2221b9cSchristos 	ATF_TP_ADD_TC(tp, hsearch_r_two);
397a2221b9cSchristos 
3987a60df32Spgoyette 	return atf_no_error();
3997a60df32Spgoyette }
400