2 #include "ucw/getopt.h"
3 #include "ucw/fastbuf.h"
4 #include "ucw/ff-binary.h"
5 #include "ucw/lizard.h"
11 static char *options = CF_SHORT_OPTS "cdtx";
12 static char *help = "\
13 Usage: lizard-test <options> input-file [output-file]\n\
19 -t\t\tCompress, decompress, and compare (in memory only, default)\n\
20 -x\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)
60 stat(argv[optind], &st);
62 struct fastbuf *fi = bopen(argv[optind], O_RDONLY, 1<<16);
65 lo = li * LIZARD_MAX_MULTIPLY + LIZARD_MAX_ADD;
66 li += LIZARD_NEEDS_CHARS;
76 li = bread(fi, mi, li);
81 printf("->expected %d (%08x) ", lo, adler);
84 lo = lizard_compress(mi, li, mo);
87 lo = lizard_decompress(mi, mo);
88 if (adler32(mo, lo) != adler)
89 printf("wrong Adler32 ");
96 struct fastbuf *fo = bopen(argv[optind+1], O_CREAT | O_TRUNC | O_WRONLY, 1<<16);
100 bputl(fo, adler32(mi, li));
108 if (li >= (int) CPU_PAGE_SIZE)
109 smaller_li = li - CPU_PAGE_SIZE;
112 struct lizard_buffer *buf = lizard_alloc();
113 byte *ptr = lizard_decompress_safe(mo, buf, crash ? smaller_li : li);
116 else if (memcmp(mi, ptr, li))