aboutsummaryrefslogtreecommitdiff
path: root/src/regex/test_regex_graph_api.c
diff options
context:
space:
mode:
authorMaximilian Szengel <gnunet@maxsz.de>2012-09-07 16:38:49 +0000
committerMaximilian Szengel <gnunet@maxsz.de>2012-09-07 16:38:49 +0000
commit88638fd30b3c7898e1209b8128adf42b1e4bd315 (patch)
tree47433205bf0092f5144e4c0b1b2ac3807654582e /src/regex/test_regex_graph_api.c
parent9f81c1a85bb5485bdd2b4dd5a95fc02d2f6deeb4 (diff)
downloadgnunet-88638fd30b3c7898e1209b8128adf42b1e4bd315.tar.gz
gnunet-88638fd30b3c7898e1209b8128adf42b1e4bd315.zip
coverage
Diffstat (limited to 'src/regex/test_regex_graph_api.c')
-rw-r--r--src/regex/test_regex_graph_api.c157
1 files changed, 157 insertions, 0 deletions
diff --git a/src/regex/test_regex_graph_api.c b/src/regex/test_regex_graph_api.c
new file mode 100644
index 000000000..0f1b72b61
--- /dev/null
+++ b/src/regex/test_regex_graph_api.c
@@ -0,0 +1,157 @@
1/*
2 This file is part of GNUnet
3 (C) 2012 Christian Grothoff (and other contributing authors)
4
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.
9
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.
14
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.
19*/
20/**
21 * @file regex/test_regex_graph_api.c
22 * @brief test for regex_graph.c
23 * @author Maximilian Szengel
24 */
25#include <regex.h>
26#include <time.h>
27#include "platform.h"
28#include "gnunet_regex_lib.h"
29
30/**
31 * Check if 'filename' exists and is not empty.
32 *
33 * @param filename name of the file that should be checked
34 *
35 * @return 0 if ok, non 0 on error.
36 */
37int
38filecheck (const char *filename)
39{
40 int error = 0;
41 FILE *fp = NULL;
42
43 // Check if file was created and delete it again
44 fp = fopen (filename, "r");
45
46 if (NULL == fp)
47 {
48 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not find graph %s\n", filename);
49 error++;
50 }
51
52 fseek (fp, 0L, SEEK_END);
53 if (1 > ftell (fp))
54 {
55 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
56 "Graph writing failed, got empty file (%s)!\n", filename);
57 error++;
58 }
59
60 return error;
61}
62
63int
64main (int argc, char *argv[])
65{
66 GNUNET_log_setup ("test-regex",
67#if VERBOSE
68 "DEBUG",
69#else
70 "WARNING",
71#endif
72 NULL);
73
74 int error;
75 struct GNUNET_REGEX_Automaton *a;
76 unsigned int i;
77 const char *filename = "test_graph.dot";
78
79 error = 0;
80
81 const char *regex[10] = {
82 "ab(c|d)+c*(a(b|c)+d)+(bla)+",
83 "(bla)*",
84 "b(lab)*la",
85 "(ab)*",
86 "ab(c|d)+c*(a(b|c)+d)+(bla)(bla)*",
87 "z(abc|def)?xyz",
88 "1*0(0|1)*",
89 "a*b*",
90 "a+X*y+c|p|R|Z*K*y*R+w|Y*6+n+h*k*w+V*F|W*B*e*",
91 "a"
92 };
93
94 for (i = 0; i < 10; i++)
95 {
96 // Check NFA graph creation
97 a = GNUNET_REGEX_construct_nfa (regex[i], strlen (regex[i]));
98 GNUNET_REGEX_automaton_save_graph (a, filename, GNUNET_REGEX_GRAPH_DEFAULT);
99 GNUNET_REGEX_automaton_destroy (a);
100 error += filecheck (filename);
101
102 a = GNUNET_REGEX_construct_nfa (regex[i], strlen (regex[i]));
103 GNUNET_REGEX_automaton_save_graph (a, filename,
104 GNUNET_REGEX_GRAPH_DEFAULT |
105 GNUNET_REGEX_GRAPH_VERBOSE);
106 GNUNET_REGEX_automaton_destroy (a);
107 error += filecheck (filename);
108
109 a = GNUNET_REGEX_construct_nfa (regex[i], strlen (regex[i]));
110 GNUNET_REGEX_automaton_save_graph (a, filename,
111 GNUNET_REGEX_GRAPH_DEFAULT |
112 GNUNET_REGEX_GRAPH_COLORING);
113 GNUNET_REGEX_automaton_destroy (a);
114 error += filecheck (filename);
115
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_GRAPH_COLORING);
121 GNUNET_REGEX_automaton_destroy (a);
122 error += filecheck (filename);
123
124
125 // Check DFA graph creation
126 a = GNUNET_REGEX_construct_dfa (regex[i], strlen (regex[i]));
127 GNUNET_REGEX_automaton_save_graph (a, filename, GNUNET_REGEX_GRAPH_DEFAULT);
128 GNUNET_REGEX_automaton_destroy (a);
129 error += filecheck (filename);
130
131 a = GNUNET_REGEX_construct_dfa (regex[i], strlen (regex[i]));
132 GNUNET_REGEX_automaton_save_graph (a, filename,
133 GNUNET_REGEX_GRAPH_DEFAULT |
134 GNUNET_REGEX_GRAPH_VERBOSE);
135 GNUNET_REGEX_automaton_destroy (a);
136 error += filecheck (filename);
137
138 a = GNUNET_REGEX_construct_dfa (regex[i], strlen (regex[i]));
139 GNUNET_REGEX_automaton_save_graph (a, filename,
140 GNUNET_REGEX_GRAPH_DEFAULT |
141 GNUNET_REGEX_GRAPH_COLORING);
142 GNUNET_REGEX_automaton_destroy (a);
143 error += filecheck (filename);
144
145
146 a = GNUNET_REGEX_construct_dfa (regex[i], strlen (regex[i]));
147 GNUNET_REGEX_automaton_save_graph (a, filename,
148 GNUNET_REGEX_GRAPH_DEFAULT |
149 GNUNET_REGEX_GRAPH_VERBOSE |
150 GNUNET_REGEX_GRAPH_COLORING);
151 GNUNET_REGEX_automaton_destroy (a);
152 error += filecheck (filename);
153
154 }
155
156 return error;
157}