aboutsummaryrefslogtreecommitdiff
path: root/src/regex
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/regex
parent7edcf5a06f2e8e17b333036ccce2d628269bf836 (diff)
downloadgnunet-252ed9c8c13ae532d8b54bd2da236bfc20489e53.tar.gz
gnunet-252ed9c8c13ae532d8b54bd2da236bfc20489e53.zip
test update
Diffstat (limited to 'src/regex')
-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
4 files changed, 90 insertions, 15 deletions
diff --git a/src/regex/Makefile.am b/src/regex/Makefile.am
index 7b9d31095..c6886cb3a 100644
--- a/src/regex/Makefile.am
+++ b/src/regex/Makefile.am
@@ -19,15 +19,22 @@ libgnunetregex_la_LDFLAGS = \
19 -version-info 0:0:0 19 -version-info 0:0:0
20 20
21check_PROGRAMS = \ 21check_PROGRAMS = \
22 test_regex 22 test_regex_eval_api \
23 test_regex_iterate_api
23 24
24if ENABLE_TEST_RUN 25if ENABLE_TEST_RUN
25TESTS = $(check_PROGRAMS) 26TESTS = $(check_PROGRAMS)
26endif 27endif
27 28
28test_regex_SOURCES = \ 29test_regex_eval_api_SOURCES = \
29 test_regex.c 30 test_regex_eval_api.c
30test_regex_LDADD = \ 31test_regex_eval_api_LDADD = \
32 $(top_builddir)/src/regex/libgnunetregex.la \
33 $(top_builddir)/src/util/libgnunetutil.la
34
35test_regex_iterate_api_SOURCES = \
36 test_regex_iterate_api.c
37test_regex_iterate_api_LDADD = \
31 $(top_builddir)/src/regex/libgnunetregex.la \ 38 $(top_builddir)/src/regex/libgnunetregex.la \
32 $(top_builddir)/src/util/libgnunetutil.la 39 $(top_builddir)/src/util/libgnunetutil.la
33 40
diff --git a/src/regex/regex.c b/src/regex/regex.c
index 51ceab26a..ae28fb488 100644
--- a/src/regex/regex.c
+++ b/src/regex/regex.c
@@ -927,9 +927,12 @@ dfa_merge_nondistinguishable_states (struct GNUNET_REGEX_Context *ctx,
927 int change; 927 int change;
928 928
929 change = 1; 929 change = 1;
930 for (i = 0, s1 = a->states_head; i < a->state_count && NULL != s1; 930 for (i = 0, s1 = a->states_head;
931 i < a->state_count && NULL != s1;
931 i++, s1 = s1->next) 932 i++, s1 = s1->next)
933 {
932 s1->marked = i; 934 s1->marked = i;
935 }
933 936
934 // Mark all pairs of accepting/!accepting states 937 // Mark all pairs of accepting/!accepting states
935 for (s1 = a->states_head; NULL != s1; s1 = s1->next) 938 for (s1 = a->states_head; NULL != s1; s1 = s1->next)
@@ -980,7 +983,7 @@ dfa_merge_nondistinguishable_states (struct GNUNET_REGEX_Context *ctx,
980 983
981 struct GNUNET_REGEX_State *s2_next; 984 struct GNUNET_REGEX_State *s2_next;
982 985
983 for (i = 0, s1 = a->states_head; NULL != s1; s1 = s1->next) 986 for (s1 = a->states_head; NULL != s1; s1 = s1->next)
984 { 987 {
985 for (s2 = a->states_head; NULL != s2 && s1 != s2; s2 = s2_next) 988 for (s2 = a->states_head; NULL != s2 && s1 != s2; s2 = s2_next)
986 { 989 {
@@ -1697,8 +1700,10 @@ GNUNET_REGEX_construct_dfa (const char *regex, const size_t len)
1697 GNUNET_free (dfa_stack); 1700 GNUNET_free (dfa_stack);
1698 GNUNET_REGEX_automaton_destroy (nfa); 1701 GNUNET_REGEX_automaton_destroy (nfa);
1699 1702
1703 GNUNET_REGEX_automaton_save_graph (dfa, "dfa_before.dot");
1700 dfa_minimize (&ctx, dfa); 1704 dfa_minimize (&ctx, dfa);
1701 scc_tarjan (&ctx, dfa); 1705 /*GNUNET_REGEX_automaton_save_graph (dfa, "dfa_after.dot");*/
1706 /*scc_tarjan (&ctx, dfa);*/
1702 1707
1703 return dfa; 1708 return dfa;
1704} 1709}
@@ -1760,7 +1765,7 @@ GNUNET_REGEX_automaton_save_graph (struct GNUNET_REGEX_Automaton *a,
1760 1765
1761 p = fopen (filename, "w"); 1766 p = fopen (filename, "w");
1762 1767
1763 if (p == NULL) 1768 if (NULL == p)
1764 { 1769 {
1765 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not open file for writing: %s", 1770 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not open file for writing: %s",
1766 filename); 1771 filename);
@@ -1788,8 +1793,6 @@ GNUNET_REGEX_automaton_save_graph (struct GNUNET_REGEX_Automaton *a,
1788 GNUNET_free (s_acc); 1793 GNUNET_free (s_acc);
1789 } 1794 }
1790 1795
1791 s->marked = 1;
1792
1793 for (ctran = s->transitions_head; NULL != ctran; ctran = ctran->next) 1796 for (ctran = s->transitions_head; NULL != ctran; ctran = ctran->next)
1794 { 1797 {
1795 if (NULL == ctran->to_state) 1798 if (NULL == ctran->to_state)
@@ -2009,8 +2012,8 @@ state_get_edges (struct GNUNET_REGEX_State *s, struct GNUNET_REGEX_Edge *edges)
2009 { 2012 {
2010 if (NULL != t->to_state) 2013 if (NULL != t->to_state)
2011 { 2014 {
2012 edges[count].label = &t->label; 2015 /*edges[count].label = &t->label;*/
2013 edges[count].destination = t->to_state->hash; 2016 /*edges[count].destination = t->to_state->hash;*/
2014 count++; 2017 count++;
2015 } 2018 }
2016 } 2019 }
@@ -2041,7 +2044,6 @@ iterate_edge (struct GNUNET_REGEX_State *s, GNUNET_REGEX_KeyIterator iterator,
2041 2044
2042 iterator (iterator_cls, &s->hash, NULL, s->accepting, num_edges, edges); 2045 iterator (iterator_cls, &s->hash, NULL, s->accepting, num_edges, edges);
2043 2046
2044
2045 for (t = s->transitions_head; NULL != t; t = t->next) 2047 for (t = s->transitions_head; NULL != t; t = t->next)
2046 iterate_edge (t->to_state, iterator, iterator_cls); 2048 iterate_edge (t->to_state, iterator, iterator_cls);
2047 } 2049 }
@@ -2060,5 +2062,10 @@ GNUNET_REGEX_iterate_all_edges (struct GNUNET_REGEX_Automaton *a,
2060 GNUNET_REGEX_KeyIterator iterator, 2062 GNUNET_REGEX_KeyIterator iterator,
2061 void *iterator_cls) 2063 void *iterator_cls)
2062{ 2064{
2065 struct GNUNET_REGEX_State *s;
2066
2067 for (s = a->start; NULL != s; s = s->next)
2068 s->marked = GNUNET_NO;
2069
2063 iterate_edge (a->start, iterator, iterator_cls); 2070 iterate_edge (a->start, iterator, iterator_cls);
2064} 2071}
diff --git a/src/regex/test_regex.c b/src/regex/test_regex_eval_api.c
index c09dc184a..49cdb3931 100644
--- a/src/regex/test_regex.c
+++ b/src/regex/test_regex_eval_api.c
@@ -18,7 +18,7 @@
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20/** 20/**
21 * @file regex/test_regex.c 21 * @file regex/test_regex_eval_api.c
22 * @brief test for regex.c 22 * @brief test for regex.c
23 * @author Maximilian Szengel 23 * @author Maximilian Szengel
24 */ 24 */
@@ -293,7 +293,7 @@ main (int argc, char *argv[])
293 293
294 srand (time (NULL)); 294 srand (time (NULL));
295 for (i = 0; i < 100; i++) 295 for (i = 0; i < 100; i++)
296 check_rand += test_random (200, 250, 20); 296 check_rand += test_random (100, 150, 20);
297 297
298 return check_nfa + check_dfa + check_rand; 298 return check_nfa + check_dfa + check_rand;
299} 299}
diff --git a/src/regex/test_regex_iterate_api.c b/src/regex/test_regex_iterate_api.c
new file mode 100644
index 000000000..913e94f2b
--- /dev/null
+++ b/src/regex/test_regex_iterate_api.c
@@ -0,0 +1,61 @@
1/*
2 This file is part of GNUnet
3 (C) 2012 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20/**
21 * @file regex/test_regex_iterate_api.c
22 * @brief test for regex.c
23 * @author Maximilian Szengel
24 */
25#include <regex.h>
26#include <time.h>
27#include "platform.h"
28#include "gnunet_regex_lib.h"
29
30void key_iterator(void *cls, const GNUNET_HashCode *key, const char *proof,
31 int accepting, unsigned int num_edges,
32 const struct GNUNET_REGEX_Edge *edges)
33{
34 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Iterating...\n");
35}
36
37int
38main (int argc, char *argv[])
39{
40 GNUNET_log_setup ("test-regex",
41#if VERBOSE
42 "DEBUG",
43#else
44 "WARNING",
45#endif
46 NULL);
47
48 int error;
49 const char *regex;
50 struct GNUNET_REGEX_Automaton *dfa;
51
52 error = 0;
53 regex = "ab?(abcd)?";
54
55 dfa = GNUNET_REGEX_construct_dfa (regex, strlen (regex));
56 GNUNET_REGEX_automaton_save_graph (dfa, "dfa.dot");
57 GNUNET_REGEX_iterate_all_edges (dfa, key_iterator, NULL);
58 GNUNET_REGEX_automaton_destroy (dfa);
59
60 return error;
61}