Update test suite for corestrings and log module changes. Update test data for rejection of hostless http(s) urls.

This commit is contained in:
Michael Drake 2014-02-11 11:34:42 +00:00
parent 42be1ffa7b
commit ef6b20fe83
2 changed files with 33 additions and 11 deletions

View File

@ -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

View File

@ -6,12 +6,10 @@
#include <libwapcaplet/libwapcaplet.h>
#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);