File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / confuse / tests / quote_before_print.c
Revision 1.1.1.2 (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

    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: 	CFG_STR("parameter", NULL, CFGF_NONE),
   12: 	CFG_END()
   13: };
   14: 
   15: int main(void)
   16: {
   17: 	FILE *fp;
   18: 	char *param;
   19: 	cfg_t *cfg = cfg_init(opts, CFGF_NONE);
   20: 
   21: 	fail_unless(cfg);
   22: 
   23: 	/* set a string parameter to a string including a quote character
   24: 	 */
   25: 	cfg_setstr(cfg, "parameter", "text \" with quotes and \\");
   26: 
   27: 	/* print the config to a temporary file
   28: 	 */
   29: 	fp = tmpfile();
   30: 	fail_unless(fp);
   31: 	cfg_print(cfg, fp);
   32: 	cfg_free(cfg);
   33: 
   34: 	/* read it back, we expect 'parameter' to include a quote character
   35: 	 */
   36: 	rewind(fp);
   37: 	cfg = cfg_init(opts, CFGF_NONE);
   38: 	fail_unless(cfg);
   39: 	fail_unless(cfg_parse_fp(cfg, fp) == CFG_SUCCESS);
   40: 	fail_unless(fclose(fp) == 0);
   41: 
   42: 	param = cfg_getstr(cfg, "parameter");
   43: 	fail_unless(param);
   44: 
   45: 	fail_unless(strcmp(param, "text \" with quotes and \\") == 0);
   46: 	cfg_free(cfg);
   47: 
   48: 	return 0;
   49: }

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