File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / confuse / tests / empty_string.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Wed Mar 17 00:49:17 2021 UTC (3 years, 3 months ago) by misho
Branches: confuse, MAIN
CVS tags: v3_3, HEAD
confuse 3.3

#include "check_confuse.h"
#include <stdio.h>
#include <string.h>

#ifndef HAVE_FMEMOPEN
extern FILE *fmemopen(void *buf, size_t size, const char *type);
#endif

int main(void)
{
	cfg_opt_t opts[] = {
		CFG_STR("string", "hello", CFGF_NONE),
		CFG_END()
	};
	cfg_t *cfg;
	char buf[100]; /* should be enough */
	FILE *f;

	/*
	 * override the default with a config with an empty string
	 * and then generate a temporary config file with that
	 */
	cfg = cfg_init(opts, 0);
	fail_unless(cfg_parse_buf(cfg, "string = ''") == CFG_SUCCESS);
	fail_unless(strcmp(cfg_getstr(cfg, "string"), "") == 0);
	f = fmemopen(buf, sizeof(buf), "w+");
	fail_unless(f != NULL);
	cfg_print(cfg, f);
	cfg_free(cfg);

	/*
	 * try to reload the generated temporary config file to check
	 * that the default is indeed overridden by an empty string
	 */
	cfg = cfg_init(opts, 0);
	fseek(f, 0L, SEEK_SET);
	fail_unless(cfg_parse_fp(cfg, f) == CFG_SUCCESS);
	fclose(f);
	fail_unless(strcmp(cfg_getstr(cfg, "string"), "") == 0);
	cfg_free(cfg);

	return 0;
}

/**
 * Local Variables:
 *  indent-tabs-mode: t
 *  c-file-style: "linux"
 * End:
 */

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>