Annotation of embedaddon/confuse/tests/suite_ptr.c, revision 1.1.1.1
1.1 misho 1: #include "check_confuse.h"
2: #include <string.h>
3:
4: static int parse_ptr(cfg_t *cfg, cfg_opt_t *opt,
5: const char *value, void *result)
6: {
7: int *ptr;
8:
9: if (!strcmp(value, "nil")) {
10: *(void **)result = NULL;
11: return 0;
12: }
13:
14: ptr = malloc(sizeof(int));
15: if (!ptr)
16: return -1;
17:
18: *ptr = atoi(value);
19: *(void **)result = ptr;
20: return 0;
21: }
22:
23: int main(void)
24: {
25: cfg_opt_t opts[] = {
26: CFG_PTR_CB("ptr", 0, CFGF_NONE, parse_ptr, free),
27: CFG_PTR_CB("ptr-nil", "nil", CFGF_NONE, parse_ptr, free),
28: CFG_PTR_CB("ptr-one", "1", CFGF_NONE, parse_ptr, free),
29: CFG_END()
30: };
31:
32: cfg_t *cfg = cfg_init(opts, 0);
33: fail_unless(cfg_parse_buf(cfg, "") == CFG_SUCCESS);
34: fail_unless(cfg_size(cfg, "ptr") == 0);
35: fail_unless(cfg_getptr(cfg, "ptr") == 0);
36: fail_unless(cfg_size(cfg, "ptr-nil") == 1);
37: fail_unless(cfg_getptr(cfg, "ptr-nil") == 0);
38: fail_unless(cfg_size(cfg, "ptr-one") == 1);
39: fail_unless(cfg_getptr(cfg, "ptr-one") != 0);
40: cfg_free(cfg);
41:
42: return 0;
43: }
44:
45: /**
46: * Local Variables:
47: * indent-tabs-mode: t
48: * c-file-style: "linux"
49: * End:
50: */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>