summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlfred E. Heggestad <aeh@db.org>2016-06-19 23:56:19 +0200
committerAlfred E. Heggestad <aeh@db.org>2016-06-19 23:56:19 +0200
commit599b548213b0f18b8b23050e894fabeea527e72b (patch)
tree30c2c225bcf9fec3d9b62680ab052855aea63cb7
parent8ef4c56ae0a0d18ceb77a3e62629ac216cab8ebd (diff)
test: added testcase for SIP OPTIONS
-rw-r--r--src/ua.c4
-rw-r--r--test/main.c8
-rw-r--r--test/test.h1
-rw-r--r--test/ua.c116
4 files changed, 125 insertions, 4 deletions
diff --git a/src/ua.c b/src/ua.c
index d87f11d..ed5ba99 100644
--- a/src/ua.c
+++ b/src/ua.c
@@ -909,8 +909,6 @@ int ua_options_send(struct ua *ua, const char *uri,
struct mbuf *dialbuf;
int err = 0;
- (void)arg;
-
if (!ua || !str_isset(uri))
return EINVAL;
@@ -924,7 +922,7 @@ int ua_options_send(struct ua *ua, const char *uri,
dialbuf->buf[dialbuf->end] = '\0';
- err = sip_req_send(ua, "OPTIONS", (char *)dialbuf->buf, resph, NULL,
+ err = sip_req_send(ua, "OPTIONS", (char *)dialbuf->buf, resph, arg,
"Accept: application/sdp\r\n"
"Content-Length: 0\r\n"
"\r\n");
diff --git a/test/main.c b/test/main.c
index db99328..061f8ff 100644
--- a/test/main.c
+++ b/test/main.c
@@ -29,6 +29,7 @@ static const struct test tests[] = {
TEST(test_mos),
TEST(test_network),
TEST(test_ua_alloc),
+ TEST(test_ua_options),
TEST(test_ua_register),
TEST(test_ua_register_dns),
TEST(test_ua_register_auth),
@@ -136,6 +137,7 @@ int main(int argc, char *argv[])
{
struct config *config;
size_t i, ntests;
+ bool verbose = false;
int err;
err = libre_init();
@@ -161,7 +163,11 @@ int main(int argc, char *argv[])
return 0;
case 'v':
- log_enable_info(true);
+ if (verbose)
+ log_enable_debug(true);
+ else
+ log_enable_info(true);
+ verbose = true;
break;
default:
diff --git a/test/test.h b/test/test.h
index cd00514..fe9cd4c 100644
--- a/test/test.h
+++ b/test/test.h
@@ -93,6 +93,7 @@ int test_ua_register(void);
int test_ua_register_dns(void);
int test_ua_register_auth(void);
int test_ua_register_auth_dns(void);
+int test_ua_options(void);
int test_mos(void);
int test_network(void);
diff --git a/test/ua.c b/test/ua.c
index abebe0c..6a131ea 100644
--- a/test/ua.c
+++ b/test/ua.c
@@ -10,15 +10,27 @@
#include "sip/sipsrv.h"
+#define MAGIC 0x9044bbfc
+
+
struct test {
struct sip_server *srvv[16];
size_t srvc;
struct ua *ua;
int err;
unsigned got_register_ok;
+ unsigned n_resp;
+ uint32_t magic;
};
+static void test_init(struct test *t)
+{
+ memset(t, 0, sizeof(*t));
+ t->magic = MAGIC;
+}
+
+
static void test_reset(struct test *t)
{
size_t i;
@@ -31,6 +43,13 @@ static void test_reset(struct test *t)
}
+static void test_abort(struct test *t, int err)
+{
+ t->err = err;
+ re_cancel();
+}
+
+
static void ua_event_handler(struct ua *ua, enum ua_event ev,
struct call *call, const char *prm, void *arg)
{
@@ -589,3 +608,100 @@ int test_ua_register_auth_dns(void)
out:
return err;
}
+
+
+static void options_resp_handler(int err, const struct sip_msg *msg, void *arg)
+{
+ struct test *t = arg;
+ const struct sip_hdr *hdr;
+ struct pl content;
+ uint32_t clen;
+
+ ASSERT_EQ(MAGIC, t->magic);
+
+ if (err) {
+ test_abort(t, err);
+ return;
+ }
+ if (msg->scode != 200) {
+ test_abort(t, EPROTO);
+ return;
+ }
+
+ ++t->n_resp;
+
+ /* Verify SIP headers */
+
+ ASSERT_TRUE(sip_msg_hdr_has_value(msg, SIP_HDR_ALLOW, "INVITE"));
+ ASSERT_TRUE(sip_msg_hdr_has_value(msg, SIP_HDR_ALLOW, "ACK"));
+ ASSERT_TRUE(sip_msg_hdr_has_value(msg, SIP_HDR_ALLOW, "BYE"));
+ ASSERT_TRUE(sip_msg_hdr_has_value(msg, SIP_HDR_ALLOW, "CANCEL"));
+
+ hdr = sip_msg_hdr(msg, SIP_HDR_CONTACT);
+ ASSERT_TRUE(hdr != NULL);
+ ASSERT_TRUE(hdr->val.l != 0);
+
+ ASSERT_EQ(0, pl_strcasecmp(&msg->ctyp.type, "application"));
+ ASSERT_EQ(0, pl_strcasecmp(&msg->ctyp.subtype, "sdp"));
+
+ clen = pl_u32(&msg->clen);
+ ASSERT_TRUE(clen > 0);
+
+ /* Verify the SDP content */
+
+ pl_set_mbuf(&content, msg->mb);
+
+ ASSERT_EQ(0, re_regex(content.p, content.l, "v=0"));
+ ASSERT_EQ(0, re_regex(content.p, content.l, "a=tool:baresip"));
+ ASSERT_EQ(0, re_regex(content.p, content.l, "m=audio"));
+
+ out:
+ if (err)
+ t->err = err;
+ re_cancel();
+}
+
+
+int test_ua_options(void)
+{
+ struct test t;
+ struct sa laddr;
+ char uri[256];
+ int n, err = 0;
+
+ test_init(&t);
+
+ err = ua_init("test", true, false, false, false);
+ TEST_ERR(err);
+
+ err = sip_transp_laddr(uag_sip(), &laddr, SIP_TRANSP_UDP, NULL);
+ TEST_ERR(err);
+
+ err = ua_alloc(&t.ua, "Foo <sip:user:pass@127.0.0.1>;regint=0");
+ TEST_ERR(err);
+
+ n = re_snprintf(uri, sizeof(uri),
+ "sip:user@127.0.0.1:%u", sa_port(&laddr));
+ ASSERT_TRUE(n > 0);
+
+ err = ua_options_send(t.ua, uri, options_resp_handler, &t);
+ TEST_ERR(err);
+
+ /* run main-loop with timeout, wait for events */
+ err = re_main_timeout(5000);
+ if (err)
+ goto out;
+
+ TEST_ERR(t.err);
+
+ /* verify after test is complete */
+ ASSERT_EQ(1, t.n_resp);
+
+ out:
+ test_reset(&t);
+
+ ua_stop_all(true);
+ ua_close();
+
+ return err;
+}