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

0.98.2
Kevin Lin 11 years ago
parent e22e387abb
commit f4f331ae26
  1. 2
      m4/reorganization/libs/xml.m4
  2. 10
      test/Makefile.am
  3. 37
      unit_tests/check_clamav.c
  4. 9
      unit_tests/check_common.sh

@ -93,3 +93,5 @@ else
AC_SUBST(XML_CPPFLAGS)
AC_SUBST(XML_LIBS)
fi
AM_CONDITIONAL([HAVE_LIBXML2], test "x$HAVE_LIBXML2" = "xyes")

@ -1,4 +1,4 @@
FILES = clam-v2.rar clam-v3.rar clam.cab clam.exe clam.zip \
FILES = clam.cab clam.exe clam.zip \
clam.arj clam.exe.rtf clam.exe.szdd clam.tar.gz clam.chm clam.sis \
clam-aspack.exe clam-pespin.exe clam-upx.exe clam-fsg.exe clam-mew.exe\
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 \
clam_IScab_ext.exe clam_ISmsi_int.exe clam_ISmsi_ext.exe clam.7z \
clam_cache_emax.tgz clam.iso clamjol.iso
if ENABLE_UNRAR
FILES += clam-v2.rar clam-v3.rar
endif
if HAVE_LIBBZ2
FILES += clam.exe.bz2 clam.bz2.zip
endif
if HAVE_LIBXML2
#placeholder
endif
SPLIT_DIR=$(top_srcdir)/test/.split
all: $(FILES)

@ -382,24 +382,31 @@ END_TEST
static char **testfiles = NULL;
static unsigned testfiles_n = 0;
#if HAVE_BZLIB_H
static const int expected_testfiles = 48;
#else
static const int expected_testfiles = 46;
#endif
static unsigned skip_unrar_files(void)
static unsigned skip_files(void)
{
unsigned skipped = 0;
/* skip .rar files if unrar is disabled */
const char *s = getenv("unrar_disabled");
if (s && !strcmp(s, "1")) {
skipped += 2;
}
if (!s)
return 0;
/* skip .bz2 files if bzip is disabled */
#if HAVE_BZLIB_H
#else
skipped += 2;
#endif
if (strcmp(s, "1"))
return 0;
/* skip [placeholder] files if xml is disabled */
#if HAVE_LIBXML2
#else
skipped += 0;
#endif
/* number of .rar files we skipp */
return 2;
return skipped;
}
static void init_testfiles(void)
@ -417,10 +424,6 @@ static void init_testfiles(void)
while ((dirent = readdir(d))) {
if (strncmp(dirent->d_name, "clam", 4))
continue;
if (strstr(dirent->d_name, ".rar") && skip_unrar_files()) {
cli_dbgmsg("skipping (no unrar) %s\n", dirent->d_name);
continue;
}
i++;
testfiles = cli_realloc(testfiles, i*sizeof(*testfiles));
fail_unless(!!testfiles, "cli_realloc");
@ -429,7 +432,7 @@ static void init_testfiles(void)
testfiles_n = i;
if (get_fpu_endian() == FPU_ENDIAN_UNKNOWN)
expect--;
expect -= skip_unrar_files();
expect -= skip_files();
fail_unless_fmt(testfiles_n == expect, "testfiles: %d != %d", testfiles_n, expect);
closedir(d);
@ -645,7 +648,7 @@ static Suite *test_cl_suite(void)
#ifdef CHECK_HAVE_LOOPS
if (get_fpu_endian() == FPU_ENDIAN_UNKNOWN)
expect--;
expect -= skip_unrar_files();
expect -= skip_files();
tcase_add_loop_test(tc_cl_scan, test_cl_scandesc, 0, expect);
tcase_add_loop_test(tc_cl_scan, test_cl_scandesc_allscan, 0, expect);
tcase_add_loop_test(tc_cl_scan, test_cl_scanfile, 0, expect);

@ -122,13 +122,8 @@ test_end() {
}
scan_failed() {
if test "X$unrar_disabled" = "X1" && test `grep -v '\.rar' $1 | grep OK | wc -l` -eq 0
then
error "UNRAR is disabled, won't be able to detect unrar files!"
else
cat $1
die "$2";
fi
cat $1
die "$2";
}
# ----------- valgrind wrapper

Loading…
Cancel
Save