2 #include <ucw/getopt.h>
3 #include <ucw/fastbuf.h>
4 #include <ucw/ff-binary.h>
5 #include <ucw/lizard.h>
11 #include <sys/types.h>
13 static char *options = CF_SHORT_OPTS "cdtx";
14 static char *help = "\
15 Usage: lizard-test <options> input-file [output-file]\n\
21 -t\t\tCompress, decompress, and compare (in memory only, default)\n\
22 -x\t\tLet the test crash by shrinking the output buffer\n\
33 main(int argc, char **argv)
39 while ((opt = cf_getopt(argc, argv, options, CF_NO_LONG_OPTS, NULL)) >= 0)
53 if (action == 't' && argc != optind+1
54 || action != 't' && argc != optind+2)
62 stat(argv[optind], &st);
64 struct fastbuf *fi = bopen(argv[optind], O_RDONLY, 1<<16);
67 lo = li * LIZARD_MAX_MULTIPLY + LIZARD_MAX_ADD;
68 li += LIZARD_NEEDS_CHARS;
78 li = bread(fi, mi, li);
83 printf("->expected %d (%08x) ", lo, adler);
86 lo = lizard_compress(mi, li, mo);
89 lo = lizard_decompress(mi, mo);
90 if (adler32(mo, lo) != adler)
91 printf("wrong Adler32 ");
98 struct fastbuf *fo = bopen(argv[optind+1], O_CREAT | O_TRUNC | O_WRONLY, 1<<16);
102 bputl(fo, adler32(mi, li));
110 if (li >= (int) CPU_PAGE_SIZE)
111 smaller_li = li - CPU_PAGE_SIZE;
114 struct lizard_buffer *buf = lizard_alloc();
115 byte *ptr = lizard_decompress_safe(mo, buf, crash ? smaller_li : li);
118 else if (memcmp(mi, ptr, li))