1 | /* |
|
|
2 | * test-regex.c |
|
|
3 | * |
|
|
4 | * Test for the simple-regex module. |
|
|
5 | * |
|
|
6 | * Copyright (C) 2004,2005 Martin Schlemmer <azarah@nosferatu.za.org> |
|
|
7 | * |
|
|
8 | * |
|
|
9 | * This program is free software; you can redistribute it and/or modify it |
|
|
10 | * under the terms of the GNU General Public License as published by the |
|
|
11 | * Free Software Foundation version 2 of the License. |
|
|
12 | * |
|
|
13 | * This program is distributed in the hope that it will be useful, but |
|
|
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
|
16 | * General Public License for more details. |
|
|
17 | * |
|
|
18 | * You should have received a copy of the GNU General Public License along |
|
|
19 | * with this program; if not, write to the Free Software Foundation, Inc., |
|
|
20 | * 675 Mass Ave, Cambridge, MA 02139, USA. |
|
|
21 | * |
|
|
22 | * $Header$ |
|
|
23 | */ |
|
|
24 | |
|
|
25 | #include <errno.h> |
|
|
26 | #include <stdio.h> |
|
|
27 | #include <stdlib.h> |
|
|
28 | #include <string.h> |
|
|
29 | |
|
|
30 | #include "debug.h" |
|
|
31 | #include "simple-regex.h" |
|
|
32 | |
|
|
33 | char *test_data[] = { |
|
|
34 | /* string, pattern, match (1 = yes, 0 = no) */ |
|
|
35 | "ab", "a?[ab]b", "1", |
|
|
36 | "abb", "a?[ab]b", "1", |
|
|
37 | "aab", "a?[ab]b", "1", |
|
|
38 | "a", "a?a?a?a", "1", |
|
|
39 | "aa", "a?a?a?a", "1", |
|
|
40 | "aa", "a?a?a?aa", "1", |
|
|
41 | "aaa", "a?a?a?aa", "1", |
|
|
42 | "ab", "[ab]*", "1", |
|
|
43 | "abc", "[ab]*.", "1", |
|
|
44 | "ab", "[ab]*b+", "1", |
|
|
45 | "ab", "a?[ab]*b+", "1", |
|
|
46 | "aaaaaaaaaaaaaaaaaaaaaaa", "a*b", "0", |
|
|
47 | "aaaaaaaaabaaabbaaaaaa", "a*b+a*b*ba+", "1", |
|
|
48 | "ababababab", "a.*", "1", |
|
|
49 | "baaaaaaaab", "a*", "0", |
|
|
50 | NULL |
|
|
51 | }; |
|
|
52 | |
|
|
53 | int main() { |
|
|
54 | regex_data_t tmp_data; |
|
|
55 | char buf[256], string[100], regex[100]; |
|
|
56 | int i; |
|
|
57 | |
|
|
58 | for (i = 0; NULL != test_data[i]; i += 3) { |
|
|
59 | snprintf(string, 99, "'%s'", test_data[i]); |
|
|
60 | snprintf(regex, 99, "'%s'", test_data[i + 1]); |
|
|
61 | snprintf(buf, 255, "string = %s, pattern = %s", string, regex); |
|
|
62 | printf("%-60s", buf); |
|
|
63 | DO_REGEX(tmp_data, test_data[i], test_data[i + 1], error); |
|
|
64 | if (REGEX_MATCH(tmp_data) && (REGEX_FULL_MATCH == tmp_data.match)) { |
|
|
65 | if (0 != strncmp(test_data[i + 2], "1", 1)) |
|
|
66 | goto error; |
|
|
67 | } else { |
|
|
68 | if (0 != strncmp(test_data[i + 2], "0", 1)) |
|
|
69 | goto error; |
|
|
70 | } |
|
|
71 | |
|
|
72 | printf("%s\n", "[ \033[32;01mOK\033[0m ]"); |
|
|
73 | } |
|
|
74 | |
|
|
75 | return 0; |
|
|
76 | error: |
|
|
77 | printf("%s\n", "[ \033[31;01m!!\033[0m ]"); |
|
|
78 | |
|
|
79 | return 1; |
|
|
80 | } |
|
|