Remove building with NOCRYPTO option
[minix.git] / tests / lib / libc / stdio / t_fputc.c
blobed7c0dc355a0233c8fb2694ed2f9a02b2c4889fb
1 /* $NetBSD: t_fputc.c,v 1.1 2011/09/11 09:02:46 jruoho Exp $ */
3 /*-
4 * Copyright (c) 2011 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jukka Ruohonen.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
31 #include <sys/cdefs.h>
32 __RCSID("$NetBSD: t_fputc.c,v 1.1 2011/09/11 09:02:46 jruoho Exp $");
34 #include <atf-c.h>
35 #include <errno.h>
36 #include <stdio.h>
37 #include <string.h>
38 #include <unistd.h>
40 static const char *path = "fputc";
41 static void puterr(int (*)(int, FILE *));
42 static void putstr(int (*)(int, FILE *));
44 static void
45 puterr(int (*func)(int, FILE *))
47 FILE *f;
49 f = fopen(path, "w+");
51 ATF_REQUIRE(f != NULL);
52 ATF_REQUIRE(fclose(f) == 0);
53 ATF_REQUIRE(unlink(path) == 0);
54 ATF_REQUIRE(func('x', f) == EOF);
57 static void
58 putstr(int (*func)(int, FILE *))
60 const char *str = "1234567890x";
61 unsigned short i = 0;
62 char buf[10];
63 FILE *f;
65 (void)memset(buf, 'x', sizeof(buf));
67 f = fopen(path, "w+");
68 ATF_REQUIRE(f != NULL);
70 while (str[i] != 'x') {
71 ATF_REQUIRE(func(str[i], f) == str[i]);
72 i++;
75 ATF_REQUIRE(fclose(f) == 0);
77 f = fopen(path, "r");
78 ATF_REQUIRE(f != NULL);
80 ATF_REQUIRE(fread(buf, 1, 10, f) == 10);
81 ATF_REQUIRE(strncmp(buf, str, 10) == 0);
83 ATF_REQUIRE(fclose(f) == 0);
84 ATF_REQUIRE(unlink(path) == 0);
87 ATF_TC_WITH_CLEANUP(fputc_basic);
88 ATF_TC_HEAD(fputc_basic, tc)
90 atf_tc_set_md_var(tc, "descr", "A basic test of fputc(3)");
93 ATF_TC_BODY(fputc_basic, tc)
95 putstr(fputc);
98 ATF_TC_CLEANUP(fputc_basic, tc)
100 (void)unlink(path);
103 ATF_TC_WITH_CLEANUP(fputc_err);
104 ATF_TC_HEAD(fputc_err, tc)
106 atf_tc_set_md_var(tc, "descr", "Test errors from fputc(3)");
109 ATF_TC_BODY(fputc_err, tc)
111 puterr(fputc);
114 ATF_TC_CLEANUP(fputc_err, tc)
116 (void)unlink(path);
119 ATF_TC_WITH_CLEANUP(putc_basic);
120 ATF_TC_HEAD(putc_basic, tc)
122 atf_tc_set_md_var(tc, "descr", "A basic test of putc(3)");
125 ATF_TC_BODY(putc_basic, tc)
127 putstr(putc);
130 ATF_TC_CLEANUP(putc_basic, tc)
132 (void)unlink(path);
135 ATF_TC_WITH_CLEANUP(putc_err);
136 ATF_TC_HEAD(putc_err, tc)
138 atf_tc_set_md_var(tc, "descr", "Test errors from putc(3)");
141 ATF_TC_BODY(putc_err, tc)
143 puterr(putc);
146 ATF_TC_CLEANUP(putc_err, tc)
148 (void)unlink(path);
151 ATF_TC_WITH_CLEANUP(putc_unlocked_basic);
152 ATF_TC_HEAD(putc_unlocked_basic, tc)
154 atf_tc_set_md_var(tc, "descr", "A basic test of putc_unlocked(3)");
157 ATF_TC_BODY(putc_unlocked_basic, tc)
159 putstr(putc_unlocked);
162 ATF_TC_CLEANUP(putc_unlocked_basic, tc)
164 (void)unlink(path);
167 ATF_TC_WITH_CLEANUP(putc_unlocked_err);
168 ATF_TC_HEAD(putc_unlocked_err, tc)
170 atf_tc_set_md_var(tc, "descr", "Test errors from putc_unlocked(3)");
173 ATF_TC_BODY(putc_unlocked_err, tc)
175 puterr(putc_unlocked);
178 ATF_TC_CLEANUP(putc_unlocked_err, tc)
180 (void)unlink(path);
183 ATF_TP_ADD_TCS(tp)
186 ATF_TP_ADD_TC(tp, fputc_basic);
187 ATF_TP_ADD_TC(tp, fputc_err);
188 ATF_TP_ADD_TC(tp, putc_basic);
189 ATF_TP_ADD_TC(tp, putc_err);
190 ATF_TP_ADD_TC(tp, putc_unlocked_basic);
191 ATF_TP_ADD_TC(tp, putc_unlocked_err);
193 return atf_no_error();