| 1 | #include <assert.h> |
| 2 | #include <stdio.h> |
| 3 | #include <string.h> |
| 4 | #include "zutil.h" |
| 5 | |
| 6 | int main(void) { |
| 7 | unsigned char plain[32]; |
| 8 | unsigned char compressed[130]; |
| 9 | PREFIX3(stream) strm; |
| 10 | int bound; |
| 11 | z_size_t bytes; |
| 12 | |
| 13 | for (int i = 0; i <= 32; i++) { |
| 14 | memset(plain, 6, i); |
| 15 | memset(&strm, 0, sizeof(strm)); |
| 16 | PREFIX(deflateInit2)(&strm, 0, 8, 31, 1, Z_DEFAULT_STRATEGY); |
| 17 | bound = PREFIX(deflateBound)(&strm, i); |
| 18 | strm.next_in = plain; |
| 19 | strm.next_out = compressed; |
| 20 | strm.avail_in = i; |
| 21 | strm.avail_out = sizeof(compressed); |
| 22 | if (PREFIX(deflate)(&strm, Z_FINISH) != Z_STREAM_END) return -1; |
| 23 | if (strm.avail_in != 0) return -1; |
| 24 | printf("bytes = %2i, deflateBound = %2i, total_out = %2zi\n", i, bound, strm.total_out); |
| 25 | if (bound < strm.total_out) return -1; |
| 26 | if (PREFIX(deflateEnd)(&strm) != Z_OK) return -1; |
| 27 | } |
| 28 | for (int i = 0; i <= 32; i++) { |
| 29 | bytes = sizeof(compressed); |
| 30 | for (int j = 0; j < i; j++) { |
| 31 | plain[j] = j; |
| 32 | } |
| 33 | bound = PREFIX(compressBound)(i); |
| 34 | if (PREFIX(compress2)(compressed, &bytes, plain, i, 1) != Z_OK) return -1; |
| 35 | printf("bytes = %2i, compressBound = %2i, total_out = %2zi\n", i, bound, (size_t)bytes); |
| 36 | if (bytes > bound) return -1; |
| 37 | } |
| 38 | return 0; |
| 39 | } |