NeoMutt  2020-06-26-30-g76c339
Teaching an old dog new tricks
DOXYGEN
url_parse.c File Reference

Test code for url_parse() More...

#include "config.h"
#include "acutest.h"
#include "mutt/lib.h"
#include "address/lib.h"
#include "email/lib.h"
+ Include dependency graph for url_parse.c:

Go to the source code of this file.

Data Structures

struct  UrlTest
 

Macros

#define TEST_NO_MAIN
 

Functions

void check_query_string (const char *exp, const struct UrlQueryList *act)
 
void test_url_parse (void)
 

Variables

static struct UrlTest test []
 

Detailed Description

Test code for url_parse()

Authors
  • Richard Russon

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file url_parse.c.

Macro Definition Documentation

◆ TEST_NO_MAIN

#define TEST_NO_MAIN

Definition at line 23 of file url_parse.c.

Function Documentation

◆ check_query_string()

void check_query_string ( const char *  exp,
const struct UrlQueryList *  act 
)

Definition at line 193 of file url_parse.c.

194 {
195  char *next = NULL;
196  char tmp[64] = { 0 };
197  const struct UrlQuery *np = STAILQ_FIRST(act);
198  while (exp && *exp)
199  {
200  next = strchr(exp, '|');
201  mutt_str_copy(tmp, exp, next - exp + 1);
202  exp = next + 1;
203  if (!TEST_CHECK(strcmp(tmp, np->name) == 0))
204  {
205  TEST_MSG("Expected: <%s>", tmp);
206  TEST_MSG("Actual : <%s>", np->name);
207  }
208 
209  next = strchr(exp, '|');
210  mutt_str_copy(tmp, exp, next - exp + 1);
211  exp = next + 1;
212  if (!TEST_CHECK(strcmp(tmp, np->value) == 0))
213  {
214  TEST_MSG("Expected: <%s>", tmp);
215  TEST_MSG("Actual : <%s>", np->value);
216  }
217 
218  np = STAILQ_NEXT(np, entries);
219  }
220 
221  if (!TEST_CHECK(np == NULL))
222  {
223  TEST_MSG("Expected: NULL");
224  TEST_MSG("Actual : (%s, %s)", np->name, np->value);
225  }
226 }
char * name
Query name.
Definition: url.h:57
Parsed Query String.
Definition: url.h:55
#define TEST_MSG(...)
Definition: acutest.h:214
#define TEST_CHECK(cond)
Definition: acutest.h:83
char * value
Query value.
Definition: url.h:58
#define STAILQ_NEXT(elm, field)
Definition: queue.h:397
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:724
#define STAILQ_FIRST(head)
Definition: queue.h:347
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ test_url_parse()

void test_url_parse ( void  )

Definition at line 228 of file url_parse.c.

229 {
230  // struct Url *url_parse(const char *src);
231 
232  {
233  TEST_CHECK(!url_parse(NULL));
234  }
235 
236  {
237  for (size_t i = 0; i < mutt_array_size(test); i++)
238  {
239  TEST_CASE(test[i].source);
240  struct Url *url = url_parse(test[i].source);
241  if (!TEST_CHECK(!((!!url) ^ (!!test[i].valid))))
242  {
243  TEST_MSG("Expected: %sNULL", test[i].valid ? "not " : "");
244  TEST_MSG("Actual : %sNULL", url ? "not " : "");
245  }
246 
247  if (!url)
248  continue;
249 
250  if (!TEST_CHECK(test[i].url.scheme == url->scheme))
251  {
252  TEST_MSG("Expected: %d", test[i].url.scheme);
253  TEST_MSG("Actual : %d", url->scheme);
254  }
255  if (!TEST_CHECK(mutt_str_equal(test[i].url.user, url->user)))
256  {
257  TEST_MSG("Expected: %s", test[i].url.user);
258  TEST_MSG("Actual : %s", url->user);
259  }
260  if (!TEST_CHECK(mutt_str_equal(test[i].url.pass, url->pass)))
261  {
262  TEST_MSG("Expected: %s", test[i].url.pass);
263  TEST_MSG("Actual : %s", url->pass);
264  }
265  if (!TEST_CHECK(mutt_str_equal(test[i].url.host, url->host)))
266  {
267  TEST_MSG("Expected: %s", test[i].url.host);
268  TEST_MSG("Actual : %s", url->host);
269  }
270  if (!TEST_CHECK(test[i].url.port == url->port))
271  {
272  TEST_MSG("Expected: %hu", test[i].url.port);
273  TEST_MSG("Actual : %hu", url->port);
274  }
275  if (!TEST_CHECK(mutt_str_equal(test[i].url.path, url->path)))
276  {
277  TEST_MSG("Expected: %s", test[i].url.path);
278  TEST_MSG("Actual : %s", url->path);
279  }
280  check_query_string(test[i].qs_elem, &url->query_strings);
281 
282  url_free(&url);
283  }
284  }
285 
286  {
287  /* Test automatically generated URLs */
288  const char *const al[] = { "imap", "imaps" };
289  const char *const bl[] = { "", "user@", "user@host.com@", "user:pass@" };
290  const char *const cl[] = { "host.com", "[12AB::EF89]", "127.0.0.1" };
291  const char *const dl[] = { "", ":123" };
292  const char *const el[] = { "", "/", "/path", "/path/one/two", "/path.one.two" };
293  for (size_t a = 0; a < mutt_array_size(al); a++)
294  {
295  for (size_t b = 0; b < mutt_array_size(bl); b++)
296  {
297  for (size_t c = 0; c < mutt_array_size(cl); c++)
298  {
299  for (size_t d = 0; d < mutt_array_size(dl); d++)
300  {
301  for (size_t e = 0; e < mutt_array_size(el); e++)
302  {
303  char s[1024];
304  snprintf(s, sizeof(s), "%s://%s%s%s%s", al[a], bl[b], cl[c], dl[d], el[e]);
305  TEST_CASE(s);
306  struct Url *u = url_parse(s);
307  if (!TEST_CHECK(u != NULL))
308  {
309  TEST_MSG("Expected: parsed <%s>", s);
310  TEST_MSG("Actual: NULL");
311  }
312  url_free(&u);
313  }
314  }
315  }
316  }
317  }
318  }
319 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:879
char * pass
Password.
Definition: url.h:70
void check_query_string(const char *exp, const struct UrlQueryList *act)
Definition: url_parse.c:193
A parsed URL proto://user:password@host:port/path?a=1&b=2
Definition: url.h:66
enum UrlScheme scheme
Scheme, e.g. U_SMTPS.
Definition: url.h:68
#define TEST_MSG(...)
Definition: acutest.h:214
#define TEST_CHECK(cond)
Definition: acutest.h:83
void url_free(struct Url **ptr)
Free the contents of a URL.
Definition: url.c:123
static struct UrlTest test[]
Definition: url_parse.c:40
#define mutt_array_size(x)
Definition: memory.h:33
struct UrlQueryList query_strings
List of query strings.
Definition: url.h:74
char * user
Username.
Definition: url.h:69
#define TEST_CASE(name)
Definition: acutest.h:182
char * host
Host.
Definition: url.h:71
char * path
Path.
Definition: url.h:73
unsigned short port
Port.
Definition: url.h:72
struct Url * url_parse(const char *src)
Fill in Url.
Definition: url.c:234
+ Here is the call graph for this function:

Variable Documentation

◆ test

struct UrlTest test[]
static

Definition at line 40 of file url_parse.c.