2
* Phishing module test.
4
* Copyright (C) 2006 T�r�k Edvin <edwintorok@gmail.com>
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.
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.
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,
26
#include <test-config.h>
28
#include <clamav-config.h>
30
#include <phish_domaincheck_db.h>
31
#define FULLFLAG 0xFFFF
32
static struct regex_list_test {
33
const char* inputReal;
34
const char* inputDisp;
37
} regex_list_tests[] = {
38
{"www.google.com","www.google.com",0,FULLFLAG},
39
{"http://abcdef","jj",0,FULLFLAG},
40
{"http://abcdefj","jj",1,FULLFLAG},
41
{"http://ab.f.com","jj",0,FULLFLAG},
42
{"http://a.f.com","jj",1,FULLFLAG},
43
{"http://b.f.com","jj",1,FULLFLAG},
44
{"http://c.f.com","jj",1,FULLFLAG},
45
{"http://d.f.com","jj",1,FULLFLAG},
46
{"http://f.f.com","jj",0,FULLFLAG},
47
{"http://e.f.com","jj",1,FULLFLAG},
48
{"http://ae.f.net","jj",1,FULLFLAG},
49
{"http://cb.f.com","jj",0,FULLFLAG},
50
{"http://abcf","jj",0,FULLFLAG},
51
{"virus.zip","viiirii.zip",0,FULLFLAG},
52
{"http://zztest.com","jj",1,0xFEF7}
54
/*static int regex_list_tests_cnt = sizeof(regex_list_tests)/sizeof(regex_list_tests[0]);*/
55
static int regex_list_tests_i=-1;
56
static struct cl_engine* engine;
58
static void regex_list_tests_setup(void)
63
rc = cl_loaddb(REGEXTEST_FILE,&engine,&signo);
64
fail_unless(rc==0,cl_strerror(rc));
65
fail_unless(is_domainlist_ok(engine));
69
static void regex_list_tests_teardown(void)
76
static int regex_list_test_function(const char* input1,const char* input2,const unsigned short flag_expected)
78
unsigned short flags=FULLFLAG;
80
fail_unless(is_domainlist_ok(engine));
81
rc = domainlist_match(engine,input1,input2,0,&flags);
82
fail_unless(flags == flag_expected);
86
START_TEST(regex_list_test_create)
88
fail_unless( regex_list_test_function("","",FULLFLAG)!=-1,
89
"Initialization failed");
93
#define REGEX_LIST_TEST(x) \
94
START_TEST(regex_list_test_##x)\
96
const int regex_list_test_nr = (x);\
97
struct regex_list_test test = regex_list_tests[regex_list_test_nr];\
98
const int output = regex_list_test_function(test.inputReal,test.inputDisp,test.flags);\
99
const int expectedoutput = test.output;\
100
char failed_msg[512];\
101
snprintf(failed_msg,sizeof(failed_msg),"Failed at test:%d (input: %s %s;expected:%d, got:%d)",\
102
regex_list_test_nr,test.inputReal,test.inputDisp,expectedoutput,output);\
103
fail_unless(output==expectedoutput,failed_msg);\
123
#define ADD_REGEX_LIST_TEST(x) tcase_add_test(tc_core, regex_list_test_##x)
126
TCase* create_pdomain_testcase(void)
128
TCase* tc_core = tcase_create("Regex List");
129
tcase_add_test(tc_core, regex_list_test_create);
130
ADD_REGEX_LIST_TEST(0);
131
ADD_REGEX_LIST_TEST(1);
132
ADD_REGEX_LIST_TEST(2);
133
ADD_REGEX_LIST_TEST(3);
134
ADD_REGEX_LIST_TEST(4);
135
ADD_REGEX_LIST_TEST(5);
136
ADD_REGEX_LIST_TEST(6);
137
ADD_REGEX_LIST_TEST(7);
138
ADD_REGEX_LIST_TEST(8);
139
ADD_REGEX_LIST_TEST(9);
140
ADD_REGEX_LIST_TEST(10);
141
ADD_REGEX_LIST_TEST(11);
142
ADD_REGEX_LIST_TEST(12);
143
ADD_REGEX_LIST_TEST(13);
144
ADD_REGEX_LIST_TEST(14);
145
tcase_add_checked_fixture(tc_core, regex_list_tests_setup, regex_list_tests_teardown);