Date: Wed, 28 Aug 2013 10:25:04 GMT From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r256652 - soc2013/dpl/head/lib/libzcap/test Message-ID: <201308281025.r7SAP4qs010745@socsvn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: dpl Date: Wed Aug 28 10:25:04 2013 New Revision: 256652 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=256652 Log: Updated zcaplibtest. It now handles all the gzip functions. The next functions to test are the advanced ones. After that, we'll try with deflate(), inflate() and inflateBack(). Modified: soc2013/dpl/head/lib/libzcap/test/zcaplibtest.c Modified: soc2013/dpl/head/lib/libzcap/test/zcaplibtest.c ============================================================================== --- soc2013/dpl/head/lib/libzcap/test/zcaplibtest.c Wed Aug 28 07:48:44 2013 (r256651) +++ soc2013/dpl/head/lib/libzcap/test/zcaplibtest.c Wed Aug 28 10:25:04 2013 (r256652) @@ -5,6 +5,7 @@ #include <string.h> #include <err.h> +/* Basic functions */ void testzlibVersion(void); void testdeflateInit(z_streamp strm); void testdeflate(z_streamp strm); @@ -13,25 +14,29 @@ void testinflate(z_streamp strm); void testinflateEnd(z_streamp strm); -gzFile testgzopen(void); -void testgzbuffer(gzFile file); -void testgzsetparams(gzFile file); +/* gzip functions */ +/* Test non-IO and saves a compressed file */ +gzFile testgzbasic(void); +/* returns a gzFile of the written file */ gzFile testgzio(gzFile file); -void testgzdirect(gzFile file); -void testgzerror(gzFile file); -void testgzclearerr(gzFile file); +/* Test error related functions */ +void testgzerr(gzFile file); +/* Advanced functions */ void testzlibCompileFlags(void); +/* Utility functions */ void testCompressBound(void); +/* Checksum functions */ void testchecksums(void); #define SIZEOFDATA 10*1024 char *data; int i; - +/* This is part of the test of zcaplib */ +/* The program expects a shell script to manage all */ int main() { z_streamp strmdef; @@ -55,19 +60,14 @@ testinflate(strminf); testinflateEnd(strminf); - gzFile gz = testgzopen(); - testgzbuffer(gz); - testgzsetparams(gz); - gz = testgzio(gz); - testgzdirect(gz); - testgzerror(gz); - testgzclearerr(gz); - // XXX Delete foo.gz here - testzlibCompileFlags(); testCompressBound(); + gzFile gz = testgzbasic(); + gz = testgzio(gz); + testgzerr(gz); + free(strmdef); free(strminf); @@ -79,11 +79,9 @@ void testdeflateInit(z_streamp strm) { - printf("deflateInit(): "); int ret = deflateInit(strm, Z_DEFAULT_COMPRESSION); - if (strm->state != NULL || ret == 0) - printf(" %d\n", ret); - else printf("Error"); + if (strm->state == NULL || ret != 0) + printf("deflateInit(): Error: %d\n", ret); } void @@ -95,22 +93,17 @@ void testdeflateEnd(z_streamp strm) { - printf("deflateEnd(): "); int ret = deflateEnd(strm); - if (strm->state == Z_NULL || ret == 0) - printf("%d\n", ret); - else - printf("Error\n"); + if (strm->state != Z_NULL || ret != 0) + printf("deflateEnd(): Error: %d\n", ret); } void testinflateInit(z_streamp strm) { - printf("inflateInit(): "); int ret = inflateInit(strm); - if (strm->state != NULL || ret == 0) - printf(" %d\n", ret); - else printf("Error"); + if (strm->state == NULL || ret != 0) + printf("inflateInit(): Error: %d\n", ret); } void @@ -123,70 +116,51 @@ void testinflateEnd(z_streamp strm) { - printf("inflateEnd(): "); int ret = inflateEnd(strm); - if (strm->state == Z_NULL || ret == 0) - printf("%d\n", ret); - else - printf("Error\n"); + if (strm->state != Z_NULL || ret != 0) + printf("inflateEnd(): Error: %d\n", ret); } /* Advanced functions */ void testzlibCompileFlags(void) { - printf("zlibCompileFlags(): "); uLong ret = zlibCompileFlags(); - if ( ret > 0) - printf(" %lu\n", ret); - else - err(1, "Error\n"); + if (ret == 0) + printf("zlibCompileFlags(): Error: %lu\n", ret); } /* Utility functions */ void testCompressBound(void) { - printf("compressBound(): "); uLong ret = compressBound(10L); - if (ret) printf("%lu\n", ret); - else printf("-1\n"); + if (ret == 0) + printf("compressBound(): Error: %lu\n", ret); } /* Gzip Functions */ gzFile -testgzopen(void) +testgzbasic(void) { - gzFile file; - printf("gzopen(): "); + gzFile file = NULL; file = gzopen("foo.gz", "wb"); - if (file != NULL) - printf("0\n"); - else - printf("Error\n"); - return file; -} + if (file == NULL) + printf("gzopen(): Error\n"); -void -testgzbuffer(gzFile file) -{ - printf("gzbuffer(): "); int ret = gzbuffer(file, 8192); - if (ret == Z_OK) - printf("%d\n", ret); - else - printf("Error\n"); -} + if (ret != Z_OK) + printf("gzbuffer(): Error: %d\n", ret); -void -testgzsetparams(gzFile file) -{ - printf("gzsetparams(): "); - int ret = gzsetparams(file, 9, Z_HUFFMAN_ONLY); - if (ret == Z_OK) - printf("%d\n", ret); - else - printf("Error\n"); + ret = gzsetparams(file, 9, Z_HUFFMAN_ONLY); + if (ret != Z_OK) + printf("gzsetparams(): Error: %d\n", ret); + + ret = gzdirect(file); + if (ret < 0) + printf("gzdirect(): Error: %d\n", ret); + + return file; } /* This function will test all the related IO functions of gzip files */ @@ -194,169 +168,103 @@ gzFile testgzio(gzFile file) { + // Data is supposed to be the string that gets saved. + char *data = "hello, hello!\n"; char *buf = "hello"; int len = strlen(buf)+1; int ret; - - void *d = calloc(50, 1); - if (d == NULL) + void *d; + + if ((d = calloc(50, 1)) == NULL) err(1, "zcaplibtest: calloc()"); /* Writing functions */ - printf("gzwrite(): "); ret = gzwrite(file, (void *)buf, len); - if (ret != 0) - printf("%d\n", ret); - else - printf("Error\n"); + if (ret == 0) + printf("gzwrite(): Error: %d\n", ret); - printf("gzprintf(): "); - ret = gzprintf(file, ",hello %d", len); - if (ret != 0) - printf("%d\n", ret); - else - printf("Error\n"); + ret = gzputc(file, (int)','); + if (ret != ',') + printf("gzputc(): Error: %d\n", ret); + + ret = gzprintf(file, " %s", "hell"); + if (ret != 5) + printf("gzprintf(): Error: %d\n", ret); - printf("gztell(): "); ret = gztell(file); - if (ret >= 0) - printf("%d\n", ret); - else - printf("Error\n"); + if (ret == -1) + printf("gztell(): Error: %d\n", ret); - printf("gzputs(): "); - ret = gzputs(file, "\nhello lin"); - if (ret > 0) - printf("%d\n", ret); - else - printf("Error\n"); + ret = gzputs(file, "o!\n"); + if (ret < 0) + printf("gzputs(): Error: %d\n", ret); - printf("gzputc(): "); - ret = gzputc(file, (int)'e'); - if (ret >= 0) - printf("%d\n", ret); - else - printf("Error\n"); - - printf("gzflush(): "); ret = gzflush(file, Z_FINISH); - if (ret >= 0) - printf("%d\n", ret); - else - printf("Error\n"); + if (ret < 0) + printf("gzflush(): Error: %d\n", ret); - printf("gzclose(): "); ret = gzclose(file); - if (ret == Z_OK) - printf("%d\n", ret); - else - printf("Error\n"); + if (ret != Z_OK) + printf("gzclose(): Error: %d\n", ret); /* Reading functions */ file = gzopen("foo.gz", "rb"); - printf("gzseek(): "); - ret = gzseek(file, 0 , SEEK_SET); - if (ret >= 0) - printf("%d\n", ret); - else - printf("Error\n"); - - printf("gzread(): "); ret = gzread(file, d, 50); - if (ret > 0) - printf("%d\n", ret); - else - printf("Error\n"); + if (ret < 0) + printf("gzread(): Error: %d\n", ret); + printf("%s\n", d); - printf("\nContents of file:\n'"); - printf("%s'\n\n", d); + ret = gzseek(file, 0 , SEEK_SET); + if (ret != 0) + printf("gzseek(): Error: %d\n", ret); - printf("gzeof(): "); ret = gzeof(file); - if (ret > 0) - printf("%d\n", ret); - else - printf("Error\n"); + if (ret < 0) + printf("gzeof(): Error: %d\n", ret); + + ret = gzoffset(file); + if (ret < 0) + printf("gzoffset(): Error: %d\n", ret); - printf("gzrewind(): "); ret = gzrewind(file); - if (ret >= 0) - printf("%d\n", ret); - else - printf("Error\n"); + if (ret < 0) + printf("gzrewind(): Error: %d\n", ret); - printf("gzoffset(): "); - ret = gzoffset(file); - if (ret >= 0) - printf("%d\n", ret); - else - printf("Error\n"); + ret = gzgetc(file); + if (ret < 0) + printf("gzgetc(): Error: %d\n", ret); + printf("\ngetc: %c\n", ret); - printf("gzgets(): "); const char *str = gzgets(file, d, 50); - if (str != NULL) - printf("%s\n", str); - else - printf("Error\n"); + if (str == NULL) + printf("gzgets(): Error: %s\n", str); + printf("gzgets: %s\n", d); - //XXX - printf("gzgetc(): "); - ret = gzgetc(file); - if (ret >= 0) - printf("%c\n", ret); - else - printf("Error\n"); - printf("gzungetc(): "); ret = gzungetc(1, file); - if (ret >= 0) - printf("%d\n", ret); - else - printf("Error:%d\n", ret); - printf("%c\n",gzgetc(file)); - + if (ret < 0) + printf("gzungetc(): Error:%d\n", ret); + printf("gzungetc: %d\n", ret); return file; } void -testgzdirect(gzFile file) +testgzerr(gzFile file) { - printf("gzdirect(): "); - int ret = gzdirect(file); - if (ret >= 0) - printf("%d\n", ret); - else - printf("Error\n"); -} - -void -testgzerror(gzFile file) -{ - int errn; // XXX How can we test this? - printf("gzerror(): "); + int errn; const char *error = gzerror(file, &errn); - if (errn == 0) - printf("%d\n", errn); - else - printf("%d:%s\n", errn, error); -} + if (errn != 0) + printf("gzerror(): %d:%s\n", errn, error); -void -testgzclearerr(gzFile file) -{ - int errn; - printf("gzclearerr(): "); gzclearerr(file); - // XXX How can we test this? - const char *error = gzerror(file, &errn); - if (errn == 0) - printf("%d\n", errn); - else - printf("%d:%s\n", errn, error); -} + error = gzerror(file, &errn); + if (errn != 0) + printf("gzclearerr(): Error\n"); + gzclose(file); +} /* Checksum functions */ void
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201308281025.r7SAP4qs010745>
