summaryrefslogtreecommitdiff
path: root/src/util/test_regex.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/test_regex.c')
-rw-r--r--src/util/test_regex.c184
1 files changed, 92 insertions, 92 deletions
diff --git a/src/util/test_regex.c b/src/util/test_regex.c
index b47314084..c2306b971 100644
--- a/src/util/test_regex.c
+++ b/src/util/test_regex.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file tun/test_regex.c 21 * @file tun/test_regex.c
22 * @brief simple test for regex.c iptoregex functions 22 * @brief simple test for regex.c iptoregex functions
@@ -32,12 +32,12 @@
32 32
33 33
34static int 34static int
35test_iptoregex (const char *ipv4, 35test_iptoregex(const char *ipv4,
36 uint16_t port, 36 uint16_t port,
37 const char *expectedv4, 37 const char *expectedv4,
38 const char *ipv6, 38 const char *ipv6,
39 uint16_t port6, 39 uint16_t port6,
40 const char *expectedv6) 40 const char *expectedv6)
41{ 41{
42 int error = 0; 42 int error = 0;
43 43
@@ -46,136 +46,136 @@ test_iptoregex (const char *ipv4,
46 char rxv4[GNUNET_TUN_IPV4_REGEXLEN]; 46 char rxv4[GNUNET_TUN_IPV4_REGEXLEN];
47 char rxv6[GNUNET_TUN_IPV6_REGEXLEN]; 47 char rxv6[GNUNET_TUN_IPV6_REGEXLEN];
48 48
49 GNUNET_assert (1 == inet_pton (AF_INET, ipv4, &a)); 49 GNUNET_assert(1 == inet_pton(AF_INET, ipv4, &a));
50 GNUNET_TUN_ipv4toregexsearch (&a, port, rxv4); 50 GNUNET_TUN_ipv4toregexsearch(&a, port, rxv4);
51 51
52 if (0 != strcmp (rxv4, expectedv4)) 52 if (0 != strcmp(rxv4, expectedv4))
53 { 53 {
54 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 54 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
55 "Expected: %s but got: %s\n", 55 "Expected: %s but got: %s\n",
56 expectedv4, 56 expectedv4,
57 rxv4); 57 rxv4);
58 error++; 58 error++;
59 } 59 }
60 60
61 GNUNET_assert (1 == inet_pton (AF_INET6, ipv6, &b)); 61 GNUNET_assert(1 == inet_pton(AF_INET6, ipv6, &b));
62 GNUNET_TUN_ipv6toregexsearch (&b, port6, rxv6); 62 GNUNET_TUN_ipv6toregexsearch(&b, port6, rxv6);
63 if (0 != strcmp (rxv6, expectedv6)) 63 if (0 != strcmp(rxv6, expectedv6))
64 { 64 {
65 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 65 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
66 "Expected: %s but got: %s\n", 66 "Expected: %s but got: %s\n",
67 expectedv6, rxv6); 67 expectedv6, rxv6);
68 error++; 68 error++;
69 } 69 }
70 return error; 70 return error;
71} 71}
72 72
73 73
74static int 74static int
75test_policy4toregex (const char *policy, 75test_policy4toregex(const char *policy,
76 const char *regex) 76 const char *regex)
77{ 77{
78 char *r; 78 char *r;
79 int ret; 79 int ret;
80 80
81 ret = 0; 81 ret = 0;
82 r = GNUNET_TUN_ipv4policy2regex (policy); 82 r = GNUNET_TUN_ipv4policy2regex(policy);
83 if (NULL == r) 83 if (NULL == r)
84 { 84 {
85 GNUNET_break (0); 85 GNUNET_break(0);
86 return 1; 86 return 1;
87 } 87 }
88 if (0 != strcmp (regex, r)) 88 if (0 != strcmp(regex, r))
89 { 89 {
90 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 90 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
91 "Expected: `%s' but got: `%s'\n", 91 "Expected: `%s' but got: `%s'\n",
92 regex, r); 92 regex, r);
93 ret = 2; 93 ret = 2;
94 } 94 }
95 GNUNET_free (r); 95 GNUNET_free(r);
96 return ret; 96 return ret;
97} 97}
98 98
99 99
100static int 100static int
101test_policy6toregex (const char *policy, 101test_policy6toregex(const char *policy,
102 const char *regex) 102 const char *regex)
103{ 103{
104 char *r; 104 char *r;
105 int ret; 105 int ret;
106 106
107 ret = 0; 107 ret = 0;
108 r = GNUNET_TUN_ipv6policy2regex (policy); 108 r = GNUNET_TUN_ipv6policy2regex(policy);
109 if (NULL == r) 109 if (NULL == r)
110 { 110 {
111 GNUNET_break (0); 111 GNUNET_break(0);
112 return 1; 112 return 1;
113 } 113 }
114 if (0 != strcmp (regex, r)) 114 if (0 != strcmp(regex, r))
115 { 115 {
116 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 116 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
117 "Expected: `%s' but got: `%s'\n", 117 "Expected: `%s' but got: `%s'\n",
118 regex, r); 118 regex, r);
119 ret = 2; 119 ret = 2;
120 } 120 }
121 GNUNET_free (r); 121 GNUNET_free(r);
122 return ret; 122 return ret;
123} 123}
124 124
125 125
126int 126int
127main (int argc, char *argv[]) 127main(int argc, char *argv[])
128{ 128{
129 int error; 129 int error;
130 char *r; 130 char *r;
131 131
132 GNUNET_log_setup ("test-regex", "WARNING", NULL); 132 GNUNET_log_setup("test-regex", "WARNING", NULL);
133 error = 0; 133 error = 0;
134 134
135 /* this is just a performance test ... */ 135 /* this is just a performance test ... */
136 r = GNUNET_TUN_ipv4policy2regex ("1.2.3.4/16:!25;"); 136 r = GNUNET_TUN_ipv4policy2regex("1.2.3.4/16:!25;");
137 GNUNET_break (NULL != r); 137 GNUNET_break(NULL != r);
138 GNUNET_free (r); 138 GNUNET_free(r);
139 139
140 error += 140 error +=
141 test_iptoregex ("192.1.2.3", 2086, 141 test_iptoregex("192.1.2.3", 2086,
142 "4-0826-C0010203", 142 "4-0826-C0010203",
143 "FFFF::1", 8080, 143 "FFFF::1", 8080,
144 "6-1F90-FFFF0000000000000000000000000001"); 144 "6-1F90-FFFF0000000000000000000000000001");
145 error += 145 error +=
146 test_iptoregex ("187.238.255.0", 80, 146 test_iptoregex("187.238.255.0", 80,
147 "4-0050-BBEEFF00", 147 "4-0050-BBEEFF00",
148 "E1E1:73F9:51BE::0", 49, 148 "E1E1:73F9:51BE::0", 49,
149 "6-0031-E1E173F951BE00000000000000000000"); 149 "6-0031-E1E173F951BE00000000000000000000");
150 error += 150 error +=
151 test_policy4toregex ("192.1.2.0/24:80;", 151 test_policy4toregex("192.1.2.0/24:80;",
152 "4-0050-C00102" DOT DOT); 152 "4-0050-C00102" DOT DOT);
153 error += 153 error +=
154 test_policy4toregex ("192.1.0.0/16;", 154 test_policy4toregex("192.1.0.0/16;",
155 "4-" DOT DOT DOT DOT "-C001" DOT DOT DOT DOT); 155 "4-" DOT DOT DOT DOT "-C001" DOT DOT DOT DOT);
156 error += 156 error +=
157 test_policy4toregex ("192.1.0.0/16:80-81;", 157 test_policy4toregex("192.1.0.0/16:80-81;",
158 "4-(0050|0051)-C001" DOT DOT DOT DOT); 158 "4-(0050|0051)-C001" DOT DOT DOT DOT);
159 error += 159 error +=
160 test_policy4toregex ("192.1.0.0/8:!3-65535;", 160 test_policy4toregex("192.1.0.0/8:!3-65535;",
161 "4-000(0|1|2)-C0" DOT DOT DOT DOT DOT DOT); 161 "4-000(0|1|2)-C0" DOT DOT DOT DOT DOT DOT);
162 error += 162 error +=
163 test_policy4toregex ("192.1.0.0/8:!25-56;", 163 test_policy4toregex("192.1.0.0/8:!25-56;",
164 "4-(0(0(0"DOT"|1(0|1|2|3|4|5|6|7|8)|3(9|A|B|C|D|E|F)|(4|5|6|7|8|9|A|B|C|D|E|F)"DOT")|(1|2|3|4|5|6|7|8|9|A|B|C|D|E|F)"DOT DOT")|(1|2|3|4|5|6|7|8|9|A|B|C|D|E|F)"DOT DOT DOT")-C0"DOT DOT DOT DOT DOT DOT); 164 "4-(0(0(0"DOT "|1(0|1|2|3|4|5|6|7|8)|3(9|A|B|C|D|E|F)|(4|5|6|7|8|9|A|B|C|D|E|F)"DOT ")|(1|2|3|4|5|6|7|8|9|A|B|C|D|E|F)"DOT DOT ")|(1|2|3|4|5|6|7|8|9|A|B|C|D|E|F)"DOT DOT DOT ")-C0"DOT DOT DOT DOT DOT DOT);
165 error += 165 error +=
166 test_policy6toregex ("E1E1::1;", 166 test_policy6toregex("E1E1::1;",
167 "6-"DOT DOT DOT DOT"-E1E10000000000000000000000000001"); 167 "6-"DOT DOT DOT DOT "-E1E10000000000000000000000000001");
168 error += 168 error +=
169 test_policy6toregex ("E1E1:ABCD::1/120;", 169 test_policy6toregex("E1E1:ABCD::1/120;",
170 "6-"DOT DOT DOT DOT"-E1E1ABCD0000000000000000000000" DOT DOT); 170 "6-"DOT DOT DOT DOT "-E1E1ABCD0000000000000000000000" DOT DOT);
171 error += 171 error +=
172 test_policy6toregex ("E1E1:ABCD::ABCD/126;", 172 test_policy6toregex("E1E1:ABCD::ABCD/126;",
173 "6-"DOT DOT DOT DOT"-E1E1ABCD00000000000000000000ABC(C|D|E|F)"); 173 "6-"DOT DOT DOT DOT "-E1E1ABCD00000000000000000000ABC(C|D|E|F)");
174 error += 174 error +=
175 test_policy6toregex ("E1E1:ABCD::ABCD/127;", 175 test_policy6toregex("E1E1:ABCD::ABCD/127;",
176 "6-"DOT DOT DOT DOT"-E1E1ABCD00000000000000000000ABC(C|D)"); 176 "6-"DOT DOT DOT DOT "-E1E1ABCD00000000000000000000ABC(C|D)");
177 error += 177 error +=
178 test_policy6toregex ("E1E1:ABCD::ABCD/128:80;", 178 test_policy6toregex("E1E1:ABCD::ABCD/128:80;",
179 "6-0050-E1E1ABCD00000000000000000000ABCD"); 179 "6-0050-E1E1ABCD00000000000000000000ABCD");
180 return error; 180 return error;
181} 181}