diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-06-20 08:32:50 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-06-20 08:32:50 +0000 |
commit | 21a2b4f95b4488645ba5a6254fcb8919c4915f73 (patch) | |
tree | 00c92cb7103cc14fba7e63e8dee99fe711856863 /src/regex/test_regex_eval_api.c | |
parent | 5533b105943b4f6dd688c1758350cd83ebeab3b9 (diff) | |
download | gnunet-21a2b4f95b4488645ba5a6254fcb8919c4915f73.tar.gz gnunet-21a2b4f95b4488645ba5a6254fcb8919c4915f73.zip |
continuing refactoring of regex library structure, disambiguating symbol names between old regex library which is now internal and the public API; moving IP-to-regex conversion functions to tun library, as only vpn is using those to begin with
Diffstat (limited to 'src/regex/test_regex_eval_api.c')
-rw-r--r-- | src/regex/test_regex_eval_api.c | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/src/regex/test_regex_eval_api.c b/src/regex/test_regex_eval_api.c index ce6f92315..8cdefb17d 100644 --- a/src/regex/test_regex_eval_api.c +++ b/src/regex/test_regex_eval_api.c | |||
@@ -25,7 +25,7 @@ | |||
25 | #include <regex.h> | 25 | #include <regex.h> |
26 | #include <time.h> | 26 | #include <time.h> |
27 | #include "platform.h" | 27 | #include "platform.h" |
28 | #include "gnunet_regex_lib.h" | 28 | #include "regex_internal_lib.h" |
29 | #include "regex_internal.h" | 29 | #include "regex_internal.h" |
30 | 30 | ||
31 | enum Match_Result | 31 | enum Match_Result |
@@ -66,7 +66,7 @@ test_random (unsigned int rx_length, unsigned int max_str_len, | |||
66 | int eval_check; | 66 | int eval_check; |
67 | int eval_canonical; | 67 | int eval_canonical; |
68 | int eval_canonical_check; | 68 | int eval_canonical_check; |
69 | struct GNUNET_REGEX_Automaton *dfa; | 69 | struct REGEX_ITERNAL_Automaton *dfa; |
70 | regex_t rx; | 70 | regex_t rx; |
71 | regmatch_t matchptr[1]; | 71 | regmatch_t matchptr[1]; |
72 | char error[200]; | 72 | char error[200]; |
@@ -80,7 +80,7 @@ test_random (unsigned int rx_length, unsigned int max_str_len, | |||
80 | 80 | ||
81 | /* Generate random regex and a string that matches the regex */ | 81 | /* Generate random regex and a string that matches the regex */ |
82 | matching_str = GNUNET_malloc (rx_length + 1); | 82 | matching_str = GNUNET_malloc (rx_length + 1); |
83 | rand_rx = GNUNET_REGEX_generate_random_regex (rx_length, matching_str); | 83 | rand_rx = REGEX_ITERNAL_generate_random_regex (rx_length, matching_str); |
84 | 84 | ||
85 | /* Now match */ | 85 | /* Now match */ |
86 | result = 0; | 86 | result = 0; |
@@ -88,21 +88,21 @@ test_random (unsigned int rx_length, unsigned int max_str_len, | |||
88 | { | 88 | { |
89 | if (0 < i) | 89 | if (0 < i) |
90 | { | 90 | { |
91 | matching_str = GNUNET_REGEX_generate_random_string (max_str_len); | 91 | matching_str = REGEX_ITERNAL_generate_random_string (max_str_len); |
92 | } | 92 | } |
93 | 93 | ||
94 | /* Match string using DFA */ | 94 | /* Match string using DFA */ |
95 | dfa = GNUNET_REGEX_construct_dfa (rand_rx, strlen (rand_rx), 0); | 95 | dfa = REGEX_ITERNAL_construct_dfa (rand_rx, strlen (rand_rx), 0); |
96 | if (NULL == dfa) | 96 | if (NULL == dfa) |
97 | { | 97 | { |
98 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Constructing DFA failed\n"); | 98 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Constructing DFA failed\n"); |
99 | goto error; | 99 | goto error; |
100 | } | 100 | } |
101 | 101 | ||
102 | eval = GNUNET_REGEX_eval (dfa, matching_str); | 102 | eval = REGEX_ITERNAL_eval (dfa, matching_str); |
103 | /* save the canonical regex for later comparison */ | 103 | /* save the canonical regex for later comparison */ |
104 | canonical_regex = GNUNET_strdup (GNUNET_REGEX_get_canonical_regex (dfa)); | 104 | canonical_regex = GNUNET_strdup (REGEX_ITERNAL_get_canonical_regex (dfa)); |
105 | GNUNET_REGEX_automaton_destroy (dfa); | 105 | REGEX_ITERNAL_automaton_destroy (dfa); |
106 | 106 | ||
107 | /* Match string using glibc regex */ | 107 | /* Match string using glibc regex */ |
108 | if (0 != regcomp (&rx, rand_rx, REG_EXTENDED)) | 108 | if (0 != regcomp (&rx, rand_rx, REG_EXTENDED)) |
@@ -123,7 +123,7 @@ test_random (unsigned int rx_length, unsigned int max_str_len, | |||
123 | 123 | ||
124 | /* Match canonical regex */ | 124 | /* Match canonical regex */ |
125 | dfa = | 125 | dfa = |
126 | GNUNET_REGEX_construct_dfa (canonical_regex, strlen (canonical_regex), | 126 | REGEX_ITERNAL_construct_dfa (canonical_regex, strlen (canonical_regex), |
127 | 0); | 127 | 0); |
128 | if (NULL == dfa) | 128 | if (NULL == dfa) |
129 | { | 129 | { |
@@ -131,8 +131,8 @@ test_random (unsigned int rx_length, unsigned int max_str_len, | |||
131 | goto error; | 131 | goto error; |
132 | } | 132 | } |
133 | 133 | ||
134 | eval_canonical = GNUNET_REGEX_eval (dfa, matching_str); | 134 | eval_canonical = REGEX_ITERNAL_eval (dfa, matching_str); |
135 | GNUNET_REGEX_automaton_destroy (dfa); | 135 | REGEX_ITERNAL_automaton_destroy (dfa); |
136 | 136 | ||
137 | if (0 != regcomp (&rx, canonical_regex, REG_EXTENDED)) | 137 | if (0 != regcomp (&rx, canonical_regex, REG_EXTENDED)) |
138 | { | 138 | { |
@@ -192,7 +192,7 @@ error: | |||
192 | * @return 0 on successfull, non 0 otherwise | 192 | * @return 0 on successfull, non 0 otherwise |
193 | */ | 193 | */ |
194 | int | 194 | int |
195 | test_automaton (struct GNUNET_REGEX_Automaton *a, regex_t * rx, | 195 | test_automaton (struct REGEX_ITERNAL_Automaton *a, regex_t * rx, |
196 | struct Regex_String_Pair *rxstr) | 196 | struct Regex_String_Pair *rxstr) |
197 | { | 197 | { |
198 | int result; | 198 | int result; |
@@ -212,7 +212,7 @@ test_automaton (struct GNUNET_REGEX_Automaton *a, regex_t * rx, | |||
212 | 212 | ||
213 | for (i = 0; i < rxstr->string_count; i++) | 213 | for (i = 0; i < rxstr->string_count; i++) |
214 | { | 214 | { |
215 | eval = GNUNET_REGEX_eval (a, rxstr->strings[i]); | 215 | eval = REGEX_ITERNAL_eval (a, rxstr->strings[i]); |
216 | eval_check = regexec (rx, rxstr->strings[i], 1, matchptr, 0); | 216 | eval_check = regexec (rx, rxstr->strings[i], 1, matchptr, 0); |
217 | 217 | ||
218 | /* We only want to match the whole string, because that's what our DFA does, | 218 | /* We only want to match the whole string, because that's what our DFA does, |
@@ -233,7 +233,7 @@ test_automaton (struct GNUNET_REGEX_Automaton *a, regex_t * rx, | |||
233 | "string: %s\nexpected result: %i\n" | 233 | "string: %s\nexpected result: %i\n" |
234 | "gnunet regex: %i\nglibc regex: %i\nglibc error: %s\n" | 234 | "gnunet regex: %i\nglibc regex: %i\nglibc error: %s\n" |
235 | "rm_so: %i\nrm_eo: %i\n\n", rxstr->regex, | 235 | "rm_so: %i\nrm_eo: %i\n\n", rxstr->regex, |
236 | GNUNET_REGEX_get_canonical_regex (a), rxstr->strings[i], | 236 | REGEX_ITERNAL_get_canonical_regex (a), rxstr->strings[i], |
237 | rxstr->expected_results[i], eval, eval_check, error, | 237 | rxstr->expected_results[i], eval, eval_check, error, |
238 | matchptr[0].rm_so, matchptr[0].rm_eo); | 238 | matchptr[0].rm_so, matchptr[0].rm_eo); |
239 | } | 239 | } |
@@ -246,7 +246,7 @@ main (int argc, char *argv[]) | |||
246 | { | 246 | { |
247 | GNUNET_log_setup ("test-regex", "WARNING", NULL); | 247 | GNUNET_log_setup ("test-regex", "WARNING", NULL); |
248 | 248 | ||
249 | struct GNUNET_REGEX_Automaton *a; | 249 | struct REGEX_ITERNAL_Automaton *a; |
250 | regex_t rx; | 250 | regex_t rx; |
251 | int i; | 251 | int i; |
252 | int check_nfa; | 252 | int check_nfa; |
@@ -336,19 +336,19 @@ main (int argc, char *argv[]) | |||
336 | } | 336 | } |
337 | 337 | ||
338 | /* NFA test */ | 338 | /* NFA test */ |
339 | a = GNUNET_REGEX_construct_nfa (rxstr[i].regex, strlen (rxstr[i].regex)); | 339 | a = REGEX_ITERNAL_construct_nfa (rxstr[i].regex, strlen (rxstr[i].regex)); |
340 | check_nfa += test_automaton (a, &rx, &rxstr[i]); | 340 | check_nfa += test_automaton (a, &rx, &rxstr[i]); |
341 | GNUNET_REGEX_automaton_destroy (a); | 341 | REGEX_ITERNAL_automaton_destroy (a); |
342 | 342 | ||
343 | /* DFA test */ | 343 | /* DFA test */ |
344 | a = GNUNET_REGEX_construct_dfa (rxstr[i].regex, strlen (rxstr[i].regex), 0); | 344 | a = REGEX_ITERNAL_construct_dfa (rxstr[i].regex, strlen (rxstr[i].regex), 0); |
345 | check_dfa += test_automaton (a, &rx, &rxstr[i]); | 345 | check_dfa += test_automaton (a, &rx, &rxstr[i]); |
346 | check_proof = GNUNET_strdup (GNUNET_REGEX_get_canonical_regex (a)); | 346 | check_proof = GNUNET_strdup (REGEX_ITERNAL_get_canonical_regex (a)); |
347 | GNUNET_REGEX_automaton_destroy (a); | 347 | REGEX_ITERNAL_automaton_destroy (a); |
348 | 348 | ||
349 | a = GNUNET_REGEX_construct_dfa (check_proof, strlen (check_proof), 0); | 349 | a = REGEX_ITERNAL_construct_dfa (check_proof, strlen (check_proof), 0); |
350 | check_dfa += test_automaton (a, &rx, &rxstr[i]); | 350 | check_dfa += test_automaton (a, &rx, &rxstr[i]); |
351 | GNUNET_REGEX_automaton_destroy (a); | 351 | REGEX_ITERNAL_automaton_destroy (a); |
352 | if (0 != check_dfa) | 352 | if (0 != check_dfa) |
353 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "check_proof: %s\n", check_proof); | 353 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "check_proof: %s\n", check_proof); |
354 | GNUNET_free_non_null (check_proof); | 354 | GNUNET_free_non_null (check_proof); |