From ef6b20fe83895279e5e78b336f357ff657f46407 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Tue, 11 Feb 2014 11:34:42 +0000 Subject: Update test suite for corestrings and log module changes. Update test data for rejection of hostless http(s) urls. --- test/Makefile | 6 +++--- test/nsurl.c | 38 ++++++++++++++++++++++++++++++-------- 2 files changed, 33 insertions(+), 11 deletions(-) (limited to 'test') diff --git a/test/Makefile b/test/Makefile index ecd2b501a..acf9d4e65 100644 --- a/test/Makefile +++ b/test/Makefile @@ -22,9 +22,9 @@ urldbtest_SRCS := content/urldb.c utils/url.c utils/utils.c utils/log.c \ urldbtest_CFLAGS := $(shell pkg-config --cflags libwapcaplet libdom) -O2 urldbtest_LDFLAGS := $(shell pkg-config --libs libwapcaplet libdom) -nsurl_SRCS := utils/log.c utils/nsurl.c test/nsurl.c -nsurl_CFLAGS := $(shell pkg-config --cflags libwapcaplet) -nsurl_LDFLAGS := $(shell pkg-config --libs libwapcaplet) +nsurl_SRCS := utils/corestrings.c utils/log.c utils/nsurl.c test/nsurl.c +nsurl_CFLAGS := $(shell pkg-config --cflags libwapcaplet libdom) +nsurl_LDFLAGS := $(shell pkg-config --libs libwapcaplet libdom) nsoption_SRCS := utils/log.c utils/nsoption.c test/nsoption.c nsoption_CFLAGS := -Dnsgtk diff --git a/test/nsurl.c b/test/nsurl.c index 66bc05780..3e859d994 100644 --- a/test/nsurl.c +++ b/test/nsurl.c @@ -6,12 +6,10 @@ #include #include "desktop/netsurf.h" +#include "utils/corestrings.h" #include "utils/log.h" #include "utils/nsurl.h" -/* desktop/netsurf.h */ -bool verbose_log = true; - struct test_pairs { const char* test; const char* res; @@ -30,9 +28,10 @@ static void netsurf_lwc_iterator(lwc_string *str, void *pw) } static const struct test_pairs create_tests[] = { - { "http:", "http:" }, - { "http:/", "http:" }, - { "http://", "http:" }, + { "", NULL }, + { "http:", NULL }, + { "http:/", NULL }, + { "http://", NULL }, { "http:a", "http://a/" }, { "http:a/", "http://a/" }, { "http:a/b", "http://a/b" }, @@ -182,6 +181,13 @@ int main(void) const struct test_triplets *ttest; int passed = 0; int count = 0; + nserror err; + + verbose_log = true; + + if (corestrings_init() != NSERROR_OK) { + assert(0 && "Failed to init corestrings."); + } /* Create base URL */ if (nsurl_create("http://a/b/c/d;p?q", &base) != NSERROR_OK) { @@ -228,8 +234,22 @@ int main(void) /* Create tests */ LOG(("Testing nsurl_create")); for (test = create_tests; test->test != NULL; test++) { - if (nsurl_create(test->test, &base) != NSERROR_OK) { - LOG(("Failed to create URL:\n\t\t%s.", test->test)); + err = nsurl_create(test->test, &base); + if (err != NSERROR_OK || test->res == NULL) { + if (test->res == NULL && err != NSERROR_OK) { + LOG(("\tPASS: \"%s\"\t--> BAD INPUT", + test->test)); + passed++; + } else if (test->res != NULL && err != NSERROR_OK) { + LOG(("Failed to create URL:\n\t\t%s.", + test->test)); + } else { + LOG(("\tFAIL: \"%s\"\t--> %s", + test->test, nsurl_access(base))); + LOG(("\t\tExpecting BAD INPUT")); + } + if (err == NSERROR_OK) + nsurl_unref(base); } else { if (strcmp(nsurl_access(base), test->res) == 0) { LOG(("\tPASS: \"%s\"\t--> %s", @@ -286,6 +306,8 @@ int main(void) LOG(("Failed %d out of %d", count - passed, count)); } + corestrings_fini(); + LOG(("Remaining lwc strings:")); lwc_iterate_strings(netsurf_lwc_iterator, NULL); -- cgit v1.2.3