summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAlfred E. Heggestad <aeh@db.org>2016-02-14 17:58:09 +0100
committerAlfred E. Heggestad <aeh@db.org>2016-02-14 17:58:09 +0100
commitd69860809e79de1638f44fd7c06c5b71364060c5 (patch)
treebe37d8b573ead154a9571d8c04beda1d379af3ea /test
parent7c1aa26a289f18ce5dda6021166d7fcfedcb8911 (diff)
test: add testcases for call hangup from both sides
Diffstat (limited to 'test')
-rw-r--r--test/call.c95
-rw-r--r--test/main.c12
-rw-r--r--test/test.h2
3 files changed, 102 insertions, 7 deletions
diff --git a/test/call.c b/test/call.c
index 893b25e..64854fd 100644
--- a/test/call.c
+++ b/test/call.c
@@ -17,6 +17,12 @@ enum behaviour {
BEHAVIOUR_REJECT
};
+enum action {
+ ACTION_RECANCEL = 0,
+ ACTION_HANGUP_A,
+ ACTION_HANGUP_B
+};
+
struct agent {
struct agent *peer;
struct ua *ua;
@@ -33,6 +39,7 @@ struct fixture {
struct agent a, b;
struct sa laddr_sip;
enum behaviour behaviour;
+ enum action estab_action;
char buri[256];
int err;
};
@@ -100,7 +107,6 @@ static void event_handler(struct ua *ua, enum ua_event ev,
else if (ua == f->b.ua)
ag = &f->b;
else {
- warning("ua %p not found\n", ua);
return;
}
@@ -133,8 +139,25 @@ static void event_handler(struct ua *ua, enum ua_event ev,
case UA_EVENT_CALL_ESTABLISHED:
++ag->n_established;
+ /* are both agents established? */
if (ag->peer->n_established) {
- re_cancel();
+
+ switch (f->estab_action) {
+
+ case ACTION_RECANCEL:
+ re_cancel();
+ break;
+
+ case ACTION_HANGUP_A:
+ f->a.failed = true;
+ ua_hangup(f->a.ua, NULL, 0, 0);
+ break;
+
+ case ACTION_HANGUP_B:
+ f->b.failed = true;
+ ua_hangup(f->b.ua, NULL, 0, 0);
+ break;
+ }
}
break;
@@ -266,3 +289,71 @@ int test_call_af_mismatch(void)
return err;
}
+
+
+int test_call_answer_hangup_a(void)
+{
+ struct fixture fix, *f = &fix;
+ int err = 0;
+
+ fixture_init(f);
+
+ f->behaviour = BEHAVIOUR_ANSWER;
+ f->estab_action = ACTION_HANGUP_A;
+
+ /* 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(0, fix.a.close_scode);
+
+ ASSERT_EQ(1, fix.b.n_established);
+ ASSERT_EQ(1, fix.b.n_closed);
+ ASSERT_EQ(0, fix.b.close_scode);
+
+ out:
+ fixture_close(f);
+
+ return err;
+}
+
+
+int test_call_answer_hangup_b(void)
+{
+ struct fixture fix, *f = &fix;
+ int err = 0;
+
+ fixture_init(f);
+
+ f->behaviour = BEHAVIOUR_ANSWER;
+ f->estab_action = ACTION_HANGUP_B;
+
+ /* 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(1, fix.a.n_closed);
+ ASSERT_EQ(0, fix.a.close_scode);
+
+ ASSERT_EQ(1, fix.b.n_established);
+ ASSERT_EQ(0, fix.b.n_closed);
+ ASSERT_EQ(0, fix.b.close_scode);
+
+ out:
+ fixture_close(f);
+
+ return err;
+}
diff --git a/test/main.c b/test/main.c
index de46b11..3a2cf37 100644
--- a/test/main.c
+++ b/test/main.c
@@ -19,14 +19,16 @@ struct test {
#define TEST(a) {a, #a}
static const struct test tests[] = {
+ TEST(test_call_af_mismatch),
+ TEST(test_call_answer),
+ TEST(test_call_answer_hangup_a),
+ TEST(test_call_answer_hangup_b),
+ TEST(test_call_reject),
TEST(test_cmd),
+ TEST(test_cplusplus),
TEST(test_ua_alloc),
- TEST(test_uag_find_param),
TEST(test_ua_register),
- TEST(test_cplusplus),
- TEST(test_call_answer),
- TEST(test_call_reject),
- TEST(test_call_af_mismatch),
+ TEST(test_uag_find_param),
};
diff --git a/test/test.h b/test/test.h
index fc90989..4a91d28 100644
--- a/test/test.h
+++ b/test/test.h
@@ -82,6 +82,8 @@ int test_ua_register(void);
int test_call_answer(void);
int test_call_reject(void);
int test_call_af_mismatch(void);
+int test_call_answer_hangup_a(void);
+int test_call_answer_hangup_b(void);
#ifdef __cplusplus