aboutsummaryrefslogtreecommitdiff
path: root/src/regex/test_regex_eval_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/regex/test_regex_eval_api.c')
-rw-r--r--src/regex/test_regex_eval_api.c385
1 files changed, 0 insertions, 385 deletions
diff --git a/src/regex/test_regex_eval_api.c b/src/regex/test_regex_eval_api.c
deleted file mode 100644
index be3649dbd..000000000
--- a/src/regex/test_regex_eval_api.c
+++ /dev/null
@@ -1,385 +0,0 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2012 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20/**
21 * @file regex/test_regex_eval_api.c
22 * @brief test for regex.c
23 * @author Maximilian Szengel
24 */
25#include <regex.h>
26#include <time.h>
27#include "platform.h"
28#include "regex_internal_lib.h"
29#include "regex_test_lib.h"
30#include "regex_internal.h"
31
32enum Match_Result
33{
34 match = 0,
35 nomatch = 1
36};
37
38struct Regex_String_Pair
39{
40 char *regex;
41 int string_count;
42 char *strings[20];
43 enum Match_Result expected_results[20];
44};
45
46
47/**
48 * Random regex test. Generate a random regex as well as 'str_count' strings to
49 * match it against. Will match using GNUNET_REGEX implementation and compare
50 * the result to glibc regex result. 'rx_length' has to be smaller then
51 * 'max_str_len'.
52 *
53 * @param rx_length length of the regular expression.
54 * @param max_str_len maximum length of the random strings.
55 * @param str_count number of generated random strings.
56 *
57 * @return 0 on success, non 0 otherwise.
58 */
59int
60test_random (unsigned int rx_length, unsigned int max_str_len,
61 unsigned int str_count)
62{
63 unsigned int i;
64 char *rand_rx;
65 char *matching_str;
66 int eval;
67 int eval_check;
68 int eval_canonical;
69 int eval_canonical_check;
70 struct REGEX_INTERNAL_Automaton *dfa;
71 regex_t rx;
72 regmatch_t matchptr[1];
73 char error[200];
74 int result;
75 char *canonical_regex = NULL;
76
77 /* At least one string is needed for matching */
78 GNUNET_assert (str_count > 0);
79 /* The string should be at least as long as the regex itself */
80 GNUNET_assert (max_str_len >= rx_length);
81
82 /* Generate random regex and a string that matches the regex */
83 matching_str = GNUNET_malloc (rx_length + 1);
84 rand_rx = REGEX_TEST_generate_random_regex (rx_length, matching_str);
85
86 /* Now match */
87 result = 0;
88 for (i = 0; i < str_count; i++)
89 {
90 if (0 < i)
91 {
92 matching_str = REGEX_TEST_generate_random_string (max_str_len);
93 }
94
95 /* Match string using DFA */
96 dfa = REGEX_INTERNAL_construct_dfa (rand_rx, strlen (rand_rx), 0);
97 if (NULL == dfa)
98 {
99 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Constructing DFA failed\n");
100 goto error;
101 }
102
103 eval = REGEX_INTERNAL_eval (dfa, matching_str);
104 /* save the canonical regex for later comparison */
105 canonical_regex = GNUNET_strdup (REGEX_INTERNAL_get_canonical_regex (dfa));
106 REGEX_INTERNAL_automaton_destroy (dfa);
107
108 /* Match string using glibc regex */
109 if (0 != regcomp (&rx, rand_rx, REG_EXTENDED))
110 {
111 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
112 "Could not compile regex using regcomp: %s\n", rand_rx);
113 goto error;
114 }
115
116 eval_check = regexec (&rx, matching_str, 1, matchptr, 0);
117 regfree (&rx);
118
119 /* We only want to match the whole string, because that's what our DFA does,
120 * too. */
121 if ((eval_check == 0) &&
122 ((matchptr[0].rm_so != 0) || (matchptr[0].rm_eo != strlen (
123 matching_str)) ))
124 eval_check = 1;
125
126 /* Match canonical regex */
127 dfa =
128 REGEX_INTERNAL_construct_dfa (canonical_regex, strlen (canonical_regex),
129 0);
130 if (NULL == dfa)
131 {
132 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Constructing DFA failed\n");
133 goto error;
134 }
135
136 eval_canonical = REGEX_INTERNAL_eval (dfa, matching_str);
137 REGEX_INTERNAL_automaton_destroy (dfa);
138
139 if (0 != regcomp (&rx, canonical_regex, REG_EXTENDED))
140 {
141 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
142 "Could not compile regex using regcomp: %s\n",
143 canonical_regex);
144 goto error;
145 }
146
147 eval_canonical_check = regexec (&rx, matching_str, 1, matchptr, 0);
148 regfree (&rx);
149
150 /* We only want to match the whole string, because that's what our DFA does,
151 * too. */
152 if ((eval_canonical_check == 0) &&
153 ((matchptr[0].rm_so != 0) || (matchptr[0].rm_eo != strlen (
154 matching_str)) ))
155 eval_canonical_check = 1;
156
157 /* compare results */
158 if ((eval_check != eval) || (eval_canonical != eval_canonical_check) )
159 {
160 regerror (eval_check, &rx, error, sizeof error);
161 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
162 "Unexpected result:\nregex: %s\ncanonical_regex: %s\n\
163 string: %s\ngnunet regex: %i\nglibc regex: %i\n\
164 canonical regex: %i\ncanonical regex glibc: %i\n\
165 glibc error: %s\n\n", rand_rx, canonical_regex, matching_str,
166 eval, eval_check, eval_canonical, eval_canonical_check,
167 error);
168 result += 1;
169 }
170 GNUNET_free (canonical_regex);
171 GNUNET_free (matching_str);
172 canonical_regex = NULL;
173 matching_str = NULL;
174 }
175
176 GNUNET_free (rand_rx);
177
178 return result;
179
180error:
181 GNUNET_free (matching_str);
182 GNUNET_free (rand_rx);
183 GNUNET_free (canonical_regex);
184 return -1;
185}
186
187
188/**
189 * Automaton test that compares the result of matching regular expression 'rx'
190 * with the strings and expected results in 'rxstr' with the result of matching
191 * the same strings with glibc regex.
192 *
193 * @param a automaton.
194 * @param rx compiled glibc regex.
195 * @param rxstr regular expression and strings with expected results to
196 * match against.
197 *
198 * @return 0 on successful, non 0 otherwise
199 */
200int
201test_automaton (struct REGEX_INTERNAL_Automaton *a, regex_t *rx,
202 struct Regex_String_Pair *rxstr)
203{
204 int result;
205 int eval;
206 int eval_check;
207 char error[200];
208 regmatch_t matchptr[1];
209 int i;
210
211 if (NULL == a)
212 {
213 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Automaton was NULL\n");
214 return 1;
215 }
216
217 result = 0;
218
219 for (i = 0; i < rxstr->string_count; i++)
220 {
221 eval = REGEX_INTERNAL_eval (a, rxstr->strings[i]);
222 eval_check = regexec (rx, rxstr->strings[i], 1, matchptr, 0);
223
224 /* We only want to match the whole string, because that's what our DFA does,
225 * too. */
226 if ((eval_check == 0) &&
227 ((matchptr[0].rm_so != 0) ||
228 (matchptr[0].rm_eo != strlen (rxstr->strings[i])) ))
229 eval_check = 1;
230
231 if (((rxstr->expected_results[i] == match) && ((0 != eval) || (0 !=
232 eval_check) ))
233 || ((rxstr->expected_results[i] == nomatch) &&
234 ((0 == eval) || (0 == eval_check) )))
235 {
236 result = 1;
237 regerror (eval_check, rx, error, sizeof error);
238 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
239 "Unexpected result:\nregex: %s\ncanonical_regex: %s\n"
240 "string: %s\nexpected result: %i\n"
241 "gnunet regex: %i\nglibc regex: %i\nglibc error: %s\n"
242 "rm_so: %i\nrm_eo: %i\n\n", rxstr->regex,
243 REGEX_INTERNAL_get_canonical_regex (a), rxstr->strings[i],
244 rxstr->expected_results[i], eval, eval_check, error,
245 matchptr[0].rm_so, matchptr[0].rm_eo);
246 }
247 }
248 return result;
249}
250
251
252int
253main (int argc, char *argv[])
254{
255 GNUNET_log_setup ("test-regex", "WARNING", NULL);
256
257 struct REGEX_INTERNAL_Automaton *a;
258 regex_t rx;
259 int i;
260 int check_nfa;
261 int check_dfa;
262 int check_rand;
263 char *check_proof;
264
265 struct Regex_String_Pair rxstr[19] = {
266 { "ab?(abcd)?", 5,
267 { "ababcd", "abab", "aabcd", "a", "abb" },
268 { match, nomatch, match, match, nomatch } },
269 { "ab(c|d)+c*(a(b|c)d)+", 5,
270 { "abcdcdcdcdddddabd", "abcd",
271 "abcddddddccccccccccccccccccccccccabdacdabd",
272 "abccccca", "abcdcdcdccdabdabd" },
273 { match, nomatch, match, nomatch, match } },
274 { "ab+c*(a(bx|c)d)+", 5,
275 { "abcdcdcdcdddddabd", "abcd",
276 "abcddddddccccccccccccccccccccccccabdacdabd",
277 "abccccca", "abcdcdcdccdabdabd" },
278 { nomatch, nomatch, nomatch, nomatch, nomatch } },
279 { "a+X*y+c|p|R|Z*K*y*R+w|Y*6+n+h*k*w+V*F|W*B*e*", 1,
280 { "kaXycQepRZKyRwY6nhkwVFWBegNVtLPj39XhJJ6bEifRSZRYZg" },
281 { nomatch } },
282 {
283 "k|a+X*y+c|Q*e|p|R|Z*K*y*R+w|Y*6+n+h*k*w+V*F|W*B*e*g|N+V|t+L|P*j*3*9+X*h*J|J*6|b|E*i*f*R+S|Z|R|Y*Z|g*",
284 1,
285 { "kaXycQepRZKyRwY6nhkwVFWBegNVtLPj39XhJJ6bEifRSZRYZg" },
286 { nomatch }
287 },
288 {
289 "F?W+m+2*6*c*s|P?U?a|B|y*i+t+A|V|6*C*7*e?Z*n*i|J?5+g?W*V?7*j?p?1|r?B?C+E+3+6*i+W*P?K?0|D+7?y*m+3?g?K?",
290 1,
291 { "osfjsodfonONONOnosndfsdnfsd" },
292 { nomatch }
293 },
294 {
295 "V|M*o?x*p*d+h+b|E*m?h?Y*E*O?W*W*P+o?Z+H*M|I*q+C*a+5?5*9|b?z|G*y*k?R|p+u|8*h?B+l*H|e|L*O|1|F?v*0?5|C+",
296 1,
297 { "VMoxpdhbEmhYEOWWPoZHMIqCa559bzGykRpu8hBlHeLO1Fv05C" },
298 { nomatch }
299 },
300 { "(bla)*", 8,
301 { "", "bla", "blabla", "bl", "la", "b", "l", "a" },
302 { match, match, match, nomatch, nomatch, nomatch, nomatch, nomatch } },
303 { "ab(c|d)+c*(a(b|c)+d)+(bla)(bla)*", 8,
304 { "ab", "abcabdbla", "abdcccccccccccabcbccdblablabla", "bl", "la", "b",
305 "l",
306 "a" },
307 { nomatch, match, match, nomatch, nomatch, nomatch, nomatch, nomatch } },
308 { "a|aa*a", 6,
309 { "", "a", "aa", "aaa", "aaaa", "aaaaa" },
310 { nomatch, match, match, match, match, match } },
311 { "ab(c|d)+c*(a(b|c)+d)+(bla)+", 1,
312 { "abcabdblaacdbla" },
313 { nomatch } },
314 { "(ac|b)+", 8,
315 { "b", "bb", "ac", "", "acb", "bacbacac", "acacac", "abc" },
316 { match, match, match, nomatch, match, match, match, nomatch } },
317 { "(ab|c)+", 7,
318 { "", "ab", "c", "abc", "ababcc", "acc", "abac" },
319 { nomatch, match, match, match, match, nomatch, nomatch } },
320 { "((j|2j)K|(j|2j)AK|(j|2j)(D|e|(j|2j)A(D|e))D*K)", 1,
321 { "", "2j2jADK", "j2jADK" },
322 { nomatch, match, match } },
323 { "((j|2j)K|(j|2j)(D|e|((j|2j)j|(j|2j)2j)A(D|e))D*K|(j|2j)AK)", 2,
324 { "", "2j2jjADK", "j2jADK" },
325 { nomatch, match, match } },
326 { "ab(c|d)+c*(a(b|c)d)+", 1,
327 { "abacd" },
328 { nomatch } },
329 { "d|5kl", 1,
330 { "d5kl" },
331 { nomatch } },
332 { "a()b", 1,
333 { "ab" },
334 { match } },
335 {
336 "GNVPN-0001-PAD(001110101001001010(0|1)*|001110101001001010000(0|1)*|001110101001001010001(0|1)*|001110101001001010010(0|1)*|001110101001001010011(0|1)*|001110101001001010100(0|1)*|001110101001001010101(0|1)*|001110101001001010110(0|1)*|001110101001001010111(0|1)*|0011101010110110(0|1)*|001110101011011000000(0|1)*|001110101011011000001(0|1)*|001110101011011000010(0|1)*|001110101011011000011(0|1)*|001110101011011000100(0|1)*|001110101011011000101(0|1)*|001110101011011000110(0|1)*|001110101011011000111(0|1)*|001110101011011001000(0|1)*|001110101011011001001(0|1)*|001110101011011001010(0|1)*|001110101011011001011(0|1)*|001110101011011001100(0|1)*|001110101011011001101(0|1)*|001110101011011001110(0|1)*|001110101011011001111(0|1)*|001110101011011010000(0|1)*|001110101011011010001(0|1)*|001110101011011010010(0|1)*|001110101011011010011(0|1)*|001110101011011010100(0|1)*|001110101011011010101(0|1)*|001110101011011010110(0|1)*|001110101011011010111(0|1)*|001110101011011011000(0|1)*|001110101011011011001(0|1)*|001110101011011011010(0|1)*|001110101011011011011(0|1)*|001110101011011011100(0|1)*|001110101011011011101(0|1)*|001110101011011011110(0|1)*|001110101011011011111(0|1)*|0011101110111101(0|1)*|001110111011110100000(0|1)*|001110111011110100001(0|1)*|001110111011110100010(0|1)*|001110111011110100011(0|1)*|001110111011110100100(0|1)*|001110111011110100101(0|1)*|001110111011110100110(0|1)*|001110111011110100111(0|1)*|001110111011110101000(0|1)*|001110111011110101001(0|1)*|001110111011110101010(0|1)*|001110111011110101011(0|1)*|001110111011110101100(0|1)*|001110111011110101101(0|1)*|001110111011110101110(0|1)*|001110111011110101111(0|1)*|001110111011110110000(0|1)*|001110111011110110001(0|1)*|001110111011110110010(0|1)*|001110111011110110011(0|1)*|001110111011110110100(0|1)*|001110111011110110101(0|1)*|001110111011110110110(0|1)*|001110111011110110111(0|1)*|001110111011110111000(0|1)*|001110111011110111001(0|1)*|001110111011110111010(0|1)*|001110111011110111011(0|1)*|001110111011110111100(0|1)*|001110111011110111101(0|1)*|001110111011110111110(0|1)*|0111010001010110(0|1)*|011101000101011000000(0|1)*|011101000101011000001(0|1)*|011101000101011000010(0|1)*|011101000101011000011(0|1)*|011101000101011000100(0|1)*|011101000101011000101(0|1)*|011101000101011000110(0|1)*|011101000101011000111(0|1)*|011101000101011001000(0|1)*|011101000101011001001(0|1)*|011101000101011001010(0|1)*|011101000101011001011(0|1)*|011101000101011001100(0|1)*|011101000101011001101(0|1)*|011101000101011001110(0|1)*|011101000101011001111(0|1)*|011101000101011010000(0|1)*|011101000101011010001(0|1)*|011101000101011010010(0|1)*|011101000101011010011(0|1)*|011101000101011010100(0|1)*|011101000101011010101(0|1)*|011101000101011010110(0|1)*|011101000101011010111(0|1)*|011101000101011011000(0|1)*|011101000101011011001(0|1)*|011101000101011011010(0|1)*|011101000101011011011(0|1)*|011101000101011011100(0|1)*|011101000101011011101(0|1)*|011101000101011011110(0|1)*|011101000101011011111(0|1)*|0111010001010111(0|1)*|011101000101011100000(0|1)*|011101000101011100001(0|1)*|011101000101011100010(0|1)*|011101000101011100011(0|1)*|011101000101011100100(0|1)*|011101000101011100101(0|1)*|011101000101011100110(0|1)*|011101000101011100111(0|1)*|011101000101011101000(0|1)*|011101000101011101001(0|1)*|011101000101011101010(0|1)*|011101000101011101011(0|1)*|011101000101011101100(0|1)*|011101000101011101101(0|1)*|011101000101011101110(0|1)*|011101000101011101111(0|1)*|011101000101011110000(0|1)*|011101000101011110001(0|1)*|011101000101011110010(0|1)*|011101000101011110011(0|1)*|011101000101011110100(0|1)*|011101000101011110101(0|1)*|011101000101011110110(0|1)*|011101000101011110111(0|1)*|011101000101011111000(0|1)*|011101000101011111001(0|1)*|011101000101011111010(0|1)*|011101000101011111011(0|1)*|011101000101011111100(0|1)*|011101000101011111101(0|1)*|011101000101011111110(0|1)*|011101000101011111111(0|1)*|0111010001011000(0|1)*|011101000101100000000(0|1)*|011101000101100000001(0|1)*|011101000101100000010(0|1)*|011101000101100000011(0|1)*|011101000101100000100(0|1)*|011101000101100000101(0|1)*|011101000101100000110(0|1)*|011101000101100000111(0|1)*|011101000101100001000(0|1)*|011101000101100001001(0|1)*|011101000101100001010(0|1)*|011101000101100001011(0|1)*|011101000101100001100(0|1)*|011101000101100001101(0|1)*|011101000101100001110(0|1)*|011101000101100001111(0|1)*|011101000101100010000(0|1)*|011101000101100010001(0|1)*|011101000101100010010(0|1)*|011101000101100010011(0|1)*|011101000101100010100(0|1)*|011101000101100010101(0|1)*|011101000101100010110(0|1)*|011101000101100010111(0|1)*|011101000101100011000(0|1)*|011101000101100011001(0|1)*|011101000101100011010(0|1)*|011101000101100011011(0|1)*|011101000101100011100(0|1)*|011101000101100011101(0|1)*|011101000101100011110(0|1)*|011101000101100011111(0|1)*|01110100010110010(0|1)*|011101000101100100000(0|1)*|011101000101100100001(0|1)*|011101000101100100010(0|1)*|011101000101100100011(0|1)*|011101000101100100100(0|1)*|011101000101100100101(0|1)*|011101000101100100110(0|1)*|011101000101100100111(0|1)*|011101000101100101000(0|1)*|011101000101100101001(0|1)*|011101000101100101010(0|1)*|011101000101100101011(0|1)*|011101000101100101100(0|1)*|011101000101100101101(0|1)*|011101000101100101110(0|1)*|011101000101100101111(0|1)*|011101000101100101111000(0|1)*|1100101010011100(0|1)*|110010101001110000000(0|1)*|110010101001110000000001(0|1)*|110010101001110000000010(0|1)*|110010101001110000000110(0|1)*|110010101001110000001(0|1)*|110010101001110000001000(0|1)*|110010101001110000001001(0|1)*|110010101001110000001010(0|1)*|110010101001110000001011(0|1)*|110010101001110000001101(0|1)*|110010101001110000001110(0|1)*|110010101001110000010(0|1)*|110010101001110000011(0|1)*|110010101001110000100(0|1)*|110010101001110000101(0|1)*|110010101001110000110(0|1)*|110010101001110000111(0|1)*|110010101001110001000(0|1)*|110010101001110001001(0|1)*|110010101001110001010(0|1)*|110010101001110001011(0|1)*|110010101001110001100(0|1)*|110010101001110001101(0|1)*|110010101001110001110(0|1)*|110010101001110001111(0|1)*|110010101001110010000(0|1)*|110010101001110010001(0|1)*|110010101001110010010(0|1)*|110010101001110010011(0|1)*|110010101001110010100(0|1)*|110010101001110010101(0|1)*|110010101001110010110(0|1)*|110010101001110010111(0|1)*|110010101001110011000(0|1)*|110010101001110011001(0|1)*|110010101001110011010(0|1)*|110010101001110011011(0|1)*|110010101001110011100(0|1)*|110010101001110011101(0|1)*|110010101001110011110(0|1)*|110010101001110011111(0|1)*|1101101010111010(0|1)*|110110101011101000000(0|1)*|110110101011101000000001(0|1)*|110110101011101000001000(0|1)*|110110101011101000001001(0|1)*|110110101011101000001010(0|1)*|110110101011101000001011(0|1)*|110110101011101000001100(0|1)*|110110101011101000001110(0|1)*|110110101011101000001111(0|1)*|110110101011101000010(0|1)*|110110101011101000010000(0|1)*|110110101011101000010001(0|1)*|110110101011101000010010(0|1)*|110110101011101000010011(0|1)*|110110101011101000011(0|1)*|110110101011101000100(0|1)*|110110101011101000101(0|1)*|110110101011101000110(0|1)*|110110101011101000111(0|1)*|110110101011101001000(0|1)*|110110101011101001001(0|1)*|110110101011101001010(0|1)*|110110101011101001011(0|1)*|110110101011101001100(0|1)*|110110101011101001101(0|1)*|110110101011101001110(0|1)*|110110101011101001111(0|1)*|110110101011101010000(0|1)*|110110101011101010001(0|1)*|110110101011101010010(0|1)*|110110101011101010011(0|1)*|110110101011101010100(0|1)*|110110101011101010101(0|1)*|110110101011101010110(0|1)*|110110101011101010111(0|1)*|110110101011101011000(0|1)*|110110101011101011001(0|1)*|110110101011101011010(0|1)*|110110101011101011011(0|1)*|110110101011101011100(0|1)*|110110101011101011101(0|1)*|110110101011101011110(0|1)*|110110101011101011111(0|1)*|1101101011010100(0|1)*|110110101101010000000(0|1)*|110110101101010000001(0|1)*|110110101101010000010(0|1)*|110110101101010000011(0|1)*|110110101101010000100(0|1)*|110110101101010000101(0|1)*|110110101101010000110(0|1)*|110110101101010000111(0|1)*|110110101101010001000(0|1)*|110110101101010001001(0|1)*|110110101101010001010(0|1)*|110110101101010001011(0|1)*|110110101101010001100(0|1)*|110110101101010001101(0|1)*|110110101101010001110(0|1)*|110110101101010001111(0|1)*|110110101101010010000(0|1)*|110110101101010010001(0|1)*|110110101101010010010(0|1)*|110110101101010010011(0|1)*|110110101101010010100(0|1)*|1101101011010100101000(0|1)*|110110101101010010101(0|1)*|110110101101010010110(0|1)*|110110101101010010111(0|1)*|110110101101010011000(0|1)*|110110101101010011010(0|1)*|110110101101010011011(0|1)*|110110101101010011100(0|1)*|110110101101010011101(0|1)*|110110101101010011110(0|1)*|110110101101010011111(0|1)*|1101111010100100(0|1)*|110111101010010000000(0|1)*|110111101010010000001(0|1)*|110111101010010000010(0|1)*|110111101010010000011(0|1)*|110111101010010000100(0|1)*|110111101010010000101(0|1)*|110111101010010000110(0|1)*|110111101010010000111(0|1)*|110111101010010001000(0|1)*|110111101010010001001(0|1)*|110111101010010001010(0|1)*|110111101010010001011(0|1)*|110111101010010001100(0|1)*|110111101010010001101(0|1)*|110111101010010001110(0|1)*|110111101010010001111(0|1)*|110111101010010010000(0|1)*|110111101010010010001(0|1)*|110111101010010010010(0|1)*|110111101010010010011(0|1)*|110111101010010010100(0|1)*|110111101010010010101(0|1)*|110111101010010010110(0|1)*|110111101010010010111(0|1)*|110111101010010011000(0|1)*|110111101010010011001(0|1)*|110111101010010011010(0|1)*|110111101010010011011(0|1)*|110111101010010011100(0|1)*|110111101010010011101(0|1)*|110111101010010011110(0|1)*|110111101010010011111(0|1)*|11011110101001010(0|1)*|110111101010010100000(0|1)*|110111101010010100001(0|1)*|110111101010010100010(0|1)*|110111101010010100011(0|1)*|110111101010010100100(0|1)*|110111101010010100101(0|1)*|110111101010010100110(0|1)*|110111101010010100111(0|1)*|110111101010010101000(0|1)*|110111101010010101001(0|1)*|110111101010010101010(0|1)*|110111101010010101011(0|1)*|110111101010010101100(0|1)*|110111101010010101101(0|1)*|110111101010010101110(0|1)*|110111101010010101111(0|1)*)",
337 2,
338 { "GNVPN-0001-PAD1101111010100101011101010101010101",
339 "GNVPN-0001-PAD11001010100111000101101010101" },
340 { match, match }
341 }
342 };
343
344 check_nfa = 0;
345 check_dfa = 0;
346 check_rand = 0;
347
348 for (i = 0; i < 19; i++)
349 {
350 if (0 != regcomp (&rx, rxstr[i].regex, REG_EXTENDED))
351 {
352 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
353 "Could not compile regex using regcomp()\n");
354 return 1;
355 }
356
357 /* NFA test */
358 a = REGEX_INTERNAL_construct_nfa (rxstr[i].regex, strlen (rxstr[i].regex));
359 check_nfa += test_automaton (a, &rx, &rxstr[i]);
360 REGEX_INTERNAL_automaton_destroy (a);
361
362 /* DFA test */
363 a = REGEX_INTERNAL_construct_dfa (rxstr[i].regex, strlen (rxstr[i].regex),
364 0);
365 check_dfa += test_automaton (a, &rx, &rxstr[i]);
366 check_proof = GNUNET_strdup (REGEX_INTERNAL_get_canonical_regex (a));
367 REGEX_INTERNAL_automaton_destroy (a);
368
369 a = REGEX_INTERNAL_construct_dfa (check_proof, strlen (check_proof), 0);
370 check_dfa += test_automaton (a, &rx, &rxstr[i]);
371 REGEX_INTERNAL_automaton_destroy (a);
372 if (0 != check_dfa)
373 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "check_proof: %s\n", check_proof);
374 GNUNET_free (check_proof);
375
376 regfree (&rx);
377 }
378
379 /* Random tests */
380 srand (time (NULL));
381 for (i = 0; i < 20; i++)
382 check_rand += test_random (50, 60, 10);
383
384 return check_nfa + check_dfa + check_rand;
385}