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/nsoption.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 test/nsoption.c (limited to 'test/nsoption.c') 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