char current_char;
int eval;
int eval_check;
+ int eval_computed;
struct GNUNET_REGEX_Automaton *dfa;
regex_t rx;
regmatch_t matchptr[1];
char error[200];
int result;
unsigned int str_len;
+ char *computed_regex;
// At least one string is needed for matching
GNUNET_assert (str_count > 0);
}
eval = GNUNET_REGEX_eval (dfa, matching_str[i]);
+ computed_regex = GNUNET_strdup (GNUNET_REGEX_get_computed_regex (dfa));
GNUNET_REGEX_automaton_destroy (dfa);
// Match string using glibc regex
eval_check = regexec (&rx, matching_str[i], 1, matchptr, 0);
regfree (&rx);
+ // Match computed regex
+ if (0 != regcomp (&rx, computed_regex, REG_EXTENDED))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Could not compile regex using regcomp: %s\n",
+ computed_regex);
+ return -1;
+ }
+
+ eval_computed = regexec (&rx, matching_str[i], 1, matchptr, 0);
+ regfree (&rx);
+ GNUNET_free (computed_regex);
+
// We only want to match the whole string, because that's what our DFA does, too.
if (eval_check == 0 &&
(matchptr[0].rm_so != 0 ||
int check_nfa;
int check_dfa;
int check_rand;
+ char *check_proof;
- struct Regex_String_Pair rxstr[4] = {
+ struct Regex_String_Pair rxstr[12] = {
{"ab?(abcd)?", 5,
{"ababcd", "abab", "aabcd", "a", "abb"},
{match, nomatch, match, match, nomatch}},
{"abcdcdcdcdddddabd", "abcd", "abcddddddccccccccccccccccccccccccabdacdabd",
"abccccca", "abcdcdcdccdabdabd"},
{nomatch, nomatch, nomatch, nomatch, nomatch}},
+ {"a+X*y+c|p|R|Z*K*y*R+w|Y*6+n+h*k*w+V*F|W*B*e*", 1,
+ {"kaXycQepRZKyRwY6nhkwVFWBegNVtLPj39XhJJ6bEifRSZRYZg"},
+ {nomatch}},
{"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,
{"kaXycQepRZKyRwY6nhkwVFWBegNVtLPj39XhJJ6bEifRSZRYZg"},
+ {nomatch}},
+ {"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,
+ {"osfjsodfonONONOnosndfsdnfsd"},
+ {nomatch}},
+ {"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,
+ {"VMoxpdhbEmhYEOWWPoZHMIqCa559bzGykRpu8hBlHeLO1Fv05C"},
+ {nomatch}},
+ {"(bla)*", 8,
+ {"", "bla", "blabla", "bl", "la", "b", "l", "a"},
+ {match, match, match, nomatch, nomatch, nomatch, nomatch, nomatch}},
+ {"ab(c|d)+c*(a(b|c)+d)+(bla)(bla)*", 8,
+ {"ab", "abcabdbla", "abdcccccccccccabcbccdblablabla", "bl", "la", "b", "l",
+ "a"},
+ {nomatch, match, match, nomatch, nomatch, nomatch, nomatch, nomatch}},
+ {"a|aa*a", 6,
+ {"", "a", "aa", "aaa", "aaaa", "aaaaa"},
+ {nomatch, match, match, match, match, match}},
+ {"ab(c|d)+c*(a(b|c)+d)+(bla)+", 1,
+ {"abcabdblaacdbla"},
+ {nomatch}},
+ {"ab(c|d)+c*(a(b|c)d)+", 1,
+ {"abacd"},
{nomatch}}
};
check_dfa = 0;
check_rand = 0;
- for (i = 0; i < 4; i++)
+ for (i = 0; i < 12; i++)
{
if (0 != regcomp (&rx, rxstr[i].regex, REG_EXTENDED))
{
// DFA test
a = GNUNET_REGEX_construct_dfa (rxstr[i].regex, strlen (rxstr[i].regex));
check_dfa += test_automaton (a, &rx, &rxstr[i]);
+ check_proof = GNUNET_strdup (GNUNET_REGEX_get_computed_regex (a));
+ GNUNET_REGEX_automaton_destroy (a);
+ a = GNUNET_REGEX_construct_dfa (check_proof, strlen (check_proof));
+ check_dfa += test_automaton (a, &rx, &rxstr[i]);
GNUNET_REGEX_automaton_destroy (a);
+ if (0 != check_dfa)
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "check_proof: %s\n", check_proof);
+ GNUNET_free_non_null (check_proof);
regfree (&rx);
}
srand (time (NULL));
- for (i = 0; i < 100; i++)
- check_rand += test_random (100, 150, 20);
+ for (i = 0; i < 150; i++)
+ check_rand += test_random (150, 200, 25);
return check_nfa + check_dfa + check_rand;
}