unit tests for uniq

git-svn: trunk@4074
remotes/push_mirror/0.95
aCaB 18 years ago
parent ac90139491
commit 5e07cfed01
  1. 4
      ChangeLog
  2. 4
      libclamav/libclamav.map
  3. 2
      unit_tests/Makefile.am
  4. 20
      unit_tests/Makefile.in
  5. 1
      unit_tests/check_clamav.c
  6. 2
      unit_tests/check_disasm.c
  7. 111
      unit_tests/check_uniq.c
  8. 1
      unit_tests/checks.h

@ -1,3 +1,7 @@
Mon Aug 4 01:46:54 CEST 2008 (acab)
------------------------------------
* unit_tests: add uniq checks
Mon Aug 4 00:20:28 CEST 2008 (acab)
------------------------------------
* test: add clam.ole.doc

@ -103,6 +103,10 @@ CLAMAV_PRIVATE {
load_regex_matcher;
html_tag_arg_free;
disasmbuf;
uniq_init;
uniq_free;
uniq_add;
uniq_get;
cli_hex2str;
local:
*;

@ -16,7 +16,7 @@ else
check_PROGRAMS = $(programs)
check_SCRIPTS = $(scripts)
endif
check_clamav_SOURCES = check_clamav.c check_jsnorm.c check_str.c check_regex.c checks.h $(top_builddir)/libclamav/clamav.h check_disasm.c
check_clamav_SOURCES = check_clamav.c check_jsnorm.c check_str.c check_regex.c checks.h $(top_builddir)/libclamav/clamav.h check_disasm.c check_uniq.c
check_clamav_CFLAGS = @CHECK_CFLAGS@ -DSRCDIR=\"$(abs_srcdir)\"
check_clamav_LDADD = $(top_builddir)/libclamav/libclamav.la @THREAD_LIBS@ @CHECK_LIBS@

@ -57,7 +57,8 @@ am_check_clamav_OBJECTS = check_clamav-check_clamav.$(OBJEXT) \
check_clamav-check_jsnorm.$(OBJEXT) \
check_clamav-check_str.$(OBJEXT) \
check_clamav-check_regex.$(OBJEXT) \
check_clamav-check_disasm.$(OBJEXT)
check_clamav-check_disasm.$(OBJEXT) \
check_clamav-check_uniq.$(OBJEXT)
check_clamav_OBJECTS = $(am_check_clamav_OBJECTS)
check_clamav_DEPENDENCIES = $(top_builddir)/libclamav/libclamav.la
check_clamav_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
@ -223,7 +224,7 @@ programs = check_clamav
scripts = check_clamd.sh check_freshclam.sh check_sigtool.sh check_clamscan.sh valgrind_tests.sh
@ENABLE_UT_INSTALL_TRUE@dist_bin_SCRIPTS = $(scripts)
@ENABLE_UT_INSTALL_FALSE@check_SCRIPTS = $(scripts)
check_clamav_SOURCES = check_clamav.c check_jsnorm.c check_str.c check_regex.c checks.h $(top_builddir)/libclamav/clamav.h check_disasm.c
check_clamav_SOURCES = check_clamav.c check_jsnorm.c check_str.c check_regex.c checks.h $(top_builddir)/libclamav/clamav.h check_disasm.c check_uniq.c
check_clamav_CFLAGS = @CHECK_CFLAGS@ -DSRCDIR=\"$(abs_srcdir)\"
check_clamav_LDADD = $(top_builddir)/libclamav/libclamav.la @THREAD_LIBS@ @CHECK_LIBS@
CLEANFILES = lcov.out *.gcno *.gcda *.log /tmp/clamd-test.log $(FILES) test-stderr.log clamscan.log valgrind.log clamdscan.log
@ -367,6 +368,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/check_clamav-check_jsnorm.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/check_clamav-check_regex.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/check_clamav-check_str.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/check_clamav-check_uniq.Po@am__quote@
.c.o:
@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
@ -459,6 +461,20 @@ check_clamav-check_disasm.obj: check_disasm.c
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_clamav_CFLAGS) $(CFLAGS) -c -o check_clamav-check_disasm.obj `if test -f 'check_disasm.c'; then $(CYGPATH_W) 'check_disasm.c'; else $(CYGPATH_W) '$(srcdir)/check_disasm.c'; fi`
check_clamav-check_uniq.o: check_uniq.c
@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_clamav_CFLAGS) $(CFLAGS) -MT check_clamav-check_uniq.o -MD -MP -MF $(DEPDIR)/check_clamav-check_uniq.Tpo -c -o check_clamav-check_uniq.o `test -f 'check_uniq.c' || echo '$(srcdir)/'`check_uniq.c
@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/check_clamav-check_uniq.Tpo $(DEPDIR)/check_clamav-check_uniq.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='check_uniq.c' object='check_clamav-check_uniq.o' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_clamav_CFLAGS) $(CFLAGS) -c -o check_clamav-check_uniq.o `test -f 'check_uniq.c' || echo '$(srcdir)/'`check_uniq.c
check_clamav-check_uniq.obj: check_uniq.c
@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_clamav_CFLAGS) $(CFLAGS) -MT check_clamav-check_uniq.obj -MD -MP -MF $(DEPDIR)/check_clamav-check_uniq.Tpo -c -o check_clamav-check_uniq.obj `if test -f 'check_uniq.c'; then $(CYGPATH_W) 'check_uniq.c'; else $(CYGPATH_W) '$(srcdir)/check_uniq.c'; fi`
@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/check_clamav-check_uniq.Tpo $(DEPDIR)/check_clamav-check_uniq.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='check_uniq.c' object='check_clamav-check_uniq.obj' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_clamav_CFLAGS) $(CFLAGS) -c -o check_clamav-check_uniq.obj `if test -f 'check_uniq.c'; then $(CYGPATH_W) 'check_uniq.c'; else $(CYGPATH_W) '$(srcdir)/check_uniq.c'; fi`
mostlyclean-libtool:
-rm -f *.lo

@ -342,6 +342,7 @@ int main(int argc, char **argv)
srunner_add_suite(sr, test_str_suite());
srunner_add_suite(sr, test_regex_suite());
srunner_add_suite(sr, test_disasm_suite());
srunner_add_suite(sr, test_uniq_suite());
srunner_set_log(sr, "test.log");
if(freopen("test-stderr.log","w+",stderr) == NULL) {

@ -3,7 +3,7 @@
*
* Copyright (C) 2008 Sourcefire, Inc.
*
* Authors: Török Edvin
* Authors: aCaB <acab@clamav.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as

@ -0,0 +1,111 @@
/*
* Unit tests for JS normalizer.
*
* Copyright (C) 2008 Sourcefire, Inc.
*
* Authors: aCaB <acab@clamav.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#if HAVE_CONFIG_H
#include "clamav-config.h"
#endif
#ifdef HAVE_CHECK
#include <check.h>
#include <stdlib.h>
#include <string.h>
#include "../libclamav/uniq.h"
#include "checks.h"
START_TEST (test_uniq_initfail) {
struct uniq *U;
U = uniq_init(0);
fail_unless(U==NULL, "uniq_init(0)!=NULL");
}
END_TEST
START_TEST (test_uniq_known) {
char *hash;
uint32_t u;
struct {
const char *key;
const uint32_t key_len;
const char *expected;
} tests[] = {
{ NULL, 0, "d41d8cd98f00b204e9800998ecf8427e" },
{ "_vba_project", 12, "ae4f6474bee50ccdf1a6b853ba8ad32a" },
{ "powerpoint document", 19, "87320d137f01f7b183eb533a1de6c62a" },
{ "worddocument", 12, "126ea3fd0ff7f18c9c5eec0c07398c49" },
{ "_1_ole10native", 14, "e74f5f7bbf0b77708bc591157d708d3d" },
{ NULL, 0, NULL }
};
int i;
struct uniq *U = uniq_init(5);
fail_unless(U!=0, "uniq_init");
for(i=0; tests[i].expected; i++) {
u = uniq_add(U, tests[i].key, tests[i].key_len, &hash);
fail_unless(u==0 && strcmp(hash, tests[i].expected)==0, "uniq_add(%s) = %u - expected %s, got %s", tests[i].key, u, tests[i].expected, hash);
}
for(i=0; tests[i].expected; i++) {
u = uniq_get(U, tests[i].key, tests[i].key_len, &hash);
fail_unless(u==1 && strcmp(hash, tests[i].expected)==0, "uniq_get(%s) = %u - expected %s, got %s", tests[i].key, u, tests[i].expected, hash);
}
uniq_free(U);
}
END_TEST
START_TEST (test_uniq_colls) {
uint32_t u;
const char *tests[] = { "_vba_project", "powerpoint document", "worddocument", "_1_ole10native" };
int i, j;
struct uniq *U = uniq_init(10);
fail_unless(U!=0, "uniq_init");
for(j=4; j>0; j--)
for (i=0; i<j; i++)
u = uniq_add(U, tests[i], strlen(tests[i]), NULL);
for (i=0; i<4; i++) {
u = uniq_add(U, tests[i], strlen(tests[i]), NULL);
fail_unless(u+i==4, "uniq_get(%s) = %u - expected %u", tests[i], u, 4-i);
}
uniq_free(U);
}
END_TEST
Suite *test_uniq_suite(void)
{
Suite *s = suite_create("unique");
TCase *tc_uniq;
tc_uniq = tcase_create("unique");
suite_add_tcase (s, tc_uniq);
tcase_add_test(tc_uniq, test_uniq_initfail);
tcase_add_test(tc_uniq, test_uniq_known);
tcase_add_test(tc_uniq, test_uniq_colls);
return s;
}
#endif

@ -4,6 +4,7 @@ Suite *test_jsnorm_suite(void);
Suite *test_str_suite(void);
Suite *test_regex_suite(void);
Suite *test_disasm_suite(void);
Suite *test_uniq_suite(void);
void errmsg_expected(void);
int open_testfile(const char *name);
#endif

Loading…
Cancel
Save