11// Copied from https://gist.github.com/arq5x/5315739 for test purposes
22
3+ #include < assert.h>
34#include < stdio.h>
45#include < string.h> // for strlen
5- # include < assert.h >
6+
67#include " zlib.h"
78
8- // adapted from: http://stackoverflow.com/questions/7540259/deflate-and-inflate-zlib-h-in-c
9- int main ( int argc, char * argv[])
10- {
9+ // adapted from:
10+ // http://stackoverflow.com/questions/7540259/deflate-and-inflate-zlib-h-in-c
11+ int main ( int argc, char *argv[]) {
1112 // original string len = 36
1213 char a[50 ] = " Hello Hello Hello Hello Hello Hello!" ;
1314
@@ -17,11 +18,9 @@ int main(int argc, char* argv[])
1718 // placeholder for the UNcompressed (inflated) version of "b"
1819 char c[50 ];
1920
20-
2121 printf (" Uncompressed size is: %lu\n " , strlen (a));
2222 printf (" Uncompressed string is: %s\n " , a);
2323
24-
2524 printf (" \n ----------\n\n " );
2625
2726 // STEP 1.
@@ -33,10 +32,11 @@ int main(int argc, char* argv[])
3332 defstream.zfree = Z_NULL;
3433 defstream.opaque = Z_NULL;
3534 // setup "a" as the input and "b" as the compressed output
36- defstream.avail_in = (uInt)strlen (a)+1 ; // size of input, string + terminator
37- defstream.next_in = (Bytef *)a; // input char array
38- defstream.avail_out = (uInt)sizeof (b); // size of output
39- defstream.next_out = (Bytef *)b; // output char array
35+ defstream.avail_in =
36+ (uInt)strlen (a) + 1 ; // size of input, string + terminator
37+ defstream.next_in = (Bytef *)a; // input char array
38+ defstream.avail_out = (uInt)sizeof (b); // size of output
39+ defstream.next_out = (Bytef *)b; // output char array
4040
4141 // the actual compression work.
4242 deflateInit (&defstream, Z_BEST_COMPRESSION);
@@ -47,10 +47,8 @@ int main(int argc, char* argv[])
4747 printf (" Compressed size is: %lu\n " , strlen (b));
4848 printf (" Compressed string is: %s\n " , b);
4949
50-
5150 printf (" \n ----------\n\n " );
5251
53-
5452 // STEP 2.
5553 // inflate b into c
5654 // zlib struct
@@ -59,10 +57,11 @@ int main(int argc, char* argv[])
5957 infstream.zfree = Z_NULL;
6058 infstream.opaque = Z_NULL;
6159 // setup "b" as the input and "c" as the compressed output
62- infstream.avail_in = (uInt)((char *)defstream.next_out - b); // size of input
63- infstream.next_in = (Bytef *)b; // input char array
64- infstream.avail_out = (uInt)sizeof (c); // size of output
65- infstream.next_out = (Bytef *)c; // output char array
60+ infstream.avail_in =
61+ (uInt)((char *)defstream.next_out - b); // size of input
62+ infstream.next_in = (Bytef *)b; // input char array
63+ infstream.avail_out = (uInt)sizeof (c); // size of output
64+ infstream.next_out = (Bytef *)c; // output char array
6665
6766 // the actual DE-compression work.
6867 inflateInit (&infstream);
@@ -72,9 +71,8 @@ int main(int argc, char* argv[])
7271 printf (" Uncompressed size is: %lu\n " , strlen (c));
7372 printf (" Uncompressed string is: %s\n " , c);
7473
75-
7674 // make sure uncompressed is exactly equal to original.
77- assert (strcmp (a,c)== 0 );
75+ assert (strcmp (a, c) == 0 );
7876
7977 return 0 ;
8078}
0 commit comments