From c1e864656dc757b0ed255b6ec33ef00c9c7d2070 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Mon, 27 May 2013 09:35:16 +0100 Subject: add tests for new options API --- test/Makefile | 10 ++++-- test/data/Choices | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ test/nsoption.c | 86 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 198 insertions(+), 2 deletions(-) create mode 100644 test/data/Choices create mode 100644 test/nsoption.c (limited to 'test') diff --git a/test/Makefile b/test/Makefile index e61e21f69..ecd2b501a 100644 --- a/test/Makefile +++ b/test/Makefile @@ -26,9 +26,12 @@ 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) +nsoption_SRCS := utils/log.c utils/nsoption.c test/nsoption.c +nsoption_CFLAGS := -Dnsgtk + .PHONY: all -all: llcache urldbtest nsurl +all: llcache urldbtest nsurl nsoption llcache: $(addprefix ../,$(llcache_SRCS)) $(CC) $(CFLAGS) $(llcache_CFLAGS) $^ -o $@ $(LDFLAGS) $(llcache_LDFLAGS) @@ -39,7 +42,10 @@ urldbtest: $(addprefix ../,$(urldbtest_SRCS)) nsurl: $(addprefix ../,$(nsurl_SRCS)) $(CC) $(CFLAGS) $(nsurl_CFLAGS) $^ -o $@ $(LDFLAGS) $(nsurl_LDFLAGS) +nsoption: $(addprefix ../,$(nsoption_SRCS)) + $(CC) $(CFLAGS) $(nsoption_CFLAGS) $^ -o $@ $(LDFLAGS) $(nsoption_LDFLAGS) + .PHONY: clean clean: - $(RM) llcache urldbtest nsurl + $(RM) llcache urldbtest nsurl nsoption diff --git a/test/data/Choices b/test/data/Choices new file mode 100644 index 000000000..f4a62afc4 --- /dev/null +++ b/test/data/Choices @@ -0,0 +1,104 @@ +http_proxy:0 +http_proxy_port:8080 +http_proxy_auth:0 +font_size:128 +font_min_size:85 +font_sans:Sans +font_serif:Serif +font_mono:Monospace +font_cursive:Serif +font_fantasy:Serif +accept_language:en +memory_cache_size:12582912 +disc_cache_size:1073741824 +disc_cache_age:28 +block_advertisements:0 +do_not_track:0 +minimum_gif_delay:10 +send_referer:1 +foreground_images:1 +background_images:1 +animate_images:1 +enable_javascript:1 +script_timeout:10 +expire_url:28 +font_default:0 +ca_path:/etc/ssl/certs +cookie_file:/home/vince/.netsurf/Cookies +cookie_jar:/home/vince/.netsurf/Cookies +homepage_url:about:welcome +search_url_bar:0 +search_provider:0 +url_suggestion:1 +window_x:0 +window_y:0 +window_width:0 +window_height:0 +window_screen_width:0 +window_screen_height:0 +toolbar_status_size:6667 +scale:100 +incremental_reflow:1 +min_reflow_period:25 +core_select_menu:1 +max_fetchers:24 +max_fetchers_per_host:5 +max_cached_fetch_handles:6 +suppress_curl_debug:1 +target_blank:1 +button_2_tab:1 +margin_top:10 +margin_bottom:10 +margin_left:10 +margin_right:10 +export_scale:70 +suppress_images:0 +remove_backgrounds:0 +enable_loosening:1 +enable_PDF_compression:1 +enable_PDF_password:0 +sys_colour_ActiveBorder:000000 +sys_colour_ActiveCaption:000000 +sys_colour_AppWorkspace:000000 +sys_colour_Background:000000 +sys_colour_ButtonFace:000000 +sys_colour_ButtonHighlight:000000 +sys_colour_ButtonShadow:000000 +sys_colour_ButtonText:000000 +sys_colour_CaptionText:000000 +sys_colour_GrayText:000000 +sys_colour_Highlight:000000 +sys_colour_HighlightText:000000 +sys_colour_InactiveBorder:000000 +sys_colour_InactiveCaption:000000 +sys_colour_InactiveCaptionText:000000 +sys_colour_InfoBackground:000000 +sys_colour_InfoText:000000 +sys_colour_Menu:000000 +sys_colour_MenuText:000000 +sys_colour_Scrollbar:000000 +sys_colour_ThreeDDarkShadow:000000 +sys_colour_ThreeDFace:000000 +sys_colour_ThreeDHighlight:000000 +sys_colour_ThreeDLightShadow:000000 +sys_colour_ThreeDShadow:000000 +sys_colour_Window:000000 +sys_colour_WindowFrame:000000 +sys_colour_WindowText:000000 +render_resample:1 +downloads_clear:0 +request_overwrite:1 +downloads_directory:/home/vince +url_file:/home/vince/.netsurf/URLs +show_single_tab:1 +button_type:1 +disable_popups:0 +disable_plugins:0 +history_age:0 +hover_urls:0 +focus_new:0 +new_blank:0 +hotlist_path:/home/vince/.netsurf/Hotlist +source_tab:0 +current_theme:0 +position_tab:0 diff --git a/test/nsoption.c b/test/nsoption.c new file mode 100644 index 000000000..1c9116acb --- /dev/null +++ b/test/nsoption.c @@ -0,0 +1,86 @@ +#include +#include +#include +#include +#include +#include + +#include "utils/errors.h" +#include "utils/log.h" +#include "utils/nsoption.h" + +bool verbose_log = true; + +nserror gui_options_init_defaults(struct nsoption_s *defaults) +{ +#if defined(riscos) + /* Set defaults for absent option strings */ + nsoption_setnull_charp(ca_bundle, strdup("NetSurf:Resources.ca-bundle")); + nsoption_setnull_charp(cookie_file, strdup("NetSurf:Cookies")); + nsoption_setnull_charp(cookie_jar, strdup(CHOICES_PREFIX "Cookies")); + + if (nsoption_charp(ca_bundle) == NULL || + nsoption_charp(cookie_file) == NULL || + nsoption_charp(cookie_jar) == NULL) { + return NSERROR_BAD_PARAMETER; + } +#elif defined(nsgtk) + char *hdir = getenv("HOME"); + char buf[PATH_MAX]; + + /* Set defaults for absent option strings */ + snprintf(buf, PATH_MAX, "%s/.netsurf/Cookies", hdir); + nsoption_setnull_charp(cookie_file, strdup(buf)); + nsoption_setnull_charp(cookie_jar, strdup(buf)); + if (nsoption_charp(cookie_file) == NULL || + nsoption_charp(cookie_jar) == NULL) { + return NSERROR_BAD_PARAMETER; + } + + if (nsoption_charp(downloads_directory) == NULL) { + snprintf(buf, PATH_MAX, "%s/", hdir); + nsoption_set_charp(downloads_directory, strdup(buf)); + } + + if (nsoption_charp(url_file) == NULL) { + snprintf(buf, PATH_MAX, "%s/.netsurf/URLs", hdir); + nsoption_set_charp(url_file, strdup(buf)); + } + + if (nsoption_charp(hotlist_path) == NULL) { + snprintf(buf, PATH_MAX, "%s/.netsurf/Hotlist", hdir); + nsoption_set_charp(hotlist_path, strdup(buf)); + } + + nsoption_setnull_charp(ca_path, strdup("/etc/ssl/certs")); + + if (nsoption_charp(url_file) == NULL || + nsoption_charp(ca_path) == NULL || + nsoption_charp(downloads_directory) == NULL || + nsoption_charp(hotlist_path) == NULL) { + return NSERROR_BAD_PARAMETER; + } + +#endif + return NSERROR_OK; +} + + +int main(int argc, char**argv) +{ + FILE *fp; + + nsoption_init(gui_options_init_defaults, NULL, NULL); + + nsoption_read("data/Choices", NULL); + + nsoption_write("Choices-short", NULL, NULL); + + fp = fopen("Choices-all", "w"); + + nsoption_dump(fp, NULL); + + fclose(fp); + + return 0; +} -- cgit v1.2.3