1279faf6 |
#include "checks.h"
#include "../libclamav/dconf.h"
#include "../libclamav/htmlnorm.h"
#include "../libclamav/others.h"
static char *dir;
static struct cli_dconf *dconf;
static void htmlnorm_setup(void)
{
dconf = cli_dconf_init();
dir = cli_gentemp(NULL);
fail_unless(!!dconf, "failed to init dconf");
fail_unless(!!dir, "cli_gentemp failed");
}
static void htmlnorm_teardown(void)
{
free(dconf);
fail_unless(cli_rmdirs(dir) == 0, "rmdirs failed");
free(dir);
dir = NULL;
}
static struct test {
const char *input;
const char *nocommentref;
const char *notagsref;
const char *jsref;
} tests[] = {
/* NULL means don't test it */
{"input/htmlnorm_buf.html","buf.nocomment.ref","buf.notags.ref",NULL},
{"input/htmlnorm_encode.html","encode.nocomment.ref",NULL,"encode.js.ref"},
{"input/htmlnorm_js_test.html","js.nocomment.ref",NULL,"js.js.ref"},
{"input/htmlnorm_test.html","test.nocomment.ref","test.notags.ref",NULL},
{"input/htmlnorm_urls.html","urls.nocomment.ref","urls.notags.ref",NULL}
};
#ifdef CHECK_HAVE_LOOPS
static void check_dir(const char *dir, const struct test *test)
{
char filename[4096];
int fd, reffd;
if (test->nocommentref) {
snprintf(filename, sizeof(filename), "%s/nocomment.html", dir);
fd = open(filename, O_RDONLY);
fail_unless(fd > 0,"unable to open: %s", filename);
reffd = open_testfile(test->nocommentref);
diff_files(fd, reffd);
close(reffd);
close(fd);
}
if (test->notagsref) {
snprintf(filename, sizeof(filename), "%s/notags.html", dir);
fd = open(filename, O_RDONLY);
fail_unless(fd > 0,"unable to open: %s", filename);
reffd = open_testfile(test->notagsref);
diff_files(fd, reffd);
close(reffd);
close(fd);
}
if (test->jsref) {
snprintf(filename, sizeof(filename), "%s/javascript", dir);
fd = open(filename, O_RDONLY);
fail_unless(fd > 0,"unable to open: %s", filename);
reffd = open_testfile(test->jsref);
diff_files(fd, reffd);
close(reffd);
close(fd);
}
}
START_TEST (test_htmlnorm_api)
{
int fd;
tag_arguments_t hrefs;
memset(&hrefs, 0, sizeof(hrefs));
fd = open_testfile(tests[_i].input);
fail_unless(fd > 0,"open_testfile failed");
fail_unless(mkdir(dir, 0700) == 0,"mkdir failed");
fail_unless(html_normalise_fd(fd, dir, NULL, dconf) == 1, "html_normalise_fd failed");
check_dir(dir, &tests[_i]);
fail_unless(cli_rmdirs(dir) == 0, "rmdirs failed");
fail_unless(mkdir(dir, 0700) == 0,"mkdir failed");
fail_unless(html_normalise_fd(fd, dir, NULL, NULL) == 1, "html_normalise_fd failed");
fail_unless(cli_rmdirs(dir) == 0, "rmdirs failed");
fail_unless(mkdir(dir, 0700) == 0,"mkdir failed");
fail_unless(html_normalise_fd(fd, dir, &hrefs, dconf) == 1, "html_normalise_fd failed");
fail_unless(cli_rmdirs(dir) == 0, "rmdirs failed");
html_tag_arg_free(&hrefs);
memset(&hrefs, 0, sizeof(hrefs));
hrefs.scanContents = 1;
fail_unless(mkdir(dir, 0700) == 0,"mkdir failed");
fail_unless(html_normalise_fd(fd, dir, &hrefs, dconf) == 1, "html_normalise_fd failed");
fail_unless(cli_rmdirs(dir) == 0, "rmdirs failed");
html_tag_arg_free(&hrefs);
close(fd);
}
END_TEST
#endif
|