2 This file is part of GNUnet
3 Copyright (C) 2012 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 * @file regex/test_regex_graph_api.c
20 * @brief test for regex_graph.c
21 * @author Maximilian Szengel
26 #include "regex_internal_lib.h"
27 #include "regex_test_lib.h"
28 #include "regex_internal.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 if (NULL == (fp = fopen (filename, "r")))
48 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not find graph %s\n", filename);
52 GNUNET_break (0 == fseek (fp, 0L, SEEK_END));
55 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
56 "Graph writing failed, got empty file (%s)!\n", filename);
60 GNUNET_assert (0 == fclose (fp));
64 if (0 != unlink (filename))
65 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "unlink", filename);
72 main (int argc, char *argv[])
75 struct REGEX_INTERNAL_Automaton *a;
77 const char *filename = "test_graph.dot";
79 const char *regex[12] = {
80 "ab(c|d)+c*(a(b|c)+d)+(bla)+",
84 "ab(c|d)+c*(a(b|c)+d)+(bla)(bla)*",
88 "a+X*y+c|p|R|Z*K*y*R+w|Y*6+n+h*k*w+V*F|W*B*e*",
91 "PADPADPADPADPADPabcdefghixxxxxxxxxxxxxjklmnop*qstoisdjfguisdfguihsdfgbdsuivggsd"
94 GNUNET_log_setup ("test-regex", "WARNING", NULL);
96 for (i = 0; i < 12; i++)
98 /* Check NFA graph creation */
99 a = REGEX_INTERNAL_construct_nfa (regex[i], strlen (regex[i]));
100 REGEX_TEST_automaton_save_graph (a, filename, REGEX_TEST_GRAPH_DEFAULT);
101 REGEX_INTERNAL_automaton_destroy (a);
102 error += filecheck (filename);
104 a = REGEX_INTERNAL_construct_nfa (regex[i], strlen (regex[i]));
105 REGEX_TEST_automaton_save_graph (a, filename,
106 REGEX_TEST_GRAPH_DEFAULT |
107 REGEX_TEST_GRAPH_VERBOSE);
108 REGEX_INTERNAL_automaton_destroy (a);
109 error += filecheck (filename);
111 a = REGEX_INTERNAL_construct_nfa (regex[i], strlen (regex[i]));
112 REGEX_TEST_automaton_save_graph (a, filename,
113 REGEX_TEST_GRAPH_DEFAULT |
114 REGEX_TEST_GRAPH_COLORING);
115 REGEX_INTERNAL_automaton_destroy (a);
116 error += filecheck (filename);
118 a = REGEX_INTERNAL_construct_nfa (regex[i], strlen (regex[i]));
119 REGEX_TEST_automaton_save_graph (a, filename,
120 REGEX_TEST_GRAPH_DEFAULT |
121 REGEX_TEST_GRAPH_VERBOSE |
122 REGEX_TEST_GRAPH_COLORING);
123 REGEX_INTERNAL_automaton_destroy (a);
124 error += filecheck (filename);
127 /* Check DFA graph creation */
128 a = REGEX_INTERNAL_construct_dfa (regex[i], strlen (regex[i]), 0);
129 REGEX_TEST_automaton_save_graph (a, filename, REGEX_TEST_GRAPH_DEFAULT);
130 REGEX_INTERNAL_automaton_destroy (a);
131 error += filecheck (filename);
133 a = REGEX_INTERNAL_construct_dfa (regex[i], strlen (regex[i]), 0);
134 REGEX_TEST_automaton_save_graph (a, filename,
135 REGEX_TEST_GRAPH_DEFAULT |
136 REGEX_TEST_GRAPH_VERBOSE);
137 REGEX_INTERNAL_automaton_destroy (a);
138 error += filecheck (filename);
140 a = REGEX_INTERNAL_construct_dfa (regex[i], strlen (regex[i]), 0);
141 REGEX_TEST_automaton_save_graph (a, filename,
142 REGEX_TEST_GRAPH_DEFAULT |
143 REGEX_TEST_GRAPH_COLORING);
144 REGEX_INTERNAL_automaton_destroy (a);
145 error += filecheck (filename);
148 a = REGEX_INTERNAL_construct_dfa (regex[i], strlen (regex[i]), 4);
149 REGEX_TEST_automaton_save_graph (a, filename, REGEX_TEST_GRAPH_DEFAULT);
150 REGEX_INTERNAL_automaton_destroy (a);
151 error += filecheck (filename);