Date: Tue, 20 Aug 2013 08:22:25 GMT From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r256190 - soc2013/dpl/head/lib/libzcap/test Message-ID: <201308200822.r7K8MPOR007264@socsvn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: dpl Date: Tue Aug 20 08:22:24 2013 New Revision: 256190 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=256190 Log: Use err() instead of fprintf();exit(). 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 Tue Aug 20 08:21:42 2013 (r256189) +++ soc2013/dpl/head/lib/libzcap/test/zcaplibtest.c Tue Aug 20 08:22:24 2013 (r256190) @@ -2,6 +2,7 @@ #include <stdio.h> #include <stdlib.h> +#include <err.h> void testzlibVersion(void); void testdeflateInit(z_streamp strm); @@ -22,17 +23,13 @@ int main() { - if ( (strm = malloc(sizeof (z_stream))) == NULL) { - printf("zcaplibtest: malloc()"); - abort(); - } + if ( (strm = malloc(sizeof (z_stream))) == NULL) + err(1, "zcaplibtest: malloc()"); - if ( (data = malloc(10*1024)) == NULL) { - printf("zcaplibtest: malloc()"); - abort(); - } + if ( (data = malloc(10*1024)) == NULL) + err(1, "zcaplibtest: malloc()"); - for (i=0; i<(10*1024); i++) { + for (i=0; i < (10*1024); i++) { data[i] = rand(); } @@ -91,10 +88,9 @@ if ( (ret = zlibCompileFlags()) > 0) printf("OK\n"); - else - printf("Error\n"); - printf("zlibCompileFlags: %lu\n", ret); - + else + err(1, "Error\n"); + return; } @@ -108,41 +104,31 @@ void testchecksums(void) { - long data[2]; - - uLong first = 0; - uLong second = 0; - uLong all = 0; - uLong combined = 0; - int lsize = sizeof(long); + uLong first, second, combined; + first = second = combined = 0; + + first = adler32(0L, Z_NULL, 0); + printf("adler32: %ld\n", first ); + first = adler32(first, (void *)data, 5*1024); + printf("adler32: %ld\n", first ); + second = adler32(first, (void *)(data+5*1024), 5*1024); + printf("adler32: %ld\n", second ); - data[0] = random(); - data[1] = random(); + combined = adler32_combine(first, second, 5*1024); + printf("adler32_combine(): %ld\n", combined ); - first = adler32(0, (void *)data, sizeof(long)); - printf("adler32(0, %ld, %d): %ld\n", data[0], sizeof(long), first ); printf("adler32\t...\t"); - if (first != 0) + if (second == combined) printf("OK\n"); else - printf("Error\n"); - - second = adler32(0, (void *)(data+lsize), sizeof(long)); - printf("adler32(0, %ld, %d): %ld\n", data[1], sizeof(long), second ); - - combined = adler32_combine(first, second, sizeof(long)); - printf("adler32_combine(%ld, %ld, %d): %ld\n", first, second, sizeof(long), combined ); - - all = adler32(0L, (void *)data, 2*sizeof(long)); - printf("adler32(0, %ld, %d): %ld\n", data[0], 2*sizeof(long), all ); - + err(1, "Error\n"); printf("adler32_combine()\t...\t"); - if (all == combined) + if (second == combined) printf("OK\n"); else - printf("Error\n"); + err(1, "Error\n"); return;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201308200822.r7K8MPOR007264>
