version 1.1.1.1, 2017/01/24 14:48:56
|
version 1.1.1.2, 2021/03/17 00:49:17
|
Line 1
|
Line 1
|
#include "check_confuse.h" |
#include "check_confuse.h" |
#include <string.h> |
#include <string.h> |
#include <sys/types.h> |
#include <sys/types.h> |
#include <sys/socket.h> |
|
#include <netinet/in.h> |
|
#include <arpa/inet.h> |
|
|
|
void suppress_errors(cfg_t *cfg, const char *fmt, va_list ap); |
void suppress_errors(cfg_t *cfg, const char *fmt, va_list ap); |
|
|
Line 12 static int func_alias_called = 0;
|
Line 9 static int func_alias_called = 0;
|
|
|
static int func_alias(cfg_t *cfg, cfg_opt_t *opt, int argc, const char **argv) |
static int func_alias(cfg_t *cfg, cfg_opt_t *opt, int argc, const char **argv) |
{ |
{ |
func_alias_called = 1; | func_alias_called = 1; |
|
|
fail_unless(cfg != 0); | fail_unless(cfg != 0); |
fail_unless(opt != 0); | fail_unless(opt != 0); |
fail_unless(strcmp(opt->name, "alias") == 0); | fail_unless(strcmp(opt->name, "alias") == 0); |
fail_unless(opt->type == CFGT_FUNC); | fail_unless(opt->type == CFGT_FUNC); |
fail_unless(argv != 0); | fail_unless(argv != 0); |
fail_unless(strcmp(argv[0], "ll") == 0); | fail_unless(strcmp(argv[0], "ll") == 0); |
fail_unless(strcmp(argv[1], "ls -l") == 0); | fail_unless(strcmp(argv[1], "ls -l") == 0); |
|
|
if(argc != 2) | if (argc != 2) |
return -1; | return -1; |
|
|
return 0; | return 0; |
} |
} |
|
|
static void func_setup(void) |
static void func_setup(void) |
{ |
{ |
cfg_opt_t opts[] = | cfg_opt_t opts[] = { |
{ | CFG_FUNC("alias", func_alias), |
CFG_FUNC("alias", func_alias), | CFG_END() |
CFG_END() | }; |
}; | |
|
|
cfg = cfg_init(opts, 0); | cfg = cfg_init(opts, 0); |
/* cfg_set_error_function(cfg, suppress_errors); */ | /* cfg_set_error_function(cfg, suppress_errors); */ |
} |
} |
|
|
static void func_teardown(void) |
static void func_teardown(void) |
{ |
{ |
cfg_free(cfg); | cfg_free(cfg); |
} |
} |
|
|
static void func_test(void) |
static void func_test(void) |
{ |
{ |
char *buf; | char *buf; |
|
|
func_alias_called = 0; | func_alias_called = 0; |
buf = "alias(ll, 'ls -l')"; | buf = "alias(ll, 'ls -l')"; |
fail_unless(cfg_parse_buf(cfg, buf) == CFG_SUCCESS); | fail_unless(cfg_parse_buf(cfg, buf) == CFG_SUCCESS); |
fail_unless(func_alias_called == 1); | fail_unless(func_alias_called == 1); |
|
|
func_alias_called = 0; | func_alias_called = 0; |
buf = "alias(ll, 'ls -l', 2)"; | buf = "alias(ll, 'ls -l', 2)"; |
fail_unless(cfg_parse_buf(cfg, buf) == CFG_PARSE_ERROR); | fail_unless(cfg_parse_buf(cfg, buf) == CFG_PARSE_ERROR); |
fail_unless(func_alias_called == 1); | fail_unless(func_alias_called == 1); |
|
|
buf = "unalias(ll, 'ls -l')"; | buf = "unalias(ll, 'ls -l')"; |
fail_unless(cfg_parse_buf(cfg, buf) == CFG_PARSE_ERROR); | fail_unless(cfg_parse_buf(cfg, buf) == CFG_PARSE_ERROR); |
} |
} |
|
|
int | int main(void) |
main(void) | |
{ |
{ |
func_setup(); | func_setup(); |
func_test(); | func_test(); |
func_teardown(); | func_teardown(); |
|
|
return 0; | return 0; |
} |
} |
|
|