3 #include "lib/fastbuf.h"
4 #include "lib/lizard.h"
12 static char *options = CF_SHORT_OPTS "cdtx";
13 static char *help = "\
14 Usage: lizard-test <options> input-file [output-file]\n\
20 -t\t\tCompress, decompress, and compare (in memory only, default)\n\
21 -x\t\tLet the test crash by shrinking the output buffer\n\
32 main(int argc, char **argv)
38 while ((opt = cf_get_opt(argc, argv, options, CF_NO_LONG_OPTS, NULL)) >= 0)
52 if (action == 't' && argc != optind+1
53 || action != 't' && argc != optind+2)
61 stat(argv[optind], &st);
63 struct fastbuf *fi = bopen(argv[optind], O_RDONLY, 1<<16);
66 lo = li * LIZARD_MAX_MULTIPLY + LIZARD_MAX_ADD;
67 li += LIZARD_NEEDS_CHARS;
77 li = bread(fi, mi, li);
82 printf("->expected %d (%08x) ", lo, adler);
85 lo = lizard_compress(mi, li, mo);
88 lo = lizard_decompress(mi, mo);
89 if (adler32(mo, lo) != adler)
90 printf("wrong Adler32 ");
97 struct fastbuf *fo = bopen(argv[optind+1], O_CREAT | O_TRUNC | O_WRONLY, 1<<16);
101 bputl(fo, adler32(mi, li));
109 if (li >= (int) PAGE_SIZE)
110 smaller_li = li - PAGE_SIZE;
113 struct lizard_buffer *buf = lizard_alloc();
114 byte *ptr = lizard_decompress_safe(mo, buf, crash ? smaller_li : li);
117 else if (memcmp(mi, ptr, li))