From b5ef94356f336bf382eb0fcc634d3420d1104d50 Mon Sep 17 00:00:00 2001 From: Martin Pieuchot Date: Thu, 28 Mar 2013 09:35:59 +0000 Subject: More tests for negative seeks, prodded by matthew@ --- regress/lib/libc/fmemopen/fmemopentest.c | 41 +++++++++++++++++++++- .../lib/libc/open_memstream/open_memstreamtest.c | 24 ++++++++++++- 2 files changed, 63 insertions(+), 2 deletions(-) diff --git a/regress/lib/libc/fmemopen/fmemopentest.c b/regress/lib/libc/fmemopen/fmemopentest.c index 57063aeb0a8..203c93be650 100644 --- a/regress/lib/libc/fmemopen/fmemopentest.c +++ b/regress/lib/libc/fmemopen/fmemopentest.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fmemopentest.c,v 1.2 2013/03/27 15:08:13 mpi Exp $ */ +/* $OpenBSD: fmemopentest.c,v 1.3 2013/03/28 09:35:58 mpi Exp $ */ /* * Copyright (c) 2011 Martin Pieuchot @@ -160,6 +160,44 @@ writetest(void) return (failures); } +int +seektest(void) +{ + FILE *s1; + char string[] = "long string for testing seek"; + size_t len, slen; + int failures = 0; + + slen = strlen(string) + 1; + + s1 = fmemopen(string, slen, "r"); + if (s1 == NULL) + return (1); + + if (fseek(s1, 8, SEEK_SET) != 0) { + warnx("failed to fseek. (14)"); + failures++; + } + + if (ftell(s1) != 8) { + warnx("failed seek test. (15)"); + failures++; + } + + /* Try to seek backward */ + if (fseek(s1, -1, SEEK_CUR) != 0) { + warnx("failed to fseek. (16)"); + failures++; + } + + if (ftell(s1) != 7) { + warnx("failed seeking backward. (17)"); + failures++; + } + + return (failures); +} + int main(void) { @@ -168,6 +206,7 @@ main(void) failures += simpletest(); failures += updatetest(); failures += writetest(); + failures += seektest(); return (failures); } diff --git a/regress/lib/libc/open_memstream/open_memstreamtest.c b/regress/lib/libc/open_memstream/open_memstreamtest.c index b9c0221b1a5..a2327f21c50 100644 --- a/regress/lib/libc/open_memstream/open_memstreamtest.c +++ b/regress/lib/libc/open_memstream/open_memstreamtest.c @@ -1,4 +1,5 @@ -/* $OpenBSD: open_memstreamtest.c,v 1.2 2013/03/25 03:33:28 guenther Exp $ */ +/* $OpenBSD: open_memstreamtest.c,v 1.3 2013/03/28 09:35:58 mpi Exp $ */ + /* * Copyright (c) 2011 Martin Pieuchot * @@ -137,6 +138,27 @@ main(void) failures++; } + if (fseek(fp, 8, SEEK_SET) != 0) { + warnx("failed to fseek. (19)"); + failures++; + } + + if (ftell(fp) != 8) { + warnx("failed seek test. (20)"); + failures++; + } + + /* Try to seek backward */ + if (fseek(fp, -1, SEEK_CUR) != 0) { + warnx("failed to fseek. (21)"); + failures++; + } + + if (ftell(fp) != 7) { + warnx("failed seeking backward. (22)"); + failures++; + } + free(buf); return (failures); -- cgit v1.2.3