2 This file is part of GNUnet.
3 (C) 2009, 2010 Christian Grothoff (and other contributing authors)
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.
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.
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.
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"
29 struct SplittedHTTPAddress
38 clean (struct SplittedHTTPAddress *addr)
42 GNUNET_free_non_null (addr->host);
43 GNUNET_free_non_null (addr->path);
44 GNUNET_free_non_null (addr->protocol);
45 GNUNET_free_non_null (addr);
51 check (struct SplittedHTTPAddress *addr,
60 if (((NULL == addr->protocol) && (NULL != protocol)) ||
61 ((NULL != addr->protocol) && (NULL == protocol)))
66 else if ((NULL != addr->protocol) && (NULL != protocol))
68 if (0 != strcmp(addr->protocol, protocol))
75 if (((NULL == addr->host) && (NULL != host)) ||
76 ((NULL != addr->host) && (NULL == host)))
81 else if ((NULL != addr->host) && (NULL != host))
83 if (0 != strcmp(addr->host, host))
91 if (((NULL == addr->path) && (NULL != path)) ||
92 ((NULL != addr->path) && (NULL == path)))
97 else if ((NULL != addr->path) && (NULL != path))
99 if (0 != strcmp(addr->path, path))
106 if ((addr->port != port))
116 check_pass (char *src,
122 struct SplittedHTTPAddress * spa;
123 spa = http_split_address (src);
127 return GNUNET_SYSERR;
131 if (GNUNET_OK != check(spa, protocol, host, port, path))
135 return GNUNET_SYSERR;
143 check_fail (char *src)
145 struct SplittedHTTPAddress * spa;
146 spa = http_split_address (src);
151 return GNUNET_SYSERR;
158 test_pass_hostname ()
160 check_pass("http://test.local", "http", "test.local", HTTP_DEFAULT_PORT, "");
161 check_pass("http://test.local/", "http", "test.local", HTTP_DEFAULT_PORT, "/");
162 check_pass("http://test.local/path", "http", "test.local", HTTP_DEFAULT_PORT, "/path");
163 check_pass("http://test.local/path/", "http", "test.local", HTTP_DEFAULT_PORT, "/path/");
164 check_pass("http://test.local/path/more", "http", "test.local", HTTP_DEFAULT_PORT, "/path/more");
165 check_pass("http://test.local:81", "http", "test.local", 81, "");
166 check_pass("http://test.local:81/", "http", "test.local", 81, "/");
167 check_pass("http://test.local:81/path", "http", "test.local", 81, "/path");
168 check_pass("http://test.local:81/path/", "http", "test.local", 81, "/path/");
169 check_pass("http://test.local:81/path/more", "http", "test.local", 81, "/path/more");
177 check_pass("http://127.0.0.1", "http", "127.0.0.1", HTTP_DEFAULT_PORT, "");
178 check_pass("http://127.0.0.1/", "http", "127.0.0.1", HTTP_DEFAULT_PORT, "/");
179 check_pass("http://127.0.0.1/path", "http", "127.0.0.1", HTTP_DEFAULT_PORT, "/path");
180 check_pass("http://127.0.0.1/path/", "http", "127.0.0.1", HTTP_DEFAULT_PORT, "/path/");
181 check_pass("http://127.0.0.1:81", "http", "127.0.0.1", 81, "");
182 check_pass("http://127.0.0.1:81/", "http", "127.0.0.1", 81, "/");
183 check_pass("http://127.0.0.1:81/path", "http", "127.0.0.1", 81, "/path");
184 check_pass("http://127.0.0.1:81/path/", "http", "127.0.0.1", 81, "/path/");
185 check_pass("http://127.0.0.1:81/path/more", "http", "127.0.0.1", 81, "/path/more");
191 check_pass("http://[::1]", "http", "[::1]", HTTP_DEFAULT_PORT, "");
192 check_pass("http://[::1]/", "http", "[::1]", HTTP_DEFAULT_PORT, "/");
193 check_pass("http://[::1]/path", "http", "[::1]", HTTP_DEFAULT_PORT, "/path");
194 check_pass("http://[::1]/path/", "http", "[::1]", HTTP_DEFAULT_PORT, "/path/");
195 check_pass("http://[::1]:81", "http", "[::1]", 81, "");
196 check_pass("http://[::1]:81/", "http", "[::1]", 81, "/");
197 check_pass("http://[::1]:81/path", "http", "[::1]", 81, "/path");
198 check_pass("http://[::1]:81/path/", "http", "[::1]", 81, "/path/");
199 check_pass("http://[::1]:81/path/more", "http", "[::1]", 81, "/path/more");
206 if (GNUNET_SYSERR == check_fail (""))
208 if (GNUNET_SYSERR == check_fail ("http"))
210 if (GNUNET_SYSERR == check_fail ("://"))
212 if (GNUNET_SYSERR == check_fail ("http://"))
214 if (GNUNET_SYSERR == check_fail ("//localhost"))
216 if (GNUNET_SYSERR == check_fail ("//:80"))
218 if (GNUNET_SYSERR == check_fail ("//:80/"))
220 if (GNUNET_SYSERR == check_fail ("//:80:"))
222 if (GNUNET_SYSERR == check_fail ("http://localhost:a/"))
224 if (GNUNET_SYSERR == check_fail ("http://127.0.0.1:a/"))
229 main (int argc, char *argv[])
232 struct SplittedHTTPAddress * spa;
233 GNUNET_log_setup ("test", "DEBUG", NULL);
235 spa = http_split_address ("");
242 http_split_address ("http://");
249 http_split_address ("://");
256 test_pass_hostname ();
264 /* end of test_http_common.c */