aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaximilian Szengel <gnunet@maxsz.de>2012-04-18 14:02:20 +0000
committerMaximilian Szengel <gnunet@maxsz.de>2012-04-18 14:02:20 +0000
commit252ed9c8c13ae532d8b54bd2da236bfc20489e53 (patch)
tree5ffce88dbd6ef458152848fe1db47b9f369e1d66 /src
parent7edcf5a06f2e8e17b333036ccce2d628269bf836 (diff)
test update
Diffstat (limited to 'src')
-rw-r--r--src/include/gnunet_regex_lib.h16
-rw-r--r--src/regex/Makefile.am15
-rw-r--r--src/regex/regex.c25
-rw-r--r--src/regex/test_regex_eval_api.c (renamed from src/regex/test_regex.c)4
-rw-r--r--src/regex/test_regex_iterate_api.c61
5 files changed, 99 insertions, 22 deletions
diff --git a/src/include/gnunet_regex_lib.h b/src/include/gnunet_regex_lib.h
index e1469b25c4..aec37c1734 100644
--- a/src/include/gnunet_regex_lib.h
+++ b/src/include/gnunet_regex_lib.h
@@ -112,14 +112,19 @@ GNUNET_REGEX_eval (struct GNUNET_REGEX_Automaton *a,
const char *string);
/**
+ * Get the first key for the given 'input_string'. This hashes
+ * the first x bits of the 'input_strings'.
+ *
+ * @param input_string string.
+ * @param string_len length of the 'input_string'.
+ * @param key pointer to where to write the hash code.
+ *
* @return number of bits of 'input_string' that have been consumed
* to construct the key
*/
unsigned int
-GNUNET_REGEX_get_first_key (const char *input_string,
- unsigned int string_len,
- GNUNET_HashCode *key);
-
+GNUNET_REGEX_get_first_key (const char *input_string, unsigned int string_len,
+ GNUNET_HashCode * key);
/**
* Check if the given 'proof' matches the given 'key'.
@@ -133,7 +138,6 @@ int
GNUNET_REGEX_check_proof (const char *proof,
const GNUNET_HashCode *key);
-
/**
* Iterator callback function.
*
@@ -151,7 +155,6 @@ typedef void (*GNUNET_REGEX_KeyIterator)(void *cls,
unsigned int num_edges,
const struct GNUNET_REGEX_Edge *edges);
-
/**
* Iterate over all edges starting from start state of automaton 'a'. Calling
* iterator for each edge.
@@ -165,7 +168,6 @@ GNUNET_REGEX_iterate_all_edges (struct GNUNET_REGEX_Automaton *a,
GNUNET_REGEX_KeyIterator iterator,
void *iterator_cls);
-
#if 0 /* keep Emacsens' auto-indent happy */
{
#endif
diff --git a/src/regex/Makefile.am b/src/regex/Makefile.am
index 7b9d31095c..c6886cb3a5 100644
--- a/src/regex/Makefile.am
+++ b/src/regex/Makefile.am
@@ -19,15 +19,22 @@ libgnunetregex_la_LDFLAGS = \
-version-info 0:0:0
check_PROGRAMS = \
- test_regex
+ test_regex_eval_api \
+ test_regex_iterate_api
if ENABLE_TEST_RUN
TESTS = $(check_PROGRAMS)
endif
-test_regex_SOURCES = \
- test_regex.c
-test_regex_LDADD = \
+test_regex_eval_api_SOURCES = \
+ test_regex_eval_api.c
+test_regex_eval_api_LDADD = \
+ $(top_builddir)/src/regex/libgnunetregex.la \
+ $(top_builddir)/src/util/libgnunetutil.la
+
+test_regex_iterate_api_SOURCES = \
+ test_regex_iterate_api.c
+test_regex_iterate_api_LDADD = \
$(top_builddir)/src/regex/libgnunetregex.la \
$(top_builddir)/src/util/libgnunetutil.la
diff --git a/src/regex/regex.c b/src/regex/regex.c
index 51ceab26a2..ae28fb4889 100644
--- a/src/regex/regex.c
+++ b/src/regex/regex.c
@@ -927,9 +927,12 @@ dfa_merge_nondistinguishable_states (struct GNUNET_REGEX_Context *ctx,
int change;
change = 1;
- for (i = 0, s1 = a->states_head; i < a->state_count && NULL != s1;
+ for (i = 0, s1 = a->states_head;
+ i < a->state_count && NULL != s1;
i++, s1 = s1->next)
+ {
s1->marked = i;
+ }
// Mark all pairs of accepting/!accepting states
for (s1 = a->states_head; NULL != s1; s1 = s1->next)
@@ -980,7 +983,7 @@ dfa_merge_nondistinguishable_states (struct GNUNET_REGEX_Context *ctx,
struct GNUNET_REGEX_State *s2_next;
- for (i = 0, s1 = a->states_head; NULL != s1; s1 = s1->next)
+ for (s1 = a->states_head; NULL != s1; s1 = s1->next)
{
for (s2 = a->states_head; NULL != s2 && s1 != s2; s2 = s2_next)
{
@@ -1697,8 +1700,10 @@ GNUNET_REGEX_construct_dfa (const char *regex, const size_t len)
GNUNET_free (dfa_stack);
GNUNET_REGEX_automaton_destroy (nfa);
+ GNUNET_REGEX_automaton_save_graph (dfa, "dfa_before.dot");
dfa_minimize (&ctx, dfa);
- scc_tarjan (&ctx, dfa);
+ /*GNUNET_REGEX_automaton_save_graph (dfa, "dfa_after.dot");*/
+ /*scc_tarjan (&ctx, dfa);*/
return dfa;
}
@@ -1760,7 +1765,7 @@ GNUNET_REGEX_automaton_save_graph (struct GNUNET_REGEX_Automaton *a,
p = fopen (filename, "w");
- if (p == NULL)
+ if (NULL == p)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not open file for writing: %s",
filename);
@@ -1788,8 +1793,6 @@ GNUNET_REGEX_automaton_save_graph (struct GNUNET_REGEX_Automaton *a,
GNUNET_free (s_acc);
}
- s->marked = 1;
-
for (ctran = s->transitions_head; NULL != ctran; ctran = ctran->next)
{
if (NULL == ctran->to_state)
@@ -2009,8 +2012,8 @@ state_get_edges (struct GNUNET_REGEX_State *s, struct GNUNET_REGEX_Edge *edges)
{
if (NULL != t->to_state)
{
- edges[count].label = &t->label;
- edges[count].destination = t->to_state->hash;
+ /*edges[count].label = &t->label;*/
+ /*edges[count].destination = t->to_state->hash;*/
count++;
}
}
@@ -2041,7 +2044,6 @@ iterate_edge (struct GNUNET_REGEX_State *s, GNUNET_REGEX_KeyIterator iterator,
iterator (iterator_cls, &s->hash, NULL, s->accepting, num_edges, edges);
-
for (t = s->transitions_head; NULL != t; t = t->next)
iterate_edge (t->to_state, iterator, iterator_cls);
}
@@ -2060,5 +2062,10 @@ GNUNET_REGEX_iterate_all_edges (struct GNUNET_REGEX_Automaton *a,
GNUNET_REGEX_KeyIterator iterator,
void *iterator_cls)
{
+ struct GNUNET_REGEX_State *s;
+
+ for (s = a->start; NULL != s; s = s->next)
+ s->marked = GNUNET_NO;
+
iterate_edge (a->start, iterator, iterator_cls);
}
diff --git a/src/regex/test_regex.c b/src/regex/test_regex_eval_api.c
index c09dc184af..49cdb3931c 100644
--- a/src/regex/test_regex.c
+++ b/src/regex/test_regex_eval_api.c
@@ -18,7 +18,7 @@
Boston, MA 02111-1307, USA.
*/
/**
- * @file regex/test_regex.c
+ * @file regex/test_regex_eval_api.c
* @brief test for regex.c
* @author Maximilian Szengel
*/
@@ -293,7 +293,7 @@ main (int argc, char *argv[])
srand (time (NULL));
for (i = 0; i < 100; i++)
- check_rand += test_random (200, 250, 20);
+ check_rand += test_random (100, 150, 20);
return check_nfa + check_dfa + check_rand;
}
diff --git a/src/regex/test_regex_iterate_api.c b/src/regex/test_regex_iterate_api.c
new file mode 100644
index 0000000000..913e94f2b2
--- /dev/null
+++ b/src/regex/test_regex_iterate_api.c
@@ -0,0 +1,61 @@
+/*
+ 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_iterate_api.c
+ * @brief test for regex.c
+ * @author Maximilian Szengel
+ */
+#include <regex.h>
+#include <time.h>
+#include "platform.h"
+#include "gnunet_regex_lib.h"
+
+void key_iterator(void *cls, const GNUNET_HashCode *key, const char *proof,
+ int accepting, unsigned int num_edges,
+ const struct GNUNET_REGEX_Edge *edges)
+{
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Iterating...\n");
+}
+
+int
+main (int argc, char *argv[])
+{
+ GNUNET_log_setup ("test-regex",
+#if VERBOSE
+ "DEBUG",
+#else
+ "WARNING",
+#endif
+ NULL);
+
+ int error;
+ const char *regex;
+ struct GNUNET_REGEX_Automaton *dfa;
+
+ error = 0;
+ regex = "ab?(abcd)?";
+
+ dfa = GNUNET_REGEX_construct_dfa (regex, strlen (regex));
+ GNUNET_REGEX_automaton_save_graph (dfa, "dfa.dot");
+ GNUNET_REGEX_iterate_all_edges (dfa, key_iterator, NULL);
+ GNUNET_REGEX_automaton_destroy (dfa);
+
+ return error;
+}