summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/account.c6
-rw-r--r--test/call.c69
-rw-r--r--test/event.c55
-rw-r--r--test/main.c2
-rw-r--r--test/mock/mock_aucodec.c12
-rw-r--r--test/mock/mock_menc.c126
-rw-r--r--test/mock/mock_vidcodec.c4
-rw-r--r--test/mock/mock_vidsrc.c9
-rw-r--r--test/sip/domain.c3
-rw-r--r--test/sip/sipsrv.c2
-rw-r--r--test/sip/sipsrv.h7
-rw-r--r--test/sip/user.c13
-rw-r--r--test/srcs.mk2
-rw-r--r--test/test.h10
-rw-r--r--test/ua.c18
-rw-r--r--test/video.c4
16 files changed, 314 insertions, 28 deletions
diff --git a/test/account.c b/test/account.c
index bf03b03..cb62acd 100644
--- a/test/account.c
+++ b/test/account.c
@@ -15,9 +15,10 @@
static const char str[] =
- "\"Mr User\" <sip:user:pass@domain.com>"
+ "\"Mr User\" <sip:user@domain.com>"
";answermode=auto"
";auth_user=xuser"
+ ";auth_pass=pass"
";outbound=\"sip:edge.domain.com\""
";ptime=10"
";regint=600"
@@ -45,7 +46,7 @@ int test_account(void)
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("", 0, 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);
@@ -53,6 +54,7 @@ int test_account(void)
/* verify all decoded parameters */
ASSERT_TRUE(ANSWERMODE_AUTO == account_answermode(acc));
ASSERT_STREQ("xuser", account_auth_user(acc));
+ ASSERT_STREQ("pass", account_auth_pass(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));
diff --git a/test/call.c b/test/call.c
index 34c5fd5..ec12524 100644
--- a/test/call.c
+++ b/test/call.c
@@ -176,6 +176,8 @@ static void event_handler(struct ua *ua, enum ua_event ev,
case UA_EVENT_CALL_ESTABLISHED:
++ag->n_established;
+ ASSERT_TRUE(str_isset(call_id(call)));
+
/* are both agents established? */
if (ag->n_established >= f->exp_estab &&
ag->peer->n_established >= f->exp_estab) {
@@ -828,8 +830,15 @@ static void float_sample_handler(const void *sampv, size_t sampc, void *arg)
(void)sampv;
(void)sampc;
- if (sampc && fix->a.n_established && fix->b.n_established)
+ /* Wait until the call is established and the incoming
+ * audio samples are successfully decoded.
+ */
+ if (sampc && fix->a.n_established && fix->b.n_established &&
+ audio_rxaubuf_started(call_audio(ua_call(fix->a.ua))) &&
+ audio_rxaubuf_started(call_audio(ua_call(fix->b.ua)))
+ ) {
re_cancel();
+ }
}
@@ -840,7 +849,7 @@ static int test_media_base(enum audio_mode txmode)
struct auplay *auplay = NULL;
int err = 0;
- fixture_init(f);
+ fixture_init_prm(f, ";ptime=1");
conf_config()->audio.txmode = txmode;
@@ -861,7 +870,7 @@ static int test_media_base(enum audio_mode txmode)
TEST_ERR(err);
/* run main-loop with timeout, wait for events */
- err = re_main_timeout(5000);
+ err = re_main_timeout(15000);
TEST_ERR(err);
TEST_ERR(fix.err);
@@ -896,11 +905,65 @@ int test_call_format_float(void)
err = test_media_base(AUDIO_MODE_POLL);
ASSERT_EQ(0, err);
+#ifdef HAVE_PTHREAD
err = test_media_base(AUDIO_MODE_THREAD);
ASSERT_EQ(0, err);
+#endif
conf_config()->audio.txmode = AUDIO_MODE_POLL;
out:
return err;
}
+
+
+int test_call_mediaenc(void)
+{
+ struct fixture fix, *f = &fix;
+ struct ausrc *ausrc = NULL;
+ struct auplay *auplay = NULL;
+ int err = 0;
+
+ mock_menc_register();
+
+ /* Enable a dummy media encryption protocol */
+ fixture_init_prm(f, ";mediaenc=xrtp;ptime=1");
+
+ err = mock_ausrc_register(&ausrc);
+ TEST_ERR(err);
+ err = mock_auplay_register(&auplay, float_sample_handler, f);
+ TEST_ERR(err);
+
+ f->estab_action = ACTION_NOTHING;
+
+ f->behaviour = BEHAVIOUR_ANSWER;
+
+ /* Make a call from A to B */
+ err = ua_connect(f->a.ua, 0, NULL, f->buri, NULL, VIDMODE_OFF);
+ TEST_ERR(err);
+
+ /* run main-loop with timeout, wait for events */
+ err = re_main_timeout(5000);
+ TEST_ERR(err);
+ TEST_ERR(fix.err);
+
+ ASSERT_EQ(1, fix.a.n_established);
+ ASSERT_EQ(0, fix.a.n_closed);
+
+ ASSERT_EQ(1, fix.b.n_established);
+ ASSERT_EQ(0, fix.b.n_closed);
+
+ /* XXX: verify that the call was encrypted */
+
+ out:
+ fixture_close(f);
+ mem_deref(auplay);
+ mem_deref(ausrc);
+
+ mock_menc_unregister();
+
+ if (fix.err)
+ return fix.err;
+
+ return err;
+}
diff --git a/test/event.c b/test/event.c
new file mode 100644
index 0000000..563d5d3
--- /dev/null
+++ b/test/event.c
@@ -0,0 +1,55 @@
+/**
+ * @file test/event.c Baresip selftest -- event handling
+ *
+ * Copyright (C) 2010 Creytiv.com
+ */
+#include <string.h>
+#include <re.h>
+#include <baresip.h>
+#include "test.h"
+
+
+int test_event(void)
+{
+ struct odict *od = NULL;
+ size_t i;
+ int err = 0;
+
+ static const enum ua_event eventv[] = {
+ UA_EVENT_REGISTERING,
+ UA_EVENT_REGISTER_OK,
+ UA_EVENT_REGISTER_FAIL,
+ UA_EVENT_UNREGISTERING,
+ UA_EVENT_SHUTDOWN,
+ UA_EVENT_EXIT
+ /* .. more events .. */
+ };
+
+ for (i=0; i<ARRAY_SIZE(eventv); i++) {
+
+ const enum ua_event ev = eventv[i];
+ const struct odict_entry *entry;
+
+ err = odict_alloc(&od, 8);
+ ASSERT_EQ(0, err);
+
+ err = event_encode_dict(od, NULL, ev, NULL, NULL);
+ ASSERT_EQ(0, err);
+
+ /* verify that something was added */
+ ASSERT_TRUE(odict_count(od, false) >= 2);
+
+ /* verify the mandatory entries */
+ entry = odict_lookup(od, "type");
+ ASSERT_TRUE(entry != NULL);
+ ASSERT_EQ(ODICT_STRING, entry->type);
+ ASSERT_STREQ(uag_event_str(ev), entry->u.str);
+
+ od = mem_deref(od);
+ }
+
+ out:
+ mem_deref(od);
+
+ return err;
+}
diff --git a/test/main.c b/test/main.c
index e917f2d..01937f4 100644
--- a/test/main.c
+++ b/test/main.c
@@ -30,6 +30,7 @@ static const struct test tests[] = {
TEST(test_call_answer_hangup_b),
TEST(test_call_reject),
TEST(test_call_rtp_timeout),
+ TEST(test_call_mediaenc),
TEST(test_call_multiple),
TEST(test_call_max),
TEST(test_call_dtmf),
@@ -44,6 +45,7 @@ static const struct test tests[] = {
TEST(test_cmd_long),
TEST(test_contact),
TEST(test_cplusplus),
+ TEST(test_event),
TEST(test_message),
TEST(test_mos),
TEST(test_network),
diff --git a/test/mock/mock_aucodec.c b/test/mock/mock_aucodec.c
index fd91721..8115a36 100644
--- a/test/mock/mock_aucodec.c
+++ b/test/mock/mock_aucodec.c
@@ -16,9 +16,10 @@
static int mock_l16_encode(struct auenc_state *st, uint8_t *buf, size_t *len,
- const int16_t *sampv, size_t sampc)
+ int fmt, const void *sampv_void, size_t sampc)
{
int16_t *p = (void *)buf;
+ const int16_t *sampv = sampv_void;
(void)st;
if (!buf || !len || !sampv)
@@ -27,6 +28,9 @@ static int mock_l16_encode(struct auenc_state *st, uint8_t *buf, size_t *len,
if (*len < sampc*2)
return ENOMEM;
+ if (fmt != AUFMT_S16LE)
+ return ENOTSUP;
+
*len = 2 + sampc*2;
*p++ = L16_HEADER;
@@ -39,10 +43,11 @@ static int mock_l16_encode(struct auenc_state *st, uint8_t *buf, size_t *len,
static int mock_l16_decode(struct audec_state *st,
- int16_t *sampv, size_t *sampc,
+ int fmt, void *sampv_void, size_t *sampc,
const uint8_t *buf, size_t len)
{
int16_t *p = (void *)buf;
+ int16_t *sampv = sampv_void;
uint16_t hdr;
(void)st;
@@ -55,6 +60,9 @@ static int mock_l16_decode(struct audec_state *st,
if (*sampc < len/2)
return ENOMEM;
+ if (fmt != AUFMT_S16LE)
+ return ENOTSUP;
+
*sampc = (len - 2)/2;
hdr = *p++;
diff --git a/test/mock/mock_menc.c b/test/mock/mock_menc.c
new file mode 100644
index 0000000..cbd2a5f
--- /dev/null
+++ b/test/mock/mock_menc.c
@@ -0,0 +1,126 @@
+/**
+ * @file mock/mock_menc.c Mock media encryption
+ *
+ * Copyright (C) 2010 - 2018 Creytiv.com
+ */
+
+#include <string.h>
+#include <re.h>
+#include <baresip.h>
+#include "../test.h"
+
+
+#define SECRET_KEY 0xdd
+
+
+struct menc_media {
+ void *rtpsock;
+ struct udp_helper *uh_rtp;
+};
+
+
+/*
+ * Encrypt/decrypt an RTP payload with a dummy key.
+ * We use a simple XOR scheme for simplicity.
+ */
+static void mock_crypt(struct mbuf *mb)
+{
+ size_t i, len = mbuf_get_left(mb);
+
+ for (i = RTP_HEADER_SIZE; i < len; i++) {
+ mb->buf[mb->pos + i] ^= SECRET_KEY;
+ }
+}
+
+
+static void media_destructor(void *data)
+{
+ struct menc_media *mm = data;
+
+ mem_deref(mm->uh_rtp);
+ mem_deref(mm->rtpsock);
+}
+
+
+static bool send_handler(int *err, struct sa *dst, struct mbuf *mb, void *arg)
+{
+ struct menc_media *mm = arg;
+ (void)mm;
+ (void)err;
+ (void)dst;
+
+ mock_crypt(mb);
+
+ return false; /* continue processing */
+}
+
+
+static bool recv_handler(struct sa *src, struct mbuf *mb, void *arg)
+{
+ struct menc_media *mm = arg;
+ (void)mm;
+ (void)src;
+
+ mock_crypt(mb);
+
+ return false; /* continue processing */
+}
+
+
+static int mock_media_alloc(struct menc_media **mmp, struct menc_sess *sess,
+ struct rtp_sock *rtp, int proto,
+ void *rtpsock, void *rtcpsock,
+ struct sdp_media *sdpm)
+{
+ struct menc_media *mm;
+ const int layer = 10; /* above zero */
+ int err = 0;
+ (void)sess;
+ (void)rtp;
+ (void)rtcpsock;
+
+ if (!mmp || !sdpm)
+ return EINVAL;
+ if (proto != IPPROTO_UDP)
+ return EPROTONOSUPPORT;
+
+ mm = *mmp;
+ if (!mm) {
+ mm = mem_zalloc(sizeof(*mm), media_destructor);
+ if (!mm)
+ return ENOMEM;
+
+ mm->rtpsock = mem_ref(rtpsock);
+ err = udp_register_helper(&mm->uh_rtp, rtpsock, layer,
+ send_handler, recv_handler, mm);
+ if (err)
+ goto out;
+
+ *mmp = mm;
+ }
+
+ out:
+ if (err)
+ mem_deref(mm);
+
+ return err;
+}
+
+
+static struct menc menc_mock = {
+ .id = "XRTP",
+ .sdp_proto = "RTP/XAVP",
+ .mediah = mock_media_alloc
+};
+
+
+void mock_menc_register(void)
+{
+ menc_register(baresip_mencl(), &menc_mock);
+}
+
+
+void mock_menc_unregister(void)
+{
+ menc_unregister(&menc_mock);
+}
diff --git a/test/mock/mock_vidcodec.c b/test/mock/mock_vidcodec.c
index 9609e65..93f7a7f 100644
--- a/test/mock/mock_vidcodec.c
+++ b/test/mock/mock_vidcodec.c
@@ -22,7 +22,7 @@ struct hdr {
struct videnc_state {
int64_t pts;
- unsigned fps;
+ double fps;
videnc_packet_h *pkth;
void *arg;
};
@@ -88,7 +88,7 @@ static int mock_encode(struct videnc_state *ves, bool update,
{
struct mbuf *hdr;
uint8_t payload[2] = {0,0};
- uint32_t rtp_ts;
+ uint64_t rtp_ts;
int err;
(void)update;
diff --git a/test/mock/mock_vidsrc.c b/test/mock/mock_vidsrc.c
index 8f92bc4..781e04a 100644
--- a/test/mock/mock_vidsrc.c
+++ b/test/mock/mock_vidsrc.c
@@ -14,7 +14,8 @@ struct vidsrc_st {
struct vidframe *frame;
struct tmr tmr;
- int fps;
+ uint64_t timestamp;
+ double fps;
vidsrc_frame_h *frameh;
void *arg;
};
@@ -27,7 +28,9 @@ static void tmr_handler(void *arg)
tmr_start(&st->tmr, 1000/st->fps, tmr_handler, st);
if (st->frameh)
- st->frameh(st->frame, st->arg);
+ st->frameh(st->frame, st->timestamp, st->arg);
+
+ st->timestamp += VIDEO_TIMEBASE / st->fps;
}
@@ -71,7 +74,7 @@ static int mock_vidsrc_alloc(struct vidsrc_st **stp, const struct vidsrc *vs,
tmr_start(&st->tmr, 0, tmr_handler, st);
- info("mock_vidsrc: new instance with size %u x %u (%d fps)\n",
+ info("mock_vidsrc: new instance with size %u x %u (%.2f fps)\n",
size->w, size->h, prm->fps);
out:
diff --git a/test/sip/domain.c b/test/sip/domain.c
index 063e3b9..2aec1a9 100644
--- a/test/sip/domain.c
+++ b/test/sip/domain.c
@@ -163,7 +163,8 @@ int domain_auth(struct sip_server *srv,
break;
}
- err = httpauth_digest_response_auth(&resp, &msg->met,usr->ha1);
+ err = httpauth_digest_response_auth(&resp, &msg->met,
+ user_ha1(usr));
if (err)
return err;
diff --git a/test/sip/sipsrv.c b/test/sip/sipsrv.c
index 374ea3b..1174893 100644
--- a/test/sip/sipsrv.c
+++ b/test/sip/sipsrv.c
@@ -322,7 +322,7 @@ int sip_server_uri(struct sip_server *srv, char *uri, size_t sz,
return err;
/* NOTE: angel brackets needed to parse ;transport parameter */
- if (re_snprintf(uri, sz, "<sip:x:x@%J%s>",
+ if (re_snprintf(uri, sz, "<sip:x@%J%s>",
&laddr, sip_transp_param(tp)) < 0)
return ENOMEM;
diff --git a/test/sip/sipsrv.h b/test/sip/sipsrv.h
index a4b8bbf..1f1076c 100644
--- a/test/sip/sipsrv.h
+++ b/test/sip/sipsrv.h
@@ -111,12 +111,9 @@ void location_rollback(struct list *locl);
* User
*/
-struct user {
- struct le he;
- uint8_t ha1[MD5_SIZE];
- char *name;
-};
+struct user;
int user_add(struct hash *ht, const char *username, const char *password,
const char *realm);
struct user *user_find(struct hash *ht, const struct pl *name);
+const uint8_t *user_ha1(const struct user *usr);
diff --git a/test/sip/user.c b/test/sip/user.c
index 99fb47d..73a101e 100644
--- a/test/sip/user.c
+++ b/test/sip/user.c
@@ -7,6 +7,13 @@
#include "sipsrv.h"
+struct user {
+ struct le he;
+ uint8_t ha1[MD5_SIZE];
+ char *name;
+};
+
+
static void destructor(void *arg)
{
struct user *usr = arg;
@@ -71,3 +78,9 @@ struct user *user_find(struct hash *ht, const struct pl *name)
return NULL;
}
+
+
+const uint8_t *user_ha1(const struct user *usr)
+{
+ return usr ? usr->ha1 : NULL;
+}
diff --git a/test/srcs.mk b/test/srcs.mk
index 0bcb6de..6cd6d3d 100644
--- a/test/srcs.mk
+++ b/test/srcs.mk
@@ -14,6 +14,7 @@ TEST_SRCS += call.c
TEST_SRCS += cmd.c
TEST_SRCS += contact.c
TEST_SRCS += cplusplus.c
+TEST_SRCS += event.c
TEST_SRCS += message.c
TEST_SRCS += mos.c
TEST_SRCS += net.c
@@ -43,6 +44,7 @@ endif
TEST_SRCS += mock/mock_aucodec.c
TEST_SRCS += mock/mock_auplay.c
TEST_SRCS += mock/mock_ausrc.c
+TEST_SRCS += mock/mock_menc.c
ifneq ($(USE_VIDEO),)
TEST_SRCS += mock/mock_vidsrc.c
TEST_SRCS += mock/mock_vidcodec.c
diff --git a/test/test.h b/test/test.h
index f276a8d..8072cfd 100644
--- a/test/test.h
+++ b/test/test.h
@@ -150,6 +150,14 @@ int mock_auplay_register(struct auplay **auplayp,
/*
+ * Mock Media encryption
+ */
+
+void mock_menc_register(void);
+void mock_menc_unregister(void);
+
+
+/*
* Mock Video-source
*/
@@ -181,6 +189,7 @@ int test_account(void);
int test_aulevel(void);
int test_cmd(void);
int test_cmd_long(void);
+int test_event(void);
int test_contact(void);
int test_ua_alloc(void);
int test_uag_find_param(void);
@@ -207,6 +216,7 @@ int test_call_video(void);
int test_call_aulevel(void);
int test_call_progress(void);
int test_call_format_float(void);
+int test_call_mediaenc(void);
#ifdef USE_VIDEO
int test_video(void);
diff --git a/test/ua.c b/test/ua.c
index 4f04e4f..0621e92 100644
--- a/test/ua.c
+++ b/test/ua.c
@@ -293,7 +293,7 @@ static int reg_dns(enum sip_transp tp)
t.srvc = server_count;
/* NOTE: angel brackets needed to parse ;transport parameter */
- if (re_snprintf(aor, sizeof(aor), "<sip:x:x@%s;transport=%s>",
+ if (re_snprintf(aor, sizeof(aor), "<sip:x@%s;transport=%s>",
domain, sip_transp_name(tp)) < 0)
return ENOMEM;
@@ -362,7 +362,7 @@ int test_ua_register_dns(void)
#define USER "alfredh"
-#define PASS "pass%40word" /* NOTE: url-encoded */
+#define PASS "pass@word"
#define DOMAIN "localhost"
static int reg_auth(enum sip_transp tp)
@@ -384,7 +384,7 @@ static int reg_auth(enum sip_transp tp)
TEST_ERR(err);
err = user_add(domain_lookup(t.srvv[0], DOMAIN)->ht_usr,
- "alfredh", "pass@word", DOMAIN);
+ USER, PASS, DOMAIN);
TEST_ERR(err);
t.srvv[0]->auth_enabled = true;
@@ -395,10 +395,12 @@ static int reg_auth(enum sip_transp tp)
/* NOTE: angel brackets needed to parse ;transport parameter */
if (re_snprintf(aor, sizeof(aor),
- "<sip:%s:%s@%s>;outbound=\"sip:%J;transport=%s\"",
+ "<sip:%s@%s>"
+ ";auth_pass=%s"
+ ";outbound=\"sip:%J;transport=%s\"",
USER,
- PASS,
DOMAIN,
+ PASS,
&laddr,
sip_transp_name(tp)) < 0)
return ENOMEM;
@@ -540,8 +542,10 @@ static int reg_auth_dns(enum sip_transp tp)
t.srvc = server_count;
/* NOTE: angel brackets needed to parse ;transport parameter */
- if (re_snprintf(aor, sizeof(aor), "<sip:%s:%s@%s;transport=%s>",
- username, password, domain, sip_transp_name(tp)) < 0)
+ if (re_snprintf(aor, sizeof(aor),
+ "<sip:%s@%s;transport=%s>;auth_pass=%s",
+ username, domain, sip_transp_name(tp),
+ password) < 0)
return ENOMEM;
/*
diff --git a/test/video.c b/test/video.c
index 09c5e77..c2b829b 100644
--- a/test/video.c
+++ b/test/video.c
@@ -30,8 +30,8 @@ int test_video(void)
ASSERT_EQ( 300000000, video_calc_rtp_timestamp( 100000, 30));
ASSERT_EQ(3000000000, video_calc_rtp_timestamp(1000000, 30));
- ASSERT_EQ(4294965000, video_calc_rtp_timestamp(1431655, 30));
- ASSERT_EQ( 704, video_calc_rtp_timestamp(1431656, 30));
+ ASSERT_EQ(4294965000ULL, video_calc_rtp_timestamp(1431655, 30));
+ ASSERT_EQ(4294968000ULL, video_calc_rtp_timestamp(1431656, 30));
out:
return err;