0.1.1
by Stephen Gran
Import upstream version 0.94.dfsg |
1 |
/*
|
2 |
* Unit tests for JS normalizer.
|
|
3 |
*
|
|
4 |
* Copyright (C) 2008 Sourcefire, Inc.
|
|
5 |
*
|
|
6 |
* Authors: aCaB <acab@clamav.net>
|
|
7 |
*
|
|
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.
|
|
11 |
*
|
|
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.
|
|
16 |
*
|
|
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,
|
|
20 |
* MA 02110-1301, USA.
|
|
21 |
*/
|
|
22 |
#if HAVE_CONFIG_H
|
|
23 |
#include "clamav-config.h" |
|
24 |
#endif
|
|
25 |
||
26 |
#include <check.h> |
|
27 |
#include <stdlib.h> |
|
28 |
#include <string.h> |
|
29 |
||
30 |
#include "../libclamav/uniq.h" |
|
31 |
#include "checks.h" |
|
32 |
||
33 |
START_TEST (test_uniq_initfail) { |
|
34 |
struct uniq *U; |
|
35 |
U = uniq_init(0); |
|
36 |
fail_unless(U==NULL, "uniq_init(0)!=NULL"); |
|
37 |
}
|
|
38 |
END_TEST
|
|
39 |
||
40 |
START_TEST (test_uniq_known) { |
|
41 |
char *hash; |
|
42 |
uint32_t u; |
|
43 |
struct { |
|
44 |
const char *key; |
|
45 |
const uint32_t key_len; |
|
46 |
const char *expected; |
|
47 |
} tests[] = { |
|
48 |
{ NULL, 0, "d41d8cd98f00b204e9800998ecf8427e" }, |
|
49 |
{ "_vba_project", 12, "ae4f6474bee50ccdf1a6b853ba8ad32a" }, |
|
50 |
{ "powerpoint document", 19, "87320d137f01f7b183eb533a1de6c62a" }, |
|
51 |
{ "worddocument", 12, "126ea3fd0ff7f18c9c5eec0c07398c49" }, |
|
52 |
{ "_1_ole10native", 14, "e74f5f7bbf0b77708bc591157d708d3d" }, |
|
53 |
{ NULL, 0, NULL } |
|
54 |
};
|
|
55 |
int i; |
|
56 |
||
57 |
struct uniq *U = uniq_init(5); |
|
58 |
fail_unless(U!=0, "uniq_init"); |
|
59 |
||
60 |
for(i=0; tests[i].expected; i++) { |
|
61 |
u = uniq_add(U, tests[i].key, tests[i].key_len, &hash); |
|
56
by Scott Kitterman
* Merge from Debian Unstable (LP: #296704). Remaining Ubuntu changes: |
62 |
fail_unless_fmt(u==0 && strcmp(hash, tests[i].expected)==0, "uniq_add(%s) = %u - expected %s, got %s", tests[i].key, u, tests[i].expected, hash); |
0.1.1
by Stephen Gran
Import upstream version 0.94.dfsg |
63 |
}
|
64 |
||
65 |
for(i=0; tests[i].expected; i++) { |
|
66 |
u = uniq_get(U, tests[i].key, tests[i].key_len, &hash); |
|
56
by Scott Kitterman
* Merge from Debian Unstable (LP: #296704). Remaining Ubuntu changes: |
67 |
fail_unless_fmt(u==1 && strcmp(hash, tests[i].expected)==0, "uniq_get(%s) = %u - expected %s, got %s", tests[i].key, u, tests[i].expected, hash); |
0.1.1
by Stephen Gran
Import upstream version 0.94.dfsg |
68 |
}
|
69 |
||
70 |
uniq_free(U); |
|
71 |
}
|
|
72 |
END_TEST
|
|
73 |
||
74 |
||
75 |
START_TEST (test_uniq_colls) { |
|
76 |
uint32_t u; |
|
77 |
const char *tests[] = { "_vba_project", "powerpoint document", "worddocument", "_1_ole10native" }; |
|
78 |
int i, j; |
|
79 |
||
80 |
struct uniq *U = uniq_init(10); |
|
81 |
fail_unless(U!=0, "uniq_init"); |
|
82 |
||
83 |
for(j=4; j>0; j--) |
|
84 |
for (i=0; i<j; i++) |
|
85 |
u = uniq_add(U, tests[i], strlen(tests[i]), NULL); |
|
86 |
||
87 |
for (i=0; i<4; i++) { |
|
88 |
u = uniq_add(U, tests[i], strlen(tests[i]), NULL); |
|
56
by Scott Kitterman
* Merge from Debian Unstable (LP: #296704). Remaining Ubuntu changes: |
89 |
fail_unless_fmt(u+i==4, "uniq_get(%s) = %u - expected %u", tests[i], u, 4-i); |
0.1.1
by Stephen Gran
Import upstream version 0.94.dfsg |
90 |
}
|
91 |
||
92 |
uniq_free(U); |
|
93 |
}
|
|
94 |
END_TEST
|
|
95 |
||
96 |
Suite *test_uniq_suite(void) |
|
97 |
{
|
|
98 |
Suite *s = suite_create("unique"); |
|
99 |
TCase *tc_uniq; |
|
100 |
tc_uniq = tcase_create("unique"); |
|
101 |
suite_add_tcase (s, tc_uniq); |
|
102 |
tcase_add_test(tc_uniq, test_uniq_initfail); |
|
103 |
tcase_add_test(tc_uniq, test_uniq_known); |
|
104 |
tcase_add_test(tc_uniq, test_uniq_colls); |
|
105 |
return s; |
|
106 |
}
|
|
107 |