~ubuntu-branches/ubuntu/raring/clamav/raring

« back to all changes in this revision

Viewing changes to unit_tests/check_uniq.c

  • Committer: Bazaar Package Importer
  • Author(s): Stephen Gran
  • Date: 2008-09-05 17:25:34 UTC
  • mfrom: (0.35.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080905172534-yi3f8fkye1o7u1r3
* New upstream version (closes: #497662, #497773)
  - lots of new options for clamd.conf
  - fixes CVEs CVE-2008-3912, CVE-2008-3913, CVE-2008-3914, and
    CVE-2008-1389
* No longer supports --unzip option, so typo is gone (closes: #496276)
* Translations:
  - sv (thanks Martin Bagge <brother@bsnet.se>) (closes: #491760)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
#ifdef HAVE_CHECK
 
27
 
 
28
#include <check.h>
 
29
#include <stdlib.h>
 
30
#include <string.h>
 
31
 
 
32
#include "../libclamav/uniq.h"
 
33
#include "checks.h"
 
34
 
 
35
START_TEST (test_uniq_initfail) {
 
36
  struct uniq *U;
 
37
  U = uniq_init(0);
 
38
  fail_unless(U==NULL, "uniq_init(0)!=NULL");
 
39
}
 
40
END_TEST
 
41
 
 
42
START_TEST (test_uniq_known) {
 
43
  char *hash;
 
44
  uint32_t u;
 
45
  struct {
 
46
    const char *key;
 
47
    const uint32_t key_len;
 
48
    const char *expected;
 
49
  } tests[] = {
 
50
    { NULL, 0, "d41d8cd98f00b204e9800998ecf8427e" }, 
 
51
    { "_vba_project", 12, "ae4f6474bee50ccdf1a6b853ba8ad32a" },
 
52
    { "powerpoint document", 19, "87320d137f01f7b183eb533a1de6c62a" },
 
53
    { "worddocument", 12, "126ea3fd0ff7f18c9c5eec0c07398c49" },
 
54
    { "_1_ole10native", 14, "e74f5f7bbf0b77708bc591157d708d3d" },
 
55
    { NULL, 0, NULL }
 
56
  };
 
57
  int i;
 
58
 
 
59
  struct uniq *U = uniq_init(5);
 
60
  fail_unless(U!=0, "uniq_init");
 
61
 
 
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);
 
65
  }
 
66
 
 
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);
 
70
  }
 
71
 
 
72
  uniq_free(U);
 
73
}
 
74
END_TEST
 
75
 
 
76
 
 
77
START_TEST (test_uniq_colls) {
 
78
  uint32_t u;
 
79
  const char *tests[] = { "_vba_project", "powerpoint document", "worddocument", "_1_ole10native" };
 
80
  int i, j;
 
81
 
 
82
  struct uniq *U = uniq_init(10);
 
83
  fail_unless(U!=0, "uniq_init");
 
84
 
 
85
  for(j=4; j>0; j--)
 
86
    for (i=0; i<j; i++)
 
87
      u = uniq_add(U, tests[i], strlen(tests[i]), NULL);
 
88
  
 
89
  for (i=0; i<4; i++) {
 
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);
 
92
  }
 
93
 
 
94
  uniq_free(U);
 
95
}
 
96
END_TEST
 
97
 
 
98
Suite *test_uniq_suite(void)
 
99
{
 
100
    Suite *s = suite_create("unique");
 
101
    TCase *tc_uniq;
 
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);
 
107
    return s;
 
108
}
 
109
 
 
110
 
 
111
#endif