summaryrefslogtreecommitdiff
path: root/test/contact.c
diff options
context:
space:
mode:
authorAlfred E. Heggestad <aeh@db.org>2016-07-24 18:00:40 +0200
committerAlfred E. Heggestad <aeh@db.org>2016-07-24 18:00:40 +0200
commit713f55a1f9958222f85238bde40482b566cf040e (patch)
tree7ca0800a14cec6f9cbe6794a3bdcea9b42001db7 /test/contact.c
parent0a987e0a95b3473f8bc5e70455c92232d9990114 (diff)
contact: make contacts re-entrant
Diffstat (limited to 'test/contact.c')
-rw-r--r--test/contact.c55
1 files changed, 55 insertions, 0 deletions
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 <string.h>
+#include <re.h>
+#include <baresip.h>
+#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;
+}