X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Flizard-test.c;h=22fc96e49a60cf69a4f7976c3d2bf5b9f8e7742c;hb=f282fc30d94338be07c13a86765fdbe3b2536c0c;hp=0b8c95290b1c317da0ff5ecf7fd4f9a0b1697687;hpb=da73e286d4f7a69184cd673db622333d16d2775c;p=libucw.git diff --git a/lib/lizard-test.c b/lib/lizard-test.c index 0b8c9529..22fc96e4 100644 --- a/lib/lizard-test.c +++ b/lib/lizard-test.c @@ -1,11 +1,12 @@ #include "lib/lib.h" -#include "lib/conf.h" +#include "lib/conf2.h" #include "lib/fastbuf.h" #include "lib/lizard.h" #include #include #include #include +#include #include static char *options = CF_SHORT_OPTS "cdtx"; @@ -17,7 +18,7 @@ CF_USAGE "-c\t\tCompress\n\ -d\t\tDecompress\n\ -t\t\tCompress, decompress, and compare (in memory only, default)\n\ --x, -xx\t\tLet the test crash by shrinking the output buffer\n\ +-x\t\tLet the test crash by shrinking the output buffer\n\ "; static void NONRET @@ -34,7 +35,7 @@ main(int argc, char **argv) uns action = 't'; uns crash = 0; log_init(argv[0]); - while ((opt = cf_getopt(argc, argv, options, CF_NO_LONG_OPTS, NULL)) >= 0) + while ((opt = cf_get_opt(argc, argv, options, CF_NO_LONG_OPTS, NULL)) >= 0) switch (opt) { case 'c': @@ -54,6 +55,7 @@ main(int argc, char **argv) void *mi, *mo; int li, lo; + uns adler = 0; struct stat st; stat(argv[optind], &st); @@ -67,7 +69,8 @@ main(int argc, char **argv) else { lo = bgetl(fi); - li -= 4; + adler = bgetl(fi); + li -= 8; } mi = xmalloc(li); mo = xmalloc(lo); @@ -76,12 +79,16 @@ main(int argc, char **argv) printf("%d ", li); if (action == 'd') - printf("->expected %d ", lo); + printf("->expected %d (%08x) ", lo, adler); fflush(stdout); if (action != 'd') lo = lizard_compress(mi, li, mo); else + { lo = lizard_decompress(mi, mo); + if (adler32(mo, lo) != adler) + printf("wrong Adler32 "); + } printf("-> %d ", lo); fflush(stdout); @@ -89,7 +96,10 @@ main(int argc, char **argv) { struct fastbuf *fo = bopen(argv[optind+1], O_CREAT | O_TRUNC | O_WRONLY, 1<<16); if (action == 'c') + { bputl(fo, li); + bputl(fo, adler32(mi, li)); + } bwrite(fo, mo, lo); bclose(fo); } @@ -100,13 +110,11 @@ main(int argc, char **argv) smaller_li = li - PAGE_SIZE; else smaller_li = 0; - struct lizard_buffer *buf = lizard_alloc(crash==1 ? smaller_li : li); - int lv = lizard_decompress_safe(mo, buf, crash==2 ? smaller_li : li); - printf("-> %d ", lv); - fflush(stdout); - if (lv < 0) - printf("err:%m "); - else if (lv != li || memcmp(mi, buf->ptr, li)) + struct lizard_buffer *buf = lizard_alloc(); + byte *ptr = lizard_decompress_safe(mo, buf, crash ? smaller_li : li); + if (!ptr) + printf("err: %m"); + else if (memcmp(mi, ptr, li)) printf("WRONG"); else printf("OK");