# HG changeset patch # User Eric Blake # Date 1197570342 25200 # Node ID c00c359f1ca994ee5ad36dfce84f2140139abf29 # Parent 4af5a4be9c8c63eac53d004edfc357a65d39e1f6 Beef up fseek tests. * tests/test-fseek.c (main): Also test eof handling. * tests/test-fseeko.c (main): Likewise. Reported by Larry Jones. Signed-off-by: Eric Blake diff -r 4af5a4be9c8c -r c00c359f1ca9 ChangeLog --- a/ChangeLog Thu Dec 13 11:11:53 2007 -0700 +++ b/ChangeLog Thu Dec 13 11:25:42 2007 -0700 @@ -1,3 +1,10 @@ +2007-12-13 Eric Blake + + Beef up fseek tests. + * tests/test-fseek.c (main): Also test eof handling. + * tests/test-fseeko.c (main): Likewise. + Reported by Larry Jones. + 2007-12-13 Larry Jones (tiny change) Fix fseeko on BSD-based platforms. diff -r 4af5a4be9c8c -r c00c359f1ca9 tests/test-fseek.c --- a/tests/test-fseek.c Thu Dec 13 11:11:53 2007 -0700 +++ b/tests/test-fseek.c Thu Dec 13 11:25:42 2007 -0700 @@ -25,5 +25,21 @@ { /* Assume stdin is seekable iff argc > 1. */ int expected = argc > 1 ? 0 : -1; - return fseek (stdin, 0, SEEK_CUR) != expected; + if (fseek (stdin, 0, SEEK_CUR) != expected) + return 1; + if (argc > 1) + { + /* Test that fseek resets end-of-file marker. */ + if (fseek (stdin, 0, SEEK_END)) + return 1; + if (fgetc (stdin) != EOF) + return 1; + if (!feof (stdin)) + return 1; + if (fseek (stdin, 0, SEEK_END)) + return 1; + if (feof (stdin)) + return 1; + } + return 0; } diff -r 4af5a4be9c8c -r c00c359f1ca9 tests/test-fseeko.c --- a/tests/test-fseeko.c Thu Dec 13 11:11:53 2007 -0700 +++ b/tests/test-fseeko.c Thu Dec 13 11:25:42 2007 -0700 @@ -31,5 +31,21 @@ /* Exit with success only if fseek/fseeko agree. */ int r1 = fseeko (stdin, (off_t)0, SEEK_CUR); int r2 = fseek (stdin, (long)0, SEEK_CUR); - return ! (r1 == r2 && r1 == expected); + if (r1 != r2 || r1 != expected) + return 1; + if (argc > 1) + { + /* Test that fseek resets end-of-file marker. */ + if (fseeko (stdin, (off_t) 0, SEEK_END)) + return 1; + if (fgetc (stdin) != EOF) + return 1; + if (!feof (stdin)) + return 1; + if (fseeko (stdin, (off_t) 0, SEEK_END)) + return 1; + if (feof (stdin)) + return 1; + } + return 0; }