File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / confuse / tests / suite_func.c
Revision 1.1: download - view: text, annotated - select for diffs - revision graph
Tue Jan 24 14:48:56 2017 UTC (7 years, 5 months ago) by misho
CVS tags: MAIN, HEAD
Initial revision

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>