diff options
| author | guenther <> | 2013-03-25 03:33:28 +0000 |
|---|---|---|
| committer | guenther <> | 2013-03-25 03:33:28 +0000 |
| commit | 6dc75a457f873697edfd93f1a03194d5d8c01dd4 (patch) | |
| tree | 28c82f471f157b4be6e7450ea7073633d4f2ffca | |
| parent | fe06028553c72e4063735e46f4f76fda7a6c9d39 (diff) | |
| download | openbsd-6dc75a457f873697edfd93f1a03194d5d8c01dd4.tar.gz openbsd-6dc75a457f873697edfd93f1a03194d5d8c01dd4.tar.bz2 openbsd-6dc75a457f873697edfd93f1a03194d5d8c01dd4.zip | |
Add some more tests; prodded by mpi@
Diffstat (limited to '')
| -rw-r--r-- | src/regress/lib/libc/open_memstream/open_memstreamtest.c | 70 |
1 files changed, 58 insertions, 12 deletions
diff --git a/src/regress/lib/libc/open_memstream/open_memstreamtest.c b/src/regress/lib/libc/open_memstream/open_memstreamtest.c index 09194908e9..b9c0221b1a 100644 --- a/src/regress/lib/libc/open_memstream/open_memstreamtest.c +++ b/src/regress/lib/libc/open_memstream/open_memstreamtest.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: open_memstreamtest.c,v 1.1 2013/01/01 17:43:07 mpi Exp $ */ | 1 | /* $OpenBSD: open_memstreamtest.c,v 1.2 2013/03/25 03:33:28 guenther Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2011 Martin Pieuchot <mpi@openbsd.org> | 3 | * Copyright (c) 2011 Martin Pieuchot <mpi@openbsd.org> |
| 4 | * | 4 | * |
| @@ -23,6 +23,9 @@ | |||
| 23 | 23 | ||
| 24 | #define OFFSET 16384 | 24 | #define OFFSET 16384 |
| 25 | 25 | ||
| 26 | const char start[] = "start"; | ||
| 27 | const char hello[] = "hello"; | ||
| 28 | |||
| 26 | int | 29 | int |
| 27 | main(void) | 30 | main(void) |
| 28 | { | 31 | { |
| @@ -30,7 +33,7 @@ main(void) | |||
| 30 | char *buf = (char *)0xff; | 33 | char *buf = (char *)0xff; |
| 31 | size_t size = 0; | 34 | size_t size = 0; |
| 32 | off_t off; | 35 | off_t off; |
| 33 | int i = 0, failures = 0; | 36 | int i, failures = 0; |
| 34 | 37 | ||
| 35 | if ((fp = open_memstream(&buf, &size)) == NULL) { | 38 | if ((fp = open_memstream(&buf, &size)) == NULL) { |
| 36 | warn("open_memstream failed"); | 39 | warn("open_memstream failed"); |
| @@ -63,31 +66,74 @@ main(void) | |||
| 63 | failures++; | 66 | failures++; |
| 64 | } | 67 | } |
| 65 | 68 | ||
| 66 | if (fprintf(fp, "hello") == EOF) { | 69 | if (fprintf(fp, hello) == EOF) { |
| 67 | warnx("fprintf failed. (6)"); | 70 | warnx("fprintf failed. (6)"); |
| 68 | failures++; | 71 | failures++; |
| 69 | } | 72 | } |
| 70 | 73 | ||
| 71 | if (fclose(fp) == EOF) { | 74 | if (fflush(fp) == EOF) { |
| 72 | warnx("fclose failed. (7)"); | 75 | warnx("fflush failed. (7)"); |
| 76 | failures++; | ||
| 77 | } | ||
| 78 | |||
| 79 | if (size != OFFSET + sizeof(hello)-1) { | ||
| 80 | warnx("failed, size %zu should be %u. (8)", | ||
| 81 | size, OFFSET + sizeof(hello)-1); | ||
| 82 | failures++; | ||
| 83 | } | ||
| 84 | |||
| 85 | if (fseek(fp, 0, SEEK_SET) != 0) { | ||
| 86 | warnx("failed to fseek. (9)"); | ||
| 87 | failures++; | ||
| 88 | } | ||
| 89 | |||
| 90 | if (fprintf(fp, start) == EOF) { | ||
| 91 | warnx("fprintf failed. (10)"); | ||
| 92 | failures++; | ||
| 93 | } | ||
| 94 | |||
| 95 | if (fflush(fp) == EOF) { | ||
| 96 | warnx("fflush failed. (11)"); | ||
| 73 | failures++; | 97 | failures++; |
| 74 | } | 98 | } |
| 75 | 99 | ||
| 76 | if (size != OFFSET + 5) { | 100 | if (size != sizeof(start)-1) { |
| 77 | warnx("failed, size %zu should be %u\n", size, OFFSET + 5); | 101 | warnx("failed, size %zu should be %u. (12)", |
| 102 | size, sizeof(start)-1); | ||
| 78 | failures++; | 103 | failures++; |
| 79 | } | 104 | } |
| 80 | 105 | ||
| 81 | /* Needed for sparse files */ | 106 | /* Needed for sparse files */ |
| 82 | while (i != OFFSET) | 107 | if (strncmp(buf, start, sizeof(start)-1) != 0) { |
| 83 | if (buf[i++] != '\0') { | 108 | warnx("failed, buffer didn't start with '%s'. (13)", start); |
| 84 | warnx("failed, buffer non zero'ed (offset %d). (8)", i); | 109 | failures++; |
| 110 | } | ||
| 111 | for (i = sizeof(start)-1; i < OFFSET; i++) | ||
| 112 | if (buf[i] != '\0') { | ||
| 113 | warnx("failed, buffer non zero (offset %d). (14)", i); | ||
| 85 | failures++; | 114 | failures++; |
| 86 | break; | 115 | break; |
| 87 | } | 116 | } |
| 88 | 117 | ||
| 89 | if (memcmp(buf + OFFSET, "hello", 5) != 0) { | 118 | if (memcmp(buf + OFFSET, hello, sizeof(hello)-1) != 0) { |
| 90 | warnx("written string incorrect. (9)"); | 119 | warnx("written string incorrect. (15)"); |
| 120 | failures++; | ||
| 121 | } | ||
| 122 | |||
| 123 | /* verify that simply seeking past the end doesn't increase the size */ | ||
| 124 | if (fseek(fp, 100, SEEK_END) != 0) { | ||
| 125 | warnx("failed to fseek. (16)"); | ||
| 126 | failures++; | ||
| 127 | } | ||
| 128 | |||
| 129 | if (fclose(fp) == EOF) { | ||
| 130 | warnx("fclose failed. (17)"); | ||
| 131 | failures++; | ||
| 132 | } | ||
| 133 | |||
| 134 | if (size != OFFSET + sizeof(hello)-1) { | ||
| 135 | warnx("failed, size %zu should be %u. (18)", | ||
| 136 | size, OFFSET + sizeof(hello)-1); | ||
| 91 | failures++; | 137 | failures++; |
| 92 | } | 138 | } |
| 93 | 139 | ||
