瀏覽代碼

Implement regression test for ftell-ungetc bug

oddcoder 4 年之前
父節點
當前提交
6fba592fdb
共有 4 個文件被更改,包括 66 次插入0 次删除
  1. 1 0
      tests/Makefile
  2. 0 0
      tests/expected/stdio/ungetc_ftell.stderr
  3. 28 0
      tests/expected/stdio/ungetc_ftell.stdout
  4. 37 0
      tests/stdio/ungetc_ftell.c

+ 1 - 0
tests/Makefile

@@ -43,6 +43,7 @@ EXPECT_NAMES=\
 	stdio/sprintf \
 	stdio/printf_space_pad \
 	stdio/ungetc_multiple \
+	stdio/ungetc_ftell \
 	stdlib/a64l \
 	stdlib/alloc \
 	stdlib/atof \

+ 0 - 0
tests/expected/stdio/ungetc_ftell.stderr


+ 28 - 0
tests/expected/stdio/ungetc_ftell.stdout

@@ -0,0 +1,28 @@
+#, 0
+i, 1
+n, 2
+h, -9
+e, -8
+l, -7
+l, -6
+o, -5
+ , -4
+w, -3
+o, -2
+r, -1
+l, 0
+d, 1
+
+, 2
+c, 3
+l, 4
+u, 5
+d, 6
+e, 7
+ , 8
+<, 9
+s, 10
+t, 11
+d, 12
+i, 13
+o, 14

+ 37 - 0
tests/stdio/ungetc_ftell.c

@@ -0,0 +1,37 @@
+#include <stdio.h>
+int main() {
+	FILE *f = fopen("stdio/ungetc_ftell.c", "r");
+	printf("%c, %ld\n", getc(f), ftell(f));
+	printf("%c, %ld\n", getc(f), ftell(f));
+	printf("%c, %ld\n", getc(f), ftell(f));
+	ungetc('\n', f);ungetc('d', f);
+	ungetc('l', f);	ungetc('r', f);
+	ungetc('o', f);	ungetc('w', f);
+	ungetc(' ', f);	ungetc('o', f);
+	ungetc('l', f);	ungetc('l', f);
+	ungetc('e', f);	ungetc('h', f);
+	printf("%c, %ld\n", getc(f), ftell(f));
+	printf("%c, %ld\n", getc(f), ftell(f));
+	printf("%c, %ld\n", getc(f), ftell(f));
+	printf("%c, %ld\n", getc(f), ftell(f));
+	printf("%c, %ld\n", getc(f), ftell(f));
+	printf("%c, %ld\n", getc(f), ftell(f));
+	printf("%c, %ld\n", getc(f), ftell(f));
+	printf("%c, %ld\n", getc(f), ftell(f));
+	printf("%c, %ld\n", getc(f), ftell(f));
+	printf("%c, %ld\n", getc(f), ftell(f));
+	printf("%c, %ld\n", getc(f), ftell(f));
+	printf("%c, %ld\n", getc(f), ftell(f));
+	printf("%c, %ld\n", getc(f), ftell(f));
+	printf("%c, %ld\n", getc(f), ftell(f));
+	printf("%c, %ld\n", getc(f), ftell(f));
+	printf("%c, %ld\n", getc(f), ftell(f));
+	printf("%c, %ld\n", getc(f), ftell(f));
+	printf("%c, %ld\n", getc(f), ftell(f));
+	printf("%c, %ld\n", getc(f), ftell(f));
+	printf("%c, %ld\n", getc(f), ftell(f));
+	printf("%c, %ld\n", getc(f), ftell(f));
+	printf("%c, %ld\n", getc(f), ftell(f));
+	printf("%c, %ld\n", getc(f), ftell(f));
+	printf("%c, %ld\n", getc(f), ftell(f));
+}