test_regex_eval_api.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. /*
  2. This file is part of GNUnet
  3. Copyright (C) 2012 GNUnet e.V.
  4. GNUnet is free software: you can redistribute it and/or modify it
  5. under the terms of the GNU Affero General Public License as published
  6. by the Free Software Foundation, either version 3 of the License,
  7. or (at your option) any later version.
  8. GNUnet is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Affero General Public License for more details.
  12. You should have received a copy of the GNU Affero General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. SPDX-License-Identifier: AGPL3.0-or-later
  15. */
  16. /**
  17. * @file regex/test_regex_eval_api.c
  18. * @brief test for regex.c
  19. * @author Maximilian Szengel
  20. */
  21. #include <regex.h>
  22. #include <time.h>
  23. #include "platform.h"
  24. #include "regex_internal_lib.h"
  25. #include "regex_test_lib.h"
  26. #include "regex_internal.h"
  27. enum Match_Result
  28. {
  29. match = 0,
  30. nomatch = 1
  31. };
  32. struct Regex_String_Pair
  33. {
  34. char *regex;
  35. int string_count;
  36. char *strings[20];
  37. enum Match_Result expected_results[20];
  38. };
  39. /**
  40. * Random regex test. Generate a random regex as well as 'str_count' strings to
  41. * match it against. Will match using GNUNET_REGEX implementation and compare
  42. * the result to glibc regex result. 'rx_length' has to be smaller then
  43. * 'max_str_len'.
  44. *
  45. * @param rx_length length of the regular expression.
  46. * @param max_str_len maximum length of the random strings.
  47. * @param str_count number of generated random strings.
  48. *
  49. * @return 0 on success, non 0 otherwise.
  50. */
  51. int
  52. test_random (unsigned int rx_length, unsigned int max_str_len,
  53. unsigned int str_count)
  54. {
  55. unsigned int i;
  56. char *rand_rx;
  57. char *matching_str;
  58. int eval;
  59. int eval_check;
  60. int eval_canonical;
  61. int eval_canonical_check;
  62. struct REGEX_INTERNAL_Automaton *dfa;
  63. regex_t rx;
  64. regmatch_t matchptr[1];
  65. char error[200];
  66. int result;
  67. char *canonical_regex = NULL;
  68. /* At least one string is needed for matching */
  69. GNUNET_assert (str_count > 0);
  70. /* The string should be at least as long as the regex itself */
  71. GNUNET_assert (max_str_len >= rx_length);
  72. /* Generate random regex and a string that matches the regex */
  73. matching_str = GNUNET_malloc (rx_length + 1);
  74. rand_rx = REGEX_TEST_generate_random_regex (rx_length, matching_str);
  75. /* Now match */
  76. result = 0;
  77. for (i = 0; i < str_count; i++)
  78. {
  79. if (0 < i)
  80. {
  81. matching_str = REGEX_TEST_generate_random_string (max_str_len);
  82. }
  83. /* Match string using DFA */
  84. dfa = REGEX_INTERNAL_construct_dfa (rand_rx, strlen (rand_rx), 0);
  85. if (NULL == dfa)
  86. {
  87. GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Constructing DFA failed\n");
  88. goto error;
  89. }
  90. eval = REGEX_INTERNAL_eval (dfa, matching_str);
  91. /* save the canonical regex for later comparison */
  92. canonical_regex = GNUNET_strdup (REGEX_INTERNAL_get_canonical_regex (dfa));
  93. REGEX_INTERNAL_automaton_destroy (dfa);
  94. /* Match string using glibc regex */
  95. if (0 != regcomp (&rx, rand_rx, REG_EXTENDED))
  96. {
  97. GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
  98. "Could not compile regex using regcomp: %s\n", rand_rx);
  99. goto error;
  100. }
  101. eval_check = regexec (&rx, matching_str, 1, matchptr, 0);
  102. regfree (&rx);
  103. /* We only want to match the whole string, because that's what our DFA does,
  104. * too. */
  105. if ((eval_check == 0) &&
  106. ((matchptr[0].rm_so != 0) || (matchptr[0].rm_eo != strlen (
  107. matching_str)) ))
  108. eval_check = 1;
  109. /* Match canonical regex */
  110. dfa =
  111. REGEX_INTERNAL_construct_dfa (canonical_regex, strlen (canonical_regex),
  112. 0);
  113. if (NULL == dfa)
  114. {
  115. GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Constructing DFA failed\n");
  116. goto error;
  117. }
  118. eval_canonical = REGEX_INTERNAL_eval (dfa, matching_str);
  119. REGEX_INTERNAL_automaton_destroy (dfa);
  120. if (0 != regcomp (&rx, canonical_regex, REG_EXTENDED))
  121. {
  122. GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
  123. "Could not compile regex using regcomp: %s\n",
  124. canonical_regex);
  125. goto error;
  126. }
  127. eval_canonical_check = regexec (&rx, matching_str, 1, matchptr, 0);
  128. regfree (&rx);
  129. /* We only want to match the whole string, because that's what our DFA does,
  130. * too. */
  131. if ((eval_canonical_check == 0) &&
  132. ((matchptr[0].rm_so != 0) || (matchptr[0].rm_eo != strlen (
  133. matching_str)) ))
  134. eval_canonical_check = 1;
  135. /* compare results */
  136. if ((eval_check != eval) || (eval_canonical != eval_canonical_check) )
  137. {
  138. regerror (eval_check, &rx, error, sizeof error);
  139. GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
  140. "Unexpected result:\nregex: %s\ncanonical_regex: %s\n\
  141. string: %s\ngnunet regex: %i\nglibc regex: %i\n\
  142. canonical regex: %i\ncanonical regex glibc: %i\n\
  143. glibc error: %s\n\n", rand_rx, canonical_regex, matching_str,
  144. eval, eval_check, eval_canonical, eval_canonical_check,
  145. error);
  146. result += 1;
  147. }
  148. GNUNET_free (canonical_regex);
  149. GNUNET_free (matching_str);
  150. canonical_regex = NULL;
  151. matching_str = NULL;
  152. }
  153. GNUNET_free (rand_rx);
  154. return result;
  155. error:
  156. GNUNET_free (matching_str);
  157. GNUNET_free (rand_rx);
  158. GNUNET_free (canonical_regex);
  159. return -1;
  160. }
  161. /**
  162. * Automaton test that compares the result of matching regular expression 'rx'
  163. * with the strings and expected results in 'rxstr' with the result of matching
  164. * the same strings with glibc regex.
  165. *
  166. * @param a automaton.
  167. * @param rx compiled glibc regex.
  168. * @param rxstr regular expression and strings with expected results to
  169. * match against.
  170. *
  171. * @return 0 on successfull, non 0 otherwise
  172. */
  173. int
  174. test_automaton (struct REGEX_INTERNAL_Automaton *a, regex_t *rx,
  175. struct Regex_String_Pair *rxstr)
  176. {
  177. int result;
  178. int eval;
  179. int eval_check;
  180. char error[200];
  181. regmatch_t matchptr[1];
  182. int i;
  183. if (NULL == a)
  184. {
  185. GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Automaton was NULL\n");
  186. return 1;
  187. }
  188. result = 0;
  189. for (i = 0; i < rxstr->string_count; i++)
  190. {
  191. eval = REGEX_INTERNAL_eval (a, rxstr->strings[i]);
  192. eval_check = regexec (rx, rxstr->strings[i], 1, matchptr, 0);
  193. /* We only want to match the whole string, because that's what our DFA does,
  194. * too. */
  195. if ((eval_check == 0) &&
  196. ((matchptr[0].rm_so != 0) ||
  197. (matchptr[0].rm_eo != strlen (rxstr->strings[i])) ))
  198. eval_check = 1;
  199. if (((rxstr->expected_results[i] == match) && ((0 != eval) || (0 !=
  200. eval_check) ))
  201. || ((rxstr->expected_results[i] == nomatch) &&
  202. ((0 == eval) || (0 == eval_check) )))
  203. {
  204. result = 1;
  205. regerror (eval_check, rx, error, sizeof error);
  206. GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
  207. "Unexpected result:\nregex: %s\ncanonical_regex: %s\n"
  208. "string: %s\nexpected result: %i\n"
  209. "gnunet regex: %i\nglibc regex: %i\nglibc error: %s\n"
  210. "rm_so: %i\nrm_eo: %i\n\n", rxstr->regex,
  211. REGEX_INTERNAL_get_canonical_regex (a), rxstr->strings[i],
  212. rxstr->expected_results[i], eval, eval_check, error,
  213. matchptr[0].rm_so, matchptr[0].rm_eo);
  214. }
  215. }
  216. return result;
  217. }
  218. int
  219. main (int argc, char *argv[])
  220. {
  221. GNUNET_log_setup ("test-regex", "WARNING", NULL);
  222. struct REGEX_INTERNAL_Automaton *a;
  223. regex_t rx;
  224. int i;
  225. int check_nfa;
  226. int check_dfa;
  227. int check_rand;
  228. char *check_proof;
  229. struct Regex_String_Pair rxstr[19] = {
  230. { "ab?(abcd)?", 5,
  231. { "ababcd", "abab", "aabcd", "a", "abb" },
  232. { match, nomatch, match, match, nomatch } },
  233. { "ab(c|d)+c*(a(b|c)d)+", 5,
  234. { "abcdcdcdcdddddabd", "abcd",
  235. "abcddddddccccccccccccccccccccccccabdacdabd",
  236. "abccccca", "abcdcdcdccdabdabd" },
  237. { match, nomatch, match, nomatch, match } },
  238. { "ab+c*(a(bx|c)d)+", 5,
  239. { "abcdcdcdcdddddabd", "abcd",
  240. "abcddddddccccccccccccccccccccccccabdacdabd",
  241. "abccccca", "abcdcdcdccdabdabd" },
  242. { nomatch, nomatch, nomatch, nomatch, nomatch } },
  243. { "a+X*y+c|p|R|Z*K*y*R+w|Y*6+n+h*k*w+V*F|W*B*e*", 1,
  244. { "kaXycQepRZKyRwY6nhkwVFWBegNVtLPj39XhJJ6bEifRSZRYZg" },
  245. { nomatch } },
  246. {
  247. "k|a+X*y+c|Q*e|p|R|Z*K*y*R+w|Y*6+n+h*k*w+V*F|W*B*e*g|N+V|t+L|P*j*3*9+X*h*J|J*6|b|E*i*f*R+S|Z|R|Y*Z|g*",
  248. 1,
  249. { "kaXycQepRZKyRwY6nhkwVFWBegNVtLPj39XhJJ6bEifRSZRYZg" },
  250. { nomatch }
  251. },
  252. {
  253. "F?W+m+2*6*c*s|P?U?a|B|y*i+t+A|V|6*C*7*e?Z*n*i|J?5+g?W*V?7*j?p?1|r?B?C+E+3+6*i+W*P?K?0|D+7?y*m+3?g?K?",
  254. 1,
  255. { "osfjsodfonONONOnosndfsdnfsd" },
  256. { nomatch }
  257. },
  258. {
  259. "V|M*o?x*p*d+h+b|E*m?h?Y*E*O?W*W*P+o?Z+H*M|I*q+C*a+5?5*9|b?z|G*y*k?R|p+u|8*h?B+l*H|e|L*O|1|F?v*0?5|C+",
  260. 1,
  261. { "VMoxpdhbEmhYEOWWPoZHMIqCa559bzGykRpu8hBlHeLO1Fv05C" },
  262. { nomatch }
  263. },
  264. { "(bla)*", 8,
  265. { "", "bla", "blabla", "bl", "la", "b", "l", "a" },
  266. { match, match, match, nomatch, nomatch, nomatch, nomatch, nomatch } },
  267. { "ab(c|d)+c*(a(b|c)+d)+(bla)(bla)*", 8,
  268. { "ab", "abcabdbla", "abdcccccccccccabcbccdblablabla", "bl", "la", "b",
  269. "l",
  270. "a" },
  271. { nomatch, match, match, nomatch, nomatch, nomatch, nomatch, nomatch } },
  272. { "a|aa*a", 6,
  273. { "", "a", "aa", "aaa", "aaaa", "aaaaa" },
  274. { nomatch, match, match, match, match, match } },
  275. { "ab(c|d)+c*(a(b|c)+d)+(bla)+", 1,
  276. { "abcabdblaacdbla" },
  277. { nomatch } },
  278. { "(ac|b)+", 8,
  279. { "b", "bb", "ac", "", "acb", "bacbacac", "acacac", "abc" },
  280. { match, match, match, nomatch, match, match, match, nomatch } },
  281. { "(ab|c)+", 7,
  282. { "", "ab", "c", "abc", "ababcc", "acc", "abac" },
  283. { nomatch, match, match, match, match, nomatch, nomatch } },
  284. { "((j|2j)K|(j|2j)AK|(j|2j)(D|e|(j|2j)A(D|e))D*K)", 1,
  285. { "", "2j2jADK", "j2jADK" },
  286. { nomatch, match, match } },
  287. { "((j|2j)K|(j|2j)(D|e|((j|2j)j|(j|2j)2j)A(D|e))D*K|(j|2j)AK)", 2,
  288. { "", "2j2jjADK", "j2jADK" },
  289. { nomatch, match, match } },
  290. { "ab(c|d)+c*(a(b|c)d)+", 1,
  291. { "abacd" },
  292. { nomatch } },
  293. { "d|5kl", 1,
  294. { "d5kl" },
  295. { nomatch } },
  296. { "a()b", 1,
  297. { "ab" },
  298. { match } },
  299. {
  300. "GNVPN-0001-PAD(001110101001001010(0|1)*|001110101001001010000(0|1)*|001110101001001010001(0|1)*|001110101001001010010(0|1)*|001110101001001010011(0|1)*|001110101001001010100(0|1)*|001110101001001010101(0|1)*|001110101001001010110(0|1)*|001110101001001010111(0|1)*|0011101010110110(0|1)*|001110101011011000000(0|1)*|001110101011011000001(0|1)*|001110101011011000010(0|1)*|001110101011011000011(0|1)*|001110101011011000100(0|1)*|001110101011011000101(0|1)*|001110101011011000110(0|1)*|001110101011011000111(0|1)*|001110101011011001000(0|1)*|001110101011011001001(0|1)*|001110101011011001010(0|1)*|001110101011011001011(0|1)*|001110101011011001100(0|1)*|001110101011011001101(0|1)*|001110101011011001110(0|1)*|001110101011011001111(0|1)*|001110101011011010000(0|1)*|001110101011011010001(0|1)*|001110101011011010010(0|1)*|001110101011011010011(0|1)*|001110101011011010100(0|1)*|001110101011011010101(0|1)*|001110101011011010110(0|1)*|001110101011011010111(0|1)*|001110101011011011000(0|1)*|001110101011011011001(0|1)*|001110101011011011010(0|1)*|001110101011011011011(0|1)*|001110101011011011100(0|1)*|001110101011011011101(0|1)*|001110101011011011110(0|1)*|001110101011011011111(0|1)*|0011101110111101(0|1)*|001110111011110100000(0|1)*|001110111011110100001(0|1)*|001110111011110100010(0|1)*|001110111011110100011(0|1)*|001110111011110100100(0|1)*|001110111011110100101(0|1)*|001110111011110100110(0|1)*|001110111011110100111(0|1)*|001110111011110101000(0|1)*|001110111011110101001(0|1)*|001110111011110101010(0|1)*|001110111011110101011(0|1)*|001110111011110101100(0|1)*|001110111011110101101(0|1)*|001110111011110101110(0|1)*|001110111011110101111(0|1)*|001110111011110110000(0|1)*|001110111011110110001(0|1)*|001110111011110110010(0|1)*|001110111011110110011(0|1)*|001110111011110110100(0|1)*|001110111011110110101(0|1)*|001110111011110110110(0|1)*|001110111011110110111(0|1)*|001110111011110111000(0|1)*|001110111011110111001(0|1)*|001110111011110111010(0|1)*|001110111011110111011(0|1)*|001110111011110111100(0|1)*|001110111011110111101(0|1)*|001110111011110111110(0|1)*|0111010001010110(0|1)*|011101000101011000000(0|1)*|011101000101011000001(0|1)*|011101000101011000010(0|1)*|011101000101011000011(0|1)*|011101000101011000100(0|1)*|011101000101011000101(0|1)*|011101000101011000110(0|1)*|011101000101011000111(0|1)*|011101000101011001000(0|1)*|011101000101011001001(0|1)*|011101000101011001010(0|1)*|011101000101011001011(0|1)*|011101000101011001100(0|1)*|011101000101011001101(0|1)*|011101000101011001110(0|1)*|011101000101011001111(0|1)*|011101000101011010000(0|1)*|011101000101011010001(0|1)*|011101000101011010010(0|1)*|011101000101011010011(0|1)*|011101000101011010100(0|1)*|011101000101011010101(0|1)*|011101000101011010110(0|1)*|011101000101011010111(0|1)*|011101000101011011000(0|1)*|011101000101011011001(0|1)*|011101000101011011010(0|1)*|011101000101011011011(0|1)*|011101000101011011100(0|1)*|011101000101011011101(0|1)*|011101000101011011110(0|1)*|011101000101011011111(0|1)*|0111010001010111(0|1)*|011101000101011100000(0|1)*|011101000101011100001(0|1)*|011101000101011100010(0|1)*|011101000101011100011(0|1)*|011101000101011100100(0|1)*|011101000101011100101(0|1)*|011101000101011100110(0|1)*|011101000101011100111(0|1)*|011101000101011101000(0|1)*|011101000101011101001(0|1)*|011101000101011101010(0|1)*|011101000101011101011(0|1)*|011101000101011101100(0|1)*|011101000101011101101(0|1)*|011101000101011101110(0|1)*|011101000101011101111(0|1)*|011101000101011110000(0|1)*|011101000101011110001(0|1)*|011101000101011110010(0|1)*|011101000101011110011(0|1)*|011101000101011110100(0|1)*|011101000101011110101(0|1)*|011101000101011110110(0|1)*|011101000101011110111(0|1)*|011101000101011111000(0|1)*|011101000101011111001(0|1)*|011101000101011111010(0|1)*|011101000101011111011(0|1)*|011101000101011111100(0|1)*|011101000101011111101(0|1)*|011101000101011111110(0|1)*|011101000101011111111(0|1)*|0111010001011000(0|1)*|011101000101100000000(0|1)*|011101000101100000001(0|1)*|011101000101100000010(0|1)*|011101000101100000011(0|1)*|011101000101100000100(0|1)*|011101000101100000101(0|1)*|011101000101100000110(0|1)*|011101000101100000111(0|1)*|011101000101100001000(0|1)*|011101000101100001001(0|1)*|011101000101100001010(0|1)*|011101000101100001011(0|1)*|011101000101100001100(0|1)*|011101000101100001101(0|1)*|011101000101100001110(0|1)*|011101000101100001111(0|1)*|011101000101100010000(0|1)*|011101000101100010001(0|1)*|011101000101100010010(0|1)*|011101000101100010011(0|1)*|011101000101100010100(0|1)*|011101000101100010101(0|1)*|011101000101100010110(0|1)*|011101000101100010111(0|1)*|011101000101100011000(0|1)*|011101000101100011001(0|1)*|011101000101100011010(0|1)*|011101000101100011011(0|1)*|011101000101100011100(0|1)*|011101000101100011101(0|1)*|011101000101100011110(0|1)*|011101000101100011111(0|1)*|01110100010110010(0|1)*|011101000101100100000(0|1)*|011101000101100100001(0|1)*|011101000101100100010(0|1)*|011101000101100100011(0|1)*|011101000101100100100(0|1)*|011101000101100100101(0|1)*|011101000101100100110(0|1)*|011101000101100100111(0|1)*|011101000101100101000(0|1)*|011101000101100101001(0|1)*|011101000101100101010(0|1)*|011101000101100101011(0|1)*|011101000101100101100(0|1)*|011101000101100101101(0|1)*|011101000101100101110(0|1)*|011101000101100101111(0|1)*|011101000101100101111000(0|1)*|1100101010011100(0|1)*|110010101001110000000(0|1)*|110010101001110000000001(0|1)*|110010101001110000000010(0|1)*|110010101001110000000110(0|1)*|110010101001110000001(0|1)*|110010101001110000001000(0|1)*|110010101001110000001001(0|1)*|110010101001110000001010(0|1)*|110010101001110000001011(0|1)*|110010101001110000001101(0|1)*|110010101001110000001110(0|1)*|110010101001110000010(0|1)*|110010101001110000011(0|1)*|110010101001110000100(0|1)*|110010101001110000101(0|1)*|110010101001110000110(0|1)*|110010101001110000111(0|1)*|110010101001110001000(0|1)*|110010101001110001001(0|1)*|110010101001110001010(0|1)*|110010101001110001011(0|1)*|110010101001110001100(0|1)*|110010101001110001101(0|1)*|110010101001110001110(0|1)*|110010101001110001111(0|1)*|110010101001110010000(0|1)*|110010101001110010001(0|1)*|110010101001110010010(0|1)*|110010101001110010011(0|1)*|110010101001110010100(0|1)*|110010101001110010101(0|1)*|110010101001110010110(0|1)*|110010101001110010111(0|1)*|110010101001110011000(0|1)*|110010101001110011001(0|1)*|110010101001110011010(0|1)*|110010101001110011011(0|1)*|110010101001110011100(0|1)*|110010101001110011101(0|1)*|110010101001110011110(0|1)*|110010101001110011111(0|1)*|1101101010111010(0|1)*|110110101011101000000(0|1)*|110110101011101000000001(0|1)*|110110101011101000001000(0|1)*|110110101011101000001001(0|1)*|110110101011101000001010(0|1)*|110110101011101000001011(0|1)*|110110101011101000001100(0|1)*|110110101011101000001110(0|1)*|110110101011101000001111(0|1)*|110110101011101000010(0|1)*|110110101011101000010000(0|1)*|110110101011101000010001(0|1)*|110110101011101000010010(0|1)*|110110101011101000010011(0|1)*|110110101011101000011(0|1)*|110110101011101000100(0|1)*|110110101011101000101(0|1)*|110110101011101000110(0|1)*|110110101011101000111(0|1)*|110110101011101001000(0|1)*|110110101011101001001(0|1)*|110110101011101001010(0|1)*|110110101011101001011(0|1)*|110110101011101001100(0|1)*|110110101011101001101(0|1)*|110110101011101001110(0|1)*|110110101011101001111(0|1)*|110110101011101010000(0|1)*|110110101011101010001(0|1)*|110110101011101010010(0|1)*|110110101011101010011(0|1)*|110110101011101010100(0|1)*|110110101011101010101(0|1)*|110110101011101010110(0|1)*|110110101011101010111(0|1)*|110110101011101011000(0|1)*|110110101011101011001(0|1)*|110110101011101011010(0|1)*|110110101011101011011(0|1)*|110110101011101011100(0|1)*|110110101011101011101(0|1)*|110110101011101011110(0|1)*|110110101011101011111(0|1)*|1101101011010100(0|1)*|110110101101010000000(0|1)*|110110101101010000001(0|1)*|110110101101010000010(0|1)*|110110101101010000011(0|1)*|110110101101010000100(0|1)*|110110101101010000101(0|1)*|110110101101010000110(0|1)*|110110101101010000111(0|1)*|110110101101010001000(0|1)*|110110101101010001001(0|1)*|110110101101010001010(0|1)*|110110101101010001011(0|1)*|110110101101010001100(0|1)*|110110101101010001101(0|1)*|110110101101010001110(0|1)*|110110101101010001111(0|1)*|110110101101010010000(0|1)*|110110101101010010001(0|1)*|110110101101010010010(0|1)*|110110101101010010011(0|1)*|110110101101010010100(0|1)*|1101101011010100101000(0|1)*|110110101101010010101(0|1)*|110110101101010010110(0|1)*|110110101101010010111(0|1)*|110110101101010011000(0|1)*|110110101101010011010(0|1)*|110110101101010011011(0|1)*|110110101101010011100(0|1)*|110110101101010011101(0|1)*|110110101101010011110(0|1)*|110110101101010011111(0|1)*|1101111010100100(0|1)*|110111101010010000000(0|1)*|110111101010010000001(0|1)*|110111101010010000010(0|1)*|110111101010010000011(0|1)*|110111101010010000100(0|1)*|110111101010010000101(0|1)*|110111101010010000110(0|1)*|110111101010010000111(0|1)*|110111101010010001000(0|1)*|110111101010010001001(0|1)*|110111101010010001010(0|1)*|110111101010010001011(0|1)*|110111101010010001100(0|1)*|110111101010010001101(0|1)*|110111101010010001110(0|1)*|110111101010010001111(0|1)*|110111101010010010000(0|1)*|110111101010010010001(0|1)*|110111101010010010010(0|1)*|110111101010010010011(0|1)*|110111101010010010100(0|1)*|110111101010010010101(0|1)*|110111101010010010110(0|1)*|110111101010010010111(0|1)*|110111101010010011000(0|1)*|110111101010010011001(0|1)*|110111101010010011010(0|1)*|110111101010010011011(0|1)*|110111101010010011100(0|1)*|110111101010010011101(0|1)*|110111101010010011110(0|1)*|110111101010010011111(0|1)*|11011110101001010(0|1)*|110111101010010100000(0|1)*|110111101010010100001(0|1)*|110111101010010100010(0|1)*|110111101010010100011(0|1)*|110111101010010100100(0|1)*|110111101010010100101(0|1)*|110111101010010100110(0|1)*|110111101010010100111(0|1)*|110111101010010101000(0|1)*|110111101010010101001(0|1)*|110111101010010101010(0|1)*|110111101010010101011(0|1)*|110111101010010101100(0|1)*|110111101010010101101(0|1)*|110111101010010101110(0|1)*|110111101010010101111(0|1)*)",
  301. 2,
  302. { "GNVPN-0001-PAD1101111010100101011101010101010101",
  303. "GNVPN-0001-PAD11001010100111000101101010101" },
  304. { match, match }
  305. }
  306. };
  307. check_nfa = 0;
  308. check_dfa = 0;
  309. check_rand = 0;
  310. for (i = 0; i < 19; i++)
  311. {
  312. if (0 != regcomp (&rx, rxstr[i].regex, REG_EXTENDED))
  313. {
  314. GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
  315. "Could not compile regex using regcomp()\n");
  316. return 1;
  317. }
  318. /* NFA test */
  319. a = REGEX_INTERNAL_construct_nfa (rxstr[i].regex, strlen (rxstr[i].regex));
  320. check_nfa += test_automaton (a, &rx, &rxstr[i]);
  321. REGEX_INTERNAL_automaton_destroy (a);
  322. /* DFA test */
  323. a = REGEX_INTERNAL_construct_dfa (rxstr[i].regex, strlen (rxstr[i].regex),
  324. 0);
  325. check_dfa += test_automaton (a, &rx, &rxstr[i]);
  326. check_proof = GNUNET_strdup (REGEX_INTERNAL_get_canonical_regex (a));
  327. REGEX_INTERNAL_automaton_destroy (a);
  328. a = REGEX_INTERNAL_construct_dfa (check_proof, strlen (check_proof), 0);
  329. check_dfa += test_automaton (a, &rx, &rxstr[i]);
  330. REGEX_INTERNAL_automaton_destroy (a);
  331. if (0 != check_dfa)
  332. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "check_proof: %s\n", check_proof);
  333. GNUNET_free (check_proof);
  334. regfree (&rx);
  335. }
  336. /* Random tests */
  337. srand (time (NULL));
  338. for (i = 0; i < 20; i++)
  339. check_rand += test_random (50, 60, 10);
  340. return check_nfa + check_dfa + check_rand;
  341. }