1 /* $NetBSD: t_clearerr.c,v 1.1 2011/05/01 16:36:37 jruoho Exp $ */
4 * Copyright (c) 2009, Stathis Kamperis
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
19 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
20 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
22 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/cdefs.h>
30 __RCSID("$NetBSD: t_clearerr.c,v 1.1 2011/05/01 16:36:37 jruoho Exp $");
36 static const char path
[] = "/etc/passwd";
38 ATF_TC(clearerr_basic
);
39 ATF_TC_HEAD(clearerr_basic
, tc
)
41 atf_tc_set_md_var(tc
, "descr", "A basic test of clearerr(3)");
44 ATF_TC_BODY(clearerr_basic
, tc
)
49 fp
= fopen(path
, "r");
50 ATF_REQUIRE(fp
!= NULL
);
53 (void)fread(buf
, sizeof(buf
), 1, fp
);
55 ATF_REQUIRE(feof(fp
) != 0);
60 ATF_REQUIRE(errno
== 0);
61 ATF_REQUIRE(feof(fp
) == 0);
62 ATF_REQUIRE(fclose(fp
) != EOF
);
66 ATF_TC_HEAD(clearerr_err
, tc
)
68 atf_tc_set_md_var(tc
, "descr", "Test that clearerr(3) does not fail");
71 ATF_TC_BODY(clearerr_err
, tc
)
75 fp
= fopen(path
, "r");
77 ATF_REQUIRE(fp
!= NULL
);
78 ATF_REQUIRE(fclose(fp
) == 0);
83 ATF_REQUIRE(errno
== 0);
89 ATF_TP_ADD_TC(tp
, clearerr_basic
);
90 ATF_TP_ADD_TC(tp
, clearerr_err
);
92 return atf_no_error();