aboutsummaryrefslogtreecommitdiff
path: root/lib/mlibc/tests/ansi/ungetc.c
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2024-03-07 17:28:52 -0500
committerIan Moffett <ian@osmora.org>2024-03-07 18:24:51 -0500
commitf5e48e94a2f4d4bbd6e5628c7f2afafc6dbcc459 (patch)
tree93b156621dc0303816b37f60ba88051b702d92f6 /lib/mlibc/tests/ansi/ungetc.c
parentbd5969fc876a10b18613302db7087ef3c40f18e1 (diff)
build: Build mlibc + add distclean target
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'lib/mlibc/tests/ansi/ungetc.c')
-rw-r--r--lib/mlibc/tests/ansi/ungetc.c74
1 files changed, 0 insertions, 74 deletions
diff --git a/lib/mlibc/tests/ansi/ungetc.c b/lib/mlibc/tests/ansi/ungetc.c
deleted file mode 100644
index 8773c6d..0000000
--- a/lib/mlibc/tests/ansi/ungetc.c
+++ /dev/null
@@ -1,74 +0,0 @@
-#include <stdio.h>
-#include <assert.h>
-
-#ifdef USE_HOST_LIBC
-#define TEST_FILE "ungetc-host-libc.tmp"
-#else
-#define TEST_FILE "ungetc.tmp"
-#endif
-
-void test(int buffering) {
- FILE *f = fopen(TEST_FILE, "w");
- for(int c = '0'; c <= '9'; c++) {
- fputc(c, f);
- }
- fclose(f);
-
- f = fopen(TEST_FILE, "r");
- if (!buffering) {
- setbuf(f, NULL);
- }
-
- assert(ungetc('x', f) == 'x');
- assert(fgetc(f) == 'x');
-
- // Test pushing back the same character
- for (int c = '0'; c <= '9'; c++) {
- assert(fgetc(f) == c);
- assert(ungetc(c, f) == c);
- assert(fgetc(f) == c);
- }
- assert(fgetc(f) == EOF);
- assert(ungetc(EOF, f) == EOF);
-
- // Even though the spec does not guarantee it, we should be able to
- // ungetc more than one character.
- assert(ungetc('x', f) == 'x');
- assert(ungetc('y', f) == 'y');
- assert(fgetc(f) == 'y');
- assert(fgetc(f) == 'x');
-
- // Seeking should discard the effects of ungetc.
- assert(ungetc('x', f) == 'x');
- rewind(f);
-
- // Test pushing back a different character
- for (int c = '0'; c <= '9'; c++) {
- assert(fgetc(f) == c);
- assert(ungetc(c - '0' + 'a', f) == c - '0' + 'a');
- assert(fgetc(f) == c - '0' + 'a');
- }
-
-#ifndef USE_HOST_LIBC
- // Too many ungetcs should fail.
- int eof = 0;
- for (int i = 0; i < 100; i++) {
- if (ungetc('x', f) == EOF) {
- eof = 1;
- break;
- }
- }
- assert(eof);
-#endif
-
- fclose(f);
-
- // TODO: Test with other operations, like fread.
-}
-
-int main() {
- fprintf(stderr, "with buffering...\n");
- test(1);
- fprintf(stderr, "without buffering...\n");
- test(0);
-}