]> mj.ucw.cz Git - libucw.git/blobdiff - lib/lizard-test.c
Merged obj2buck.h and buck2obj.h to object.h, the number of includes
[libucw.git] / lib / lizard-test.c
index 38a76c56647f4265ca358914a7dfa3668ccd4e1c..ba78e022cadd28ac52d404c31e45a921dab0f302 100644 (file)
@@ -6,16 +6,18 @@
 #include <stdlib.h>
 #include <fcntl.h>
 #include <unistd.h>
+#include <sys/user.h>
 
-static char *options = CF_SHORT_OPTS "cdt";
+static char *options = CF_SHORT_OPTS "cdtx";
 static char *help = "\
 Usage: lizard-test <options> input-file [output-file]\n\
 \n\
 Options:\n"
 CF_USAGE
-"-c\t\tCompress (default)\n\
+"-c\t\tCompress\n\
 -d\t\tDecompress\n\
--t\t\tCompress, decompress, and compare (in memory only)\n\
+-t\t\tCompress, decompress, and compare (in memory only, default)\n\
+-x\t\tLet the test crash by shrinking the output buffer\n\
 ";
 
 static void NONRET
@@ -29,7 +31,8 @@ int
 main(int argc, char **argv)
 {
   int opt;
-  uns action = 'c';
+  uns action = 't';
+  uns crash = 0;
   log_init(argv[0]);
   while ((opt = cf_getopt(argc, argv, options, CF_NO_LONG_OPTS, NULL)) >= 0)
     switch (opt)
@@ -39,6 +42,9 @@ main(int argc, char **argv)
       case 't':
        action = opt;
        break;
+      case 'x':
+       crash++;
+       break;
       default:
        usage();
     }
@@ -47,7 +53,7 @@ main(int argc, char **argv)
     usage();
 
   void *mi, *mo;
-  uns li, lo;
+  int li, lo;
 
   struct stat st;
   stat(argv[optind], &st);
@@ -89,16 +95,20 @@ main(int argc, char **argv)
   }
   else
   {
-    void *mv;
-    uns lv;
-    mv = xmalloc(li);
-    lv = lizard_decompress(mo, mv);
-    printf("-> %d ", lv);
-    fflush(stdout);
-    if (lv != li || memcmp(mi, mv, lv))
+    int smaller_li;
+    if (li >= (int) PAGE_SIZE)
+      smaller_li = li - PAGE_SIZE;
+    else
+      smaller_li = 0;
+    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");
+    lizard_free(buf);
   }
   printf("\n");
 }