test-fullmode.c 39.7 KB
Newer Older
1 2 3
/*
 * This file is part of the Nice GLib ICE library.
 *
4 5
 * Unit test for ICE full-mode related features.
 *
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
 * (C) 2007 Nokia Corporation. All rights reserved.
 *  Contact: Kai Vehmanen
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is the Nice GLib ICE library.
 *
 * The Initial Developers of the Original Code are Collabora Ltd and Nokia
 * Corporation. All Rights Reserved.
 *
 * Contributors:
 *   Kai Vehmanen, Nokia
 *
 * Alternatively, the contents of this file may be used under the terms of the
 * the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which
 * case the provisions of LGPL are applicable instead of those above. If you
 * wish to allow use of your version of this file only under the terms of the
 * LGPL and not to allow others to use your version of this file under the
 * MPL, indicate your decision by deleting the provisions above and replace
 * them with the notice and other provisions required by the LGPL. If you do
 * not delete the provisions above, a recipient may use your version of this
 * file under either the MPL or the LGPL.
 */
37 38 39
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
40

Youness Alaoui's avatar
Youness Alaoui committed
41 42
#include "agent.h"

43 44 45 46
#include <stdlib.h>
#include <string.h>


47
#define USE_TURN 0
48
#define USE_LOOPBACK 1
49
#define USE_PROXY 0
50
#define USE_UPNP 0
51
#define USE_RELIABLE 0
52
#define TEST_GOOGLE 0
53

54 55 56 57 58
#define PROXY_IP "127.0.0.1"
#define PROXY_PORT 1080
#define PROXY_USERNAME NULL
#define PROXY_PASSWORD NULL

59 60 61 62 63
#if USE_PROXY
#define PROXY_TYPE NICE_PROXY_TYPE_SOCKS5
#else
#define PROXY_TYPE NICE_PROXY_TYPE_NONE
#endif
64

65 66 67 68 69 70 71
#if TEST_GOOGLE
#define NICE_COMPATIBILITY NICE_COMPATIBILITY_GOOGLE

#if USE_TURN
#undef USE_LOOPBACK
#define USE_LOOPBACK 0

72
#define TURN_IP "209.85.163.126"
73
#define TURN_PORT 443
74 75 76 77
#define TURN_USER "ih9ppiM0P6vN34DB"
#define TURN_PASS ""
#define TURN_USER2 TURN_USER
#define TURN_PASS2 TURN_PASS
78
#define TURN_TYPE NICE_RELAY_TYPE_TURN_TLS
79 80 81 82

#endif

#else
83
#define NICE_COMPATIBILITY NICE_COMPATIBILITY_RFC5245
84 85 86 87 88 89 90 91 92 93 94
#if USE_LOOPBACK
#define USE_TURN_SERVER_ORG 1
#else
#define USE_TURN_SERVER_ORG 0
#endif

#define NUMB_IP "64.251.22.149"
#define NUMB_PORT 3478
#define NUMB_USER "youness.alaoui@collabora.co.uk"
#define NUMB_PASS "badger"

95 96 97 98
#define TSORG_IP "127.0.0.1"
#define TSORG_PORT 3478
#define TSORG_USER "toto"
#define TSORG_PASS "password"
99 100 101 102 103 104 105


#if USE_TURN_SERVER_ORG
#define TURN_IP TSORG_IP
#define TURN_PORT TSORG_PORT
#define TURN_USER TSORG_USER
#define TURN_PASS TSORG_PASS
106 107
#define TURN_USER2 TSORG_USER
#define TURN_PASS2 TSORG_PASS
108
#define TURN_TYPE NICE_RELAY_TYPE_TURN_TCP
109 110 111 112 113
#else
#define TURN_IP NUMB_IP
#define TURN_PORT NUMB_PORT
#define TURN_USER NUMB_USER
#define TURN_PASS NUMB_PASS
114 115
#define TURN_USER2 NUMB_USER
#define TURN_PASS2 NUMB_PASS
116
#define TURN_TYPE NICE_RELAY_TYPE_TURN_UDP
117 118
#endif

119 120
#endif

121

122 123
static NiceComponentState global_lagent_state[2] = { NICE_COMPONENT_STATE_LAST, NICE_COMPONENT_STATE_LAST };
static NiceComponentState global_ragent_state[2] = { NICE_COMPONENT_STATE_LAST, NICE_COMPONENT_STATE_LAST };
124 125 126 127
static guint global_components_ready = 0;
static guint global_components_ready_exit = 0;
static guint global_components_failed = 0;
static guint global_components_failed_exit = 0;
128
static GMainLoop *global_mainloop = NULL;
129 130
static gboolean global_lagent_gathering_done = FALSE;
static gboolean global_ragent_gathering_done = FALSE;
131 132 133 134
static gboolean global_lagent_ibr_received = FALSE;
static gboolean global_ragent_ibr_received = FALSE;
static int global_lagent_cands = 0;
static int global_ragent_cands = 0;
135
static gint global_ragent_read = 0;
136
static guint global_exit_when_ibr_received = 0;
137

138
static void priv_print_global_status (void)
139
{
140
  g_debug ("\tgathering_done=%d", global_lagent_gathering_done && global_ragent_gathering_done);
141 142
  g_debug ("\tlstate[rtp]=%d [rtcp]=%d", global_lagent_state[0], global_lagent_state[1]);
  g_debug ("\trstate[rtp]=%d [rtcp]=%d", global_ragent_state[0], global_ragent_state[1]);
143
  g_debug ("\tL cands=%d R cands=%d", global_lagent_cands, global_ragent_cands);
144 145 146 147
}

static gboolean timer_cb (gpointer pointer)
{
148
  g_debug ("test-fullmode:%s: %p", G_STRFUNC, pointer);
149 150 151 152

  /* signal status via a global variable */

  /* note: should not be reached, abort */
153
  g_error ("ERROR: test has got stuck, aborting...");
154 155

  return FALSE;
156 157
}

158 159
static void cb_writable (NiceAgent*agent, guint stream_id, guint component_id,
    gpointer user_data)
160
{
161 162 163
  guint *ls_id = user_data;

  if (stream_id == *ls_id && component_id == 1) {
164
    g_debug ("Transport is now writable, stopping mainloop");
165 166
    *ls_id = 0;
  }
167 168
}

169 170
static void cb_nice_recv (NiceAgent *agent, guint stream_id, guint component_id, guint len, gchar *buf, gpointer user_data)
{
171
  g_debug ("test-fullmode:%s: %p", G_STRFUNC, user_data);
172 173

  /* XXX: dear compiler, these are for you: */
174 175
  (void)agent; (void)stream_id; (void)component_id; (void)buf;

176 177 178 179 180 181 182 183
  /*
   * Lets ignore stun packets that got through
   */
  if (len < 8)
    return;
  if (strncmp ("12345678", buf, 8))
    return;

184 185 186
  if (component_id == 2)
    return;

187
  if (GPOINTER_TO_UINT (user_data) == 2) {
188
    g_debug ("right agent received %d bytes, stopping mainloop", len);
189 190 191
    global_ragent_read = len;
    g_main_loop_quit (global_mainloop);
  }
192 193
}

194
static void cb_candidate_gathering_done(NiceAgent *agent, guint stream_id, gpointer data)
195
{
196
  g_debug ("test-fullmode:%s: %p", G_STRFUNC, data);
197

198
  if (GPOINTER_TO_UINT (data) == 1)
199
    global_lagent_gathering_done = TRUE;
200
  else if (GPOINTER_TO_UINT (data) == 2)
201 202 203 204 205
    global_ragent_gathering_done = TRUE;

  if (global_lagent_gathering_done &&
      global_ragent_gathering_done)
    g_main_loop_quit (global_mainloop);
206 207 208 209 210

  /* XXX: dear compiler, these are for you: */
  (void)agent;
}

211 212
static void cb_component_state_changed (NiceAgent *agent, guint stream_id, guint component_id, guint state, gpointer data)
{
213
  gboolean ready_to_connected = FALSE;
214
  g_debug ("test-fullmode:%s: %p", G_STRFUNC, data);
215

216 217 218 219
  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;
220
    global_lagent_state[component_id - 1] = state;
221 222 223 224
  } 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;
225
    global_ragent_state[component_id - 1] = state;
226 227
  }

228 229
  if (state == NICE_COMPONENT_STATE_READY)
    global_components_ready++;
230 231
  else if (state == NICE_COMPONENT_STATE_CONNECTED && ready_to_connected)
    global_components_ready--;
232 233 234
  if (state == NICE_COMPONENT_STATE_FAILED)
    global_components_failed++;

235 236
  g_debug ("test-fullmode: checks READY/EXIT-AT %u/%u.", global_components_ready, global_components_ready_exit);
  g_debug ("test-fullmode: checks FAILED/EXIT-AT %u/%u.", global_components_failed, global_components_failed_exit);
237 238

  /* signal status via a global variable */
239 240
  if (global_components_ready == global_components_ready_exit &&
      global_components_failed == global_components_failed_exit) {
241
    g_debug ("Components ready/failed achieved. Stopping mailoop");
242 243 244 245
    g_main_loop_quit (global_mainloop); 
    return;
  }

246
#if 0
247 248 249 250 251
  /* signal status via a global variable */
  if (global_components_failed == global_components_failed_exit) {
    g_main_loop_quit (global_mainloop); 
    return;
  }
252
#endif
253 254 255 256

  /* XXX: dear compiler, these are for you: */
  (void)agent; (void)stream_id; (void)data; (void)component_id;
}
257 258 259 260

static void cb_new_selected_pair(NiceAgent *agent, guint stream_id, guint component_id, 
				 gchar *lfoundation, gchar* rfoundation, gpointer data)
{
261
  g_debug ("test-fullmode:%s: %p", G_STRFUNC, data);
262

263
  if (GPOINTER_TO_UINT (data) == 1)
264
    ++global_lagent_cands;
265
  else if (GPOINTER_TO_UINT (data) == 2)
266 267 268
    ++global_ragent_cands;

  /* XXX: dear compiler, these are for you: */
269
  (void)agent; (void)stream_id; (void)component_id; (void)lfoundation; (void)rfoundation;
270 271 272 273 274
}

static void cb_new_candidate(NiceAgent *agent, guint stream_id, guint component_id, 
			     gchar *foundation, gpointer data)
{
275
  g_debug ("test-fullmode:%s: %p", G_STRFUNC, data);
276

277
  /* XXX: dear compiler, these are for you: */
278
  (void)agent; (void)stream_id; (void)data; (void)component_id; (void)foundation;
279 280 281 282
}

static void cb_initial_binding_request_received(NiceAgent *agent, guint stream_id, gpointer data)
{
283
  g_debug ("test-fullmode:%s: %p", G_STRFUNC, data);
284

285
  if (GPOINTER_TO_UINT (data) == 1)
286
    global_lagent_ibr_received = TRUE;
287
  else if (GPOINTER_TO_UINT (data) == 2)
288 289
    global_ragent_ibr_received = TRUE;

290 291 292 293
  if (global_exit_when_ibr_received) {
    g_debug ("Received initial binding request. Stopping mailoop");
    g_main_loop_quit (global_mainloop);
  }
294

295 296 297 298
  /* XXX: dear compiler, these are for you: */
  (void)agent; (void)stream_id; (void)data;
}

299
static void set_candidates (NiceAgent *from, guint from_stream,
300
    NiceAgent *to, guint to_stream, guint component, gboolean remove_non_relay)
301
{
302
  GSList *cands = NULL, *i;
303

304
  cands = nice_agent_get_local_candidates (from, from_stream, component);
305 306 307 308 309 310 311 312 313
  if (remove_non_relay) {
  restart:
    for (i = cands; i; i = i->next) {
      NiceCandidate *cand = i->data;
      if (cand->type != NICE_CANDIDATE_TYPE_RELAYED) {
        cands = g_slist_remove (cands, cand);
        nice_candidate_free (cand);
        goto restart;
      }
314 315
    }
  }
316
  nice_agent_set_remote_candidates (to, to_stream, component, cands);
317 318 319

  for (i = cands; i; i = i->next)
    nice_candidate_free ((NiceCandidate *) i->data);
320 321 322
  g_slist_free (cands);
}

323 324 325 326 327 328 329 330 331 332 333 334 335 336
static void set_credentials (NiceAgent *lagent, guint lstream,
    NiceAgent *ragent, guint rstream)
{
  gchar *ufrag = NULL, *password = NULL;

  nice_agent_get_local_credentials(lagent, lstream, &ufrag, &password);
  nice_agent_set_remote_credentials (ragent, rstream, ufrag, password);
  g_free (ufrag);
  g_free (password);
  nice_agent_get_local_credentials(ragent, rstream, &ufrag, &password);
  nice_agent_set_remote_credentials (lagent, lstream, ufrag, password);
  g_free (ufrag);
  g_free (password);
}
337

338
static int run_full_test (NiceAgent *lagent, NiceAgent *ragent, NiceAddress *baseaddr, guint ready, guint failed)
339 340
{
  guint ls_id, rs_id;
341
  gint ret;
342

343 344 345
  /* XXX: dear compiler, this is for you */
  (void)baseaddr;

346 347
  /* step: initialize variables modified by the callbacks */
  global_components_ready = 0;
348
  global_components_ready_exit = ready;
349
  global_components_failed = 0;
350
  global_components_failed_exit = failed;
351 352 353 354
  global_lagent_gathering_done = FALSE;
  global_ragent_gathering_done = FALSE;
  global_lagent_ibr_received =
    global_ragent_ibr_received = FALSE;
355
  global_lagent_cands =
356 357 358 359 360
    global_ragent_cands = 0;

  g_object_set (G_OBJECT (lagent), "controlling-mode", TRUE, NULL);
  g_object_set (G_OBJECT (ragent), "controlling-mode", FALSE, NULL);

361 362
  /* step: add one stream, with RTP+RTCP components, to each agent */
  ls_id = nice_agent_add_stream (lagent, 2);
363

364
  rs_id = nice_agent_add_stream (ragent, 2);
365 366
  g_assert (ls_id > 0);
  g_assert (rs_id > 0);
367 368
#if USE_TURN
  nice_agent_set_relay_info(lagent, ls_id, 1,
369
      TURN_IP, TURN_PORT, TURN_USER, TURN_PASS, TURN_TYPE);
370
  nice_agent_set_relay_info(lagent, ls_id, 2,
371
      TURN_IP, TURN_PORT, TURN_USER, TURN_PASS, TURN_TYPE);
372
  nice_agent_set_relay_info(ragent, rs_id, 1,
373
      TURN_IP, TURN_PORT, TURN_USER2, TURN_PASS2, TURN_TYPE);
374
  nice_agent_set_relay_info(ragent, rs_id, 2,
375
      TURN_IP, TURN_PORT, TURN_USER2, TURN_PASS2, TURN_TYPE);
376 377
#endif

378

379 380 381 382 383 384 385 386 387 388 389 390
  /* 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);
  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);
  g_assert (nice_agent_gather_candidates (ragent, rs_id) == TRUE);

391
#if USE_LOOPBACK
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433
  {
    GSList *cands = NULL, *i;
    NiceCandidate *cand = NULL;

    cands = nice_agent_get_local_candidates (lagent, ls_id, 1);
    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);

    cands = nice_agent_get_local_candidates (lagent, ls_id, 2);
    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);

    cands = nice_agent_get_local_candidates (ragent, rs_id, 1);
    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);

    cands = nice_agent_get_local_candidates (ragent, rs_id, 2);
    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);

  }
#endif
434

435 436
  /* step: attach to mainloop (needed to register the fds) */
  nice_agent_attach_recv (lagent, ls_id, NICE_COMPONENT_TYPE_RTP,
437 438
      g_main_loop_get_context (global_mainloop), cb_nice_recv,
      GUINT_TO_POINTER (1));
439
  nice_agent_attach_recv (lagent, ls_id, NICE_COMPONENT_TYPE_RTCP,
440 441
      g_main_loop_get_context (global_mainloop), cb_nice_recv,
      GUINT_TO_POINTER (1));
442
  nice_agent_attach_recv (ragent, rs_id, NICE_COMPONENT_TYPE_RTP,
443 444
      g_main_loop_get_context (global_mainloop), cb_nice_recv,
      GUINT_TO_POINTER (2));
445
  nice_agent_attach_recv (ragent, rs_id, NICE_COMPONENT_TYPE_RTCP,
446 447
      g_main_loop_get_context (global_mainloop), cb_nice_recv,
      GUINT_TO_POINTER (2));
448 449

  /* step: run mainloop until local candidates are ready
450
   *       (see timer_cb() above) */
451 452 453 454 455 456 457
  if (global_lagent_gathering_done != TRUE ||
      global_ragent_gathering_done != TRUE) {
    g_debug ("test-fullmode: Added streams, running mainloop until 'candidate-gathering-done'...");
    g_main_loop_run (global_mainloop);
    g_assert (global_lagent_gathering_done == TRUE);
    g_assert (global_ragent_gathering_done == TRUE);
  }
458

459
  set_credentials (lagent, ls_id, ragent, rs_id);
460

461
  /* step: pass the remote candidates to agents  */
462 463 464 465
  set_candidates (ragent, rs_id, lagent, ls_id, NICE_COMPONENT_TYPE_RTP, USE_TURN);
  set_candidates (ragent, rs_id, lagent, ls_id, NICE_COMPONENT_TYPE_RTCP, USE_TURN);
  set_candidates (lagent, ls_id, ragent, rs_id, NICE_COMPONENT_TYPE_RTP, USE_TURN);
  set_candidates (lagent, ls_id, ragent, rs_id, NICE_COMPONENT_TYPE_RTCP, USE_TURN);
466 467 468

  g_debug ("test-fullmode: Set properties, next running mainloop until connectivity checks succeed...");

469
  /* step: run the mainloop until connectivity checks succeed
470 471 472 473 474 475 476
   *       (see timer_cb() above) */
  g_main_loop_run (global_mainloop);

  /* note: verify that STUN binding requests were sent */
  g_assert (global_lagent_ibr_received == TRUE);
  g_assert (global_ragent_ibr_received == TRUE);

477 478
  /* note: test payload send and receive */
  global_ragent_read = 0;
479 480 481 482 483
  ret = nice_agent_send (lagent, ls_id, 1, 16, "1234567812345678");
  if (ret == -1)
  {
    gboolean reliable = FALSE;
    g_object_get (G_OBJECT (lagent), "reliable", &reliable, NULL);
484
    g_debug ("Sending data returned -1 in %s mode", reliable?"Reliable":"Non-reliable");
485 486
    if (reliable) {
      gulong signal_handler;
487 488
      guint ls_id_copy = ls_id;

489
      signal_handler = g_signal_connect (G_OBJECT (lagent),
490
          "reliable-transport-writable", G_CALLBACK (cb_writable), &ls_id_copy);
491
      g_debug ("Running mainloop until transport is writable");
492 493
      while (ls_id_copy == ls_id)
        g_main_context_iteration (NULL, TRUE);
494 495 496 497 498
      g_signal_handler_disconnect(G_OBJECT (lagent), signal_handler);

      ret = nice_agent_send (lagent, ls_id, 1, 16, "1234567812345678");
    }
  }
499
  g_debug ("Sent %d bytes", ret);
500
  g_assert (ret == 16);
501 502
  while (global_ragent_read != 16)
    g_main_context_iteration (NULL, TRUE);
503 504 505 506 507 508 509 510 511 512 513 514
  g_assert (global_ragent_read == 16);

  g_debug ("test-fullmode: Ran mainloop, removing streams...");

  /* step: clean up resources and exit */

  nice_agent_remove_stream (lagent, ls_id);
  nice_agent_remove_stream (ragent, rs_id);

  return 0;
}

515
/*
516 517 518 519 520 521 522
 * Simulate the case where answer to the offer is delayed and
 * some STUN connectivity checks reach the offering party
 * before it gets the remote SDP information.
 */
static int run_full_test_delayed_answer (NiceAgent *lagent, NiceAgent *ragent, NiceAddress *baseaddr, guint ready, guint failed)
{
  guint ls_id, rs_id;
523
  gint ret;
524 525 526 527 528 529 530 531 532 533 534 535 536 537

  /* XXX: dear compiler, this is for you */
  (void)baseaddr;

  /* step: initialize variables modified by the callbacks */
  global_components_ready = 0;
  global_components_ready_exit = ready;
  global_components_failed = 0;
  global_components_failed_exit = failed;
  global_lagent_gathering_done = FALSE;
  global_ragent_gathering_done = FALSE;
  global_lagent_ibr_received =
    global_ragent_ibr_received = FALSE;
  global_exit_when_ibr_received = 1;
538
  global_lagent_cands =
539 540 541 542 543 544 545
    global_ragent_cands = 0;

  g_object_set (G_OBJECT (lagent), "controlling-mode", TRUE, NULL);
  g_object_set (G_OBJECT (ragent), "controlling-mode", FALSE, NULL);

  /* step: add one stream, with RTP+RTCP components, to each agent */
  ls_id = nice_agent_add_stream (lagent, 2);
546

547 548 549
  rs_id = nice_agent_add_stream (ragent, 2);
  g_assert (ls_id > 0);
  g_assert (rs_id > 0);
550

551 552 553
  /* We don't try this with TURN because as long as both agents don't
     have the remote candidates, they won't be able to create the
     permission on the TURN server, so the connchecks will never go through */
554

555 556 557
  nice_agent_gather_candidates (lagent, ls_id);
  nice_agent_gather_candidates (ragent, rs_id);

558 559
  /* step: attach to mainloop (needed to register the fds) */
  nice_agent_attach_recv (lagent, ls_id, NICE_COMPONENT_TYPE_RTP,
560 561
      g_main_loop_get_context (global_mainloop), cb_nice_recv,
      GUINT_TO_POINTER (1));
562
  nice_agent_attach_recv (lagent, ls_id, NICE_COMPONENT_TYPE_RTCP,
563 564
      g_main_loop_get_context (global_mainloop), cb_nice_recv,
      GUINT_TO_POINTER (1));
565
  nice_agent_attach_recv (ragent, rs_id, NICE_COMPONENT_TYPE_RTP,
566 567
      g_main_loop_get_context (global_mainloop), cb_nice_recv,
      GUINT_TO_POINTER (2));
568
  nice_agent_attach_recv (ragent, rs_id, NICE_COMPONENT_TYPE_RTCP,
569 570
      g_main_loop_get_context (global_mainloop), cb_nice_recv,
      GUINT_TO_POINTER (2));
571

572
  /* step: run mainloop until local candidates are ready
573 574 575 576 577 578 579 580 581
   *       (see timer_cb() above) */
  if (global_lagent_gathering_done != TRUE ||
      global_ragent_gathering_done != TRUE) {
    g_debug ("test-fullmode: Added streams, running mainloop until 'candidate-gathering-done'...");
    g_main_loop_run (global_mainloop);
    g_assert (global_lagent_gathering_done == TRUE);
    g_assert (global_ragent_gathering_done == TRUE);
  }

582
  set_credentials (lagent, ls_id, ragent, rs_id);
583 584

  /* step: set remote candidates for agent R (answering party) */
585 586 587 588
  /* We have to disable TURN for this test because with the delayed answer,
     we can't create turn permissions, so we won't receive any connchecks */
  set_candidates (lagent, ls_id, ragent, rs_id, NICE_COMPONENT_TYPE_RTP, FALSE);
  set_candidates (lagent, ls_id, ragent, rs_id, NICE_COMPONENT_TYPE_RTCP, FALSE);
589 590 591 592 593 594 595 596 597 598 599 600 601

  g_debug ("test-fullmode: Set properties, next running mainloop until first check is received...");

  /* step: run the mainloop until first connectivity check receveid */
  g_main_loop_run (global_mainloop);
  global_exit_when_ibr_received = 0;

  /* note: verify that STUN binding requests were sent */
  g_assert (global_lagent_ibr_received == TRUE);

  g_debug ("test-fullmode: Delayed answer received, continuing processing..");

  /* step: pass remove candidates to agent L (offering party) */
602 603
  set_candidates (ragent, rs_id, lagent, ls_id, NICE_COMPONENT_TYPE_RTP, FALSE);
  set_candidates (ragent, rs_id, lagent, ls_id, NICE_COMPONENT_TYPE_RTCP, FALSE);
604 605 606 607 608

  g_debug ("test-fullmode: Running mainloop until connectivity checks succeeed.");

  g_main_loop_run (global_mainloop);
  g_assert (global_ragent_ibr_received == TRUE);
609
  g_assert (global_components_failed == 0);
610 611 612

  /* note: test payload send and receive */
  global_ragent_read = 0;
613
  ret = nice_agent_send (lagent, ls_id, 1, 16, "1234567812345678");
614
  if (ret == -1) {
615 616 617 618
    gboolean reliable = FALSE;
    g_object_get (G_OBJECT (lagent), "reliable", &reliable, NULL);
    if (reliable) {
      gulong signal_handler;
619 620
      guint ls_id_copy = ls_id;

621
      signal_handler = g_signal_connect (G_OBJECT (lagent),
622 623 624 625
          "reliable-transport-writable", G_CALLBACK (cb_writable), &ls_id_copy);
      g_debug ("Running mainloop until transport is writable");
      while (ls_id_copy == ls_id)
        g_main_context_iteration (NULL, TRUE);
626 627 628 629 630 631 632
      g_signal_handler_disconnect(G_OBJECT (lagent), signal_handler);

      ret = nice_agent_send (lagent, ls_id, 1, 16, "1234567812345678");
    }
  }
  global_ragent_read = 0;
  g_assert (ret == 16);
633 634 635 636 637 638 639 640 641 642 643 644 645
  g_main_loop_run (global_mainloop);
  g_assert (global_ragent_read == 16);

  g_debug ("test-fullmode: Ran mainloop, removing streams...");

  /* step: clean up resources and exit */

  nice_agent_remove_stream (lagent, ls_id);
  nice_agent_remove_stream (ragent, rs_id);

  return 0;
}

646 647 648 649
static int run_full_test_wrong_password (NiceAgent *lagent, NiceAgent *ragent, NiceAddress *baseaddr)
{
  guint ls_id, rs_id;

650 651 652
  /* XXX: dear compiler, this is for you */
  (void)baseaddr;

653
  global_components_ready = 0;
654
  global_components_ready_exit = 0;
655 656
  global_components_failed = 0;
  global_components_failed_exit = 2;
657 658 659
  global_lagent_state[0] =   global_lagent_state[1] = 
    global_ragent_state[0] = global_ragent_state[1] 
    = NICE_COMPONENT_STATE_LAST;
660 661 662 663 664 665 666 667 668 669
  global_lagent_gathering_done = 
    global_ragent_gathering_done = FALSE;
  global_lagent_cands = 
    global_ragent_cands = 0;

  g_object_set (G_OBJECT (lagent), "controlling-mode", TRUE, NULL);
  g_object_set (G_OBJECT (ragent), "controlling-mode", FALSE, NULL);

  /* step: add one stream, with one component, to each agent */
  ls_id = nice_agent_add_stream (lagent, 1);
670

671 672 673
  rs_id = nice_agent_add_stream (ragent, 1);
  g_assert (ls_id > 0);
  g_assert (rs_id > 0);
674

675 676
#if USE_TURN
  nice_agent_set_relay_info(lagent, ls_id, 1,
677
      TURN_IP, TURN_PORT, TURN_USER, TURN_PASS, TURN_TYPE);
678
  nice_agent_set_relay_info(ragent, rs_id, 1,
679
      TURN_IP, TURN_PORT, TURN_USER, TURN_PASS, TURN_TYPE);
680
#endif
681

682 683 684
  nice_agent_gather_candidates (lagent, ls_id);
  nice_agent_gather_candidates (ragent, rs_id);

685 686
  /* step: attach to mainloop (needed to register the fds) */
  nice_agent_attach_recv (lagent, ls_id, NICE_COMPONENT_TYPE_RTP,
687 688
      g_main_loop_get_context (global_mainloop), cb_nice_recv,
      GUINT_TO_POINTER (1));
689
  nice_agent_attach_recv (ragent, rs_id, NICE_COMPONENT_TYPE_RTP,
690 691
      g_main_loop_get_context (global_mainloop), cb_nice_recv,
      GUINT_TO_POINTER (2));
692

693
  /* step: run mainloop until local candidates are ready
694 695 696 697 698 699 700 701 702 703
   *       (see timer_cb() above) */
  if (global_lagent_gathering_done != TRUE ||
      global_ragent_gathering_done != TRUE) {
    g_debug ("test-fullmode: Added streams, running mainloop until 'candidate-gathering-done'...");
    g_main_loop_run (global_mainloop);
    g_assert (global_lagent_gathering_done == TRUE);
    g_assert (global_ragent_gathering_done == TRUE);
  }

  g_debug ("test-fullmode: Got local candidates...");
704

705
  set_credentials (lagent, ls_id, ragent, rs_id);
706 707 708 709
  nice_agent_set_remote_credentials (ragent, rs_id, "wrong", "password");
  nice_agent_set_remote_credentials (lagent, ls_id, "wrong2", "password2");


710
  /* step: pass the remote candidates to agents  */
711 712
  set_candidates (ragent, rs_id, lagent, ls_id, NICE_COMPONENT_TYPE_RTP, USE_TURN);
  set_candidates (lagent, ls_id, ragent, rs_id, NICE_COMPONENT_TYPE_RTP, USE_TURN);
713 714 715

  g_debug ("test-fullmode: Set properties, next running mainloop until connectivity checks succeed...");

716
  /* step: run the mainloop until connectivity checks succeed
717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737
   *       (see timer_cb() above) */
  g_main_loop_run (global_mainloop);

  /* note: verify that correct number of local candidates were reported */
  g_assert (global_lagent_cands == 0);
  g_assert (global_ragent_cands == 0);

  g_debug ("test-fullmode: Ran mainloop, removing streams...");

  /* step: clean up resources and exit */

  nice_agent_remove_stream (lagent, ls_id);
  nice_agent_remove_stream (ragent, rs_id);

  return 0;
}

static int run_full_test_control_conflict (NiceAgent *lagent, NiceAgent *ragent, NiceAddress *baseaddr, gboolean role)
{
  guint ls_id, rs_id;

738 739 740
  /* XXX: dear compiler, this is for you */
  (void)baseaddr;

741 742 743
  global_components_ready = 0;
  global_components_ready_exit = 2;
  global_components_failed = 0;
744
  global_components_failed_exit = 0;
745 746 747 748 749 750 751 752 753 754 755 756
  global_lagent_gathering_done =
    global_ragent_gathering_done = FALSE;
  global_lagent_cands = 
    global_ragent_cands = 0;
  global_lagent_ibr_received =
    global_ragent_ibr_received = FALSE;

  g_object_set (G_OBJECT (lagent), "controlling-mode", role, NULL);
  g_object_set (G_OBJECT (ragent), "controlling-mode", role, NULL);

  /* step: add one stream, with one component, to each agent */
  ls_id = nice_agent_add_stream (lagent, 1);
757

758 759 760
  rs_id = nice_agent_add_stream (ragent, 1);
  g_assert (ls_id > 0);
  g_assert (rs_id > 0);
761

762 763
#if USE_TURN
  nice_agent_set_relay_info(lagent, ls_id, 1,
764
      TURN_IP, TURN_PORT, TURN_USER, TURN_PASS, TURN_TYPE);
765
  nice_agent_set_relay_info(ragent, rs_id, 1,
766
      TURN_IP, TURN_PORT, TURN_USER, TURN_PASS, TURN_TYPE);
767
#endif
768

769 770 771
  nice_agent_gather_candidates (lagent, ls_id);
  nice_agent_gather_candidates (ragent, rs_id);

772 773
  /* step: attach to mainloop (needed to register the fds) */
  nice_agent_attach_recv (lagent, ls_id, NICE_COMPONENT_TYPE_RTP,
774 775
      g_main_loop_get_context (global_mainloop), cb_nice_recv,
      GUINT_TO_POINTER (1));
776
  nice_agent_attach_recv (ragent, rs_id, NICE_COMPONENT_TYPE_RTP,
777 778
      g_main_loop_get_context (global_mainloop), cb_nice_recv,
      GUINT_TO_POINTER (2));
779

780 781 782 783 784 785 786 787 788 789 790
  /* step: run mainloop until local candidates are ready 
   *       (see timer_cb() above) */
  if (global_lagent_gathering_done != TRUE ||
      global_ragent_gathering_done != TRUE) {
    g_debug ("test-fullmode: Added streams, running mainloop until 'candidate-gathering-done'...");
    g_main_loop_run (global_mainloop);
    g_assert (global_lagent_gathering_done == TRUE);
    g_assert (global_ragent_gathering_done == TRUE);
  }

  g_debug ("test-fullmode: Got local candidates...");
791 792 793

  set_credentials (lagent, ls_id, ragent, rs_id);

794
  /* step: pass the remote candidates to agents  */
795 796
  set_candidates (ragent, rs_id, lagent, ls_id, NICE_COMPONENT_TYPE_RTP, USE_TURN);
  set_candidates (lagent, ls_id, ragent, rs_id, NICE_COMPONENT_TYPE_RTP, USE_TURN);
797 798 799

  g_debug ("test-fullmode: Set properties, next running mainloop until connectivity checks succeed...");

800
  /* step: run the mainloop until connectivity checks succeed
801 802 803
   *       (see timer_cb() above) */
  g_main_loop_run (global_mainloop);

804 805 806 807 808
  /* When using TURN, we get peer reflexive candidates for the host cands
     that we removed so we can get another new_selected_pair signal later
     depending on timing/racing, we could double (or not) the amount we expected
  */
#if !(USE_TURN)
809 810 811
  /* note: verify that correct number of local candidates were reported */
  g_assert (global_lagent_cands == 1);
  g_assert (global_ragent_cands == 1);
812
#endif
813

814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829
  g_debug ("test-fullmode: Ran mainloop, removing streams...");

  /* step: clean up resources and exit */

  nice_agent_remove_stream (lagent, ls_id);
  nice_agent_remove_stream (ragent, rs_id);

  return 0;
}

int main (void)
{
  NiceAgent *lagent, *ragent;      /* agent's L and R */
  NiceAddress baseaddr;
  int result;
  guint timer_id;
830
  const char *stun_server = NULL, *stun_server_port = NULL;
831

832 833 834 835 836
#ifdef G_OS_WIN32
  WSADATA w;

  WSAStartup(0x0202, &w);
#endif
837

838 839 840 841 842 843 844 845
  global_mainloop = g_main_loop_new (NULL, FALSE);

  /* Note: impl limits ...
   * - no multi-stream support
   * - no IPv6 support
   */

  /* step: create the agents L and R */
846 847 848 849 850 851 852 853 854 855 856 857
#if USE_RELIABLE
  lagent = nice_agent_new_reliable (g_main_loop_get_context (global_mainloop),
      NICE_COMPATIBILITY);
  ragent = nice_agent_new_reliable (g_main_loop_get_context (global_mainloop),
      NICE_COMPATIBILITY);
#else
  lagent = nice_agent_new (g_main_loop_get_context (global_mainloop),
      NICE_COMPATIBILITY);
  ragent = nice_agent_new (g_main_loop_get_context (global_mainloop),
      NICE_COMPATIBILITY);
#endif

Youness Alaoui's avatar
Youness Alaoui committed
858 859 860 861
  g_object_set (G_OBJECT (lagent), "ice-tcp", FALSE,  NULL);
  g_object_set (G_OBJECT (ragent), "ice-tcp", FALSE,  NULL);


862 863
  nice_agent_set_software (lagent, "Test-fullmode, Left Agent");
  nice_agent_set_software (ragent, "Test-fullmode, Right Agent");
864 865

  /* step: add a timer to catch state changes triggered by signals */
866 867 868 869 870
#if USE_TURN
  timer_id = g_timeout_add (300000, timer_cb, NULL);
#else
  timer_id = g_timeout_add (30000, timer_cb, NULL);
#endif
871 872

  /* step: specify which local interface to use */
873
#if USE_LOOPBACK
874
  if (!nice_address_set_from_string (&baseaddr, "127.0.0.1"))
875 876 877
    g_assert_not_reached ();
  nice_agent_add_local_address (lagent, &baseaddr);
  nice_agent_add_local_address (ragent, &baseaddr);
878
#endif
879

880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901
  g_signal_connect (G_OBJECT (lagent), "candidate-gathering-done",
      G_CALLBACK (cb_candidate_gathering_done), GUINT_TO_POINTER(1));
  g_signal_connect (G_OBJECT (ragent), "candidate-gathering-done",
      G_CALLBACK (cb_candidate_gathering_done), GUINT_TO_POINTER (2));
  g_signal_connect (G_OBJECT (lagent), "component-state-changed",
      G_CALLBACK (cb_component_state_changed), GUINT_TO_POINTER (1));
  g_signal_connect (G_OBJECT (ragent), "component-state-changed",
      G_CALLBACK (cb_component_state_changed), GUINT_TO_POINTER (2));
  g_signal_connect (G_OBJECT (lagent), "new-selected-pair",
      G_CALLBACK (cb_new_selected_pair), GUINT_TO_POINTER(1));
  g_signal_connect (G_OBJECT (ragent), "new-selected-pair",
      G_CALLBACK (cb_new_selected_pair), GUINT_TO_POINTER (2));
  g_signal_connect (G_OBJECT (lagent), "new-candidate",
      G_CALLBACK (cb_new_candidate), GUINT_TO_POINTER (1));
  g_signal_connect (G_OBJECT (ragent), "new-candidate",
      G_CALLBACK (cb_new_candidate), GUINT_TO_POINTER (2));
  g_signal_connect (G_OBJECT (lagent), "initial-binding-request-received",
      G_CALLBACK (cb_initial_binding_request_received),
      GUINT_TO_POINTER (1));
  g_signal_connect (G_OBJECT (ragent), "initial-binding-request-received",
      G_CALLBACK (cb_initial_binding_request_received),
      GUINT_TO_POINTER (2));
902

903 904 905 906 907 908 909 910 911
  stun_server = getenv ("NICE_STUN_SERVER");
  stun_server_port = getenv ("NICE_STUN_SERVER_PORT");
  if (stun_server) {
    g_object_set (G_OBJECT (lagent), "stun-server", stun_server,  NULL);
    g_object_set (G_OBJECT (lagent), "stun-server-port", atoi (stun_server_port),  NULL);
    g_object_set (G_OBJECT (ragent), "stun-server", stun_server,  NULL);
    g_object_set (G_OBJECT (ragent), "stun-server-port", atoi (stun_server_port),  NULL);
  }

912
  g_object_set (G_OBJECT (lagent), "upnp", USE_UPNP,  NULL);
913 914 915 916 917
  g_object_set (G_OBJECT (lagent), "proxy-ip", PROXY_IP,  NULL);
  g_object_set (G_OBJECT (lagent), "proxy-port", PROXY_PORT, NULL);
  g_object_set (G_OBJECT (lagent), "proxy-type", PROXY_TYPE, NULL);
  g_object_set (G_OBJECT (lagent), "proxy-username", PROXY_USERNAME, NULL);
  g_object_set (G_OBJECT (lagent), "proxy-password", PROXY_PASSWORD, NULL);
918
  g_object_set (G_OBJECT (ragent), "upnp", USE_UPNP,  NULL);
919 920 921 922 923 924
  g_object_set (G_OBJECT (ragent), "proxy-ip", PROXY_IP,  NULL);
  g_object_set (G_OBJECT (ragent), "proxy-port", PROXY_PORT, NULL);
  g_object_set (G_OBJECT (ragent), "proxy-type", PROXY_TYPE, NULL);
  g_object_set (G_OBJECT (ragent), "proxy-username", PROXY_USERNAME, NULL);
  g_object_set (G_OBJECT (ragent), "proxy-password", PROXY_PASSWORD, NULL);

925
  /* step: test setter/getter functions for properties */
926
  {
927
    guint max_checks = 0;
928 929 930 931 932
    gchar *string = NULL;
    guint port = 0;
    gboolean mode = FALSE;
    g_object_get (G_OBJECT (lagent), "stun-server", &string, NULL);
    g_assert (stun_server == NULL || strcmp (string, stun_server) == 0);
933
    g_free (string);
934 935
    g_object_get (G_OBJECT (lagent), "stun-server-port", &port, NULL);
    g_assert (stun_server_port == NULL || port == (guint)atoi (stun_server_port));
936 937 938 939 940
    g_object_get (G_OBJECT (lagent), "proxy-ip", &string, NULL);
    g_assert (strcmp (string, PROXY_IP) == 0);
    g_free (string);
    g_object_get (G_OBJECT (lagent), "proxy-port", &port, NULL);
    g_assert (port == PROXY_PORT);
941 942
    g_object_get (G_OBJECT (lagent), "controlling-mode", &mode, NULL);
    g_assert (mode == TRUE);
943 944 945
    g_object_set (G_OBJECT (lagent), "max-connectivity-checks", 300, NULL);
    g_object_get (G_OBJECT (lagent), "max-connectivity-checks", &max_checks, NULL);
    g_assert (max_checks == 300);
946
  }
947

948 949
  /* step: run test the first time */
  g_debug ("test-fullmode: TEST STARTS / running test for the 1st time");
950
  result = run_full_test (lagent, ragent, &baseaddr, 4 ,0);
951
  priv_print_global_status ();
952
  g_assert (result == 0);
953 954 955 956
  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);
957 958 959 960 961
  /* When using TURN, we get peer reflexive candidates for the host cands
     that we removed so we can get another new_selected_pair signal later
     depending on timing/racing, we could double (or not) the amount we expected
  */
#if !(USE_TURN)
962
  /* note: verify that correct number of local candidates were reported */
963 964 965
    g_assert (global_lagent_cands == 2);
    g_assert (global_ragent_cands == 2);
#endif
966

967 968

  /* step: run test again without unref'ing agents */
969
  g_debug ("test-fullmode: TEST STARTS / running test for the 2nd time");
970
  result = run_full_test (lagent, ragent, &baseaddr, 4, 0);
971 972
  priv_print_global_status ();
  g_assert (result == 0);
973 974 975 976
  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);
977 978 979 980 981
  /* When using TURN, we get peer reflexive candidates for the host cands
     that we removed so we can get another new_selected_pair signal later
     depending on timing/racing, we could double (or not) the amount we expected
  */
#if !(USE_TURN)
982 983 984
  /* note: verify that correct number of local candidates were reported */
  g_assert (global_lagent_cands == 2);
  g_assert (global_ragent_cands == 2);
985
#endif
986

987

988 989 990 991 992 993 994 995 996 997
  /* step: run test simulating delayed SDP answer */
  g_debug ("test-fullmode: TEST STARTS / delayed SDP answer");
  result = run_full_test_delayed_answer (lagent, ragent, &baseaddr, 4, 0);
  priv_print_global_status ();
  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);
  /* note: verify that correct number of local candidates were reported */
998 999 1000 1001 1002
  /* When using TURN, we get peer reflexive candidates for the host cands
     that we removed so we can get another new_selected_pair signal later
     depending on timing/racing, we could double (or not) the amount we expected
  */
#if !(USE_TURN)
1003 1004
  g_assert (global_lagent_cands == 2);
  g_assert (global_ragent_cands == 2);
1005
#endif
1006

1007 1008 1009
#if TEST_GOOGLE
  return result;
#endif
1010

1011 1012 1013 1014 1015
  /* run test with incorrect credentials (make sure process fails) */
  g_debug ("test-fullmode: TEST STARTS / incorrect credentials");
  result = run_full_test_wrong_password (lagent, ragent, &baseaddr);
  priv_print_global_status ();
  g_assert (result == 0);
1016 1017 1018 1019 1020
  g_assert (global_lagent_state[0] == NICE_COMPONENT_STATE_FAILED);
  g_assert (global_lagent_state[1] == NICE_COMPONENT_STATE_LAST);
  g_assert (global_ragent_state[0] == NICE_COMPONENT_STATE_FAILED);
  g_assert (global_ragent_state[1] == NICE_COMPONENT_STATE_LAST);

1021 1022 1023 1024 1025
  /* The max connectivity checks test can't be run with TURN because
     we'll have 3 local candidates instead of 1 and the checks will
     be random, so we can't predict how many will fail/succeed */
#if USE_TURN == 0

1026 1027 1028 1029 1030 1031
  /* step: run test with a hard limit for connecitivity checks */
  g_debug ("test-fullmode: TEST STARTS / max connectivity checks");
  g_object_set (G_OBJECT (lagent), "max-connectivity-checks", 1, NULL);
  g_object_set (G_OBJECT (ragent), "max-connectivity-checks", 1, NULL);
  result = run_full_test (lagent, ragent, &baseaddr, 2, 2);
  priv_print_global_status ();
1032
  g_assert (result == 0);
1033 1034 1035
  /* should FAIL as agent L can't send any checks: */
  g_assert (global_lagent_state[0] == NICE_COMPONENT_STATE_FAILED ||
	    global_lagent_state[1] == NICE_COMPONENT_STATE_FAILED);
1036 1037 1038 1039
  g_assert (global_lagent_state[0] == NICE_COMPONENT_STATE_FAILED ||
	    global_lagent_state[1] == NICE_COMPONENT_STATE_FAILED);
#endif

1040 1041 1042 1043 1044
  g_object_set (G_OBJECT (lagent), "max-connectivity-checks", 100, NULL);
  g_object_set (G_OBJECT (ragent), "max-connectivity-checks", 100, NULL);
  result = run_full_test (lagent, ragent, &baseaddr, 4, 0);
  priv_print_global_status ();
  /* should SUCCEED as agent L can send the checks: */
1045
  g_assert (result == 0);
1046 1047 1048 1049 1050 1051 1052 1053
  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);
1054
  g_object_set (G_OBJECT (lagent), "max-connectivity-checks", 100, NULL);
1055

1056 1057 1058 1059 1060
  /* run test with a conflict in controlling mode: controlling-controlling */
  g_debug ("test-fullmode: TEST STARTS / controlling mode conflict case-1");
  result = run_full_test_control_conflict (lagent, ragent, &baseaddr, TRUE);
  priv_print_global_status ();
  g_assert (result == 0);
1061 1062 1063 1064 1065

  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);
1066

1067 1068 1069 1070 1071
  /* run test with a conflict in controlling mode: controlled-controlled */
  g_debug ("test-fullmode: TEST STARTS / controlling mode conflict case-2");
  result = run_full_test_control_conflict (lagent, ragent, &baseaddr, FALSE);
  priv_print_global_status ();
  g_assert (result == 0);
1072 1073 1074 1075
  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);
1076 1077 1078 1079

  g_object_unref (lagent);
  g_object_unref (ragent);

1080 1081
  g_main_loop_unref (global_mainloop);
  global_mainloop = NULL;
1082 1083

  g_source_remove (timer_id);
1084 1085 1086
#ifdef G_OS_WIN32
  WSACleanup();
#endif
1087 1088
  return result;
}