diff options
author | Maximilian Szengel <gnunet@maxsz.de> | 2012-06-06 14:35:05 +0000 |
---|---|---|
committer | Maximilian Szengel <gnunet@maxsz.de> | 2012-06-06 14:35:05 +0000 |
commit | 07ca698bc1cee73020c218dd6f13aceb187700cd (patch) | |
tree | f4a0155bc59b73d28265f9ee4ba0944ed4278d2e /src/regex/test_regex_eval_api.c | |
parent | 983df8eafd4a10a2f5053264806cbcdeb96f0dd4 (diff) | |
download | gnunet-07ca698bc1cee73020c218dd6f13aceb187700cd.tar.gz gnunet-07ca698bc1cee73020c218dd6f13aceb187700cd.zip |
Test for computed regex.
Diffstat (limited to 'src/regex/test_regex_eval_api.c')
-rw-r--r-- | src/regex/test_regex_eval_api.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/regex/test_regex_eval_api.c b/src/regex/test_regex_eval_api.c index c63e97c11..392fb3b36 100644 --- a/src/regex/test_regex_eval_api.c +++ b/src/regex/test_regex_eval_api.c | |||
@@ -60,12 +60,14 @@ test_random (unsigned int rx_length, unsigned int max_str_len, | |||
60 | char current_char; | 60 | char current_char; |
61 | int eval; | 61 | int eval; |
62 | int eval_check; | 62 | int eval_check; |
63 | int eval_computed; | ||
63 | struct GNUNET_REGEX_Automaton *dfa; | 64 | struct GNUNET_REGEX_Automaton *dfa; |
64 | regex_t rx; | 65 | regex_t rx; |
65 | regmatch_t matchptr[1]; | 66 | regmatch_t matchptr[1]; |
66 | char error[200]; | 67 | char error[200]; |
67 | int result; | 68 | int result; |
68 | unsigned int str_len; | 69 | unsigned int str_len; |
70 | char *computed_regex; | ||
69 | 71 | ||
70 | // At least one string is needed for matching | 72 | // At least one string is needed for matching |
71 | GNUNET_assert (str_count > 0); | 73 | GNUNET_assert (str_count > 0); |
@@ -151,6 +153,7 @@ test_random (unsigned int rx_length, unsigned int max_str_len, | |||
151 | } | 153 | } |
152 | 154 | ||
153 | eval = GNUNET_REGEX_eval (dfa, matching_str[i]); | 155 | eval = GNUNET_REGEX_eval (dfa, matching_str[i]); |
156 | computed_regex = GNUNET_strdup (GNUNET_REGEX_get_computed_regex (dfa)); | ||
154 | GNUNET_REGEX_automaton_destroy (dfa); | 157 | GNUNET_REGEX_automaton_destroy (dfa); |
155 | 158 | ||
156 | // Match string using glibc regex | 159 | // Match string using glibc regex |
@@ -164,6 +167,19 @@ test_random (unsigned int rx_length, unsigned int max_str_len, | |||
164 | eval_check = regexec (&rx, matching_str[i], 1, matchptr, 0); | 167 | eval_check = regexec (&rx, matching_str[i], 1, matchptr, 0); |
165 | regfree (&rx); | 168 | regfree (&rx); |
166 | 169 | ||
170 | // Match computed regex | ||
171 | if (0 != regcomp (&rx, computed_regex, REG_EXTENDED)) | ||
172 | { | ||
173 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
174 | "Could not compile regex using regcomp: %s\n", | ||
175 | computed_regex); | ||
176 | return -1; | ||
177 | } | ||
178 | |||
179 | eval_computed = regexec (&rx, matching_str[i], 1, matchptr, 0); | ||
180 | regfree (&rx); | ||
181 | GNUNET_free (computed_regex); | ||
182 | |||
167 | // We only want to match the whole string, because that's what our DFA does, too. | 183 | // We only want to match the whole string, because that's what our DFA does, too. |
168 | if (eval_check == 0 && | 184 | if (eval_check == 0 && |
169 | (matchptr[0].rm_so != 0 || | 185 | (matchptr[0].rm_so != 0 || |