]> granicus.if.org Git - neomutt/commitdiff
Additional tests for URL
authorPietro Cerutti <gahr@gahr.ch>
Thu, 15 Nov 2018 16:38:51 +0000 (16:38 +0000)
committerRichard Russon <rich@flatcap.org>
Fri, 16 Nov 2018 11:21:19 +0000 (11:21 +0000)
test/url.c

index 592ab84534dcfd8db67104e0694604f89643bbb9..10557a1034bf8b1439d4ab6410abed68c7c3bdcd 100644 (file)
@@ -2,20 +2,35 @@
 #include "acutest.h"
 #include "email/url.h"
 
+typedef bool (*check_query_string)(const struct UrlQueryStringHead *q);
+
+bool check_query_string_eq(const struct UrlQueryStringHead *q)
+{
+  const struct UrlQueryString *np = STAILQ_FIRST(q);
+  if (strcmp(np->name, "encoding") != 0)
+    return false;
+  if (strcmp(np->value, "binary") != 0)
+    return false;
+  if (STAILQ_NEXT(np, entries) != NULL)
+    return false;
+  return true;
+}
+
 static struct
 {
   const char *source;
   bool valid;
+  check_query_string f;
   struct Url url;
 } test[] = {
   {
     "foobar foobar",
     false,
-    {}
   },
   {
     "imaps://foouser:foopass@imap.example.com:456",
     true,
+    NULL,
     {
       U_IMAPS,
       "foouser",
@@ -24,6 +39,32 @@ static struct
       456,
       NULL
     }
+  },
+  {
+    "SmTp://user@example.com", /* scheme is lower-cased */
+    true,
+    NULL,
+    {
+      U_SMTP,
+      "user",
+      NULL,
+      "example.com",
+      0,
+      NULL
+    }
+  },
+  {
+    "pop://user@example.com@pop.example.com:234/some/where?encoding=binary",
+    true,
+    check_query_string_eq,
+    {
+      U_POP,
+      "user@example.com",
+      NULL,
+      "pop.example.com",
+      234,
+      "some/where",
+    }
   }
 };
 
@@ -73,8 +114,10 @@ void test_url(void)
       TEST_MSG("Expected: %s", test[i].url.path);
       TEST_MSG("Actual  : %s", url->path);
     }
-
-    // TODO - test query string
+    if (test[i].f)
+    {
+      TEST_CHECK(test[i].f(&url->query_strings));
+    }
 
     url_free(&url);
   }