Annotation of embedaddon/confuse/tests/suite_func.c, revision 1.1.1.2
1.1 misho 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: {
1.1.1.2 ! misho 12: func_alias_called = 1;
1.1 misho 13:
1.1.1.2 ! misho 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);
1.1 misho 21:
1.1.1.2 ! misho 22: if (argc != 2)
! 23: return -1;
1.1 misho 24:
1.1.1.2 ! misho 25: return 0;
1.1 misho 26: }
27:
28: static void func_setup(void)
29: {
1.1.1.2 ! misho 30: cfg_opt_t opts[] = {
! 31: CFG_FUNC("alias", func_alias),
! 32: CFG_END()
! 33: };
1.1 misho 34:
1.1.1.2 ! misho 35: cfg = cfg_init(opts, 0);
! 36: /* cfg_set_error_function(cfg, suppress_errors); */
1.1 misho 37: }
38:
39: static void func_teardown(void)
40: {
1.1.1.2 ! misho 41: cfg_free(cfg);
1.1 misho 42: }
43:
44: static void func_test(void)
45: {
1.1.1.2 ! misho 46: char *buf;
1.1 misho 47:
1.1.1.2 ! misho 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);
1.1 misho 57:
1.1.1.2 ! misho 58: buf = "unalias(ll, 'ls -l')";
! 59: fail_unless(cfg_parse_buf(cfg, buf) == CFG_PARSE_ERROR);
1.1 misho 60: }
61:
1.1.1.2 ! misho 62: int main(void)
1.1 misho 63: {
1.1.1.2 ! misho 64: func_setup();
! 65: func_test();
! 66: func_teardown();
1.1 misho 67:
1.1.1.2 ! misho 68: return 0;
1.1 misho 69: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>