2 This file is part of GNUnet
3 (C) 2012 Christian Grothoff (and other contributing authors)
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.
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.
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.
21 * @file regex/test_regex_graph_api.c
22 * @brief test for regex_graph.c
23 * @author Maximilian Szengel
28 #include "gnunet_regex_lib.h"
29 #include "regex_internal.h"
34 * Check if 'filename' exists and is not empty.
36 * @param filename name of the file that should be checked
38 * @return 0 if ok, non 0 on error.
41 filecheck (const char *filename)
46 /* Check if file was created and delete it again */
47 if (NULL == (fp = fopen (filename, "r")))
49 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not find graph %s\n", filename);
53 GNUNET_break (0 == fseek (fp, 0L, SEEK_END));
56 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
57 "Graph writing failed, got empty file (%s)!\n", filename);
61 GNUNET_assert (0 == fclose (fp));
65 if (0 != unlink (filename))
66 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "unlink", filename);
73 main (int argc, char *argv[])
76 struct GNUNET_REGEX_Automaton *a;
78 const char *filename = "test_graph.dot";
80 const char *regex[12] = {
81 "ab(c|d)+c*(a(b|c)+d)+(bla)+",
85 "ab(c|d)+c*(a(b|c)+d)+(bla)(bla)*",
89 "a+X*y+c|p|R|Z*K*y*R+w|Y*6+n+h*k*w+V*F|W*B*e*",
92 "PADPADPADPADPADPabcdefghixxxxxxxxxxxxxjklmnop*qstoisdjfguisdfguihsdfgbdsuivggsd"
95 GNUNET_log_setup ("test-regex", "WARNING", NULL);
97 for (i = 0; i < 12; i++)
99 /* Check NFA graph creation */
100 a = GNUNET_REGEX_construct_nfa (regex[i], strlen (regex[i]));
101 GNUNET_REGEX_automaton_save_graph (a, filename, GNUNET_REGEX_GRAPH_DEFAULT);
102 GNUNET_REGEX_automaton_destroy (a);
103 error += filecheck (filename);
105 a = GNUNET_REGEX_construct_nfa (regex[i], strlen (regex[i]));
106 GNUNET_REGEX_automaton_save_graph (a, filename,
107 GNUNET_REGEX_GRAPH_DEFAULT |
108 GNUNET_REGEX_GRAPH_VERBOSE);
109 GNUNET_REGEX_automaton_destroy (a);
110 error += filecheck (filename);
112 a = GNUNET_REGEX_construct_nfa (regex[i], strlen (regex[i]));
113 GNUNET_REGEX_automaton_save_graph (a, filename,
114 GNUNET_REGEX_GRAPH_DEFAULT |
115 GNUNET_REGEX_GRAPH_COLORING);
116 GNUNET_REGEX_automaton_destroy (a);
117 error += filecheck (filename);
119 a = GNUNET_REGEX_construct_nfa (regex[i], strlen (regex[i]));
120 GNUNET_REGEX_automaton_save_graph (a, filename,
121 GNUNET_REGEX_GRAPH_DEFAULT |
122 GNUNET_REGEX_GRAPH_VERBOSE |
123 GNUNET_REGEX_GRAPH_COLORING);
124 GNUNET_REGEX_automaton_destroy (a);
125 error += filecheck (filename);
128 /* Check DFA graph creation */
129 a = GNUNET_REGEX_construct_dfa (regex[i], strlen (regex[i]), 0);
130 GNUNET_REGEX_automaton_save_graph (a, filename, GNUNET_REGEX_GRAPH_DEFAULT);
131 GNUNET_REGEX_automaton_destroy (a);
132 error += filecheck (filename);
134 a = GNUNET_REGEX_construct_dfa (regex[i], strlen (regex[i]), 0);
135 GNUNET_REGEX_automaton_save_graph (a, filename,
136 GNUNET_REGEX_GRAPH_DEFAULT |
137 GNUNET_REGEX_GRAPH_VERBOSE);
138 GNUNET_REGEX_automaton_destroy (a);
139 error += filecheck (filename);
141 a = GNUNET_REGEX_construct_dfa (regex[i], strlen (regex[i]), 0);
142 GNUNET_REGEX_automaton_save_graph (a, filename,
143 GNUNET_REGEX_GRAPH_DEFAULT |
144 GNUNET_REGEX_GRAPH_COLORING);
145 GNUNET_REGEX_automaton_destroy (a);
146 error += filecheck (filename);
149 a = GNUNET_REGEX_construct_dfa (regex[i], strlen (regex[i]), 4);
150 GNUNET_REGEX_automaton_save_graph (a, filename, GNUNET_REGEX_GRAPH_DEFAULT);
151 GNUNET_REGEX_automaton_destroy (a);
152 error += filecheck (filename);