/** * @file test/main.c Selftest for Baresip core * * Copyright (C) 2010 Creytiv.com */ #ifdef SOLARIS #define __EXTENSIONS__ 1 #endif #include #include #include #include "test.h" typedef int (test_exec_h)(void); struct test { test_exec_h *exec; const char *name; }; #define TEST(a) {a, #a} static const struct test tests[] = { TEST(test_account), TEST(test_aulevel), TEST(test_call_af_mismatch), TEST(test_call_answer), TEST(test_call_answer_hangup_a), TEST(test_call_answer_hangup_b), TEST(test_call_reject), TEST(test_call_rtp_timeout), TEST(test_call_multiple), TEST(test_call_max), TEST(test_call_dtmf), TEST(test_call_aulevel), TEST(test_call_progress), #ifdef USE_VIDEO TEST(test_call_video), TEST(test_video), #endif TEST(test_cmd), TEST(test_cmd_long), TEST(test_contact), TEST(test_cplusplus), TEST(test_message), TEST(test_mos), TEST(test_network), TEST(test_play), TEST(test_ua_alloc), TEST(test_ua_options), TEST(test_ua_register), TEST(test_ua_register_dns), TEST(test_ua_register_auth), TEST(test_ua_register_auth_dns), TEST(test_uag_find_param), }; static int run_one_test(const struct test *test) { int err; re_printf("[ RUN ] %s\n", test->name); err = test->exec(); if (err) { warning("%s: test failed (%m)\n", test->name, err); return err; } re_printf("[ OK ]\n"); return 0; } static int run_tests(void) { size_t i; int err; for (i=0; i\n" "options:\n" "\t-l List all testcases and exit\n" "\t-v Verbose output (INFO level)\n" ); } int main(int argc, char *argv[]) { struct config *config; size_t i, ntests; bool verbose = false; int err; err = libre_init(); if (err) return err; log_enable_info(false); for (;;) { const int c = getopt(argc, argv, "hlv"); if (0 > c) break; switch (c) { case '?': case 'h': usage(); return -2; case 'l': test_listcases(); return 0; case 'v': if (verbose) log_enable_debug(true); else log_enable_info(true); verbose = true; break; default: break; } } if (argc >= (optind + 1)) ntests = argc - optind; else ntests = ARRAY_SIZE(tests); re_printf("running baresip selftest version %s with %zu tests\n", BARESIP_VERSION, ntests); /* note: run SIP-traffic on localhost */ config = conf_config(); if (!config) { err = ENOENT; goto out; } err = baresip_init(config, false); if (err) goto out; str_ncpy(config->sip.local, "127.0.0.1:0", sizeof(config->sip.local)); uag_set_exit_handler(ua_exit_handler, NULL); if (argc >= (optind + 1)) { for (i=0; i