add tests for new options API

This commit is contained in:
Vincent Sanders 2013-05-27 09:35:16 +01:00
parent a2769ec68b
commit c1e864656d
4 changed files with 199 additions and 2 deletions

1
.gitignore vendored
View File

@ -12,6 +12,7 @@ windows/res/preferences
\!NetSurf/Resources/nl/Templates,fec
\!NetSurf/Resources/nl/Messages
\!NetSurf/Resources/it/Messages
test/nsoption
test/nsurl
test/urldbtest
test/llcache

View File

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

104
test/data/Choices Normal file
View File

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

86
test/nsoption.c Normal file
View File

@ -0,0 +1,86 @@
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#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;
}