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
10cfg_opt_t opts[] =
11{
12	CFG_STR("parameter", NULL, CFGF_NONE),
13	CFG_END()
14};
15
16int
17main(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
50