Browse code

unit_tests: fixed testing involving optional features: unrar. bzip2, and xml

Kevin Lin authored on 2014/03/19 06:23:27
Showing 4 changed files
... ...
@@ -93,3 +93,5 @@ else
93 93
   AC_SUBST(XML_CPPFLAGS)
94 94
   AC_SUBST(XML_LIBS)
95 95
 fi
96
+
97
+AM_CONDITIONAL([HAVE_LIBXML2], test "x$HAVE_LIBXML2" = "xyes")
... ...
@@ -1,4 +1,4 @@
1
-FILES = clam-v2.rar clam-v3.rar clam.cab clam.exe clam.zip \
1
+FILES = clam.cab clam.exe clam.zip \
2 2
 	clam.arj clam.exe.rtf clam.exe.szdd clam.tar.gz clam.chm clam.sis \
3 3
 	clam-aspack.exe clam-pespin.exe clam-upx.exe clam-fsg.exe clam-mew.exe\
4 4
 	clam-nsis.exe clam-petite.exe clam-upack.exe clam-wwpack.exe clam.pdf\
... ...
@@ -9,10 +9,18 @@ FILES = clam-v2.rar clam-v3.rar clam.cab clam.exe clam.zip \
9 9
 	clam_IScab_ext.exe clam_ISmsi_int.exe clam_ISmsi_ext.exe clam.7z \
10 10
 	clam_cache_emax.tgz clam.iso clamjol.iso
11 11
 
12
+if ENABLE_UNRAR
13
+FILES += clam-v2.rar clam-v3.rar
14
+endif
15
+
12 16
 if HAVE_LIBBZ2
13 17
 FILES += clam.exe.bz2 clam.bz2.zip
14 18
 endif
15 19
 
20
+if HAVE_LIBXML2
21
+#placeholder
22
+endif
23
+
16 24
 SPLIT_DIR=$(top_srcdir)/test/.split
17 25
 
18 26
 all: $(FILES)
... ...
@@ -382,24 +382,31 @@ END_TEST
382 382
 static char **testfiles = NULL;
383 383
 static unsigned testfiles_n = 0;
384 384
 
385
-#if HAVE_BZLIB_H
386 385
 static const int expected_testfiles = 48;
387
-#else
388
-static const int expected_testfiles = 46;
389
-#endif
390 386
 
391
-static unsigned skip_unrar_files(void)
387
+static unsigned skip_files(void)
392 388
 {
389
+    unsigned skipped = 0;
390
+
391
+    /* skip .rar files if unrar is disabled */
393 392
     const char *s = getenv("unrar_disabled");
393
+    if (s && !strcmp(s, "1")) {
394
+        skipped += 2;
395
+    }
394 396
 
395
-    if (!s)
396
-        return 0;
397
+    /* skip .bz2 files if bzip is disabled */
398
+#if HAVE_BZLIB_H
399
+#else
400
+    skipped += 2;
401
+#endif
397 402
 
398
-    if (strcmp(s, "1"))
399
-        return 0;
403
+    /* skip [placeholder] files if xml is disabled */
404
+#if HAVE_LIBXML2
405
+#else
406
+    skipped += 0;
407
+#endif
400 408
 
401
-    /* number of .rar files we skipp */
402
-    return 2;
409
+    return skipped;
403 410
 }
404 411
 
405 412
 static void init_testfiles(void)
... ...
@@ -417,10 +424,6 @@ static void init_testfiles(void)
417 417
     while ((dirent = readdir(d))) {
418 418
 	if (strncmp(dirent->d_name, "clam", 4))
419 419
 	    continue;
420
-	if (strstr(dirent->d_name, ".rar") && skip_unrar_files()) {
421
-            cli_dbgmsg("skipping (no unrar) %s\n", dirent->d_name);
422
-            continue;
423
-        }
424 420
         i++;
425 421
 	testfiles = cli_realloc(testfiles, i*sizeof(*testfiles));
426 422
 	fail_unless(!!testfiles, "cli_realloc");
... ...
@@ -429,7 +432,7 @@ static void init_testfiles(void)
429 429
     testfiles_n = i;
430 430
     if (get_fpu_endian() == FPU_ENDIAN_UNKNOWN)
431 431
         expect--;
432
-    expect -= skip_unrar_files();
432
+    expect -= skip_files();
433 433
     fail_unless_fmt(testfiles_n == expect, "testfiles: %d != %d", testfiles_n, expect);
434 434
 
435 435
     closedir(d);
... ...
@@ -645,7 +648,7 @@ static Suite *test_cl_suite(void)
645 645
 #ifdef CHECK_HAVE_LOOPS
646 646
     if (get_fpu_endian() == FPU_ENDIAN_UNKNOWN)
647 647
         expect--;
648
-    expect -= skip_unrar_files();
648
+    expect -= skip_files();
649 649
     tcase_add_loop_test(tc_cl_scan, test_cl_scandesc, 0, expect);
650 650
     tcase_add_loop_test(tc_cl_scan, test_cl_scandesc_allscan, 0, expect);
651 651
     tcase_add_loop_test(tc_cl_scan, test_cl_scanfile, 0, expect);
... ...
@@ -122,13 +122,8 @@ test_end() {
122 122
 }
123 123
 
124 124
 scan_failed() {
125
-    if test "X$unrar_disabled" = "X1" && test `grep -v '\.rar' $1 | grep OK | wc -l` -eq 0
126
-    then
127
-	error "UNRAR is disabled, won't be able to detect unrar files!"
128
-    else
129
-	cat $1
130
-    	die "$2";
131
-    fi
125
+    cat $1
126
+    die "$2";
132 127
 }
133 128
 
134 129
 # ----------- valgrind wrapper