summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2011-10-14 21:29:13 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2011-10-14 21:29:13 +0000
commitca4dfc7f1e5e06ca55c854ca293bcd935040eda0 (patch)
treea67c22d9ed772201855c8fd3b766857bff8730d7 /test
parentdeae02c0e7472a92e108a2174202d79c9c484c80 (diff)
downloadnetsurf-ca4dfc7f1e5e06ca55c854ca293bcd935040eda0.tar.gz
netsurf-ca4dfc7f1e5e06ca55c854ca293bcd935040eda0.tar.bz2
Move nsurl test suite into test/
Fix up llcache tester to reflect nsurl changes Make handling of http:,http:/,http:// consistent Fix buffer overflow when presented with an input string: "http://" svn path=/trunk/netsurf/; revision=13051
Diffstat (limited to 'test')
-rw-r--r--test/Makefile19
-rw-r--r--test/llcache.c52
-rw-r--r--test/nsurl.c186
3 files changed, 241 insertions, 16 deletions
diff --git a/test/Makefile b/test/Makefile
index 6e1c2d3f0..283f4bb16 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -5,10 +5,12 @@ LDFLAGS := `pkg-config --libs libxml-2.0 libcurl`
llcache_CFLAGS := `pkg-config --cflags libparserutils libwapcaplet`
llcache_LDFLAGS := `pkg-config --libs libparserutils libwapcaplet`
-llcache_SRCS := content/fetch.c content/fetchers/fetch_curl.c \
- content/fetchers/fetch_data.c content/llcache.c \
+llcache_SRCS := content/fetch.c content/fetchers/curl.c \
+ content/fetchers/about.c content/fetchers/data.c \
+ content/fetchers/resource.c content/llcache.c \
content/urldb.c desktop/options.c desktop/version.c \
- utils/base64.c utils/hashtable.c utils/log.c \
+ image/image_cache.c \
+ utils/base64.c utils/hashtable.c utils/log.c utils/nsurl.c \
utils/messages.c utils/url.c utils/useragent.c utils/utf8.c \
utils/utils.c test/llcache.c
@@ -19,9 +21,13 @@ urldbtest_SRCS := content/urldb.c utils/url.c utils/utils.c utils/log.c \
urldbtest_CFLAGS := -O2
urldbtest_LDFLAGS :=
+nsurl_SRCS := utils/hashtable.c utils/log.c utils/messages.c utils/nsurl.c utils/utils.c test/nsurl.c
+nsurl_CFLAGS := `pkg-config --cflags libwapcaplet`
+nsurl_LDFLAGS := `pkg-config --libs libwapcaplet`
+
.PHONY: all
-all: llcache urldbtest
+all: llcache urldbtest nsurl
llcache: $(addprefix ../,$(llcache_SRCS))
$(CC) $(CFLAGS) $(llcache_CFLAGS) $^ -o $@ $(LDFLAGS) $(llcache_LDFLAGS)
@@ -29,7 +35,10 @@ llcache: $(addprefix ../,$(llcache_SRCS))
urldbtest: $(addprefix ../,$(urldbtest_SRCS))
$(CC) $(CFLAGS) $(urldbtest_CFLAGS) $^ -o $@ $(LDFLAGS) $(urldbtest_LDFLAGS)
+nsurl: $(addprefix ../,$(nsurl_SRCS))
+ $(CC) $(CFLAGS) $(nsurl_CFLAGS) $^ -o $@ $(LDFLAGS) $(nsurl_LDFLAGS)
+
.PHONY: clean
clean:
- $(RM) llcache urldbtest
+ $(RM) llcache urldbtest nsurl
diff --git a/test/llcache.c b/test/llcache.c
index 416c2f573..b072aff7a 100644
--- a/test/llcache.c
+++ b/test/llcache.c
@@ -7,7 +7,10 @@
#include "content/fetch.h"
#include "content/llcache.h"
#include "utils/ring.h"
+#include "utils/nsurl.h"
+#include "utils/schedule.h"
#include "utils/url.h"
+#include "utils/utils.h"
/******************************************************************************
* Things that we'd reasonably expect to have to implement *
@@ -44,6 +47,16 @@ char *filename_from_path(char *path)
return strdup(leafname);
}
+/* utils/schedule.h */
+void schedule(int t, schedule_callback_fn cb, void *pw)
+{
+}
+
+/* utils/schedule.h */
+void schedule_remove(schedule_callback_fn cb, void *pw)
+{
+}
+
/* content/fetch.h */
const char *fetch_filetype(const char *unix_path)
{
@@ -93,6 +106,7 @@ char *url_to_path(const char *url)
******************************************************************************/
#include "desktop/cookies.h"
+#include "desktop/gui.h"
#include "desktop/tree.h"
/* desktop/cookies.h -- used by urldb
@@ -129,6 +143,12 @@ void fetch_file_register(void)
{
}
+/* desktop/gui.h -- used by image_cache through about: handler */
+nsurl* gui_get_resource_url(const char *path)
+{
+ return NULL;
+}
+
/******************************************************************************
* test: protocol handler *
******************************************************************************/
@@ -145,18 +165,18 @@ typedef struct test_context {
static test_context *ring;
-bool test_initialise(const char *scheme)
+bool test_initialise(lwc_string *scheme)
{
/* Nothing to do */
return true;
}
-void test_finalise(const char *scheme)
+void test_finalise(lwc_string *scheme)
{
/* Nothing to do */
}
-void *test_setup_fetch(struct fetch *parent, const char *url, bool only_2xx,
+void *test_setup_fetch(struct fetch *parent, nsurl *url, bool only_2xx,
const char *post_urlenc,
const struct fetch_multipart_data *post_multipart,
const char **headers)
@@ -200,7 +220,7 @@ void test_process(test_context *ctx)
/** \todo Implement */
}
-void test_poll(const char *scheme)
+void test_poll(lwc_string *scheme)
{
test_context *ctx, *next;
@@ -259,24 +279,36 @@ int main(int argc, char **argv)
nserror error;
llcache_handle *handle;
llcache_handle *handle2;
+ lwc_string *scheme;
+ nsurl *url;
bool done = false;
/* Initialise subsystems */
- url_init();
fetch_init();
- fetch_add_fetcher("test", test_initialise, test_setup_fetch,
+
+ if (lwc_intern_string("test", SLEN("test"), &scheme) != lwc_error_ok) {
+ fprintf(stderr, "Failed to intern \"test\"\n");
+ return 1;
+ }
+
+ fetch_add_fetcher(scheme, test_initialise, test_setup_fetch,
test_start_fetch, test_abort_fetch, test_free_fetch,
test_poll, test_finalise);
/* Initialise low-level cache */
- error = llcache_initialise(query_handler, NULL);
+ error = llcache_initialise(query_handler, NULL, 1024 * 1024);
if (error != NSERROR_OK) {
fprintf(stderr, "llcache_initialise: %d\n", error);
return 1;
}
+ if (nsurl_create("http://www.netsurf-browser.org", &url) != NSERROR_OK) {
+ fprintf(stderr, "Failed creating url\n");
+ return 1;
+ }
+
/* Retrieve an URL from the low-level cache (may trigger fetch) */
- error = llcache_handle_retrieve("http://www.netsurf-browser.org/",
+ error = llcache_handle_retrieve(url,
LLCACHE_RETRIEVE_VERIFIABLE, NULL, NULL,
event_handler, &done, &handle);
if (error != NSERROR_OK) {
@@ -286,12 +318,11 @@ int main(int argc, char **argv)
/* Poll relevant components */
while (done == false) {
- fetch_poll();
llcache_poll();
}
done = false;
- error = llcache_handle_retrieve("http://www.netsurf-browser.org/",
+ error = llcache_handle_retrieve(url,
LLCACHE_RETRIEVE_VERIFIABLE, NULL, NULL,
event_handler, &done, &handle2);
if (error != NSERROR_OK) {
@@ -300,7 +331,6 @@ int main(int argc, char **argv)
}
while (done == false) {
- fetch_poll();
llcache_poll();
}
diff --git a/test/nsurl.c b/test/nsurl.c
new file mode 100644
index 000000000..217dd42be
--- /dev/null
+++ b/test/nsurl.c
@@ -0,0 +1,186 @@
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <libwapcaplet/libwapcaplet.h>
+
+#include "desktop/netsurf.h"
+#include "utils/nsurl.h"
+#include "utils/log.h"
+#include "utils/utils.h"
+
+/* desktop/netsurf.h */
+bool verbose_log = true;
+
+/* utils/utils.h */
+void die(const char * const error)
+{
+}
+
+/* utils/utils.h */
+void warn_user(const char *warning, const char *detail)
+{
+}
+
+struct test_pairs {
+ const char* test;
+ const char* res;
+};
+
+static const struct test_pairs create_tests[] = {
+ { "http:", "http:" },
+ { "http:/", "http:" },
+ { "http://", "http:" },
+ { "http:/a/b", "http://a/b" },
+ { "http://a/b", "http://a/b" },
+
+ { "http://www.netsurf-browser.org:8080/",
+ "http://www.netsurf-browser.org:8080/" },
+ { "http://user@www.netsurf-browser.org:8080/hello",
+ "http://user@www.netsurf-browser.org:8080/hello" },
+ { "http://user:password@www.netsurf-browser.org:8080/hello",
+ "http://user:password@www.netsurf-browser.org:8080/hello" },
+
+ { NULL, NULL }
+};
+
+static const struct test_pairs join_tests[] = {
+ /* Normal Examples rfc3986 5.4.1 */
+ { "g:h", "g:h" },
+ { "g", "http://a/b/c/g" },
+ { "./g", "http://a/b/c/g" },
+ { "g/", "http://a/b/c/g/" },
+ { "/g", "http://a/g" },
+ { "//g", "http://g" /* [1] */ "/" },
+ { "?y", "http://a/b/c/d;p?y" },
+ { "g?y", "http://a/b/c/g?y" },
+ { "#s", "http://a/b/c/d;p?q#s" },
+ { "g#s", "http://a/b/c/g#s" },
+ { "g?y#s", "http://a/b/c/g?y#s" },
+ { ";x", "http://a/b/c/;x" },
+ { "g;x", "http://a/b/c/g;x" },
+ { "g;x?y#s", "http://a/b/c/g;x?y#s" },
+ { "", "http://a/b/c/d;p?q" },
+ { ".", "http://a/b/c/" },
+ { "./", "http://a/b/c/" },
+ { "..", "http://a/b/" },
+ { "../", "http://a/b/" },
+ { "../g", "http://a/b/g" },
+ { "../..", "http://a/" },
+ { "../../", "http://a/" },
+ { "../../g", "http://a/g" },
+
+ /* Abnormal Examples rfc3986 5.4.2 */
+ { "../../../g", "http://a/g" },
+ { "../../../../g", "http://a/g" },
+
+ { "/./g", "http://a/g" },
+ { "/../g", "http://a/g" },
+ { "g.", "http://a/b/c/g." },
+ { ".g", "http://a/b/c/.g" },
+ { "g..", "http://a/b/c/g.." },
+ { "..g", "http://a/b/c/..g" },
+
+ { "./../g", "http://a/b/g" },
+ { "./g/.", "http://a/b/c/g/" },
+ { "g/./h", "http://a/b/c/g/h" },
+ { "g/../h", "http://a/b/c/h" },
+ { "g;x=1/./y", "http://a/b/c/g;x=1/y" },
+ { "g;x=1/../y", "http://a/b/c/y" },
+
+ { "g?y/./x", "http://a/b/c/g?y/./x" },
+ { "g?y/../x", "http://a/b/c/g?y/../x" },
+ { "g#s/./x", "http://a/b/c/g#s/./x" },
+ { "g#s/../x", "http://a/b/c/g#s/../x" },
+
+ { "http:g", "http:g" /* [2] */ },
+
+ /* Extra tests */
+ { " g", "http://a/b/c/g" },
+ { "http:/b/c", "http://b/c" },
+ { "http://", "http:" },
+ { "http:/", "http:" },
+ { "http:", "http:" },
+ /* [1] Extra slash beyond rfc3986 5.4.1 example, since we're
+ * testing normalisation in addition to joining */
+ /* [2] Using the strict parsers option */
+ { NULL, NULL }
+};
+
+/**
+ * Test nsurl
+ */
+int main(void)
+{
+ nsurl *base;
+ nsurl *joined;
+ char *string;
+ size_t len;
+ const char *url;
+ const struct test_pairs *test;
+
+ /* Create base URL */
+ if (nsurl_create("http://a/b/c/d;p?q", &base) != NSERROR_OK) {
+ assert(0 && "Failed to create base URL.");
+ }
+
+ if (nsurl_get(base, NSURL_WITH_FRAGMENT, &string, &len) != NSERROR_OK) {
+ LOG(("Failed to get string"));
+ } else {
+ LOG(("Testing nsurl_join with base %s", string));
+ free(string);
+ }
+
+ for (test = join_tests; test->test != NULL; test++) {
+ if (nsurl_join(base, test->test, &joined) != NSERROR_OK) {
+ LOG(("Failed to join test URL."));
+ } else {
+ if (nsurl_get(joined, NSURL_WITH_FRAGMENT,
+ &string, &len) !=
+ NSERROR_OK) {
+ LOG(("Failed to get string"));
+ } else {
+ if (strcmp(test->res, string) == 0) {
+ LOG(("\tPASS: \"%s\"\t--> %s",
+ test->test,
+ string));
+ } else {
+ LOG(("\tFAIL: \"%s\"\t--> %s",
+ test->test,
+ string));
+ LOG(("\t\tExpecting: %s",
+ test->res));
+ assert(0);
+ }
+ free(string);
+ }
+ nsurl_unref(joined);
+ }
+
+ }
+
+ nsurl_unref(base);
+
+ /* 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));
+ } else {
+ if (strcmp(nsurl_access(base), test->res) == 0) {
+ LOG(("PASS: \"%s\"\t--> %s",
+ test->test, nsurl_access(base)));
+ } else {
+ LOG(("FAIL: \"%s\"\t--> %s",
+ test->test, nsurl_access(base)));
+ LOG(("\t\tExpecting %s", test->res));
+ }
+
+ nsurl_unref(base);
+ }
+ }
+
+ return 0;
+}
+