2 This file is part of GNUnet.
3 Copyright (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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, 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"
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, "/");
152 check_pass("http://test.local/path", "http", "test.local", HTTP_DEFAULT_PORT, "/path");
153 check_pass("http://test.local/path/", "http", "test.local", HTTP_DEFAULT_PORT, "/path/");
154 check_pass("http://test.local/path/more", "http", "test.local", HTTP_DEFAULT_PORT, "/path/more");
155 check_pass("http://test.local:81", "http", "test.local", 81, "");
156 check_pass("http://test.local:81/", "http", "test.local", 81, "/");
157 check_pass("http://test.local:81/path", "http", "test.local", 81, "/path");
158 check_pass("http://test.local:81/path/", "http", "test.local", 81, "/path/");
159 check_pass("http://test.local:81/path/more", "http", "test.local", 81, "/path/more");
167 check_pass("http://127.0.0.1", "http", "127.0.0.1", HTTP_DEFAULT_PORT, "");
168 check_pass("http://127.0.0.1/", "http", "127.0.0.1", HTTP_DEFAULT_PORT, "/");
169 check_pass("http://127.0.0.1/path", "http", "127.0.0.1", HTTP_DEFAULT_PORT, "/path");
170 check_pass("http://127.0.0.1/path/", "http", "127.0.0.1", HTTP_DEFAULT_PORT, "/path/");
171 check_pass("http://127.0.0.1:81", "http", "127.0.0.1", 81, "");
172 check_pass("http://127.0.0.1:81/", "http", "127.0.0.1", 81, "/");
173 check_pass("http://127.0.0.1:81/path", "http", "127.0.0.1", 81, "/path");
174 check_pass("http://127.0.0.1:81/path/", "http", "127.0.0.1", 81, "/path/");
175 check_pass("http://127.0.0.1:81/path/more", "http", "127.0.0.1", 81, "/path/more");
182 check_pass("http://[::1]", "http", "[::1]", HTTP_DEFAULT_PORT, "");
183 check_pass("http://[::1]/", "http", "[::1]", HTTP_DEFAULT_PORT, "/");
184 check_pass("http://[::1]/path", "http", "[::1]", HTTP_DEFAULT_PORT, "/path");
185 check_pass("http://[::1]/path/", "http", "[::1]", HTTP_DEFAULT_PORT, "/path/");
186 check_pass("http://[::1]:81", "http", "[::1]", 81, "");
187 check_pass("http://[::1]:81/", "http", "[::1]", 81, "/");
188 check_pass("http://[::1]:81/path", "http", "[::1]", 81, "/path");
189 check_pass("http://[::1]:81/path/", "http", "[::1]", 81, "/path/");
190 check_pass("http://[::1]:81/path/more", "http", "[::1]", 81, "/path/more");
197 if (GNUNET_SYSERR == check_fail (""))
199 if (GNUNET_SYSERR == check_fail ("http"))
201 if (GNUNET_SYSERR == check_fail ("://"))
203 if (GNUNET_SYSERR == check_fail ("http://"))
205 if (GNUNET_SYSERR == check_fail ("//localhost"))
207 if (GNUNET_SYSERR == check_fail ("//:80"))
209 if (GNUNET_SYSERR == check_fail ("//:80/"))
211 if (GNUNET_SYSERR == check_fail ("//:80:"))
213 if (GNUNET_SYSERR == check_fail ("http://localhost:a/"))
215 if (GNUNET_SYSERR == check_fail ("http://127.0.0.1:a/"))
221 main (int argc, char *argv[])
224 struct SplittedHTTPAddress * spa;
226 GNUNET_log_setup ("test", "DEBUG", NULL);
227 spa = http_split_address ("");
235 spa = http_split_address ("http://");
242 spa = http_split_address ("://");
249 test_pass_hostname ();
257 /* end of test_http_common.c */