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/>.
19 * @file transport/test_http_common.c
20 * @brief base test case for common http functionality
23 #include "gnunet_transport_service.h"
24 #include "transport-testing.h"
25 #include "plugin_transport_http_common.h"
29 clean (struct SplittedHTTPAddress *addr)
33 GNUNET_free_non_null (addr->host);
34 GNUNET_free_non_null (addr->path);
35 GNUNET_free_non_null (addr->protocol);
41 check (struct SplittedHTTPAddress *addr,
49 if (((NULL == addr->protocol) && (NULL != protocol)) ||
50 ((NULL != addr->protocol) && (NULL == protocol)))
55 else if ((NULL != addr->protocol) && (NULL != protocol))
57 if (0 != strcmp(addr->protocol, protocol))
64 if (((NULL == addr->host) && (NULL != host)) ||
65 ((NULL != addr->host) && (NULL == host)))
70 else if ((NULL != addr->host) && (NULL != host))
72 if (0 != strcmp(addr->host, host))
79 if (((NULL == addr->path) && (NULL != path)) ||
80 ((NULL != addr->path) && (NULL == path)))
85 else if ((NULL != addr->path) && (NULL != path))
87 if (0 != strcmp(addr->path, path))
94 if ((addr->port != port))
104 check_pass (const char *src,
105 const char *protocol,
110 struct SplittedHTTPAddress *spa;
112 spa = http_split_address (src);
116 return GNUNET_SYSERR;
118 if (GNUNET_OK != check(spa, protocol, host, port, path))
122 return GNUNET_SYSERR;
130 check_fail (const char *src)
132 struct SplittedHTTPAddress * spa;
134 spa = http_split_address (src);
139 return GNUNET_SYSERR;
146 test_pass_hostname ()
148 check_pass("http://test.local", "http", "test.local", HTTP_DEFAULT_PORT, "");
149 check_pass("http://test.local/", "http", "test.local", HTTP_DEFAULT_PORT, "/");
150 check_pass("http://test.local/path", "http", "test.local", HTTP_DEFAULT_PORT, "/path");
151 check_pass("http://test.local/path/", "http", "test.local", HTTP_DEFAULT_PORT, "/path/");
152 check_pass("http://test.local/path/more", "http", "test.local", HTTP_DEFAULT_PORT, "/path/more");
153 check_pass("http://test.local:81", "http", "test.local", 81, "");
154 check_pass("http://test.local:81/", "http", "test.local", 81, "/");
155 check_pass("http://test.local:81/path", "http", "test.local", 81, "/path");
156 check_pass("http://test.local:81/path/", "http", "test.local", 81, "/path/");
157 check_pass("http://test.local:81/path/more", "http", "test.local", 81, "/path/more");
165 check_pass("http://127.0.0.1", "http", "127.0.0.1", HTTP_DEFAULT_PORT, "");
166 check_pass("http://127.0.0.1/", "http", "127.0.0.1", HTTP_DEFAULT_PORT, "/");
167 check_pass("http://127.0.0.1/path", "http", "127.0.0.1", HTTP_DEFAULT_PORT, "/path");
168 check_pass("http://127.0.0.1/path/", "http", "127.0.0.1", HTTP_DEFAULT_PORT, "/path/");
169 check_pass("http://127.0.0.1:81", "http", "127.0.0.1", 81, "");
170 check_pass("http://127.0.0.1:81/", "http", "127.0.0.1", 81, "/");
171 check_pass("http://127.0.0.1:81/path", "http", "127.0.0.1", 81, "/path");
172 check_pass("http://127.0.0.1:81/path/", "http", "127.0.0.1", 81, "/path/");
173 check_pass("http://127.0.0.1:81/path/more", "http", "127.0.0.1", 81, "/path/more");
180 check_pass("http://[::1]", "http", "[::1]", HTTP_DEFAULT_PORT, "");
181 check_pass("http://[::1]/", "http", "[::1]", HTTP_DEFAULT_PORT, "/");
182 check_pass("http://[::1]/path", "http", "[::1]", HTTP_DEFAULT_PORT, "/path");
183 check_pass("http://[::1]/path/", "http", "[::1]", HTTP_DEFAULT_PORT, "/path/");
184 check_pass("http://[::1]:81", "http", "[::1]", 81, "");
185 check_pass("http://[::1]:81/", "http", "[::1]", 81, "/");
186 check_pass("http://[::1]:81/path", "http", "[::1]", 81, "/path");
187 check_pass("http://[::1]:81/path/", "http", "[::1]", 81, "/path/");
188 check_pass("http://[::1]:81/path/more", "http", "[::1]", 81, "/path/more");
195 if (GNUNET_SYSERR == check_fail (""))
197 if (GNUNET_SYSERR == check_fail ("http"))
199 if (GNUNET_SYSERR == check_fail ("://"))
201 if (GNUNET_SYSERR == check_fail ("http://"))
203 if (GNUNET_SYSERR == check_fail ("//localhost"))
205 if (GNUNET_SYSERR == check_fail ("//:80"))
207 if (GNUNET_SYSERR == check_fail ("//:80/"))
209 if (GNUNET_SYSERR == check_fail ("//:80:"))
211 if (GNUNET_SYSERR == check_fail ("http://localhost:a/"))
213 if (GNUNET_SYSERR == check_fail ("http://127.0.0.1:a/"))
219 main (int argc, char *argv[])
222 struct SplittedHTTPAddress * spa;
224 GNUNET_log_setup ("test", "DEBUG", NULL);
225 spa = http_split_address ("");
233 spa = http_split_address ("http://");
240 spa = http_split_address ("://");
247 test_pass_hostname ();
255 /* end of test_http_common.c */