continue to fix extract result
[oweals/gnunet.git] / src / regex / test_regex_eval_api.c
index ce6f9231577bc8bbde971447e373e65fa52b2843..d598dc5087d945f9d11a023fb8f43cc87e972e91 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet
-     (C) 2012 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2012 GNUnet e.V.
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -14,8 +14,8 @@
 
      You should have received a copy of the GNU General Public License
      along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-     Boston, MA 02111-1307, USA.
+     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+     Boston, MA 02110-1301, USA.
 */
 /**
  * @file regex/test_regex_eval_api.c
@@ -25,7 +25,8 @@
 #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
@@ -66,7 +67,7 @@ test_random (unsigned int rx_length, unsigned int max_str_len,
   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];
@@ -80,7 +81,7 @@ test_random (unsigned int rx_length, unsigned int max_str_len,
 
   /* 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;
@@ -88,21 +89,21 @@ test_random (unsigned int rx_length, unsigned int max_str_len,
   {
     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))
@@ -123,7 +124,7 @@ test_random (unsigned int rx_length, unsigned int max_str_len,
 
     /* 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)
     {
@@ -131,8 +132,8 @@ test_random (unsigned int rx_length, unsigned int max_str_len,
       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))
     {
@@ -192,7 +193,7 @@ error:
  * @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;
@@ -212,7 +213,7 @@ test_automaton (struct GNUNET_REGEX_Automaton *a, regex_t * rx,
 
   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,
@@ -233,7 +234,7 @@ test_automaton (struct GNUNET_REGEX_Automaton *a, regex_t * rx,
                   "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);
     }
@@ -246,7 +247,7 @@ main (int argc, char *argv[])
 {
   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;
@@ -336,19 +337,19 @@ main (int argc, char *argv[])
     }
 
     /* 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);