summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2014-10-30 22:32:52 +0000
committerMichael Drake <tlsa@netsurf-browser.org>2014-10-30 22:34:09 +0000
commit6f09b64c5931ae3615f381436558e82d01862ed3 (patch)
tree46b5af1a0c71d6f8466bfce654aaca8fbaac29cc
parent13832a453a6a4433b4dc62fb0092810671e8751e (diff)
downloadnetsurf-6f09b64c5931ae3615f381436558e82d01862ed3.tar.gz
netsurf-6f09b64c5931ae3615f381436558e82d01862ed3.tar.bz2
Add some nsurl_nice tests.
-rw-r--r--test/nsurl.c94
1 files changed, 94 insertions, 0 deletions
diff --git a/test/nsurl.c b/test/nsurl.c
index bd7dc80dc..49ccdbad0 100644
--- a/test/nsurl.c
+++ b/test/nsurl.c
@@ -165,6 +165,32 @@ static const struct test_pairs join_tests[] = {
{ NULL, NULL }
};
+static const struct test_pairs nice_tests[] = {
+ { "www.foo.org", "www_foo_org" },
+ { "www.foo.org/index.html", "www_foo_org" },
+ { "www.foo.org/default.en", "www_foo_org" },
+ { "www.foo.org/about", "about" },
+ { "www.foo.org/about.jpg", "about.jpg" },
+ { "www.foo.org/moose/index.en", "moose" },
+ { "www.foo.org/a//index.en", "www_foo_org" },
+ { "www.foo.org/a//index.en", "www_foo_org" },
+ { "http://www.f.org//index.en", "www_f_org" },
+ { NULL, NULL }
+};
+
+static const struct test_pairs nice_strip_tests[] = {
+ { "www.foo.org", "www_foo_org" },
+ { "www.foo.org/index.html", "www_foo_org" },
+ { "www.foo.org/default.en", "www_foo_org" },
+ { "www.foo.org/about", "about" },
+ { "www.foo.org/about.jpg", "about" },
+ { "www.foo.org/moose/index.en", "moose" },
+ { "www.foo.org/a//index.en", "www_foo_org" },
+ { "www.foo.org/a//index.en", "www_foo_org" },
+ { "http://www.f.org//index.en", "www_f_org" },
+ { NULL, NULL }
+};
+
static const struct test_triplets replace_query_tests[] = {
{ "http://netsurf-browser.org/?magical=true",
"?magical=true&result=win",
@@ -284,6 +310,74 @@ int main(void)
count++;
}
+ /* nice filename tests */
+ LOG(("Testing nsurl_nice (no strip)"));
+ for (test = nice_tests; test->test != NULL; test++) {
+ err = nsurl_create(test->test, &base);
+ if (err != NSERROR_OK) {
+ LOG(("Failed to create URL:\n\t\t%s.", test->test));
+ } else {
+ char *res;
+ err = nsurl_nice(base, &res, false);
+ if (err == NSERROR_OK && test->res != NULL) {
+ if (strcmp(res, test->res) == 0) {
+ LOG(("\tPASS: \"%s\"\t--> %s",
+ test->test, res));
+ passed++;
+ } else {
+ LOG(("\tFAIL: \"%s\"\t--> %s",
+ test->test, res));
+ LOG(("\t\tExpecting %s", test->res));
+ }
+ free(res);
+ } else {
+ if (test->res == NULL && err == NSERROR_OK) {
+ LOG(("\tFAIL: \"%s\"\t--> %s",
+ test->test, res));
+ LOG(("\t\tExpecting BAD_INPUT"));
+ free(res);
+ } else {
+ LOG(("\tFAIL: \"%s\"", test->test));
+ }
+ }
+ nsurl_unref(base);
+ }
+ count++;
+ }
+ LOG(("Testing nsurl_nice (strip)"));
+ for (test = nice_strip_tests; test->test != NULL; test++) {
+ err = nsurl_create(test->test, &base);
+ if (err != NSERROR_OK) {
+ LOG(("Failed to create URL:\n\t\t%s.", test->test));
+ } else {
+ char *res;
+ err = nsurl_nice(base, &res, true);
+ if (err == NSERROR_OK && test->res != NULL) {
+ if (strcmp(res, test->res) == 0) {
+ LOG(("\tPASS: \"%s\"\t--> %s",
+ test->test, res));
+ passed++;
+ } else {
+ LOG(("\tFAIL: \"%s\"\t--> %s",
+ test->test, res));
+ LOG(("\t\tExpecting %s", test->res));
+ }
+ free(res);
+ } else {
+ if (test->res == NULL && err == NSERROR_OK) {
+ LOG(("\tFAIL: \"%s\"\t--> %s",
+ test->test, res));
+ LOG(("\t\tExpecting BAD_INPUT"));
+ free(res);
+ } else {
+ LOG(("\tFAIL: \"%s\"", test->test));
+ }
+ }
+ nsurl_unref(base);
+ }
+ count++;
+ }
+
/* Replace query tests */
LOG(("Testing nsurl_replace_query"));
for (ttest = replace_query_tests; ttest->test1 != NULL; ttest++) {