#include <regex.h>
#include <time.h>
#include "platform.h"
-#include "gnunet_regex_lib.h"
+#include "regex_internal_lib.h"
+#include "regex_test_lib.h"
#include "regex_internal.h"
enum Match_Result
int eval_check;
int eval_canonical;
int eval_canonical_check;
- struct GNUNET_REGEX_Automaton *dfa;
+ struct REGEX_INTERNAL_Automaton *dfa;
regex_t rx;
regmatch_t matchptr[1];
char error[200];
/* Generate random regex and a string that matches the regex */
matching_str = GNUNET_malloc (rx_length + 1);
- rand_rx = GNUNET_REGEX_generate_random_regex (rx_length, matching_str);
+ rand_rx = REGEX_TEST_generate_random_regex (rx_length, matching_str);
/* Now match */
result = 0;
{
if (0 < i)
{
- matching_str = GNUNET_REGEX_generate_random_string (max_str_len);
+ matching_str = REGEX_TEST_generate_random_string (max_str_len);
}
/* Match string using DFA */
- dfa = GNUNET_REGEX_construct_dfa (rand_rx, strlen (rand_rx), 0);
+ dfa = REGEX_INTERNAL_construct_dfa (rand_rx, strlen (rand_rx), 0);
if (NULL == dfa)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Constructing DFA failed\n");
goto error;
}
- eval = GNUNET_REGEX_eval (dfa, matching_str);
+ eval = REGEX_INTERNAL_eval (dfa, matching_str);
/* save the canonical regex for later comparison */
- canonical_regex = GNUNET_strdup (GNUNET_REGEX_get_canonical_regex (dfa));
- GNUNET_REGEX_automaton_destroy (dfa);
+ canonical_regex = GNUNET_strdup (REGEX_INTERNAL_get_canonical_regex (dfa));
+ REGEX_INTERNAL_automaton_destroy (dfa);
/* Match string using glibc regex */
if (0 != regcomp (&rx, rand_rx, REG_EXTENDED))
/* Match canonical regex */
dfa =
- GNUNET_REGEX_construct_dfa (canonical_regex, strlen (canonical_regex),
+ REGEX_INTERNAL_construct_dfa (canonical_regex, strlen (canonical_regex),
0);
if (NULL == dfa)
{
goto error;
}
- eval_canonical = GNUNET_REGEX_eval (dfa, matching_str);
- GNUNET_REGEX_automaton_destroy (dfa);
+ eval_canonical = REGEX_INTERNAL_eval (dfa, matching_str);
+ REGEX_INTERNAL_automaton_destroy (dfa);
if (0 != regcomp (&rx, canonical_regex, REG_EXTENDED))
{
* @return 0 on successfull, non 0 otherwise
*/
int
-test_automaton (struct GNUNET_REGEX_Automaton *a, regex_t * rx,
+test_automaton (struct REGEX_INTERNAL_Automaton *a, regex_t * rx,
struct Regex_String_Pair *rxstr)
{
int result;
for (i = 0; i < rxstr->string_count; i++)
{
- eval = GNUNET_REGEX_eval (a, rxstr->strings[i]);
+ eval = REGEX_INTERNAL_eval (a, rxstr->strings[i]);
eval_check = regexec (rx, rxstr->strings[i], 1, matchptr, 0);
/* We only want to match the whole string, because that's what our DFA does,
"string: %s\nexpected result: %i\n"
"gnunet regex: %i\nglibc regex: %i\nglibc error: %s\n"
"rm_so: %i\nrm_eo: %i\n\n", rxstr->regex,
- GNUNET_REGEX_get_canonical_regex (a), rxstr->strings[i],
+ REGEX_INTERNAL_get_canonical_regex (a), rxstr->strings[i],
rxstr->expected_results[i], eval, eval_check, error,
matchptr[0].rm_so, matchptr[0].rm_eo);
}
{
GNUNET_log_setup ("test-regex", "WARNING", NULL);
- struct GNUNET_REGEX_Automaton *a;
+ struct REGEX_INTERNAL_Automaton *a;
regex_t rx;
int i;
int check_nfa;
}
/* NFA test */
- a = GNUNET_REGEX_construct_nfa (rxstr[i].regex, strlen (rxstr[i].regex));
+ a = REGEX_INTERNAL_construct_nfa (rxstr[i].regex, strlen (rxstr[i].regex));
check_nfa += test_automaton (a, &rx, &rxstr[i]);
- GNUNET_REGEX_automaton_destroy (a);
+ REGEX_INTERNAL_automaton_destroy (a);
/* DFA test */
- a = GNUNET_REGEX_construct_dfa (rxstr[i].regex, strlen (rxstr[i].regex), 0);
+ a = REGEX_INTERNAL_construct_dfa (rxstr[i].regex, strlen (rxstr[i].regex), 0);
check_dfa += test_automaton (a, &rx, &rxstr[i]);
- check_proof = GNUNET_strdup (GNUNET_REGEX_get_canonical_regex (a));
- GNUNET_REGEX_automaton_destroy (a);
+ check_proof = GNUNET_strdup (REGEX_INTERNAL_get_canonical_regex (a));
+ REGEX_INTERNAL_automaton_destroy (a);
- a = GNUNET_REGEX_construct_dfa (check_proof, strlen (check_proof), 0);
+ a = REGEX_INTERNAL_construct_dfa (check_proof, strlen (check_proof), 0);
check_dfa += test_automaton (a, &rx, &rxstr[i]);
- GNUNET_REGEX_automaton_destroy (a);
+ REGEX_INTERNAL_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);