3 #include "lib/fastbuf.h"
4 #include "lib/lizard.h"
11 static char *options = CF_SHORT_OPTS "cdtx";
12 static char *help = "\
13 Usage: lizard-test <options> input-file [output-file]\n\
17 "-c\t\tCompress (default)\n\
19 -t\t\tCompress, decompress, and compare (in memory only)\n\
20 -x, -xx\t\tLet the test crash by shrinking the output buffer\n\
31 main(int argc, char **argv)
37 while ((opt = cf_getopt(argc, argv, options, CF_NO_LONG_OPTS, NULL)) >= 0)
51 if (action == 't' && argc != optind+1
52 || action != 't' && argc != optind+2)
59 stat(argv[optind], &st);
61 struct fastbuf *fi = bopen(argv[optind], O_RDONLY, 1<<16);
64 lo = li * LIZARD_MAX_MULTIPLY + LIZARD_MAX_ADD;
65 li += LIZARD_NEEDS_CHARS;
74 li = bread(fi, mi, li);
79 printf("->expected %d ", lo);
82 lo = lizard_compress(mi, li, mo);
84 lo = lizard_decompress(mi, mo);
90 struct fastbuf *fo = bopen(argv[optind+1], O_CREAT | O_TRUNC | O_WRONLY, 1<<16);
99 if (li >= (int) PAGE_SIZE)
100 smaller_li = li - PAGE_SIZE;
103 struct lizard_buffer *buf = lizard_alloc(crash==1 ? smaller_li : li);
104 int lv = lizard_decompress_safe(mo, buf, crash==2 ? smaller_li : li);
105 printf("-> %d ", lv);
109 else if (lv != li || memcmp(mi, buf->ptr, li))