aboutsummaryrefslogtreecommitdiff
path: root/src/regex/test_regex_proofs.c
diff options
context:
space:
mode:
authorMaximilian Szengel <gnunet@maxsz.de>2012-07-02 12:22:37 +0000
committerMaximilian Szengel <gnunet@maxsz.de>2012-07-02 12:22:37 +0000
commita4b40b20949b4ea21d98bed902906cdf56d41326 (patch)
treec21f239124ccc818ca52832b736b18ae3522230a /src/regex/test_regex_proofs.c
parentce4b5c1fa37a9b26df4345d30b6ba2c839ce23d5 (diff)
downloadgnunet-a4b40b20949b4ea21d98bed902906cdf56d41326.tar.gz
gnunet-a4b40b20949b4ea21d98bed902906cdf56d41326.zip
regex bugfixes
Diffstat (limited to 'src/regex/test_regex_proofs.c')
-rw-r--r--src/regex/test_regex_proofs.c45
1 files changed, 27 insertions, 18 deletions
diff --git a/src/regex/test_regex_proofs.c b/src/regex/test_regex_proofs.c
index 85fc3079d..831f4dc48 100644
--- a/src/regex/test_regex_proofs.c
+++ b/src/regex/test_regex_proofs.c
@@ -106,39 +106,48 @@ test_proofs_static (void)
106 unsigned int i; 106 unsigned int i;
107 unsigned int error; 107 unsigned int error;
108 108
109 const char *regex[4] = { 109 const char *regex[6] = {
110 "a|aa*a", 110 "a|aa*a",
111 "a+", 111 "a+",
112 "a*", 112 "a*",
113 "a*a*" 113 "a*a*",
114 "(F*C|WfPf|y+F*C)",
115 "y*F*C|WfPf",
116 /* "2?jA?e?D*K", */
117 /* "((j|2j)K|(j|2j)AK|(j|2j)(D|e|(j|2j)A(D|e))D*K)", */
118 /* "((j|2j)K|(j|2j)(D|e|((j|2j)j|(j|2j)2j)A(D|e))D*K|(j|2j)AK)", */
114 }; 119 };
115 120
116 char *canonical_regex; 121 const char *canon_rx1;
117 struct GNUNET_REGEX_Automaton *dfa; 122 const char *canon_rx2;
123 struct GNUNET_REGEX_Automaton *dfa1;
124 struct GNUNET_REGEX_Automaton *dfa2;
118 125
119 error = 0; 126 error = 0;
120 127
121 for (i = 0; i < 4; i += 2) 128 for (i = 0; i < 6; i += 2)
122 { 129 {
123 dfa = GNUNET_REGEX_construct_dfa (regex[i], strlen (regex[i])); 130 dfa1 = GNUNET_REGEX_construct_dfa (regex[i], strlen (regex[i]));
124 canonical_regex = GNUNET_strdup (GNUNET_REGEX_get_canonical_regex (dfa)); 131 dfa2 = GNUNET_REGEX_construct_dfa (regex[i + 1], strlen (regex[i + 1]));
125 GNUNET_REGEX_automaton_destroy (dfa); 132
133 canon_rx1 = GNUNET_REGEX_get_canonical_regex (dfa1);
134 canon_rx2 = GNUNET_REGEX_get_canonical_regex (dfa2);
126 135
127 dfa = GNUNET_REGEX_construct_dfa (regex[i + 1], strlen (regex[i + 1])); 136 error += (0 == strcmp (canon_rx1, canon_rx2)) ? 0 : 1;
128 error +=
129 (0 ==
130 strcmp (canonical_regex,
131 GNUNET_REGEX_get_canonical_regex (dfa))) ? 0 : 1;
132 137
133 if (error > 0) 138 if (error > 0)
134 { 139 {
135 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 140 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
136 "Comparing canonical regex of %s with %s failed.\n", regex[i], 141 "Comparing canonical regex failed:\nrx1: %s\ncrx1: %s\nrx2: %s\ncrx2: %s\n",
137 regex[i + 1]); 142 regex[i], canon_rx1, regex[i + 1], canon_rx2);
143
144 /* Save the graphs of the two conflicting DFAs */
145 /* GNUNET_REGEX_automaton_save_graph (dfa1, "proofs_fail_dfa1.dot"); */
146 /* GNUNET_REGEX_automaton_save_graph (dfa2, "proofs_fail_dfa2.dot"); */
138 } 147 }
139 148
140 GNUNET_free (canonical_regex); 149 GNUNET_REGEX_automaton_destroy (dfa1);
141 GNUNET_REGEX_automaton_destroy (dfa); 150 GNUNET_REGEX_automaton_destroy (dfa2);
142 } 151 }
143 152
144 return error; 153 return error;
@@ -161,7 +170,7 @@ main (int argc, char *argv[])
161 error = 0; 170 error = 0;
162 171
163 error += test_proofs_static (); 172 error += test_proofs_static ();
164// error += test_proofs_random (100, 10); 173 /* error += test_proofs_random (10000, 10); */
165 174
166 return error; 175 return error;
167} 176}