diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/account.c | 64 | ||||
-rw-r--r-- | test/main.c | 1 | ||||
-rw-r--r-- | test/srcs.mk | 1 | ||||
-rw-r--r-- | test/test.h | 22 |
4 files changed, 88 insertions, 0 deletions
diff --git a/test/account.c b/test/account.c new file mode 100644 index 0000000..6b37a6c --- /dev/null +++ b/test/account.c @@ -0,0 +1,64 @@ +/** + * @file test/account.c Tests for account + * + * Copyright (C) 2010 - 2017 Creytiv.com + */ +#include <string.h> +#include <re.h> +#include <baresip.h> +#include "test.h" + + +#define DEBUG_MODULE "account" +#define DEBUG_LEVEL 5 +#include <re_dbg.h> + + +static const char str[] = + "\"Mr User\" <sip:user:pass@domain.com>" + ";answermode=auto" + ";auth_user=xuser" + ";outbound=\"sip:edge.domain.com\"" + ";ptime=10" + ";regint=600" + ";pubint=700" + ";sipnat=outbound" + ";stunserver=\"stun:stun_user:stun_pass@stunserver.org\"" + ; + + +int test_account(void) +{ + struct account *acc = NULL; + struct sip_addr *addr; + int err = 0; + + err = account_alloc(&acc, str); + TEST_ERR(err); + ASSERT_TRUE(acc != NULL); + + /* verify the decoded SIP aor */ + addr = account_laddr(acc); + ASSERT_TRUE(addr != NULL); + TEST_STRCMP("Mr User", 7, addr->dname.p, addr->dname.l); + TEST_STRCMP("sip", 3, addr->uri.scheme.p, addr->uri.scheme.l); + TEST_STRCMP("user", 4, addr->uri.user.p, addr->uri.user.l); + TEST_STRCMP("pass", 4, addr->uri.password.p, addr->uri.password.l); + TEST_STRCMP("domain.com", 10, addr->uri.host.p, addr->uri.host.l); + ASSERT_EQ(0, addr->uri.params.l); + ASSERT_TRUE(addr->params.l > 0); + + /* verify all decoded parameters */ + ASSERT_TRUE(ANSWERMODE_AUTO == account_answermode(acc)); + ASSERT_STREQ("xuser", account_auth_user(acc)); + ASSERT_STREQ("sip:edge.domain.com", account_outbound(acc, 0)); + ASSERT_TRUE(NULL == account_outbound(acc, 1)); + ASSERT_TRUE(NULL == account_outbound(acc, 333)); + ASSERT_EQ(10, account_ptime(acc)); + ASSERT_EQ(600, account_regint(acc)); + ASSERT_EQ(700, account_pubint(acc)); + + out: + mem_deref(acc); + return err; +} diff --git a/test/main.c b/test/main.c index cbfe686..ba4deea 100644 --- a/test/main.c +++ b/test/main.c @@ -19,6 +19,7 @@ struct test { #define TEST(a) {a, #a} static const struct test tests[] = { + TEST(test_account), TEST(test_call_af_mismatch), TEST(test_call_answer), TEST(test_call_answer_hangup_a), diff --git a/test/srcs.mk b/test/srcs.mk index 29cd7b3..289607e 100644 --- a/test/srcs.mk +++ b/test/srcs.mk @@ -8,6 +8,7 @@ # # Test-cases: # +TEST_SRCS += account.c TEST_SRCS += cmd.c TEST_SRCS += contact.c TEST_SRCS += ua.c diff --git a/test/test.h b/test/test.h index 0f6d203..1d30eb9 100644 --- a/test/test.h +++ b/test/test.h @@ -53,6 +53,27 @@ goto out; \ } +#define TEST_STRCMP(expected, expn, actual, actn) \ + if (expn != actn || \ + 0 != memcmp((expected), (actual), (expn))) { \ + (void)re_fprintf(stderr, "\n"); \ + DEBUG_WARNING("TEST_STRCMP: %s:%u:" \ + " failed\n", \ + __FILE__, __LINE__); \ + (void)re_fprintf(stderr, \ + "expected string: (%zu bytes)\n" \ + "\"%b\"\n", \ + (size_t)(expn), \ + (expected), (size_t)(expn)); \ + (void)re_fprintf(stderr, \ + "actual string: (%zu bytes)\n" \ + "\"%b\"\n", \ + (size_t)(actn), \ + (actual), (size_t)(actn)); \ + err = EINVAL; \ + goto out; \ + } + /* helpers */ @@ -120,6 +141,7 @@ int mock_vidisp_register(struct vidisp **vidispp); /* test cases */ +int test_account(void); int test_cmd(void); int test_cmd_long(void); int test_contact(void); |