forked from cory/tildefriends
zlib 1.3.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4455 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
103
deps/zlib/test/example.c
vendored
103
deps/zlib/test/example.c
vendored
@ -34,37 +34,14 @@ static z_const char hello[] = "hello, hello!";
|
||||
static const char dictionary[] = "hello";
|
||||
static uLong dictId; /* Adler32 value of the dictionary */
|
||||
|
||||
void test_deflate OF((Byte *compr, uLong comprLen));
|
||||
void test_inflate OF((Byte *compr, uLong comprLen,
|
||||
Byte *uncompr, uLong uncomprLen));
|
||||
void test_large_deflate OF((Byte *compr, uLong comprLen,
|
||||
Byte *uncompr, uLong uncomprLen));
|
||||
void test_large_inflate OF((Byte *compr, uLong comprLen,
|
||||
Byte *uncompr, uLong uncomprLen));
|
||||
void test_flush OF((Byte *compr, uLong *comprLen));
|
||||
void test_sync OF((Byte *compr, uLong comprLen,
|
||||
Byte *uncompr, uLong uncomprLen));
|
||||
void test_dict_deflate OF((Byte *compr, uLong comprLen));
|
||||
void test_dict_inflate OF((Byte *compr, uLong comprLen,
|
||||
Byte *uncompr, uLong uncomprLen));
|
||||
int main OF((int argc, char *argv[]));
|
||||
|
||||
|
||||
#ifdef Z_SOLO
|
||||
|
||||
void *myalloc OF((void *, unsigned, unsigned));
|
||||
void myfree OF((void *, void *));
|
||||
|
||||
void *myalloc(q, n, m)
|
||||
void *q;
|
||||
unsigned n, m;
|
||||
{
|
||||
void *myalloc(void *q, unsigned n, unsigned m) {
|
||||
(void)q;
|
||||
return calloc(n, m);
|
||||
}
|
||||
|
||||
void myfree(void *q, void *p)
|
||||
{
|
||||
void myfree(void *q, void *p) {
|
||||
(void)q;
|
||||
free(p);
|
||||
}
|
||||
@ -77,18 +54,11 @@ static free_func zfree = myfree;
|
||||
static alloc_func zalloc = (alloc_func)0;
|
||||
static free_func zfree = (free_func)0;
|
||||
|
||||
void test_compress OF((Byte *compr, uLong comprLen,
|
||||
Byte *uncompr, uLong uncomprLen));
|
||||
void test_gzio OF((const char *fname,
|
||||
Byte *uncompr, uLong uncomprLen));
|
||||
|
||||
/* ===========================================================================
|
||||
* Test compress() and uncompress()
|
||||
*/
|
||||
void test_compress(compr, comprLen, uncompr, uncomprLen)
|
||||
Byte *compr, *uncompr;
|
||||
uLong comprLen, uncomprLen;
|
||||
{
|
||||
void test_compress(Byte *compr, uLong comprLen, Byte *uncompr,
|
||||
uLong uncomprLen) {
|
||||
int err;
|
||||
uLong len = (uLong)strlen(hello)+1;
|
||||
|
||||
@ -111,11 +81,7 @@ void test_compress(compr, comprLen, uncompr, uncomprLen)
|
||||
/* ===========================================================================
|
||||
* Test read/write of .gz files
|
||||
*/
|
||||
void test_gzio(fname, uncompr, uncomprLen)
|
||||
const char *fname; /* compressed file name */
|
||||
Byte *uncompr;
|
||||
uLong uncomprLen;
|
||||
{
|
||||
void test_gzio(const char *fname, Byte *uncompr, uLong uncomprLen) {
|
||||
#ifdef NO_GZCOMPRESS
|
||||
fprintf(stderr, "NO_GZCOMPRESS -- gz* functions cannot compress\n");
|
||||
#else
|
||||
@ -197,10 +163,7 @@ void test_gzio(fname, uncompr, uncomprLen)
|
||||
/* ===========================================================================
|
||||
* Test deflate() with small buffers
|
||||
*/
|
||||
void test_deflate(compr, comprLen)
|
||||
Byte *compr;
|
||||
uLong comprLen;
|
||||
{
|
||||
void test_deflate(Byte *compr, uLong comprLen) {
|
||||
z_stream c_stream; /* compression stream */
|
||||
int err;
|
||||
uLong len = (uLong)strlen(hello)+1;
|
||||
@ -235,10 +198,8 @@ void test_deflate(compr, comprLen)
|
||||
/* ===========================================================================
|
||||
* Test inflate() with small buffers
|
||||
*/
|
||||
void test_inflate(compr, comprLen, uncompr, uncomprLen)
|
||||
Byte *compr, *uncompr;
|
||||
uLong comprLen, uncomprLen;
|
||||
{
|
||||
void test_inflate(Byte *compr, uLong comprLen, Byte *uncompr,
|
||||
uLong uncomprLen) {
|
||||
int err;
|
||||
z_stream d_stream; /* decompression stream */
|
||||
|
||||
@ -276,10 +237,8 @@ void test_inflate(compr, comprLen, uncompr, uncomprLen)
|
||||
/* ===========================================================================
|
||||
* Test deflate() with large buffers and dynamic change of compression level
|
||||
*/
|
||||
void test_large_deflate(compr, comprLen, uncompr, uncomprLen)
|
||||
Byte *compr, *uncompr;
|
||||
uLong comprLen, uncomprLen;
|
||||
{
|
||||
void test_large_deflate(Byte *compr, uLong comprLen, Byte *uncompr,
|
||||
uLong uncomprLen) {
|
||||
z_stream c_stream; /* compression stream */
|
||||
int err;
|
||||
|
||||
@ -308,7 +267,7 @@ void test_large_deflate(compr, comprLen, uncompr, uncomprLen)
|
||||
/* Feed in already compressed data and switch to no compression: */
|
||||
deflateParams(&c_stream, Z_NO_COMPRESSION, Z_DEFAULT_STRATEGY);
|
||||
c_stream.next_in = compr;
|
||||
c_stream.avail_in = (uInt)comprLen/2;
|
||||
c_stream.avail_in = (uInt)uncomprLen/2;
|
||||
err = deflate(&c_stream, Z_NO_FLUSH);
|
||||
CHECK_ERR(err, "deflate");
|
||||
|
||||
@ -331,10 +290,8 @@ void test_large_deflate(compr, comprLen, uncompr, uncomprLen)
|
||||
/* ===========================================================================
|
||||
* Test inflate() with large buffers
|
||||
*/
|
||||
void test_large_inflate(compr, comprLen, uncompr, uncomprLen)
|
||||
Byte *compr, *uncompr;
|
||||
uLong comprLen, uncomprLen;
|
||||
{
|
||||
void test_large_inflate(Byte *compr, uLong comprLen, Byte *uncompr,
|
||||
uLong uncomprLen) {
|
||||
int err;
|
||||
z_stream d_stream; /* decompression stream */
|
||||
|
||||
@ -361,7 +318,7 @@ void test_large_inflate(compr, comprLen, uncompr, uncomprLen)
|
||||
err = inflateEnd(&d_stream);
|
||||
CHECK_ERR(err, "inflateEnd");
|
||||
|
||||
if (d_stream.total_out != 2*uncomprLen + comprLen/2) {
|
||||
if (d_stream.total_out != 2*uncomprLen + uncomprLen/2) {
|
||||
fprintf(stderr, "bad large inflate: %ld\n", d_stream.total_out);
|
||||
exit(1);
|
||||
} else {
|
||||
@ -372,10 +329,7 @@ void test_large_inflate(compr, comprLen, uncompr, uncomprLen)
|
||||
/* ===========================================================================
|
||||
* Test deflate() with full flush
|
||||
*/
|
||||
void test_flush(compr, comprLen)
|
||||
Byte *compr;
|
||||
uLong *comprLen;
|
||||
{
|
||||
void test_flush(Byte *compr, uLong *comprLen) {
|
||||
z_stream c_stream; /* compression stream */
|
||||
int err;
|
||||
uInt len = (uInt)strlen(hello)+1;
|
||||
@ -410,10 +364,7 @@ void test_flush(compr, comprLen)
|
||||
/* ===========================================================================
|
||||
* Test inflateSync()
|
||||
*/
|
||||
void test_sync(compr, comprLen, uncompr, uncomprLen)
|
||||
Byte *compr, *uncompr;
|
||||
uLong comprLen, uncomprLen;
|
||||
{
|
||||
void test_sync(Byte *compr, uLong comprLen, Byte *uncompr, uLong uncomprLen) {
|
||||
int err;
|
||||
z_stream d_stream; /* decompression stream */
|
||||
|
||||
@ -453,10 +404,7 @@ void test_sync(compr, comprLen, uncompr, uncomprLen)
|
||||
/* ===========================================================================
|
||||
* Test deflate() with preset dictionary
|
||||
*/
|
||||
void test_dict_deflate(compr, comprLen)
|
||||
Byte *compr;
|
||||
uLong comprLen;
|
||||
{
|
||||
void test_dict_deflate(Byte *compr, uLong comprLen) {
|
||||
z_stream c_stream; /* compression stream */
|
||||
int err;
|
||||
|
||||
@ -490,10 +438,8 @@ void test_dict_deflate(compr, comprLen)
|
||||
/* ===========================================================================
|
||||
* Test inflate() with a preset dictionary
|
||||
*/
|
||||
void test_dict_inflate(compr, comprLen, uncompr, uncomprLen)
|
||||
Byte *compr, *uncompr;
|
||||
uLong comprLen, uncomprLen;
|
||||
{
|
||||
void test_dict_inflate(Byte *compr, uLong comprLen, Byte *uncompr,
|
||||
uLong uncomprLen) {
|
||||
int err;
|
||||
z_stream d_stream; /* decompression stream */
|
||||
|
||||
@ -541,13 +487,10 @@ void test_dict_inflate(compr, comprLen, uncompr, uncomprLen)
|
||||
* Usage: example [output.gz [input.gz]]
|
||||
*/
|
||||
|
||||
int main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
int main(int argc, char *argv[]) {
|
||||
Byte *compr, *uncompr;
|
||||
uLong comprLen = 10000*sizeof(int); /* don't overflow on MSDOS */
|
||||
uLong uncomprLen = comprLen;
|
||||
uLong uncomprLen = 20000;
|
||||
uLong comprLen = 3 * uncomprLen;
|
||||
static const char* myVersion = ZLIB_VERSION;
|
||||
|
||||
if (zlibVersion()[0] != myVersion[0]) {
|
||||
@ -590,7 +533,7 @@ int main(argc, argv)
|
||||
|
||||
test_flush(compr, &comprLen);
|
||||
test_sync(compr, comprLen, uncompr, uncomprLen);
|
||||
comprLen = uncomprLen;
|
||||
comprLen = 3 * uncomprLen;
|
||||
|
||||
test_dict_deflate(compr, comprLen);
|
||||
test_dict_inflate(compr, comprLen, uncompr, uncomprLen);
|
||||
|
Reference in New Issue
Block a user