Annotation of embedaddon/confuse/tests/quote_before_print.c, revision 1.1.1.2

1.1       misho       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: 
1.1.1.2 ! misho      10: cfg_opt_t opts[] = {
1.1       misho      11:        CFG_STR("parameter", NULL, CFGF_NONE),
                     12:        CFG_END()
                     13: };
                     14: 
1.1.1.2 ! misho      15: int main(void)
1.1       misho      16: {
1.1.1.2 ! misho      17:        FILE *fp;
        !            18:        char *param;
1.1       misho      19:        cfg_t *cfg = cfg_init(opts, CFGF_NONE);
1.1.1.2 ! misho      20: 
1.1       misho      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:         */
1.1.1.2 ! misho      29:        fp = tmpfile();
1.1       misho      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: 
1.1.1.2 ! misho      42:        param = cfg_getstr(cfg, "parameter");
1.1       misho      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>