=========================================================================== * Test read/write of .gz files */
(fname, uncompr, uncomprLen)
| 112 | * Test read/write of .gz files |
| 113 | */ |
| 114 | void test_gzio(fname, uncompr, uncomprLen) |
| 115 | const char *fname; /* compressed file name */ |
| 116 | Byte *uncompr; |
| 117 | uLong uncomprLen; |
| 118 | { |
| 119 | #ifdef NO_GZCOMPRESS |
| 120 | fprintf(stderr, "NO_GZCOMPRESS -- gz* functions cannot compress\n"); |
| 121 | #else |
| 122 | int err; |
| 123 | int len = (int)strlen(hello)+1; |
| 124 | gzFile file; |
| 125 | z_off_t pos; |
| 126 | |
| 127 | file = gzopen(fname, "wb"); |
| 128 | if (file == NULL) { |
| 129 | fprintf(stderr, "gzopen error\n"); |
| 130 | exit(1); |
| 131 | } |
| 132 | gzputc(file, 'h'); |
| 133 | if (gzputs(file, "ello") != 4) { |
| 134 | fprintf(stderr, "gzputs err: %s\n", gzerror(file, &err)); |
| 135 | exit(1); |
| 136 | } |
| 137 | if (gzprintf(file, ", %s!", "hello") != 8) { |
| 138 | fprintf(stderr, "gzprintf err: %s\n", gzerror(file, &err)); |
| 139 | exit(1); |
| 140 | } |
| 141 | gzseek(file, 1L, SEEK_CUR); /* add one zero byte */ |
| 142 | gzclose(file); |
| 143 | |
| 144 | file = gzopen(fname, "rb"); |
| 145 | if (file == NULL) { |
| 146 | fprintf(stderr, "gzopen error\n"); |
| 147 | exit(1); |
| 148 | } |
| 149 | strcpy((char*)uncompr, "garbage"); |
| 150 | |
| 151 | if (gzread(file, uncompr, (unsigned)uncomprLen) != len) { |
| 152 | fprintf(stderr, "gzread err: %s\n", gzerror(file, &err)); |
| 153 | exit(1); |
| 154 | } |
| 155 | if (strcmp((char*)uncompr, hello)) { |
| 156 | fprintf(stderr, "bad gzread: %s\n", (char*)uncompr); |
| 157 | exit(1); |
| 158 | } else { |
| 159 | printf("gzread(): %s\n", (char*)uncompr); |
| 160 | } |
| 161 | |
| 162 | pos = gzseek(file, -8L, SEEK_CUR); |
| 163 | if (pos != 6 || gztell(file) != pos) { |
| 164 | fprintf(stderr, "gzseek error, pos=%ld, gztell=%ld\n", |
| 165 | (long)pos, (long)gztell(file)); |
| 166 | exit(1); |
| 167 | } |
| 168 | |
| 169 | if (gzgetc(file) != ' ') { |
| 170 | fprintf(stderr, "gzgetc error\n"); |
| 171 | exit(1); |
no test coverage detected