=========================================================================== * Test read/write of .gz files */
(fname, uncompr, uncomprLen)
| 137 | * Test read/write of .gz files |
| 138 | */ |
| 139 | void test_gzio(fname, uncompr, uncomprLen) |
| 140 | const char *fname; /* compressed file name */ |
| 141 | Byte *uncompr; |
| 142 | uLong uncomprLen; |
| 143 | { |
| 144 | #ifdef NO_GZCOMPRESS |
| 145 | fprintf(stderr, "NO_GZCOMPRESS -- gz* functions cannot compress\n"); |
| 146 | #else |
| 147 | int err; |
| 148 | int len = (int)strlen(hello)+1; |
| 149 | gzFile file; |
| 150 | z_off_t pos; |
| 151 | |
| 152 | file = gzopen(fname, "wb"); |
| 153 | if (file == NULL) { |
| 154 | fprintf(stderr, "gzopen error\n"); |
| 155 | exit(1); |
| 156 | } |
| 157 | gzputc(file, 'h'); |
| 158 | if (gzputs(file, "ello") != 4) { |
| 159 | fprintf(stderr, "gzputs err: %s\n", gzerror(file, &err)); |
| 160 | exit(1); |
| 161 | } |
| 162 | if (gzprintf(file, ", %s! I said hello, hello!", "hello") != 8+21) { |
| 163 | fprintf(stderr, "gzprintf err: %s\n", gzerror(file, &err)); |
| 164 | exit(1); |
| 165 | } |
| 166 | gzseek(file, 1L, SEEK_CUR); /* add one zero byte */ |
| 167 | gzclose(file); |
| 168 | |
| 169 | file = gzopen(fname, "rb"); |
| 170 | if (file == NULL) { |
| 171 | fprintf(stderr, "gzopen error\n"); |
| 172 | exit(1); |
| 173 | } |
| 174 | strcpy((char*)uncompr, "garbage"); |
| 175 | |
| 176 | if (gzread(file, uncompr, (unsigned)uncomprLen) != len) { |
| 177 | fprintf(stderr, "gzread err: %s\n", gzerror(file, &err)); |
| 178 | exit(1); |
| 179 | } |
| 180 | if (strcmp((char*)uncompr, hello)) { |
| 181 | fprintf(stderr, "bad gzread: %s\n", (char*)uncompr); |
| 182 | exit(1); |
| 183 | } else { |
| 184 | printf("gzread(): %s\n", (char*)uncompr); |
| 185 | } |
| 186 | |
| 187 | pos = gzseek(file, -8L, SEEK_CUR); |
| 188 | if (pos != 6+21 || gztell(file) != pos) { |
| 189 | fprintf(stderr, "gzseek error, pos=%ld, gztell=%ld\n", |
| 190 | (long)pos, (long)gztell(file)); |
| 191 | exit(1); |
| 192 | } |
| 193 | |
| 194 | if (gzgetc(file) != ' ') { |
| 195 | fprintf(stderr, "gzgetc error\n"); |
| 196 | exit(1); |
no test coverage detected