]> 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 2c5c14940bb9b33d80769e1ab629405f1792e872..ba78e022cadd28ac52d404c31e45a921dab0f302 100644 (file)
@@ -14,10 +14,10 @@ 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\
--x, -xx, -xxx\tMake the test crash by underestimating the output buffer\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
@@ -31,7 +31,7 @@ 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)
@@ -95,39 +95,16 @@ main(int argc, char **argv)
   }
   else
   {
-    struct lizard_buffer *buf = lizard_alloc(li);
-    uns exp_len = li;
-    if (crash==1)
-    {
-      if (exp_len >= PAGE_SIZE)
-       exp_len -= PAGE_SIZE;
-      else
-       exp_len = 0;
-      printf("Setting shorter output buffer to %d: ", exp_len);
-      fflush(stdout);
-    }
-    int lv = lizard_decompress_safe(mo, buf, exp_len);
-    printf("-> %d ", lv);
-    fflush(stdout);
-    if (crash >= 2)
-    {
-      uns guarded_pos = (lv + PAGE_SIZE-1)/PAGE_SIZE * PAGE_SIZE;
-      printf("Reading from guarded memory: %d\n", ((byte *) (buf->ptr)) [guarded_pos]);
-      if (crash == 2)
-      {
-       printf("Writing to guarded memory: ");
-       fflush(stdout);
-       ((byte *) (buf->ptr)) [guarded_pos] = 0;
-       printf("succeeded\n");
-      }
-      if (crash == 3)
-      {
-       printf("Reading behind guarded memory: ");
-       fflush(stdout);
-       printf("%d\n", ((byte *) (buf->ptr)) [guarded_pos + PAGE_SIZE] = 0);
-      }
-    }
-    if (lv != li || memcmp(mi, buf->ptr, li))
+    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");