2 This file is part of GNUnet.
3 Copyright (C) 2009, 2010 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/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
21 * @file transport/test_http_common.c
22 * @brief base test case for common http functionality
25 #include "gnunet_transport_service.h"
26 #include "transport-testing.h"
27 #include "plugin_transport_http_common.h"
31 clean (struct SplittedHTTPAddress *addr)
35 GNUNET_free_non_null (addr->host);
36 GNUNET_free_non_null (addr->path);
37 GNUNET_free_non_null (addr->protocol);
43 check (struct SplittedHTTPAddress *addr,
51 if (((NULL == addr->protocol) && (NULL != protocol)) ||
52 ((NULL != addr->protocol) && (NULL == protocol)))
57 else if ((NULL != addr->protocol) && (NULL != protocol))
59 if (0 != strcmp (addr->protocol, protocol))
66 if (((NULL == addr->host) && (NULL != host)) ||
67 ((NULL != addr->host) && (NULL == host)))
72 else if ((NULL != addr->host) && (NULL != host))
74 if (0 != strcmp (addr->host, host))
81 if (((NULL == addr->path) && (NULL != path)) ||
82 ((NULL != addr->path) && (NULL == path)))
87 else if ((NULL != addr->path) && (NULL != path))
89 if (0 != strcmp (addr->path, path))
96 if ((addr->port != port))
106 check_pass (const char *src,
107 const char *protocol,
112 struct SplittedHTTPAddress *spa;
114 spa = http_split_address (src);
118 return GNUNET_SYSERR;
120 if (GNUNET_OK != check (spa, protocol, host, port, path))
124 return GNUNET_SYSERR;
132 check_fail (const char *src)
134 struct SplittedHTTPAddress *spa;
136 spa = http_split_address (src);
141 return GNUNET_SYSERR;
148 test_pass_hostname ()
150 check_pass ("http://test.local", "http", "test.local", HTTP_DEFAULT_PORT, "");
151 check_pass ("http://test.local/", "http", "test.local", HTTP_DEFAULT_PORT,
153 check_pass ("http://test.local/path", "http", "test.local", HTTP_DEFAULT_PORT,
155 check_pass ("http://test.local/path/", "http", "test.local",
156 HTTP_DEFAULT_PORT, "/path/");
157 check_pass ("http://test.local/path/more", "http", "test.local",
158 HTTP_DEFAULT_PORT, "/path/more");
159 check_pass ("http://test.local:81", "http", "test.local", 81, "");
160 check_pass ("http://test.local:81/", "http", "test.local", 81, "/");
161 check_pass ("http://test.local:81/path", "http", "test.local", 81, "/path");
162 check_pass ("http://test.local:81/path/", "http", "test.local", 81, "/path/");
163 check_pass ("http://test.local:81/path/more", "http", "test.local", 81,
171 check_pass ("http://127.0.0.1", "http", "127.0.0.1", HTTP_DEFAULT_PORT, "");
172 check_pass ("http://127.0.0.1/", "http", "127.0.0.1", HTTP_DEFAULT_PORT, "/");
173 check_pass ("http://127.0.0.1/path", "http", "127.0.0.1", HTTP_DEFAULT_PORT,
175 check_pass ("http://127.0.0.1/path/", "http", "127.0.0.1", HTTP_DEFAULT_PORT,
177 check_pass ("http://127.0.0.1:81", "http", "127.0.0.1", 81, "");
178 check_pass ("http://127.0.0.1:81/", "http", "127.0.0.1", 81, "/");
179 check_pass ("http://127.0.0.1:81/path", "http", "127.0.0.1", 81, "/path");
180 check_pass ("http://127.0.0.1:81/path/", "http", "127.0.0.1", 81, "/path/");
181 check_pass ("http://127.0.0.1:81/path/more", "http", "127.0.0.1", 81,
189 check_pass ("http://[::1]", "http", "[::1]", HTTP_DEFAULT_PORT, "");
190 check_pass ("http://[::1]/", "http", "[::1]", HTTP_DEFAULT_PORT, "/");
191 check_pass ("http://[::1]/path", "http", "[::1]", HTTP_DEFAULT_PORT, "/path");
192 check_pass ("http://[::1]/path/", "http", "[::1]", HTTP_DEFAULT_PORT,
194 check_pass ("http://[::1]:81", "http", "[::1]", 81, "");
195 check_pass ("http://[::1]:81/", "http", "[::1]", 81, "/");
196 check_pass ("http://[::1]:81/path", "http", "[::1]", 81, "/path");
197 check_pass ("http://[::1]:81/path/", "http", "[::1]", 81, "/path/");
198 check_pass ("http://[::1]:81/path/more", "http", "[::1]", 81, "/path/more");
205 if (GNUNET_SYSERR == check_fail (""))
207 if (GNUNET_SYSERR == check_fail ("http"))
209 if (GNUNET_SYSERR == check_fail ("://"))
211 if (GNUNET_SYSERR == check_fail ("http://"))
213 if (GNUNET_SYSERR == check_fail ("//localhost"))
215 if (GNUNET_SYSERR == check_fail ("//:80"))
217 if (GNUNET_SYSERR == check_fail ("//:80/"))
219 if (GNUNET_SYSERR == check_fail ("//:80:"))
221 if (GNUNET_SYSERR == check_fail ("http://localhost:a/"))
223 if (GNUNET_SYSERR == check_fail ("http://127.0.0.1:a/"))
229 main (int argc, char *argv[])
232 struct SplittedHTTPAddress *spa;
234 GNUNET_log_setup ("test", "DEBUG", NULL);
235 spa = http_split_address ("");
243 spa = http_split_address ("http://");
250 spa = http_split_address ("://");
257 test_pass_hostname ();
266 /* end of test_http_common.c */