summaryrefslogtreecommitdiff
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.c335
1 files changed, 177 insertions, 158 deletions
diff --git a/src/regex/test_regex_eval_api.c b/src/regex/test_regex_eval_api.c
index 88a05f912..f6078c7ef 100644
--- a/src/regex/test_regex_eval_api.c
+++ b/src/regex/test_regex_eval_api.c
@@ -29,12 +29,14 @@
29#include "regex_test_lib.h" 29#include "regex_test_lib.h"
30#include "regex_internal.h" 30#include "regex_internal.h"
31 31
32enum Match_Result { 32enum Match_Result
33{
33 match = 0, 34 match = 0,
34 nomatch = 1 35 nomatch = 1
35}; 36};
36 37
37struct Regex_String_Pair { 38struct Regex_String_Pair
39{
38 char *regex; 40 char *regex;
39 int string_count; 41 int string_count;
40 char *strings[20]; 42 char *strings[20];
@@ -55,8 +57,8 @@ struct Regex_String_Pair {
55 * @return 0 on success, non 0 otherwise. 57 * @return 0 on success, non 0 otherwise.
56 */ 58 */
57int 59int
58test_random(unsigned int rx_length, unsigned int max_str_len, 60test_random (unsigned int rx_length, unsigned int max_str_len,
59 unsigned int str_count) 61 unsigned int str_count)
60{ 62{
61 unsigned int i; 63 unsigned int i;
62 char *rand_rx; 64 char *rand_rx;
@@ -73,108 +75,112 @@ test_random(unsigned int rx_length, unsigned int max_str_len,
73 char *canonical_regex = NULL; 75 char *canonical_regex = NULL;
74 76
75 /* At least one string is needed for matching */ 77 /* At least one string is needed for matching */
76 GNUNET_assert(str_count > 0); 78 GNUNET_assert (str_count > 0);
77 /* The string should be at least as long as the regex itself */ 79 /* The string should be at least as long as the regex itself */
78 GNUNET_assert(max_str_len >= rx_length); 80 GNUNET_assert (max_str_len >= rx_length);
79 81
80 /* Generate random regex and a string that matches the regex */ 82 /* Generate random regex and a string that matches the regex */
81 matching_str = GNUNET_malloc(rx_length + 1); 83 matching_str = GNUNET_malloc (rx_length + 1);
82 rand_rx = REGEX_TEST_generate_random_regex(rx_length, matching_str); 84 rand_rx = REGEX_TEST_generate_random_regex (rx_length, matching_str);
83 85
84 /* Now match */ 86 /* Now match */
85 result = 0; 87 result = 0;
86 for (i = 0; i < str_count; i++) 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)
87 { 98 {
88 if (0 < i) 99 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Constructing DFA failed\n");
89 { 100 goto error;
90 matching_str = REGEX_TEST_generate_random_string(max_str_len); 101 }
91 } 102
92 103 eval = REGEX_INTERNAL_eval (dfa, matching_str);
93 /* Match string using DFA */ 104 /* save the canonical regex for later comparison */
94 dfa = REGEX_INTERNAL_construct_dfa(rand_rx, strlen(rand_rx), 0); 105 canonical_regex = GNUNET_strdup (REGEX_INTERNAL_get_canonical_regex (dfa));
95 if (NULL == dfa) 106 REGEX_INTERNAL_automaton_destroy (dfa);
96 { 107
97 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Constructing DFA failed\n"); 108 /* Match string using glibc regex */
98 goto error; 109 if (0 != regcomp (&rx, rand_rx, REG_EXTENDED))
99 } 110 {
100 111 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
101 eval = REGEX_INTERNAL_eval(dfa, matching_str); 112 "Could not compile regex using regcomp: %s\n", rand_rx);
102 /* save the canonical regex for later comparison */ 113 goto error;
103 canonical_regex = GNUNET_strdup(REGEX_INTERNAL_get_canonical_regex(dfa)); 114 }
104 REGEX_INTERNAL_automaton_destroy(dfa); 115
105 116 eval_check = regexec (&rx, matching_str, 1, matchptr, 0);
106 /* Match string using glibc regex */ 117 regfree (&rx);
107 if (0 != regcomp(&rx, rand_rx, REG_EXTENDED)) 118
108 { 119 /* We only want to match the whole string, because that's what our DFA does,
109 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 120 * too. */
110 "Could not compile regex using regcomp: %s\n", rand_rx); 121 if ((eval_check == 0) &&
111 goto error; 122 ((matchptr[0].rm_so != 0) ||(matchptr[0].rm_eo != strlen (
112 } 123 matching_str)) ))
113 124 eval_check = 1;
114 eval_check = regexec(&rx, matching_str, 1, matchptr, 0); 125
115 regfree(&rx); 126 /* Match canonical regex */
116 127 dfa =
117 /* We only want to match the whole string, because that's what our DFA does, 128 REGEX_INTERNAL_construct_dfa (canonical_regex, strlen (canonical_regex),
118 * too. */ 129 0);
119 if (eval_check == 0 && 130 if (NULL == dfa)
120 (matchptr[0].rm_so != 0 || matchptr[0].rm_eo != strlen(matching_str))) 131 {
121 eval_check = 1; 132 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Constructing DFA failed\n");
122 133 goto error;
123 /* Match canonical regex */ 134 }
124 dfa = 135
125 REGEX_INTERNAL_construct_dfa(canonical_regex, strlen(canonical_regex), 136 eval_canonical = REGEX_INTERNAL_eval (dfa, matching_str);
126 0); 137 REGEX_INTERNAL_automaton_destroy (dfa);
127 if (NULL == dfa) 138
128 { 139 if (0 != regcomp (&rx, canonical_regex, REG_EXTENDED))
129 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Constructing DFA failed\n"); 140 {
130 goto error; 141 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
131 } 142 "Could not compile regex using regcomp: %s\n",
132 143 canonical_regex);
133 eval_canonical = REGEX_INTERNAL_eval(dfa, matching_str); 144 goto error;
134 REGEX_INTERNAL_automaton_destroy(dfa); 145 }
135 146
136 if (0 != regcomp(&rx, canonical_regex, REG_EXTENDED)) 147 eval_canonical_check = regexec (&rx, matching_str, 1, matchptr, 0);
137 { 148 regfree (&rx);
138 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 149
139 "Could not compile regex using regcomp: %s\n", 150 /* We only want to match the whole string, because that's what our DFA does,
140 canonical_regex); 151 * too. */
141 goto error; 152 if ((eval_canonical_check == 0) &&
142 } 153 ((matchptr[0].rm_so != 0) ||(matchptr[0].rm_eo != strlen (
143 154 matching_str)) ))
144 eval_canonical_check = regexec(&rx, matching_str, 1, matchptr, 0); 155 eval_canonical_check = 1;
145 regfree(&rx); 156
146 157 /* compare results */
147 /* We only want to match the whole string, because that's what our DFA does, 158 if ((eval_check != eval) ||(eval_canonical != eval_canonical_check) )
148 * too. */ 159 {
149 if (eval_canonical_check == 0 && 160 regerror (eval_check, &rx, error, sizeof error);
150 (matchptr[0].rm_so != 0 || matchptr[0].rm_eo != strlen(matching_str))) 161 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
151 eval_canonical_check = 1; 162 "Unexpected result:\nregex: %s\ncanonical_regex: %s\n\
152
153 /* compare results */
154 if (eval_check != eval || eval_canonical != eval_canonical_check)
155 {
156 regerror(eval_check, &rx, error, sizeof error);
157 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Unexpected result:\nregex: %s\ncanonical_regex: %s\n\
158 string: %s\ngnunet regex: %i\nglibc regex: %i\n\ 163 string: %s\ngnunet regex: %i\nglibc regex: %i\n\
159 canonical regex: %i\ncanonical regex glibc: %i\n\ 164 canonical regex: %i\ncanonical regex glibc: %i\n\
160 glibc error: %s\n\n", rand_rx, canonical_regex, matching_str, 165 glibc error: %s\n\n", rand_rx, canonical_regex, matching_str,
161 eval, eval_check, eval_canonical, eval_canonical_check, error); 166 eval, eval_check, eval_canonical, eval_canonical_check,
162 result += 1; 167 error);
163 } 168 result += 1;
164 GNUNET_free(canonical_regex);
165 GNUNET_free(matching_str);
166 canonical_regex = NULL;
167 matching_str = NULL;
168 } 169 }
170 GNUNET_free (canonical_regex);
171 GNUNET_free (matching_str);
172 canonical_regex = NULL;
173 matching_str = NULL;
174 }
169 175
170 GNUNET_free(rand_rx); 176 GNUNET_free (rand_rx);
171 177
172 return result; 178 return result;
173 179
174error: 180error:
175 GNUNET_free_non_null(matching_str); 181 GNUNET_free_non_null (matching_str);
176 GNUNET_free_non_null(rand_rx); 182 GNUNET_free_non_null (rand_rx);
177 GNUNET_free_non_null(canonical_regex); 183 GNUNET_free_non_null (canonical_regex);
178 return -1; 184 return -1;
179} 185}
180 186
@@ -191,8 +197,8 @@ error:
191 * @return 0 on successfull, non 0 otherwise 197 * @return 0 on successfull, non 0 otherwise
192 */ 198 */
193int 199int
194test_automaton(struct REGEX_INTERNAL_Automaton *a, regex_t * rx, 200test_automaton (struct REGEX_INTERNAL_Automaton *a, regex_t *rx,
195 struct Regex_String_Pair *rxstr) 201 struct Regex_String_Pair *rxstr)
196{ 202{
197 int result; 203 int result;
198 int eval; 204 int eval;
@@ -202,48 +208,49 @@ test_automaton(struct REGEX_INTERNAL_Automaton *a, regex_t * rx,
202 int i; 208 int i;
203 209
204 if (NULL == a) 210 if (NULL == a)
205 { 211 {
206 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Automaton was NULL\n"); 212 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Automaton was NULL\n");
207 return 1; 213 return 1;
208 } 214 }
209 215
210 result = 0; 216 result = 0;
211 217
212 for (i = 0; i < rxstr->string_count; i++) 218 for (i = 0; i < rxstr->string_count; i++)
219 {
220 eval = REGEX_INTERNAL_eval (a, rxstr->strings[i]);
221 eval_check = regexec (rx, rxstr->strings[i], 1, matchptr, 0);
222
223 /* We only want to match the whole string, because that's what our DFA does,
224 * too. */
225 if ((eval_check == 0) &&
226 ((matchptr[0].rm_so != 0) ||
227 (matchptr[0].rm_eo != strlen (rxstr->strings[i])) ))
228 eval_check = 1;
229
230 if (((rxstr->expected_results[i] == match) && ((0 != eval) ||(0 !=
231 eval_check) ))
232 || ((rxstr->expected_results[i] == nomatch) &&
233 ((0 == eval) ||(0 == eval_check) )))
213 { 234 {
214 eval = REGEX_INTERNAL_eval(a, rxstr->strings[i]); 235 result = 1;
215 eval_check = regexec(rx, rxstr->strings[i], 1, matchptr, 0); 236 regerror (eval_check, rx, error, sizeof error);
216 237 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
217 /* We only want to match the whole string, because that's what our DFA does, 238 "Unexpected result:\nregex: %s\ncanonical_regex: %s\n"
218 * too. */ 239 "string: %s\nexpected result: %i\n"
219 if (eval_check == 0 && 240 "gnunet regex: %i\nglibc regex: %i\nglibc error: %s\n"
220 (matchptr[0].rm_so != 0 || 241 "rm_so: %i\nrm_eo: %i\n\n", rxstr->regex,
221 matchptr[0].rm_eo != strlen(rxstr->strings[i]))) 242 REGEX_INTERNAL_get_canonical_regex (a), rxstr->strings[i],
222 eval_check = 1; 243 rxstr->expected_results[i], eval, eval_check, error,
223 244 matchptr[0].rm_so, matchptr[0].rm_eo);
224 if ((rxstr->expected_results[i] == match && (0 != eval || 0 != eval_check))
225 || (rxstr->expected_results[i] == nomatch &&
226 (0 == eval || 0 == eval_check)))
227 {
228 result = 1;
229 regerror(eval_check, rx, error, sizeof error);
230 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
231 "Unexpected result:\nregex: %s\ncanonical_regex: %s\n"
232 "string: %s\nexpected result: %i\n"
233 "gnunet regex: %i\nglibc regex: %i\nglibc error: %s\n"
234 "rm_so: %i\nrm_eo: %i\n\n", rxstr->regex,
235 REGEX_INTERNAL_get_canonical_regex(a), rxstr->strings[i],
236 rxstr->expected_results[i], eval, eval_check, error,
237 matchptr[0].rm_so, matchptr[0].rm_eo);
238 }
239 } 245 }
246 }
240 return result; 247 return result;
241} 248}
242 249
243int 250int
244main(int argc, char *argv[]) 251main (int argc, char *argv[])
245{ 252{
246 GNUNET_log_setup("test-regex", "WARNING", NULL); 253 GNUNET_log_setup ("test-regex", "WARNING", NULL);
247 254
248 struct REGEX_INTERNAL_Automaton *a; 255 struct REGEX_INTERNAL_Automaton *a;
249 regex_t rx; 256 regex_t rx;
@@ -270,15 +277,24 @@ main(int argc, char *argv[])
270 { "a+X*y+c|p|R|Z*K*y*R+w|Y*6+n+h*k*w+V*F|W*B*e*", 1, 277 { "a+X*y+c|p|R|Z*K*y*R+w|Y*6+n+h*k*w+V*F|W*B*e*", 1,
271 { "kaXycQepRZKyRwY6nhkwVFWBegNVtLPj39XhJJ6bEifRSZRYZg" }, 278 { "kaXycQepRZKyRwY6nhkwVFWBegNVtLPj39XhJJ6bEifRSZRYZg" },
272 { nomatch } }, 279 { nomatch } },
273 { "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*", 1, 280 {
281 "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*",
282 1,
274 { "kaXycQepRZKyRwY6nhkwVFWBegNVtLPj39XhJJ6bEifRSZRYZg" }, 283 { "kaXycQepRZKyRwY6nhkwVFWBegNVtLPj39XhJJ6bEifRSZRYZg" },
275 { nomatch } }, 284 { nomatch }
276 { "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?", 1, 285 },
286 {
287 "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?",
288 1,
277 { "osfjsodfonONONOnosndfsdnfsd" }, 289 { "osfjsodfonONONOnosndfsdnfsd" },
278 { nomatch } }, 290 { nomatch }
279 { "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+", 1, 291 },
292 {
293 "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+",
294 1,
280 { "VMoxpdhbEmhYEOWWPoZHMIqCa559bzGykRpu8hBlHeLO1Fv05C" }, 295 { "VMoxpdhbEmhYEOWWPoZHMIqCa559bzGykRpu8hBlHeLO1Fv05C" },
281 { nomatch } }, 296 { nomatch }
297 },
282 { "(bla)*", 8, 298 { "(bla)*", 8,
283 { "", "bla", "blabla", "bl", "la", "b", "l", "a" }, 299 { "", "bla", "blabla", "bl", "la", "b", "l", "a" },
284 { match, match, match, nomatch, nomatch, nomatch, nomatch, nomatch } }, 300 { match, match, match, nomatch, nomatch, nomatch, nomatch, nomatch } },
@@ -314,11 +330,13 @@ main(int argc, char *argv[])
314 { "a()b", 1, 330 { "a()b", 1,
315 { "ab" }, 331 { "ab" },
316 { match } }, 332 { match } },
317 { "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)*)", 333 {
334 "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)*)",
318 2, 335 2,
319 { "GNVPN-0001-PAD1101111010100101011101010101010101", 336 { "GNVPN-0001-PAD1101111010100101011101010101010101",
320 "GNVPN-0001-PAD11001010100111000101101010101" }, 337 "GNVPN-0001-PAD11001010100111000101101010101" },
321 { match, match } } 338 { match, match }
339 }
322 }; 340 };
323 341
324 check_nfa = 0; 342 check_nfa = 0;
@@ -326,39 +344,40 @@ main(int argc, char *argv[])
326 check_rand = 0; 344 check_rand = 0;
327 345
328 for (i = 0; i < 19; i++) 346 for (i = 0; i < 19; i++)
347 {
348 if (0 != regcomp (&rx, rxstr[i].regex, REG_EXTENDED))
329 { 349 {
330 if (0 != regcomp(&rx, rxstr[i].regex, REG_EXTENDED)) 350 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
331 { 351 "Could not compile regex using regcomp()\n");
332 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 352 return 1;
333 "Could not compile regex using regcomp()\n");
334 return 1;
335 }
336
337 /* NFA test */
338 a = REGEX_INTERNAL_construct_nfa(rxstr[i].regex, strlen(rxstr[i].regex));
339 check_nfa += test_automaton(a, &rx, &rxstr[i]);
340 REGEX_INTERNAL_automaton_destroy(a);
341
342 /* DFA test */
343 a = REGEX_INTERNAL_construct_dfa(rxstr[i].regex, strlen(rxstr[i].regex), 0);
344 check_dfa += test_automaton(a, &rx, &rxstr[i]);
345 check_proof = GNUNET_strdup(REGEX_INTERNAL_get_canonical_regex(a));
346 REGEX_INTERNAL_automaton_destroy(a);
347
348 a = REGEX_INTERNAL_construct_dfa(check_proof, strlen(check_proof), 0);
349 check_dfa += test_automaton(a, &rx, &rxstr[i]);
350 REGEX_INTERNAL_automaton_destroy(a);
351 if (0 != check_dfa)
352 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "check_proof: %s\n", check_proof);
353 GNUNET_free_non_null(check_proof);
354
355 regfree(&rx);
356 } 353 }
357 354
355 /* NFA test */
356 a = REGEX_INTERNAL_construct_nfa (rxstr[i].regex, strlen (rxstr[i].regex));
357 check_nfa += test_automaton (a, &rx, &rxstr[i]);
358 REGEX_INTERNAL_automaton_destroy (a);
359
360 /* DFA test */
361 a = REGEX_INTERNAL_construct_dfa (rxstr[i].regex, strlen (rxstr[i].regex),
362 0);
363 check_dfa += test_automaton (a, &rx, &rxstr[i]);
364 check_proof = GNUNET_strdup (REGEX_INTERNAL_get_canonical_regex (a));
365 REGEX_INTERNAL_automaton_destroy (a);
366
367 a = REGEX_INTERNAL_construct_dfa (check_proof, strlen (check_proof), 0);
368 check_dfa += test_automaton (a, &rx, &rxstr[i]);
369 REGEX_INTERNAL_automaton_destroy (a);
370 if (0 != check_dfa)
371 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "check_proof: %s\n", check_proof);
372 GNUNET_free_non_null (check_proof);
373
374 regfree (&rx);
375 }
376
358 /* Random tests */ 377 /* Random tests */
359 srand(time(NULL)); 378 srand (time (NULL));
360 for (i = 0; i < 20; i++) 379 for (i = 0; i < 20; i++)
361 check_rand += test_random(50, 60, 10); 380 check_rand += test_random (50, 60, 10);
362 381
363 return check_nfa + check_dfa + check_rand; 382 return check_nfa + check_dfa + check_rand;
364} 383}