diff --git a/distrib/sets/lists/tests/mi b/distrib/sets/lists/tests/mi index 81f8349eb9b2..dd1fa6730996 100644 --- a/distrib/sets/lists/tests/mi +++ b/distrib/sets/lists/tests/mi @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.316 2011/05/01 11:39:37 jruoho Exp $ +# $NetBSD: mi,v 1.317 2011/05/01 16:36:37 jruoho Exp $ # # Note: don't delete entries from here - mark them as "obsolete" instead. # @@ -414,6 +414,7 @@ ./usr/libdata/debug/usr/tests/lib/libc/ssp/h_vsnprintf.debug tests-lib-debug debug,atf,ssp ./usr/libdata/debug/usr/tests/lib/libc/ssp/h_vsprintf.debug tests-lib-debug debug,atf,ssp ./usr/libdata/debug/usr/tests/lib/libc/stdio tests-lib-debug +./usr/libdata/debug/usr/tests/lib/libc/stdio/t_clearerr.debug tests-lib-debug debug,atf ./usr/libdata/debug/usr/tests/lib/libc/stdio/t_fmemopen.debug tests-lib-debug debug,atf ./usr/libdata/debug/usr/tests/lib/libc/stdio/t_format.debug tests-lib-debug debug,atf ./usr/libdata/debug/usr/tests/lib/libc/stdio/t_popen.debug tests-lib-debug debug,atf @@ -1903,6 +1904,7 @@ ./usr/tests/lib/libc/ssp/t_ssp tests-lib-tests atf,ssp ./usr/tests/lib/libc/stdio tests-lib-tests ./usr/tests/lib/libc/stdio/Atffile tests-lib-tests atf +./usr/tests/lib/libc/stdio/t_clearerr tests-lib-tests atf ./usr/tests/lib/libc/stdio/t_fmemopen tests-lib-tests atf ./usr/tests/lib/libc/stdio/t_format tests-lib-tests atf ./usr/tests/lib/libc/stdio/t_popen tests-lib-tests atf diff --git a/tests/lib/libc/stdio/Makefile b/tests/lib/libc/stdio/Makefile index d669175a928a..fc6c6bfc6587 100644 --- a/tests/lib/libc/stdio/Makefile +++ b/tests/lib/libc/stdio/Makefile @@ -1,9 +1,10 @@ -# $NetBSD: Makefile,v 1.3 2010/12/23 15:27:44 pgoyette Exp $ +# $NetBSD: Makefile,v 1.4 2011/05/01 16:36:37 jruoho Exp $ .include TESTSDIR= ${TESTSBASE}/lib/libc/stdio +TESTS_C+= t_clearerr TESTS_C+= t_fmemopen TESTS_C+= t_format TESTS_C+= t_popen diff --git a/tests/lib/libc/stdio/t_clearerr.c b/tests/lib/libc/stdio/t_clearerr.c new file mode 100644 index 000000000000..251804e31702 --- /dev/null +++ b/tests/lib/libc/stdio/t_clearerr.c @@ -0,0 +1,93 @@ +/* $NetBSD: t_clearerr.c,v 1.1 2011/05/01 16:36:37 jruoho Exp $ */ + +/* + * Copyright (c) 2009, Stathis Kamperis + * 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 COPYRIGHT HOLDERS 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 + * COPYRIGHT HOLDERS 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 +__RCSID("$NetBSD: t_clearerr.c,v 1.1 2011/05/01 16:36:37 jruoho Exp $"); + +#include +#include +#include + +static const char path[] = "/etc/passwd"; + +ATF_TC(clearerr_basic); +ATF_TC_HEAD(clearerr_basic, tc) +{ + atf_tc_set_md_var(tc, "descr", "A basic test of clearerr(3)"); +} + +ATF_TC_BODY(clearerr_basic, tc) +{ + char buf[2048]; + FILE *fp; + + fp = fopen(path, "r"); + ATF_REQUIRE(fp != NULL); + + while (feof(fp) == 0) + (void)fread(buf, sizeof(buf), 1, fp); + + ATF_REQUIRE(feof(fp) != 0); + + errno = 0; + clearerr(fp); + + ATF_REQUIRE(errno == 0); + ATF_REQUIRE(feof(fp) == 0); + ATF_REQUIRE(fclose(fp) != EOF); +} + +ATF_TC(clearerr_err); +ATF_TC_HEAD(clearerr_err, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test that clearerr(3) does not fail"); +} + +ATF_TC_BODY(clearerr_err, tc) +{ + FILE *fp; + + fp = fopen(path, "r"); + + ATF_REQUIRE(fp != NULL); + ATF_REQUIRE(fclose(fp) == 0); + + errno = 0; + clearerr(fp); + + ATF_REQUIRE(errno == 0); +} + +ATF_TP_ADD_TCS(tp) +{ + + ATF_TP_ADD_TC(tp, clearerr_basic); + ATF_TP_ADD_TC(tp, clearerr_err); + + return atf_no_error(); +}