File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / confuse / tests / quote_before_print.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Tue Jan 24 14:48:56 2017 UTC (7 years, 5 months ago) by misho
Branches: confuse, MAIN
CVS tags: v2_7, HEAD
confuse 2.7

    1: /* Check that double quotes gets escaped when printing the config with
    2:  * cfg_print. Also backslashes needs to be escaped.
    3:  */
    4: 
    5: #include <stdio.h>
    6: #include <string.h>
    7: 
    8: #include "check_confuse.h"
    9: 
   10: cfg_opt_t opts[] = 
   11: {
   12: 	CFG_STR("parameter", NULL, CFGF_NONE),
   13: 	CFG_END()
   14: };
   15: 
   16: int
   17: main(void)
   18: {
   19: 	cfg_t *cfg = cfg_init(opts, CFGF_NONE);
   20: 	fail_unless(cfg);
   21: 
   22: 	/* set a string parameter to a string including a quote character
   23: 	 */
   24: 	cfg_setstr(cfg, "parameter", "text \" with quotes and \\");
   25: 
   26: 	/* print the config to a temporary file
   27: 	 */
   28: 	FILE *fp = tmpfile();
   29: 	fail_unless(fp);
   30: 	cfg_print(cfg, fp);
   31: 	cfg_free(cfg);
   32: 
   33: 	/* read it back, we expect 'parameter' to include a quote character
   34: 	 */
   35: 	rewind(fp);
   36: 	cfg = cfg_init(opts, CFGF_NONE);
   37: 	fail_unless(cfg);
   38: 	fail_unless(cfg_parse_fp(cfg, fp) == CFG_SUCCESS);
   39: 	fail_unless(fclose(fp) == 0);
   40: 
   41: 	char *param = cfg_getstr(cfg, "parameter");
   42: 	fail_unless(param);
   43: 
   44: 	fail_unless(strcmp(param, "text \" with quotes and \\") == 0);
   45: 	cfg_free(cfg);
   46: 
   47: 	return 0;
   48: }
   49: 

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