summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlivier CrĂȘte <olivier.crete@collabora.com>2019-01-28 17:18:42 -0500
committerOlivier CrĂȘte <olivier.crete@collabora.com>2019-01-28 17:18:42 -0500
commit74a3201819bfcaaad30d76a03cf2a4fe0b8aa660 (patch)
tree977121cb22e4cc07f61c90493d1cd64a53a0e736
parent02d53363f13067bfe0a5c5fdd4af7a0e240a45fb (diff)
downloadlibnice-74a3201819bfcaaad30d76a03cf2a4fe0b8aa660.tar.gz
test-fullmode: Make test non-racy too
-rw-r--r--tests/test-fullmode.c45
1 files changed, 35 insertions, 10 deletions
diff --git a/tests/test-fullmode.c b/tests/test-fullmode.c
index b599a24..71d14fe 100644
--- a/tests/test-fullmode.c
+++ b/tests/test-fullmode.c
@@ -335,10 +335,33 @@ static void set_credentials (NiceAgent *lagent, guint lstream,
g_free (password);
}
+static guint16
+get_port (NiceAgent *agent, guint stream_id, guint component_id)
+{
+ GSList *cands = nice_agent_get_local_candidates (agent, stream_id,
+ component_id);
+ GSList *item;
+ guint16 port = 0;
+
+ g_assert (cands != NULL);
+
+ for (item = cands; item; item = item->next) {
+ NiceCandidate *cand = item->data;
+ port = nice_address_get_port (&cand->addr);
+ break;
+ }
+ g_assert (port != 0);
+
+ g_slist_free_full (cands, (GDestroyNotify) nice_candidate_free);
+
+ return port;
+}
+
static int run_full_test (NiceAgent *lagent, NiceAgent *ragent, NiceAddress *baseaddr, guint ready, guint failed)
{
guint ls_id, rs_id;
gint ret;
+ guint16 port;
/* XXX: dear compiler, this is for you */
(void)baseaddr;
@@ -377,15 +400,21 @@ static int run_full_test (NiceAgent *lagent, NiceAgent *ragent, NiceAddress *bas
/* Gather candidates and test nice_agent_set_port_range */
- nice_agent_set_port_range (lagent, ls_id, 1, 10000, 10000);
- nice_agent_set_port_range (lagent, ls_id, 2, 10001, 10001);
- nice_agent_set_port_range (ragent, rs_id, 1, 12345, 12345);
- nice_agent_set_port_range (ragent, rs_id, 2, 10000, 10001);
- g_assert (nice_agent_gather_candidates (lagent, ls_id) == TRUE);
+ for (port = 10000; port < 60000; port++) {
+ nice_agent_set_port_range (lagent, ls_id, 1, port, port);
+ if (nice_agent_gather_candidates (lagent, ls_id))
+ break;
+ }
+
+ g_assert (port == get_port (lagent, ls_id, 1));
+
+ nice_agent_set_port_range (ragent, rs_id, 2, port, port);
+
g_assert (nice_agent_gather_candidates (ragent, rs_id) == FALSE);
g_assert (nice_agent_get_local_candidates (ragent, rs_id, 1) == NULL);
g_assert (nice_agent_get_local_candidates (ragent, rs_id, 2) == NULL);
- nice_agent_set_port_range (ragent, rs_id, 2, 10000, 10002);
+ nice_agent_set_port_range (ragent, rs_id, 2, 0, 0);
+ g_assert (nice_agent_gather_candidates (lagent, ls_id) == TRUE);
g_assert (nice_agent_gather_candidates (ragent, rs_id) == TRUE);
#if USE_LOOPBACK
@@ -397,7 +426,6 @@ static int run_full_test (NiceAgent *lagent, NiceAgent *ragent, NiceAddress *bas
g_assert (g_slist_length (cands) == 1);
cand = cands->data;
g_assert (cand->type == NICE_CANDIDATE_TYPE_HOST);
- g_assert (nice_address_get_port (&cand->addr) == 10000);
for (i = cands; i; i = i->next)
nice_candidate_free ((NiceCandidate *) i->data);
g_slist_free (cands);
@@ -406,7 +434,6 @@ static int run_full_test (NiceAgent *lagent, NiceAgent *ragent, NiceAddress *bas
g_assert (g_slist_length (cands) == 1);
cand = cands->data;
g_assert (cand->type == NICE_CANDIDATE_TYPE_HOST);
- g_assert (nice_address_get_port (&cand->addr) == 10001);
for (i = cands; i; i = i->next)
nice_candidate_free ((NiceCandidate *) i->data);
g_slist_free (cands);
@@ -415,7 +442,6 @@ static int run_full_test (NiceAgent *lagent, NiceAgent *ragent, NiceAddress *bas
g_assert (g_slist_length (cands) == 1);
cand = cands->data;
g_assert (cand->type == NICE_CANDIDATE_TYPE_HOST);
- g_assert (nice_address_get_port (&cand->addr) == 12345);
for (i = cands; i; i = i->next)
nice_candidate_free ((NiceCandidate *) i->data);
g_slist_free (cands);
@@ -424,7 +450,6 @@ static int run_full_test (NiceAgent *lagent, NiceAgent *ragent, NiceAddress *bas
g_assert (g_slist_length (cands) == 1);
cand = cands->data;
g_assert (cand->type == NICE_CANDIDATE_TYPE_HOST);
- g_assert (nice_address_get_port (&cand->addr) == 10002);
for (i = cands; i; i = i->next)
nice_candidate_free ((NiceCandidate *) i->data);
g_slist_free (cands);