From owner-svn-soc-all@FreeBSD.ORG Wed Aug 28 10:25:05 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 1D8F0148 for ; Wed, 28 Aug 2013 10:25:05 +0000 (UTC) (envelope-from dpl@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 094942B7B for ; Wed, 28 Aug 2013 10:25:05 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r7SAP4in010752 for ; Wed, 28 Aug 2013 10:25:04 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r7SAP4qs010745 for svn-soc-all@FreeBSD.org; Wed, 28 Aug 2013 10:25:04 GMT (envelope-from dpl@FreeBSD.org) Date: Wed, 28 Aug 2013 10:25:04 GMT Message-Id: <201308281025.r7SAP4qs010745@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to dpl@FreeBSD.org using -f From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r256652 - soc2013/dpl/head/lib/libzcap/test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 28 Aug 2013 10:25:05 -0000 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 #include +/* 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