socsvn commit: r256630 - soc2013/dpl/head/lib/libzcap/test
dpl at FreeBSD.org
dpl at FreeBSD.org
Tue Aug 27 18:19:23 UTC 2013
Author: dpl
Date: Tue Aug 27 18:19:22 2013
New Revision: 256630
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=256630
Log:
Test is work in progress, but I managed to test most of the gzip related code.
Now I have to smashed that dam*** bug.
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 27 16:50:48 2013 (r256629)
+++ soc2013/dpl/head/lib/libzcap/test/zcaplibtest.c Tue Aug 27 18:19:22 2013 (r256630)
@@ -2,6 +2,7 @@
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <err.h>
void testzlibVersion(void);
@@ -12,6 +13,14 @@
void testinflate(z_streamp strm);
void testinflateEnd(z_streamp strm);
+gzFile testgzopen(void);
+void testgzbuffer(gzFile file);
+void testgzsetparams(gzFile file);
+gzFile testgzio(gzFile file);
+void testgzdirect(gzFile file);
+void testgzerror(gzFile file);
+void testgzclearerr(gzFile file);
+
void testzlibCompileFlags(void);
void testCompressBound(void);
@@ -19,21 +28,21 @@
void testchecksums(void);
#define SIZEOFDATA 10*1024
-int i;
char *data;
-z_streamp strmdef;
-z_streamp strminf;
+int i;
+
int
main() {
+ z_streamp strmdef;
+ z_streamp strminf;
+
if ( (data = malloc(SIZEOFDATA)) == NULL)
err(1, "zcaplibtest: malloc()");
for (i=0; i < SIZEOFDATA; i+=sizeof(long))
data[i] = i;
- printf("This is a zcaplib program tester.\n");
-
if ( (strmdef = calloc(1, sizeof (z_stream))) == NULL)
err(1, "zcaplibtest: malloc()");
testdeflateInit(strmdef);
@@ -46,7 +55,17 @@
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();
free(strmdef);
@@ -56,16 +75,15 @@
return 0;
}
+/* Basic functions */
void
testdeflateInit(z_streamp strm)
{
printf("deflateInit(): ");
int ret = deflateInit(strm, Z_DEFAULT_COMPRESSION);
if (strm->state != NULL || ret == 0)
- printf("OK\n");
+ printf(" %d\n", ret);
else printf("Error");
- printf("deflateInit %d\n", ret);
- return;
}
void
@@ -80,11 +98,9 @@
printf("deflateEnd(): ");
int ret = deflateEnd(strm);
if (strm->state == Z_NULL || ret == 0)
- printf("OK\n");
+ printf("%d\n", ret);
else
printf("Error\n");
- printf("deflateEnd %d\n", ret);
- return;
}
void
@@ -93,10 +109,8 @@
printf("inflateInit(): ");
int ret = inflateInit(strm);
if (strm->state != NULL || ret == 0)
- printf("OK\n");
+ printf(" %d\n", ret);
else printf("Error");
- printf("inflateInit %d\n", ret);
- return;
}
void
@@ -112,27 +126,24 @@
printf("inflateEnd(): ");
int ret = inflateEnd(strm);
if (strm->state == Z_NULL || ret == 0)
- printf("OK\n");
+ printf("%d\n", ret);
else
printf("Error\n");
- printf("deflateEnd %d\n", ret);
- return;
}
+/* Advanced functions */
void
testzlibCompileFlags(void)
{
printf("zlibCompileFlags(): ");
uLong ret = zlibCompileFlags();
if ( ret > 0)
- printf("OK\n");
+ printf(" %lu\n", ret);
else
err(1, "Error\n");
- printf("zlibCompileFlags %lu\n", ret);
-
- return;
}
+/* Utility functions */
void
testCompressBound(void)
{
@@ -140,15 +151,220 @@
uLong ret = compressBound(10L);
if (ret) printf("%lu\n", ret);
else printf("-1\n");
- return;
+}
+
+/* Gzip Functions */
+gzFile
+testgzopen(void)
+{
+ gzFile file;
+ printf("gzopen(): ");
+ file = gzopen("foo.gz", "wb");
+ if (file != NULL)
+ printf("0\n");
+ else
+ printf("Error\n");
+ return file;
+}
+
+void
+testgzbuffer(gzFile file)
+{
+ printf("gzbuffer(): ");
+ int ret = gzbuffer(file, 8192);
+ if (ret == Z_OK)
+ printf("%d\n", ret);
+ else
+ printf("Error\n");
}
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");
+}
+
+/* This function will test all the related IO functions of gzip files */
+/* It is separated in writing functions (first), and reading functions */
+gzFile
+testgzio(gzFile file)
+{
+ char *buf = "hello";
+ int len = strlen(buf)+1;
+ int ret;
+
+ void *d = calloc(50, 1);
+ if (d == 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");
+
+ printf("gzprintf(): ");
+ ret = gzprintf(file, ",hello %d", len);
+ if (ret != 0)
+ printf("%d\n", ret);
+ else
+ printf("Error\n");
+
+ printf("gztell(): ");
+ ret = gztell(file);
+ if (ret >= 0)
+ printf("%d\n", ret);
+ else
+ printf("Error\n");
+
+ printf("gzputs(): ");
+ ret = gzputs(file, "\nhello lin");
+ if (ret > 0)
+ printf("%d\n", ret);
+ else
+ printf("Error\n");
+
+ 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");
+
+ printf("gzclose(): ");
+ ret = gzclose(file);
+ if (ret == Z_OK)
+ printf("%d\n", ret);
+ else
+ printf("Error\n");
+
+ /* 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");
+
+ printf("\nContents of file:\n'");
+ printf("%s'\n\n", d);
+
+ printf("gzeof(): ");
+ ret = gzeof(file);
+ if (ret > 0)
+ printf("%d\n", ret);
+ else
+ printf("Error\n");
+
+ printf("gzrewind(): ");
+ ret = gzrewind(file);
+ if (ret >= 0)
+ printf("%d\n", ret);
+ else
+ printf("Error\n");
+
+ printf("gzoffset(): ");
+ ret = gzoffset(file);
+ if (ret >= 0)
+ printf("%d\n", ret);
+ else
+ printf("Error\n");
+
+ printf("gzgets(): ");
+ const char *str = gzgets(file, d, 50);
+ if (str != NULL)
+ printf("%s\n", str);
+ else
+ printf("Error\n");
+
+ //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));
+
+ return file;
+}
+
+
+void
+testgzdirect(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(): ");
+ const char *error = gzerror(file, &errn);
+ if (errn == 0)
+ printf("%d\n", errn);
+ else
+ printf("%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);
+}
+
+
+/* Checksum functions */
+void
testchecksums(void)
{
/*
- * first, second: checksum of the first,second half of the data buffer.
- * allone, alltwo: checksum of the whole buffer in one,two call(s).
+ * first, second: checksum of the first/second half of the data buffer.
+ * allone, alltwo: checksum of the whole buffer in one/two call(s).
*/
uLong first, second, combined, allone, alltwo;
first = second = combined = allone = alltwo = 0L;
@@ -166,13 +382,13 @@
if (alltwo == allone)
printf("%lu\n", alltwo);
else
- printf("-1\n");
+ printf("Error\n");
printf("adler32_combine(): ");
if (allone == combined)
printf("%lu\n", combined);
else
- printf("-1\n");
+ printf("Error\n");
/* crc32 */
first = second = combined = allone = alltwo = 0L;
@@ -189,11 +405,11 @@
if (alltwo == allone)
printf("%lu\n", alltwo);
else
- printf("-1\n");
+ printf("Error\n");
printf("crc32_combine(): ");
if (allone == combined)
printf("%lu\n", combined);
else
- printf("-1\n");
+ printf("Error\n");
}
\ No newline at end of file
More information about the svn-soc-all
mailing list