aboutsummaryrefslogtreecommitdiff
path: root/src/regex/test_regex_eval_api.c
diff options
context:
space:
mode:
authorMaximilian Szengel <gnunet@maxsz.de>2012-07-02 12:22:37 +0000
committerMaximilian Szengel <gnunet@maxsz.de>2012-07-02 12:22:37 +0000
commita4b40b20949b4ea21d98bed902906cdf56d41326 (patch)
treec21f239124ccc818ca52832b736b18ae3522230a /src/regex/test_regex_eval_api.c
parentce4b5c1fa37a9b26df4345d30b6ba2c839ce23d5 (diff)
downloadgnunet-a4b40b20949b4ea21d98bed902906cdf56d41326.tar.gz
gnunet-a4b40b20949b4ea21d98bed902906cdf56d41326.zip
regex bugfixes
Diffstat (limited to 'src/regex/test_regex_eval_api.c')
-rw-r--r--src/regex/test_regex_eval_api.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/src/regex/test_regex_eval_api.c b/src/regex/test_regex_eval_api.c
index 6d575a05c..5a6575c86 100644
--- a/src/regex/test_regex_eval_api.c
+++ b/src/regex/test_regex_eval_api.c
@@ -58,7 +58,7 @@ int
58test_random (unsigned int rx_length, unsigned int max_str_len, 58test_random (unsigned int rx_length, unsigned int max_str_len,
59 unsigned int str_count) 59 unsigned int str_count)
60{ 60{
61 int i; 61 unsigned int i;
62 char *rand_rx; 62 char *rand_rx;
63 char *matching_str; 63 char *matching_str;
64 int eval; 64 int eval;
@@ -114,6 +114,11 @@ test_random (unsigned int rx_length, unsigned int max_str_len,
114 eval_check = regexec (&rx, matching_str, 1, matchptr, 0); 114 eval_check = regexec (&rx, matching_str, 1, matchptr, 0);
115 regfree (&rx); 115 regfree (&rx);
116 116
117 // We only want to match the whole string, because that's what our DFA does, too.
118 if (eval_check == 0 &&
119 (matchptr[0].rm_so != 0 || matchptr[0].rm_eo != strlen (matching_str)))
120 eval_check = 1;
121
117 // Match canonical regex 122 // Match canonical regex
118 if (0 != regcomp (&rx, canonical_regex, REG_EXTENDED)) 123 if (0 != regcomp (&rx, canonical_regex, REG_EXTENDED))
119 { 124 {
@@ -127,11 +132,6 @@ test_random (unsigned int rx_length, unsigned int max_str_len,
127 regfree (&rx); 132 regfree (&rx);
128 GNUNET_free (canonical_regex); 133 GNUNET_free (canonical_regex);
129 134
130 // We only want to match the whole string, because that's what our DFA does, too.
131 if (eval_check == 0 &&
132 (matchptr[0].rm_so != 0 || matchptr[0].rm_eo != strlen (matching_str)))
133 eval_check = 1;
134
135 // compare result 135 // compare result
136 if (eval_check != eval) 136 if (eval_check != eval)
137 { 137 {
@@ -198,11 +198,11 @@ test_automaton (struct GNUNET_REGEX_Automaton *a, regex_t * rx,
198 result = 1; 198 result = 1;
199 regerror (eval_check, rx, error, sizeof error); 199 regerror (eval_check, rx, error, sizeof error);
200 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 200 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
201 "Unexpected result:\nregex: %s\nstring: %s\nexpected result: %i\n" 201 "Unexpected result:\nregex: %s\ncanonical_regex: %s\nstring: %s\nexpected result: %i\n"
202 "gnunet regex: %i\nglibc regex: %i\nglibc error: %s\nrm_so: %i\nrm_eo: %i\n\n", 202 "gnunet regex: %i\nglibc regex: %i\nglibc error: %s\nrm_so: %i\nrm_eo: %i\n\n",
203 rxstr->regex, rxstr->strings[i], rxstr->expected_results[i], 203 rxstr->regex, GNUNET_REGEX_get_canonical_regex (a),
204 eval, eval_check, error, matchptr[0].rm_so, 204 rxstr->strings[i], rxstr->expected_results[i], eval,
205 matchptr[0].rm_eo); 205 eval_check, error, matchptr[0].rm_so, matchptr[0].rm_eo);
206 } 206 }
207 } 207 }
208 return result; 208 return result;
@@ -298,6 +298,7 @@ main (int argc, char *argv[])
298 check_dfa += test_automaton (a, &rx, &rxstr[i]); 298 check_dfa += test_automaton (a, &rx, &rxstr[i]);
299 check_proof = GNUNET_strdup (GNUNET_REGEX_get_canonical_regex (a)); 299 check_proof = GNUNET_strdup (GNUNET_REGEX_get_canonical_regex (a));
300 GNUNET_REGEX_automaton_destroy (a); 300 GNUNET_REGEX_automaton_destroy (a);
301
301 a = GNUNET_REGEX_construct_dfa (check_proof, strlen (check_proof)); 302 a = GNUNET_REGEX_construct_dfa (check_proof, strlen (check_proof));
302 check_dfa += test_automaton (a, &rx, &rxstr[i]); 303 check_dfa += test_automaton (a, &rx, &rxstr[i]);
303 GNUNET_REGEX_automaton_destroy (a); 304 GNUNET_REGEX_automaton_destroy (a);