~ubuntu-branches/ubuntu/feisty/clamav/feisty

« back to all changes in this revision

Viewing changes to contrib/phishing/test/urltest.c

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook
  • Date: 2007-02-20 10:33:44 UTC
  • mto: This revision was merged to the branch mainline in revision 16.
  • Revision ID: james.westby@ubuntu.com-20070220103344-zgcu2psnx9d98fpa
Tags: upstream-0.90
Import upstream version 0.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Phishing module test.
 
3
 *
 
4
 *  Copyright (C) 2006 T�r�k Edvin <edwintorok@gmail.com>
 
5
 *
 
6
 *  This program is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation; either version 2 of the License, or
 
9
 *  (at your option) any later version.
 
10
 *
 
11
 *  This program is distributed in the hope that it will be useful,
 
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 *  GNU General Public License for more details.
 
15
 *
 
16
 *  You should have received a copy of the GNU General Public License
 
17
 *  along with this program; if not, write to the Free Software
 
18
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 
19
 *  MA 02110-1301, USA.
 
20
 *
 
21
 *  $Log $
 
22
 */
 
23
#include <stdlib.h>
 
24
#include <stdio.h>
 
25
#include <check.h>
 
26
#include "urltest.h"
 
27
static struct url_test {
 
28
        const char* input;
 
29
        int output;
 
30
} url_tests[] = {
 
31
        {"www.google.com",1},
 
32
        {"virus.zip",0}
 
33
};
 
34
/*static int url_tests_cnt = sizeof(url_tests)/sizeof(url_tests[0]);*/
 
35
static int url_tests_i=-1;
 
36
 
 
37
struct cl_engine engine;
 
38
static void url_tests_setup(void)
 
39
{
 
40
        phishing_init(&engine);
 
41
        url_tests_i=0;
 
42
}
 
43
 
 
44
static void url_tests_teardown(void)
 
45
{
 
46
        phishing_done(&engine);
 
47
}
 
48
 
 
49
static int url_test_function(const char* input)
 
50
{
 
51
        return isURL(engine.phishcheck,input);
 
52
}
 
53
 
 
54
START_TEST(url_test_create)
 
55
{
 
56
        fail_unless( url_test_function("")!=-1,
 
57
                        "Initialization failed");
 
58
}
 
59
END_TEST
 
60
/* standard cruft */
 
61
#define URL_TEST(x) \
 
62
START_TEST(url_test_##x)\
 
63
{\
 
64
        const int url_test_nr = (x);\
 
65
        struct url_test test = url_tests[url_test_nr];\
 
66
        const int output = url_test_function(test.input);\
 
67
        const int expectedoutput = test.output;\
 
68
        char failed_msg[512];\
 
69
        snprintf(failed_msg,sizeof(failed_msg),"Failed at test:%d",url_test_nr);\
 
70
        fail_unless(output==expectedoutput,failed_msg);\
 
71
}\
 
72
END_TEST
 
73
 
 
74
 
 
75
URL_TEST(0)
 
76
URL_TEST(1)
 
77
 
 
78
#define ADD_URL_TEST(x)         tcase_add_test(tc_core, url_test_##x)
 
79
 
 
80
TCase* create_url_testcase(void)
 
81
{
 
82
        TCase* tc_core = tcase_create("Core");
 
83
        tcase_add_test(tc_core, url_test_create);
 
84
        ADD_URL_TEST(0);
 
85
        ADD_URL_TEST(1);
 
86
 
 
87
        tcase_add_checked_fixture(tc_core, url_tests_setup, url_tests_teardown);
 
88
        return tc_core;
 
89
}