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"
33 * Check if 'filename' exists and is not empty.
35 * @param filename name of the file that should be checked
37 * @return 0 if ok, non 0 on error.
40 filecheck (const char *filename)
45 // Check if file was created and delete it again
46 fp = fopen (filename, "r");
50 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not find graph %s\n", filename);
54 fseek (fp, 0L, SEEK_END);
57 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
58 "Graph writing failed, got empty file (%s)!\n", filename);
66 if (0 != unlink (filename))
68 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not remove temp files (%s)\n",
78 main (int argc, char *argv[])
80 GNUNET_log_setup ("test-regex",
89 struct GNUNET_REGEX_Automaton *a;
91 const char *filename = "test_graph.dot";
95 const char *regex[10] = {
96 "ab(c|d)+c*(a(b|c)+d)+(bla)+",
100 "ab(c|d)+c*(a(b|c)+d)+(bla)(bla)*",
104 "a+X*y+c|p|R|Z*K*y*R+w|Y*6+n+h*k*w+V*F|W*B*e*",
108 for (i = 0; i < 10; i++)
110 // Check NFA graph creation
111 a = GNUNET_REGEX_construct_nfa (regex[i], strlen (regex[i]));
112 GNUNET_REGEX_automaton_save_graph (a, filename, GNUNET_REGEX_GRAPH_DEFAULT);
113 GNUNET_REGEX_automaton_destroy (a);
114 error += filecheck (filename);
116 a = GNUNET_REGEX_construct_nfa (regex[i], strlen (regex[i]));
117 GNUNET_REGEX_automaton_save_graph (a, filename,
118 GNUNET_REGEX_GRAPH_DEFAULT |
119 GNUNET_REGEX_GRAPH_VERBOSE);
120 GNUNET_REGEX_automaton_destroy (a);
121 error += filecheck (filename);
123 a = GNUNET_REGEX_construct_nfa (regex[i], strlen (regex[i]));
124 GNUNET_REGEX_automaton_save_graph (a, filename,
125 GNUNET_REGEX_GRAPH_DEFAULT |
126 GNUNET_REGEX_GRAPH_COLORING);
127 GNUNET_REGEX_automaton_destroy (a);
128 error += filecheck (filename);
130 a = GNUNET_REGEX_construct_nfa (regex[i], strlen (regex[i]));
131 GNUNET_REGEX_automaton_save_graph (a, filename,
132 GNUNET_REGEX_GRAPH_DEFAULT |
133 GNUNET_REGEX_GRAPH_VERBOSE |
134 GNUNET_REGEX_GRAPH_COLORING);
135 GNUNET_REGEX_automaton_destroy (a);
136 error += filecheck (filename);
139 // Check DFA graph creation
140 a = GNUNET_REGEX_construct_dfa (regex[i], strlen (regex[i]));
141 GNUNET_REGEX_automaton_save_graph (a, filename, GNUNET_REGEX_GRAPH_DEFAULT);
142 GNUNET_REGEX_automaton_destroy (a);
143 error += filecheck (filename);
145 a = GNUNET_REGEX_construct_dfa (regex[i], strlen (regex[i]));
146 GNUNET_REGEX_automaton_save_graph (a, filename,
147 GNUNET_REGEX_GRAPH_DEFAULT |
148 GNUNET_REGEX_GRAPH_VERBOSE);
149 GNUNET_REGEX_automaton_destroy (a);
150 error += filecheck (filename);
152 a = GNUNET_REGEX_construct_dfa (regex[i], strlen (regex[i]));
153 GNUNET_REGEX_automaton_save_graph (a, filename,
154 GNUNET_REGEX_GRAPH_DEFAULT |
155 GNUNET_REGEX_GRAPH_COLORING);
156 GNUNET_REGEX_automaton_destroy (a);
157 error += filecheck (filename);
160 a = GNUNET_REGEX_construct_dfa (regex[i], strlen (regex[i]));
161 GNUNET_REGEX_automaton_save_graph (a, filename,
162 GNUNET_REGEX_GRAPH_DEFAULT |
163 GNUNET_REGEX_GRAPH_VERBOSE |
164 GNUNET_REGEX_GRAPH_COLORING);
165 GNUNET_REGEX_automaton_destroy (a);
166 error += filecheck (filename);