aboutsummaryrefslogtreecommitdiff
path: root/src/regex/test_regex_iterate_api.c
diff options
context:
space:
mode:
authorMaximilian Szengel <gnunet@maxsz.de>2012-09-26 14:46:32 +0000
committerMaximilian Szengel <gnunet@maxsz.de>2012-09-26 14:46:32 +0000
commite96bf692ed1707f342c8db4cc97e1294683d0595 (patch)
tree61cc7ba0eeb91164544c9fbcdd0a22001e9373f5 /src/regex/test_regex_iterate_api.c
parentfb55bbea31e2820414fd6f6f01fd5e46b32d9a71 (diff)
downloadgnunet-e96bf692ed1707f342c8db4cc97e1294683d0595.tar.gz
gnunet-e96bf692ed1707f342c8db4cc97e1294683d0595.zip
fixes
Diffstat (limited to 'src/regex/test_regex_iterate_api.c')
-rw-r--r--src/regex/test_regex_iterate_api.c30
1 files changed, 22 insertions, 8 deletions
diff --git a/src/regex/test_regex_iterate_api.c b/src/regex/test_regex_iterate_api.c
index 84bb6e9fb..37475ee91 100644
--- a/src/regex/test_regex_iterate_api.c
+++ b/src/regex/test_regex_iterate_api.c
@@ -85,15 +85,20 @@ key_iterator (void *cls, const struct GNUNET_HashCode *key, const char *proof,
85 transition_counter++; 85 transition_counter++;
86 } 86 }
87 87
88 GNUNET_free (state_id);
89
90 for (i = 0; i < ctx->string_count; i++) 88 for (i = 0; i < ctx->string_count; i++)
91 { 89 {
92 if (0 == strcmp (proof, ctx->strings[i])) 90 if (0 == strcmp (proof, ctx->strings[i]))
93 ctx->match_count++; 91 ctx->match_count++;
94 } 92 }
95 93
96 ctx->error += (GNUNET_OK == GNUNET_REGEX_check_proof (proof, key)) ? 0 : 1; 94 if (GNUNET_OK != GNUNET_REGEX_check_proof (proof, key))
95 {
96 ctx->error++;
97 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
98 "Proof check failed: proof: %s key: %s\n", proof, state_id);
99 }
100
101 GNUNET_free (state_id);
97} 102}
98 103
99int 104int
@@ -111,12 +116,12 @@ main (int argc, char *argv[])
111 struct GNUNET_REGEX_Automaton *dfa; 116 struct GNUNET_REGEX_Automaton *dfa;
112 unsigned int i; 117 unsigned int i;
113 unsigned int num_transitions; 118 unsigned int num_transitions;
114 struct IteratorContext ctx = { 0, 0, NULL };
115 char *filename = NULL; 119 char *filename = NULL;
120 struct IteratorContext ctx = { 0, 0, NULL, 0, NULL, 0 };
116 121
117 error = 0; 122 error = 0;
118 123
119 const struct RegexStringPair rxstr[10] = { 124 const struct RegexStringPair rxstr[14] = {
120 {"ab(c|d)+c*(a(b|c)+d)+(bla)+", 2, {"abcdcdca", "abcabdbl"}}, 125 {"ab(c|d)+c*(a(b|c)+d)+(bla)+", 2, {"abcdcdca", "abcabdbl"}},
121 {"abcdefghijklmnop*qst", 1, {"abcdefgh"}}, 126 {"abcdefghijklmnop*qst", 1, {"abcdefgh"}},
122 {"VPN-4-1(0|1)*", 2, {"VPN-4-10", "VPN-4-11"}}, 127 {"VPN-4-1(0|1)*", 2, {"VPN-4-10", "VPN-4-11"}},
@@ -128,13 +133,17 @@ main (int argc, char *argv[])
128 {"xyz*", 2, {"xy", "xyz"}}, 133 {"xyz*", 2, {"xy", "xyz"}},
129 {"ab", 1, {"a"}}, 134 {"ab", 1, {"a"}},
130 {"abcd:(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1):(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)", 2, {"abcd:000", "abcd:101"}}, 135 {"abcd:(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1):(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)", 2, {"abcd:000", "abcd:101"}},
131 {"x*|(0|1|2)(a|b|c|d)", 2, {"xxxxxxxx", "0a"}} 136 {"x*|(0|1|2)(a|b|c|d)", 2, {"xxxxxxxx", "0a"}},
137 {"(0|1)(0|1)23456789ABC", 1, {"11234567"}},
138 {"0*123456789ABC*", 3, {"00123456", "00000000", "12345678"}},
139 {"0123456789A*BC", 1, {"01234567"}},
140 {"GNUNETVPN000100000IPEX6-fc5a:4e1:c2ba::1", 1, {"GNUNETVP"}}
132 }; 141 };
133 142
134 const char *graph_start_str = "digraph G {\nrankdir=LR\n"; 143 const char *graph_start_str = "digraph G {\nrankdir=LR\n";
135 const char *graph_end_str = "\n}\n"; 144 const char *graph_end_str = "\n}\n";
136 145
137 for (i = 0; i < 10; i++) 146 for (i = 0; i < 14; i++)
138 { 147 {
139 // Create graph 148 // Create graph
140 if (GNUNET_YES == GNUNET_REGEX_ITERATE_SAVE_DEBUG_GRAPH) 149 if (GNUNET_YES == GNUNET_REGEX_ITERATE_SAVE_DEBUG_GRAPH)
@@ -158,6 +167,7 @@ main (int argc, char *argv[])
158 else 167 else
159 { 168 {
160 ctx.should_save_graph = GNUNET_NO; 169 ctx.should_save_graph = GNUNET_NO;
170 ctx.graph_filep = NULL;
161 } 171 }
162 172
163 // Iterate over DFA edges 173 // Iterate over DFA edges
@@ -187,7 +197,7 @@ main (int argc, char *argv[])
187 else if (ctx.match_count > ctx.string_count) 197 else if (ctx.match_count > ctx.string_count)
188 { 198 {
189 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 199 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
190 "Doublicate initial transitions for regex %s\n", 200 "Duplicate initial transitions for regex %s\n",
191 rxstr[i].regex); 201 rxstr[i].regex);
192 error += (ctx.string_count - ctx.match_count); 202 error += (ctx.string_count - ctx.match_count);
193 } 203 }
@@ -207,6 +217,10 @@ main (int argc, char *argv[])
207 217
208 for (i = 0; i < 10; i++) 218 for (i = 0; i < 10; i++)
209 { 219 {
220 ctx.string_count = rxstr[i].string_count;
221 ctx.strings = rxstr[i].strings;
222 ctx.match_count = 0;
223
210 dfa = GNUNET_REGEX_construct_dfa (rxstr[i].regex, strlen (rxstr[i].regex)); 224 dfa = GNUNET_REGEX_construct_dfa (rxstr[i].regex, strlen (rxstr[i].regex));
211 GNUNET_REGEX_dfa_add_multi_strides (NULL, dfa, 2); 225 GNUNET_REGEX_dfa_add_multi_strides (NULL, dfa, 2);
212 GNUNET_REGEX_iterate_all_edges (dfa, key_iterator, &ctx); 226 GNUNET_REGEX_iterate_all_edges (dfa, key_iterator, &ctx);