#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",
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",
+ }
}
};
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);
}