diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/Makefile | 79 | ||||
-rw-r--r-- | test/log.c | 54 | ||||
-rw-r--r-- | test/urldbtest.c | 4 |
3 files changed, 108 insertions, 29 deletions
diff --git a/test/Makefile b/test/Makefile index 7327580a9..ce3e2744b 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,55 +1,78 @@ # # NetSurf unit tests -CFLAGS := -std=c99 -g -O0 -D_BSD_SOURCE -D_POSIX_C_SOURCE -I. -I.. \ + +test_CFLAGS := -std=c99 -g -Wall \ + -D_BSD_SOURCE \ + -D_POSIX_C_SOURCE=200809L \ + -D_XOPEN_SOURCE=600 \ + -Itest -I. -I.. \ $(shell pkg-config --cflags libcurl) -LDFLAGS := $(shell pkg-config --libs libcurl) -lz +test_LDFLAGS := $(shell pkg-config --libs libcurl) -lz -llcache_CFLAGS := $(shell pkg-config --cflags libparserutils libwapcaplet libdom) -O2 -llcache_LDFLAGS := $(shell pkg-config --libs libparserutils libwapcaplet libdom) +# nsurl sources and flags +nsurl_SRCS := utils/corestrings.c utils/nsurl.c utils/idna.c test/log.c test/nsurl.c +nsurl_CFLAGS := $(shell pkg-config --cflags libwapcaplet libdom libutf8proc) -O0 +nsurl_LDFLAGS := $(shell pkg-config --libs libwapcaplet libdom libutf8proc) +# low level cache sources and flags 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/version.c \ image/image_cache.c \ utils/base64.c utils/corestrings.c utils/hashtable.c \ - utils/log.c utils/nsurl.c utils/messages.c utils/url.c \ + utils/nsurl.c utils/messages.c utils/url.c \ utils/useragent.c utils/utils.c test/llcache.c +llcache_CFLAGS := $(shell pkg-config --cflags libparserutils libwapcaplet libdom) -O2 +llcache_LDFLAGS := $(shell pkg-config --libs libparserutils libwapcaplet libdom) -urldbtest_SRCS := content/urldb.c utils/url.c utils/utils.c utils/log.c \ - utils/messages.c utils/hashtable.c \ +# url database test sources and flags +urldbtest_SRCS := content/urldb.c utils/url.c utils/utils.c utils/idna.c \ + utils/messages.c utils/hashtable.c utils/bloom.c utils/nsoption.c \ utils/filename.c utils/nsurl.c utils/corestrings.c \ - test/urldbtest.c + test/log.c test/urldbtest.c +urldbtest_CFLAGS := $(shell pkg-config --cflags libwapcaplet libdom libnsutils libutf8proc) -O2 +urldbtest_LDFLAGS := $(shell pkg-config --libs libwapcaplet libdom libnsutils libutf8proc) -urldbtest_CFLAGS := $(shell pkg-config --cflags libwapcaplet libdom libnsutils) -O2 -urldbtest_LDFLAGS := $(shell pkg-config --libs libwapcaplet libdom libnsutils) - -nsurl_SRCS := utils/corestrings.c utils/log.c utils/nsurl.c utils/idna.c desktop/version.c test/nsurl.c -nsurl_CFLAGS := $(shell pkg-config --cflags libwapcaplet libdom libutf8proc) -nsurl_LDFLAGS := $(shell pkg-config --libs libwapcaplet libdom libutf8proc) nsoption_SRCS := utils/log.c utils/nsoption.c test/nsoption.c nsoption_CFLAGS := -Dnsgtk -.PHONY: all +CLEANS += test-clean + +TESTS := nsurl urldbtest + +TESTROOT := build-$(HOST)-test + + +.PHONY:test + +test: $(TESTROOT)/created $(addprefix $(TESTROOT)/,$(TESTS)) + $(TESTROOT)/nsurl + $(TESTROOT)/urldbtest + +$(TESTROOT)/created: + $(VQ)echo " MKDIR: $(TESTROOT)" + $(Q)$(MKDIR) $(TESTROOT) + $(Q)$(TOUCH) $@ + +$(TESTROOT)/nsurl: $(nsurl_SRCS) + $(CC) $(test_CFLAGS) $(nsurl_CFLAGS) $^ -o $@ $(test_LDFLAGS) $(nsurl_LDFLAGS) + -all: nsurl - ./nsurl +$(TESTROOT)/urldbtest: $(urldbtest_SRCS) + $(CC) $(test_CFLAGS) $(urldbtest_CFLAGS) $^ -o $@ $(test_LDFLAGS) $(urldbtest_LDFLAGS) -llcache: $(addprefix ../,$(llcache_SRCS)) - $(CC) $(CFLAGS) $(llcache_CFLAGS) $^ -o $@ $(LDFLAGS) $(llcache_LDFLAGS) +$(TESTROOT)/llcache: $(llcache_SRCS) + $(CC) $(test_CFLAGS) $(llcache_CFLAGS) $^ -o $@ $(test_LDFLAGS) $(llcache_LDFLAGS) -urldbtest: $(addprefix ../,$(urldbtest_SRCS)) - $(CC) $(CFLAGS) $(urldbtest_CFLAGS) $^ -o $@ $(LDFLAGS) $(urldbtest_LDFLAGS) -nsurl: $(addprefix ../,$(nsurl_SRCS)) - $(CC) $(CFLAGS) $(nsurl_CFLAGS) $^ -o $@ $(LDFLAGS) $(nsurl_LDFLAGS) -nsoption: $(addprefix ../,$(nsoption_SRCS)) - $(CC) $(CFLAGS) $(nsoption_CFLAGS) $^ -o $@ $(LDFLAGS) $(nsoption_LDFLAGS) +$(TESTROOT)/nsoption: $(addprefix ../,$(nsoption_SRCS)) + $(CC) $(test_CFLAGS) $(nsoption_CFLAGS) $^ -o $@ $(test_LDFLAGS) $(nsoption_LDFLAGS) -.PHONY: clean +.PHONY: test-clean -clean: - $(RM) llcache urldbtest nsurl nsoption +test-clean: + $(RM) $(addprefix $(TESTROOT)/,$(TESTS)) diff --git a/test/log.c b/test/log.c new file mode 100644 index 000000000..90b4379e9 --- /dev/null +++ b/test/log.c @@ -0,0 +1,54 @@ +/* + * Copyright 2015 Vincent Sanders <vince@netsurf-browser.org> + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * NetSurf is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +/** + * \file + * Minimal unit test log implementation. + * + * It is necessary to have a logging implementation for the unit tests + * so other netsurf modules that assume this functionality work. + */ + +#include <stdarg.h> +#include <stdio.h> + +#include "utils/log.h" + +/** flag to enable verbose logging */ +bool verbose_log = false; + +nserror nslog_init(nslog_ensure_t *ensure, int *pargc, char **argv) +{ + return NSERROR_OK; +} + + +void nslog_log(const char *file, const char *func, int ln, const char *format, ...) +{ + va_list ap; + + fprintf(stderr, "%s:%i %s: ", file, ln, func); + + va_start(ap, format); + + vfprintf(stderr, format, ap); + + va_end(ap); + + fputc('\n', stderr); +} diff --git a/test/urldbtest.c b/test/urldbtest.c index 4536ddd17..f72d77f07 100644 --- a/test/urldbtest.c +++ b/test/urldbtest.c @@ -46,7 +46,7 @@ #include "utils/utils.h" int option_expire_url = 0; -bool verbose_log = true; +struct netsurf_table *guit = NULL; static void netsurf_lwc_iterator(lwc_string *str, void *pw) { @@ -163,6 +163,8 @@ int main(void) nsurl *urlr; char *path_query; + verbose_log = true; + corestrings_init(); h = urldb_add_host("127.0.0.1"); |