diff options
author | Alfred E. Heggestad <aeh@db.org> | 2016-07-23 14:52:58 +0200 |
---|---|---|
committer | Alfred E. Heggestad <aeh@db.org> | 2016-07-23 14:52:58 +0200 |
commit | 7cedfabc81c9de28c3925e2d26abd39513013697 (patch) | |
tree | 6b8107b6edfdc82aaa287ededac6e54a8aaf6c6d /test | |
parent | ed9ea7fd82a529966eee2919ddf82762cf741d91 (diff) |
call: add sequential line-numbers for multiple calls (ref #141)
Diffstat (limited to 'test')
-rw-r--r-- | test/call.c | 126 | ||||
-rw-r--r-- | test/main.c | 1 | ||||
-rw-r--r-- | test/test.h | 1 |
3 files changed, 125 insertions, 3 deletions
diff --git a/test/call.c b/test/call.c index 06c7bf3..629b890 100644 --- a/test/call.c +++ b/test/call.c @@ -43,6 +43,8 @@ struct fixture { enum action estab_action; char buri[256]; int err; + unsigned exp_estab; + unsigned exp_closed; }; @@ -53,6 +55,8 @@ struct fixture { TEST_ERR(err); \ \ f->magic = MAGIC; \ + f->exp_estab = 1; \ + f->exp_closed = 1; \ aucodec_register(&dummy_pcma); \ \ err = ua_alloc(&f->a.ua, "A <sip:a:xxx@127.0.0.1>;regint=0"); \ @@ -148,7 +152,8 @@ static void event_handler(struct ua *ua, enum ua_event ev, ++ag->n_established; /* are both agents established? */ - if (ag->peer->n_established) { + if (ag->n_established >= f->exp_estab && + ag->peer->n_established >= f->exp_estab) { switch (f->estab_action) { @@ -174,12 +179,16 @@ static void event_handler(struct ua *ua, enum ua_event ev, break; case UA_EVENT_CALL_CLOSED: - ag->failed = true; ++ag->n_closed; ag->close_scode = call_scode(call); - if (ag->peer->n_closed) { + if (ag->close_scode) + ag->failed = true; + + if (ag->n_closed >= f->exp_closed && + ag->peer->n_closed >= f->exp_closed) { + re_cancel(); } break; @@ -410,3 +419,114 @@ int test_call_rtp_timeout(void) return err; } + + +/* veriy that line-numbers are in sequence */ +static bool linenum_are_sequential(const struct ua *ua) +{ + uint32_t linenum = 0; + struct le *le; + + for (le = list_head(ua_calls(ua)) ; le ; le = le->next) { + struct call *call = le->data; + + if (call_linenum(call) <= linenum) + return false; + + linenum = call_linenum(call); + } + + return true; +} + + +int test_call_multiple(void) +{ + struct fixture fix, *f = &fix; + struct le *le; + unsigned i; + int err = 0; + + fixture_init(f); + + f->behaviour = BEHAVIOUR_ANSWER; + f->exp_estab = 4; + + /* + * Step 1 -- make 4 calls from A to B + */ + for (i=0; i<4; i++) { + err = ua_connect(f->a.ua, 0, NULL, f->buri, NULL, VIDMODE_OFF); + TEST_ERR(err); + } + + err = re_main_timeout(5000); + TEST_ERR(err); + TEST_ERR(fix.err); + + ASSERT_EQ(0, fix.a.n_incoming); + ASSERT_EQ(4, fix.a.n_established); + ASSERT_EQ(0, fix.a.n_closed); + + ASSERT_EQ(4, fix.b.n_incoming); + ASSERT_EQ(4, fix.b.n_established); + ASSERT_EQ(0, fix.b.n_closed); + + ASSERT_EQ(4, list_count(ua_calls(f->a.ua))); + ASSERT_EQ(4, list_count(ua_calls(f->b.ua))); + ASSERT_TRUE(linenum_are_sequential(f->a.ua)); + ASSERT_TRUE(linenum_are_sequential(f->b.ua)); + + + /* + * Step 2 -- hangup calls with even line-number + */ + + f->exp_closed = 2; + + le = list_head(ua_calls(f->a.ua)); + while (le) { + struct call *call = le->data; + le = le->next; + + if (!(call_linenum(call) % 2)) { + ua_hangup(f->a.ua, call, 0, 0); + } + } + + err = re_main_timeout(5000); + TEST_ERR(err); + TEST_ERR(fix.err); + + ASSERT_EQ(2, list_count(ua_calls(f->a.ua))); + ASSERT_EQ(2, list_count(ua_calls(f->b.ua))); + ASSERT_TRUE(linenum_are_sequential(f->a.ua)); + ASSERT_TRUE(linenum_are_sequential(f->b.ua)); + + + /* + * Step 3 -- make 2 calls from A to B + */ + + f->a.n_established = 0; + f->b.n_established = 0; + f->exp_estab = 2; + for (i=0; i<2; i++) { + err = ua_connect(f->a.ua, 0, NULL, f->buri, NULL, VIDMODE_OFF); + TEST_ERR(err); + } + + err = re_main_timeout(5000); + TEST_ERR(err); + TEST_ERR(fix.err); + + ASSERT_EQ(4, list_count(ua_calls(f->a.ua))); + ASSERT_EQ(4, list_count(ua_calls(f->b.ua))); + ASSERT_TRUE(linenum_are_sequential(f->a.ua)); + ASSERT_TRUE(linenum_are_sequential(f->b.ua)); + + out: + fixture_close(f); + + return err; +} diff --git a/test/main.c b/test/main.c index d403084..18442f8 100644 --- a/test/main.c +++ b/test/main.c @@ -25,6 +25,7 @@ static const struct test tests[] = { TEST(test_call_answer_hangup_b), TEST(test_call_reject), TEST(test_call_rtp_timeout), + TEST(test_call_multiple), TEST(test_cmd), TEST(test_cplusplus), TEST(test_mos), diff --git a/test/test.h b/test/test.h index 15629ba..30257cb 100644 --- a/test/test.h +++ b/test/test.h @@ -103,6 +103,7 @@ int test_call_af_mismatch(void); int test_call_answer_hangup_a(void); int test_call_answer_hangup_b(void); int test_call_rtp_timeout(void); +int test_call_multiple(void); #ifdef __cplusplus |