From 713f55a1f9958222f85238bde40482b566cf040e Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" Date: Sun, 24 Jul 2016 18:00:40 +0200 Subject: contact: make contacts re-entrant --- test/contact.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ test/main.c | 1 + test/srcs.mk | 1 + test/test.h | 1 + 4 files changed, 58 insertions(+) create mode 100644 test/contact.c (limited to 'test') diff --git a/test/contact.c b/test/contact.c new file mode 100644 index 0000000..5b357ff --- /dev/null +++ b/test/contact.c @@ -0,0 +1,55 @@ +/** + * @file test/contact.c Baresip selftest -- contacts + * + * Copyright (C) 2010 - 2016 Creytiv.com + */ +#include +#include +#include +#include "test.h" + + +int test_contact(void) +{ + struct contacts contacts; + struct contact *c; + const char *addr = "sip:neil@young.com"; + struct pl pl_addr; + int err; + + err = contact_init(&contacts); + ASSERT_EQ(0, err); + + /* Verify that we have no contacts */ + + ASSERT_EQ(0, list_count(contact_list(&contacts))); + + c = contact_find(&contacts, "sip:null@void.com"); + ASSERT_TRUE(c == NULL); + + /* Add one contact, list should have one entry and + find should return the added contact */ + + pl_set_str(&pl_addr, addr); + err = contact_add(&contacts, &c, &pl_addr); + ASSERT_EQ(0, err); + ASSERT_TRUE(c != NULL); + + ASSERT_EQ(1, list_count(contact_list(&contacts))); + + c = contact_find(&contacts, addr); + ASSERT_TRUE(c != NULL); + + ASSERT_STREQ(addr, contact_str(c)); + + /* Delete 1 contact, verify that list is empty */ + + mem_deref(c); + + ASSERT_EQ(0, list_count(contact_list(&contacts))); + + out: + contact_close(&contacts); + + return err; +} diff --git a/test/main.c b/test/main.c index c9f1964..c0bc1c1 100644 --- a/test/main.c +++ b/test/main.c @@ -28,6 +28,7 @@ static const struct test tests[] = { TEST(test_call_multiple), TEST(test_call_max), TEST(test_cmd), + TEST(test_contact), TEST(test_cplusplus), TEST(test_mos), TEST(test_network), diff --git a/test/srcs.mk b/test/srcs.mk index 06b4482..2158ca8 100644 --- a/test/srcs.mk +++ b/test/srcs.mk @@ -9,6 +9,7 @@ # Test-cases: # TEST_SRCS += cmd.c +TEST_SRCS += contact.c TEST_SRCS += ua.c TEST_SRCS += cplusplus.c TEST_SRCS += call.c diff --git a/test/test.h b/test/test.h index e8217c9..489f8e0 100644 --- a/test/test.h +++ b/test/test.h @@ -87,6 +87,7 @@ int dns_server_add_srv(struct dns_server *srv, const char *name, /* test cases */ int test_cmd(void); +int test_contact(void); int test_ua_alloc(void); int test_uag_find_param(void); int test_ua_register(void); -- cgit v1.2.3