2
* Unit tests for JS normalizer.
4
* Copyright (C) 2008 Sourcefire, Inc.
6
* Authors: aCaB <acab@clamav.net>
8
* This program is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License version 2 as
10
* published by the Free Software Foundation.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
23
#include "clamav-config.h"
32
#include "../libclamav/uniq.h"
35
START_TEST (test_uniq_initfail) {
38
fail_unless(U==NULL, "uniq_init(0)!=NULL");
42
START_TEST (test_uniq_known) {
47
const uint32_t key_len;
50
{ NULL, 0, "d41d8cd98f00b204e9800998ecf8427e" },
51
{ "_vba_project", 12, "ae4f6474bee50ccdf1a6b853ba8ad32a" },
52
{ "powerpoint document", 19, "87320d137f01f7b183eb533a1de6c62a" },
53
{ "worddocument", 12, "126ea3fd0ff7f18c9c5eec0c07398c49" },
54
{ "_1_ole10native", 14, "e74f5f7bbf0b77708bc591157d708d3d" },
59
struct uniq *U = uniq_init(5);
60
fail_unless(U!=0, "uniq_init");
62
for(i=0; tests[i].expected; i++) {
63
u = uniq_add(U, tests[i].key, tests[i].key_len, &hash);
64
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);
67
for(i=0; tests[i].expected; i++) {
68
u = uniq_get(U, tests[i].key, tests[i].key_len, &hash);
69
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);
77
START_TEST (test_uniq_colls) {
79
const char *tests[] = { "_vba_project", "powerpoint document", "worddocument", "_1_ole10native" };
82
struct uniq *U = uniq_init(10);
83
fail_unless(U!=0, "uniq_init");
87
u = uniq_add(U, tests[i], strlen(tests[i]), NULL);
90
u = uniq_add(U, tests[i], strlen(tests[i]), NULL);
91
fail_unless(u+i==4, "uniq_get(%s) = %u - expected %u", tests[i], u, 4-i);
98
Suite *test_uniq_suite(void)
100
Suite *s = suite_create("unique");
102
tc_uniq = tcase_create("unique");
103
suite_add_tcase (s, tc_uniq);
104
tcase_add_test(tc_uniq, test_uniq_initfail);
105
tcase_add_test(tc_uniq, test_uniq_known);
106
tcase_add_test(tc_uniq, test_uniq_colls);