r9637 jmb - in /branches/jmb/new-cache/test: ./ Makefile llcache.c

netsurf at semichrome.net netsurf at semichrome.net
Thu Oct 15 02:02:59 BST 2009


Author: jmb
Date: Wed Oct 14 20:02:59 2009
New Revision: 9637

URL: http://source.netsurf-browser.org?rev=9637&view=rev
Log:
Test harness for low-level cache. It's about time we had the ability to trivially build test harnesses.

Added:
    branches/jmb/new-cache/test/
    branches/jmb/new-cache/test/Makefile
    branches/jmb/new-cache/test/llcache.c

Added: branches/jmb/new-cache/test/Makefile
URL: http://source.netsurf-browser.org/branches/jmb/new-cache/test/Makefile?rev=9637&view=auto
==============================================================================
--- branches/jmb/new-cache/test/Makefile (added)
+++ branches/jmb/new-cache/test/Makefile Wed Oct 14 20:02:59 2009
@@ -1,0 +1,19 @@
+CFLAGS := -std=c99 -D_BSD_SOURCE -D_POSIX_C_SOURCE -I.. \
+		`pkg-config --cflags libxml-2.0 libcurl libparserutils`
+LDFLAGS := `pkg-config --libs libxml-2.0 libcurl libparserutils`
+
+llcache_SRCS := content/fetch.c content/fetchers/fetch_curl.c \
+		content/fetchers/fetch_data.c content/llcache.c \
+		content/urldb.c desktop/options.c desktop/version.c \
+		utils/base64.c utils/hashtable.c utils/messages.c \
+		utils/url.c utils/useragent.c utils/utf8.c utils/utils.c \
+		test/llcache.c
+
+llcache: $(addprefix ../,$(llcache_SRCS))
+	$(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS)
+
+
+.PHONY: clean
+
+clean:
+	$(RM) llcache

Added: branches/jmb/new-cache/test/llcache.c
URL: http://source.netsurf-browser.org/branches/jmb/new-cache/test/llcache.c?rev=9637&view=auto
==============================================================================
--- branches/jmb/new-cache/test/llcache.c (added)
+++ branches/jmb/new-cache/test/llcache.c Wed Oct 14 20:02:59 2009
@@ -1,0 +1,148 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "content/llcache.h"
+
+/******************************************************************************
+ * Things that we'd reasonably expect to have to implement                    *
+ ******************************************************************************/
+
+/* desktop/netsurf.h */
+bool verbose_log;
+
+/* utils/utils.h */
+void die(const char * const error)
+{
+	fprintf(stderr, "%s\n", error);
+
+	exit(1);
+}
+
+/* utils/utils.h */
+void warn_user(const char *warning, const char *detail)
+{
+	fprintf(stderr, "%s %s\n", warning, detail);
+}
+
+/* content/fetch.h */
+const char *fetch_filetype(const char *unix_path)
+{
+	return NULL;
+}
+
+/* content/fetch.h */
+char *fetch_mimetype(const char *ro_path)
+{
+	return NULL;
+}
+
+/******************************************************************************
+ * Things that are absolutely not reasonable, and should disappear            *
+ ******************************************************************************/
+
+#include "desktop/cookies.h"
+#include "desktop/tree.h"
+
+/* desktop/cookies.h -- used by urldb 
+ *
+ * URLdb should have a cookies update event + handler registration
+ */
+bool cookies_update(const char *domain, const struct cookie_data *data)
+{
+	return true;
+}
+
+/* image/bitmap.h -- used by urldb 
+ *
+ * URLdb shouldn't care about bitmaps. 
+ * This is because the legacy RO thumbnail stuff was hacked in and must die.
+ */
+void bitmap_destroy(void *bitmap)
+{
+}
+
+/* desktop/tree.h -- used by options.c 
+ *
+ * Why on earth is tree loading and saving in options.c?
+ */
+void tree_initialise(struct tree *tree)
+{
+}
+
+/* desktop/tree.h */
+struct node *tree_create_folder_node(struct node *parent, const char *title)
+{
+	return NULL;
+}
+
+/* desktop/tree.h */
+struct node *tree_create_URL_node(struct node *parent, const char *url,
+		const struct url_data *data, const char *title)
+{
+	return NULL;
+}
+
+/* desktop/tree.h */
+struct node_element *tree_find_element(struct node *node, node_element_data d)
+{
+	return NULL;
+}
+
+/******************************************************************************
+ * The actual test code                                                       *
+ ******************************************************************************/
+
+nserror query_handler(const llcache_query *query, void *pw,
+		llcache_query_response cb, void *cbpw)
+{
+	/* I'm too lazy to actually implement this. It should queue the query, 
+	 * then deliver the response from main(). */
+
+	return NSERROR_OK;
+}
+
+nserror event_handler(const llcache_handle *handle, 
+		const llcache_event *event, void *pw)
+{
+	static char *event_names[] = {
+		"HAD_HEADERS", "HAD_DATA", "DONE", "ERROR", "PROGRESS"
+	};
+	bool *done = pw;
+
+	fprintf(stdout, "%p : %s\n", handle, event_names[event->type]);
+
+	/* Inform main() that the fetch completed */
+	if (event->type == LLCACHE_EVENT_DONE)
+		*done = true;
+
+	return NSERROR_OK;
+}
+
+int main(int argc, char **argv)
+{
+	nserror error;
+	llcache_handle *handle;
+	bool done = false;
+
+	error = llcache_initialise(query_handler, NULL);
+	if (error != NSERROR_OK) {
+		fprintf(stderr, "llcache_initialise: %d\n", error);
+		return 1;
+	}
+
+	error = llcache_handle_retrieve("http://www.netsurf-browser.org/",
+			LLCACHE_RETRIEVE_VERIFIABLE, NULL, NULL,
+			event_handler, &done, &handle);
+	if (error != NSERROR_OK) {
+		fprintf(stderr, "llcache_handle_retrieve: %d\n", error);
+		return 1;
+	}
+
+	while (done == false)
+		llcache_poll();
+
+	llcache_handle_release(handle);
+
+	return 0;
+}
+




More information about the netsurf-commits mailing list