blob: 5b357ff2c8ddaefe4987c047151856dfce841d2d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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;
}
|