1: #include "check_confuse.h"
2: #include <string.h>
3: #include <sys/types.h>
4:
5: void suppress_errors(cfg_t *cfg, const char *fmt, va_list ap);
6:
7: static cfg_t *cfg = 0;
8: static int func_alias_called = 0;
9:
10: static int func_alias(cfg_t *cfg, cfg_opt_t *opt, int argc, const char **argv)
11: {
12: func_alias_called = 1;
13:
14: fail_unless(cfg != 0);
15: fail_unless(opt != 0);
16: fail_unless(strcmp(opt->name, "alias") == 0);
17: fail_unless(opt->type == CFGT_FUNC);
18: fail_unless(argv != 0);
19: fail_unless(strcmp(argv[0], "ll") == 0);
20: fail_unless(strcmp(argv[1], "ls -l") == 0);
21:
22: if (argc != 2)
23: return -1;
24:
25: return 0;
26: }
27:
28: static void func_setup(void)
29: {
30: cfg_opt_t opts[] = {
31: CFG_FUNC("alias", func_alias),
32: CFG_END()
33: };
34:
35: cfg = cfg_init(opts, 0);
36: /* cfg_set_error_function(cfg, suppress_errors); */
37: }
38:
39: static void func_teardown(void)
40: {
41: cfg_free(cfg);
42: }
43:
44: static void func_test(void)
45: {
46: char *buf;
47:
48: func_alias_called = 0;
49: buf = "alias(ll, 'ls -l')";
50: fail_unless(cfg_parse_buf(cfg, buf) == CFG_SUCCESS);
51: fail_unless(func_alias_called == 1);
52:
53: func_alias_called = 0;
54: buf = "alias(ll, 'ls -l', 2)";
55: fail_unless(cfg_parse_buf(cfg, buf) == CFG_PARSE_ERROR);
56: fail_unless(func_alias_called == 1);
57:
58: buf = "unalias(ll, 'ls -l')";
59: fail_unless(cfg_parse_buf(cfg, buf) == CFG_PARSE_ERROR);
60: }
61:
62: int main(void)
63: {
64: func_setup();
65: func_test();
66: func_teardown();
67:
68: return 0;
69: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>