test.c 2.07 KB
Newer Older
Dafydd Harries's avatar
Dafydd Harries committed
1

2
3
#include <arpa/inet.h>

Dafydd Harries's avatar
Dafydd Harries committed
4
5
#include <glib.h>

6
7
8
#include <udp.h>
#include <udp-fake.h>

Dafydd Harries's avatar
Dafydd Harries committed
9
10
#include <agent.h>

11
12
13
14
15
16
void
handle_recv (Agent *agent, guint stream_id, guint len, gchar *buf)
{
  g_assert_not_reached ();
}

Dafydd Harries's avatar
Dafydd Harries committed
17
18
19
20
gint
main (void)
{
  Agent *agent;
21
  Address addr_local, addr_remote;
Dafydd Harries's avatar
Dafydd Harries committed
22
  Candidate *candidate;
23
24
25
  UDPSocketManager mgr;

  udp_fake_socket_manager_init (&mgr);
Dafydd Harries's avatar
Dafydd Harries committed
26

27
28
  address_set_ipv4_from_string (&addr_local, "192.168.0.1");
  address_set_ipv4_from_string (&addr_remote, "192.168.0.2");
29

30
  agent = ice_agent_new (&mgr);
Dafydd Harries's avatar
Dafydd Harries committed
31
32
33
34
35
36

  g_assert (agent->local_addresses == NULL);
  g_assert (agent->local_candidates == NULL);
  g_assert (ice_agent_pop_event (agent) == NULL);

  /* add one local address */
37
  ice_agent_add_local_address (agent, &addr_local);
Dafydd Harries's avatar
Dafydd Harries committed
38
39
40

  g_assert (agent->local_addresses != NULL);
  g_assert (g_slist_length (agent->local_addresses) == 1);
41
  g_assert (address_equal ((Address *) agent->local_addresses->data,
42
        &addr_local));
Dafydd Harries's avatar
Dafydd Harries committed
43
44
45
46
47

  /* no candidates should be generated until we have a stream */
  g_assert (agent->local_candidates == NULL);

  /* add an audio stream */
48
  ice_agent_add_stream (agent, MEDIA_TYPE_AUDIO, handle_recv);
Dafydd Harries's avatar
Dafydd Harries committed
49
50
51
52
53

  /* adding a stream should cause host candidates to be generated */
  g_assert (agent->local_candidates != NULL);
  g_assert (g_slist_length (agent->local_candidates) == 1);
  candidate = (Candidate *) agent->local_candidates->data;
54
  g_assert (address_equal (&(candidate->addr), &addr_local));
Dafydd Harries's avatar
Dafydd Harries committed
55
  g_assert (candidate->id == 1);
56
57
  /* fake socket manager uses incremental port numbers starting at 1 */
  g_assert (candidate->port == 1);
Dafydd Harries's avatar
Dafydd Harries committed
58
59

  /* add remote candidate */
60
  ice_agent_add_remote_candidate (agent, CANDIDATE_TYPE_HOST, &addr_remote,
61
62
63
64
      2345);
  g_assert (agent->remote_candidates != NULL);
  g_assert (g_slist_length (agent->remote_candidates) == 1);
  candidate = (Candidate *) agent->remote_candidates->data;
65
  g_assert (address_equal (&(candidate->addr), &addr_remote));
66
  g_assert (candidate->port == 2345);
Dafydd Harries's avatar
Dafydd Harries committed
67
68
69
70
71
72
73

  /* check there's no unexpected events, and clean up */
  g_assert (ice_agent_pop_event (agent) == NULL);
  ice_agent_free (agent);
  return 0;
}