[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r23699 - gnunet/src/regex
From: |
gnunet |
Subject: |
[GNUnet-SVN] r23699 - gnunet/src/regex |
Date: |
Fri, 7 Sep 2012 18:38:49 +0200 |
Author: szengel
Date: 2012-09-07 18:38:49 +0200 (Fri, 07 Sep 2012)
New Revision: 23699
Added:
gnunet/src/regex/test_regex_graph_api.c
Modified:
gnunet/src/regex/Makefile.am
gnunet/src/regex/regex.c
gnunet/src/regex/regex_graph.c
gnunet/src/regex/test_regex_eval_api.c
gnunet/src/regex/test_regex_iterate_api.c
Log:
coverage
Modified: gnunet/src/regex/Makefile.am
===================================================================
--- gnunet/src/regex/Makefile.am 2012-09-07 12:21:12 UTC (rev 23698)
+++ gnunet/src/regex/Makefile.am 2012-09-07 16:38:49 UTC (rev 23699)
@@ -22,7 +22,8 @@
check_PROGRAMS = \
test_regex_eval_api \
test_regex_iterate_api \
- test_regex_proofs
+ test_regex_proofs \
+ test_regex_graph_api
if ENABLE_TEST_RUN
TESTS = $(check_PROGRAMS)
@@ -46,5 +47,12 @@
$(top_builddir)/src/regex/libgnunetregex.la \
$(top_builddir)/src/util/libgnunetutil.la
-EXTRA_DIST =
+test_regex_graph_api_SOURCES = \
+test_regex_graph_api.c
+test_regex_graph_api_LDADD = \
+$(top_builddir)/src/regex/libgnunetregex.la \
+$(top_builddir)/src/util/libgnunetutil.la
+
+
+EXTRA_DIST =
# test_regex_data.conf
Modified: gnunet/src/regex/regex.c
===================================================================
--- gnunet/src/regex/regex.c 2012-09-07 12:21:12 UTC (rev 23698)
+++ gnunet/src/regex/regex.c 2012-09-07 16:38:49 UTC (rev 23699)
@@ -52,105 +52,7 @@
};
-/*
- * Debug helper functions
- */
-
/**
- * Print all the transitions of state 's'.
- *
- * @param s state for which to print it's transitions.
- */
-void
-debug_print_transitions (struct GNUNET_REGEX_State *s);
-
-
-/**
- * Print information of the given state 's'.
- *
- * @param s state for which debug information should be printed.
- */
-void
-debug_print_state (struct GNUNET_REGEX_State *s)
-{
- char *proof;
-
- if (NULL == s->proof)
- proof = "NULL";
- else
- proof = s->proof;
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "State %i: %s marked: %i accepting: %i scc_id: %i transitions:
%i proof: %s\n",
- s->id, s->name, s->marked, s->accepting, s->scc_id,
- s->transition_count, proof);
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transitions:\n");
- debug_print_transitions (s);
-}
-
-
-/**
- * Print debug information for all states contained in the automaton 'a'.
- *
- * @param a automaton for which debug information of it's states should be
printed.
- */
-void
-debug_print_states (struct GNUNET_REGEX_Automaton *a)
-{
- struct GNUNET_REGEX_State *s;
-
- for (s = a->states_head; NULL != s; s = s->next)
- debug_print_state (s);
-}
-
-
-/**
- * Print debug information for given transition 't'.
- *
- * @param t transition for which to print debug info.
- */
-void
-debug_print_transition (struct GNUNET_REGEX_Transition *t)
-{
- char *to_state;
- char *from_state;
- char *label;
-
- if (NULL == t)
- return;
-
- if (0 == t->label)
- label = "0";
- else
- label = t->label;
-
- if (NULL == t->to_state)
- to_state = "NULL";
- else
- to_state = t->to_state->name;
-
- if (NULL == t->from_state)
- from_state = "NULL";
- else
- from_state = t->from_state->name;
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transition %i: From %s on %s to %s\n",
- t->id, from_state, label, to_state);
-}
-
-
-void
-debug_print_transitions (struct GNUNET_REGEX_State *s)
-{
- struct GNUNET_REGEX_Transition *t;
-
- for (t = s->transitions_head; NULL != t; t = t->next)
- debug_print_transition (t);
-}
-
-
-/**
* Compare two strings for equality. If either is NULL they are not equal.
*
* @param str1 first string for comparison.
@@ -2320,10 +2222,6 @@
}
nfa_add_question_op (&ctx);
break;
- case 92: /* escape: \ */
- regexp++;
- count++;
- /* fall through! */
default:
if (atomcount > 1)
{
Modified: gnunet/src/regex/regex_graph.c
===================================================================
--- gnunet/src/regex/regex_graph.c 2012-09-07 12:21:12 UTC (rev 23698)
+++ gnunet/src/regex/regex_graph.c 2012-09-07 16:38:49 UTC (rev 23699)
@@ -197,11 +197,8 @@
GNUNET_asprintf (&s_acc, "\"%s\" [shape=circle];\n", name, s->scc_id);
}
- if (NULL == s_acc)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not print state %s\n",
s->name);
- return;
- }
+ GNUNET_assert (NULL != s_acc);
+
fwrite (s_acc, strlen (s_acc), 1, ctx->filep);
GNUNET_free (s_acc);
s_acc = NULL;
@@ -256,12 +253,7 @@
GNUNET_free (to_name);
- if (NULL == s_tran)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not print state %s\n",
- s->name);
- return;
- }
+ GNUNET_assert (NULL != s_tran);
fwrite (s_tran, strlen (s_tran), 1, ctx->filep);
GNUNET_free (s_tran);
Modified: gnunet/src/regex/test_regex_eval_api.c
===================================================================
--- gnunet/src/regex/test_regex_eval_api.c 2012-09-07 12:21:12 UTC (rev
23698)
+++ gnunet/src/regex/test_regex_eval_api.c 2012-09-07 16:38:49 UTC (rev
23699)
@@ -252,7 +252,7 @@
int check_rand;
char *check_proof;
- struct Regex_String_Pair rxstr[17] = {
+ struct Regex_String_Pair rxstr[18] = {
{"ab?(abcd)?", 5,
{"ababcd", "abab", "aabcd", "a", "abb"},
{match, nomatch, match, match, nomatch}},
@@ -309,14 +309,17 @@
{nomatch}},
{"d|5kl", 1,
{"d5kl"},
- {nomatch}}
+ {nomatch}},
+ {"a()b", 1,
+ {"ab"},
+ {match}}
};
check_nfa = 0;
check_dfa = 0;
check_rand = 0;
- for (i = 0; i < 17; i++)
+ for (i = 0; i < 18; i++)
{
if (0 != regcomp (&rx, rxstr[i].regex, REG_EXTENDED))
{
Added: gnunet/src/regex/test_regex_graph_api.c
===================================================================
--- gnunet/src/regex/test_regex_graph_api.c (rev 0)
+++ gnunet/src/regex/test_regex_graph_api.c 2012-09-07 16:38:49 UTC (rev
23699)
@@ -0,0 +1,157 @@
+/*
+ This file is part of GNUnet
+ (C) 2012 Christian Grothoff (and other contributing authors)
+
+ GNUnet is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3, or (at your
+ option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ 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.
+*/
+/**
+ * @file regex/test_regex_graph_api.c
+ * @brief test for regex_graph.c
+ * @author Maximilian Szengel
+ */
+#include <regex.h>
+#include <time.h>
+#include "platform.h"
+#include "gnunet_regex_lib.h"
+
+/**
+ * Check if 'filename' exists and is not empty.
+ *
+ * @param filename name of the file that should be checked
+ *
+ * @return 0 if ok, non 0 on error.
+ */
+int
+filecheck (const char *filename)
+{
+ int error = 0;
+ FILE *fp = NULL;
+
+ // Check if file was created and delete it again
+ fp = fopen (filename, "r");
+
+ if (NULL == fp)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not find graph %s\n",
filename);
+ error++;
+ }
+
+ fseek (fp, 0L, SEEK_END);
+ if (1 > ftell (fp))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Graph writing failed, got empty file (%s)!\n", filename);
+ error++;
+ }
+
+ return error;
+}
+
+int
+main (int argc, char *argv[])
+{
+ GNUNET_log_setup ("test-regex",
+#if VERBOSE
+ "DEBUG",
+#else
+ "WARNING",
+#endif
+ NULL);
+
+ int error;
+ struct GNUNET_REGEX_Automaton *a;
+ unsigned int i;
+ const char *filename = "test_graph.dot";
+
+ error = 0;
+
+ const char *regex[10] = {
+ "ab(c|d)+c*(a(b|c)+d)+(bla)+",
+ "(bla)*",
+ "b(lab)*la",
+ "(ab)*",
+ "ab(c|d)+c*(a(b|c)+d)+(bla)(bla)*",
+ "z(abc|def)?xyz",
+ "1*0(0|1)*",
+ "a*b*",
+ "a+X*y+c|p|R|Z*K*y*R+w|Y*6+n+h*k*w+V*F|W*B*e*",
+ "a"
+ };
+
+ for (i = 0; i < 10; i++)
+ {
+ // Check NFA graph creation
+ a = GNUNET_REGEX_construct_nfa (regex[i], strlen (regex[i]));
+ GNUNET_REGEX_automaton_save_graph (a, filename,
GNUNET_REGEX_GRAPH_DEFAULT);
+ GNUNET_REGEX_automaton_destroy (a);
+ error += filecheck (filename);
+
+ a = GNUNET_REGEX_construct_nfa (regex[i], strlen (regex[i]));
+ GNUNET_REGEX_automaton_save_graph (a, filename,
+ GNUNET_REGEX_GRAPH_DEFAULT |
+ GNUNET_REGEX_GRAPH_VERBOSE);
+ GNUNET_REGEX_automaton_destroy (a);
+ error += filecheck (filename);
+
+ a = GNUNET_REGEX_construct_nfa (regex[i], strlen (regex[i]));
+ GNUNET_REGEX_automaton_save_graph (a, filename,
+ GNUNET_REGEX_GRAPH_DEFAULT |
+ GNUNET_REGEX_GRAPH_COLORING);
+ GNUNET_REGEX_automaton_destroy (a);
+ error += filecheck (filename);
+
+ a = GNUNET_REGEX_construct_nfa (regex[i], strlen (regex[i]));
+ GNUNET_REGEX_automaton_save_graph (a, filename,
+ GNUNET_REGEX_GRAPH_DEFAULT |
+ GNUNET_REGEX_GRAPH_VERBOSE |
+ GNUNET_REGEX_GRAPH_COLORING);
+ GNUNET_REGEX_automaton_destroy (a);
+ error += filecheck (filename);
+
+
+ // Check DFA graph creation
+ a = GNUNET_REGEX_construct_dfa (regex[i], strlen (regex[i]));
+ GNUNET_REGEX_automaton_save_graph (a, filename,
GNUNET_REGEX_GRAPH_DEFAULT);
+ GNUNET_REGEX_automaton_destroy (a);
+ error += filecheck (filename);
+
+ a = GNUNET_REGEX_construct_dfa (regex[i], strlen (regex[i]));
+ GNUNET_REGEX_automaton_save_graph (a, filename,
+ GNUNET_REGEX_GRAPH_DEFAULT |
+ GNUNET_REGEX_GRAPH_VERBOSE);
+ GNUNET_REGEX_automaton_destroy (a);
+ error += filecheck (filename);
+
+ a = GNUNET_REGEX_construct_dfa (regex[i], strlen (regex[i]));
+ GNUNET_REGEX_automaton_save_graph (a, filename,
+ GNUNET_REGEX_GRAPH_DEFAULT |
+ GNUNET_REGEX_GRAPH_COLORING);
+ GNUNET_REGEX_automaton_destroy (a);
+ error += filecheck (filename);
+
+
+ a = GNUNET_REGEX_construct_dfa (regex[i], strlen (regex[i]));
+ GNUNET_REGEX_automaton_save_graph (a, filename,
+ GNUNET_REGEX_GRAPH_DEFAULT |
+ GNUNET_REGEX_GRAPH_VERBOSE |
+ GNUNET_REGEX_GRAPH_COLORING);
+ GNUNET_REGEX_automaton_destroy (a);
+ error += filecheck (filename);
+
+ }
+
+ return error;
+}
Modified: gnunet/src/regex/test_regex_iterate_api.c
===================================================================
--- gnunet/src/regex/test_regex_iterate_api.c 2012-09-07 12:21:12 UTC (rev
23698)
+++ gnunet/src/regex/test_regex_iterate_api.c 2012-09-07 16:38:49 UTC (rev
23699)
@@ -26,7 +26,10 @@
#include <time.h>
#include "platform.h"
#include "gnunet_regex_lib.h"
+#include "regex_internal.h"
+static unsigned int transition_counter;
+
void
key_iterator (void *cls, const struct GNUNET_HashCode *key, const char *proof,
int accepting, unsigned int num_edges,
@@ -46,6 +49,7 @@
for (i = 0; i < num_edges; i++)
{
+ transition_counter++;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Edge %i: Label: %s Destination:
%s\n",
i, edges[i].label, GNUNET_h2s (&edges[i].destination));
}
@@ -67,6 +71,7 @@
int error;
int i;
struct GNUNET_REGEX_Automaton *dfa;
+ unsigned int num_transitions;
error = 0;
@@ -92,10 +97,26 @@
for (i = 0; i < 17; i++)
{
+ transition_counter = 0;
dfa = GNUNET_REGEX_construct_dfa (regex[i], strlen (regex[i]));
GNUNET_REGEX_iterate_all_edges (dfa, key_iterator, &error);
+ num_transitions = GNUNET_REGEX_get_transition_count (dfa);
+ if (transition_counter != num_transitions)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Automaton has %d transitions, iterated over %d
transitions\n",
+ num_transitions, transition_counter);
+ }
GNUNET_REGEX_automaton_destroy (dfa);
}
+ for (i = 0; i < 17; i++)
+ {
+ dfa = GNUNET_REGEX_construct_dfa (regex[i], strlen (regex[i]));
+ GNUNET_REGEX_add_multi_strides_to_dfa (NULL, dfa, 2);
+ GNUNET_REGEX_iterate_all_edges (dfa, key_iterator, &error);
+ GNUNET_REGEX_automaton_destroy (dfa);
+ }
+
return error;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r23699 - gnunet/src/regex,
gnunet <=