test-fullmode: protect against ready->connected->ready state change and accept data...
authorYouness Alaoui <youness.alaoui@collabora.co.uk>
Wed, 9 Apr 2014 03:55:00 +0000 (23:55 -0400)
committerOlivier CrĂȘte <olivier.crete@ocrete.ca>
Thu, 15 May 2014 13:44:00 +0000 (09:44 -0400)
tests/test-fullmode.c

index 3422ecc..fe66a57 100644 (file)
@@ -210,15 +210,25 @@ static void cb_candidate_gathering_done(NiceAgent *agent, guint stream_id, gpoin
 
 static void cb_component_state_changed (NiceAgent *agent, guint stream_id, guint component_id, guint state, gpointer data)
 {
+  gboolean ready_to_connected = FALSE;
   g_debug ("test-fullmode:%s: %p", G_STRFUNC, data);
 
-  if (GPOINTER_TO_UINT (data) == 1)
+  if (GPOINTER_TO_UINT (data) == 1) {
+    if (global_lagent_state[component_id - 1] == NICE_COMPONENT_STATE_READY &&
+        state == NICE_COMPONENT_STATE_CONNECTED)
+      ready_to_connected = TRUE;
     global_lagent_state[component_id - 1] = state;
-  else if (GPOINTER_TO_UINT (data) == 2)
+  } else if (GPOINTER_TO_UINT (data) == 2) {
+    if (global_ragent_state[component_id - 1] == NICE_COMPONENT_STATE_READY &&
+        state == NICE_COMPONENT_STATE_CONNECTED)
+      ready_to_connected = TRUE;
     global_ragent_state[component_id - 1] = state;
-  
+  }
+
   if (state == NICE_COMPONENT_STATE_READY)
     global_components_ready++;
+  else if (state == NICE_COMPONENT_STATE_CONNECTED && ready_to_connected)
+    global_components_ready--;
   if (state == NICE_COMPONENT_STATE_FAILED)
     global_components_failed++;
 
@@ -1031,10 +1041,14 @@ int main (void)
   priv_print_global_status ();
   /* should SUCCEED as agent L can send the checks: */
   g_assert (result == 0);
-  g_assert (global_lagent_state[0] == NICE_COMPONENT_STATE_READY);
-  g_assert (global_lagent_state[1] == NICE_COMPONENT_STATE_READY);
-  g_assert (global_ragent_state[0] == NICE_COMPONENT_STATE_READY);
-  g_assert (global_ragent_state[1] == NICE_COMPONENT_STATE_READY);
+  g_assert (global_lagent_state[0] == NICE_COMPONENT_STATE_CONNECTED ||
+      global_lagent_state[0] == NICE_COMPONENT_STATE_READY);
+  g_assert (global_lagent_state[1] == NICE_COMPONENT_STATE_CONNECTED ||
+      global_lagent_state[1] == NICE_COMPONENT_STATE_READY);
+  g_assert (global_ragent_state[0] == NICE_COMPONENT_STATE_CONNECTED ||
+      global_ragent_state[0] == NICE_COMPONENT_STATE_READY);
+  g_assert (global_ragent_state[1] == NICE_COMPONENT_STATE_CONNECTED ||
+      global_ragent_state[1] == NICE_COMPONENT_STATE_READY);
   g_object_set (G_OBJECT (lagent), "max-connectivity-checks", 100, NULL);
 
   /* run test with a conflict in controlling mode: controlling-controlling */