Commit 0ccf0d7c authored by Youness Alaoui's avatar Youness Alaoui

Port libnice tests to match new API

parent 6056277b
...@@ -41,7 +41,6 @@ ...@@ -41,7 +41,6 @@
#include "agent.h" #include "agent.h"
#include "agent-priv.h" #include "agent-priv.h"
#include "udp-fake.h"
#include <string.h> #include <string.h>
int int
...@@ -49,18 +48,16 @@ main (void) ...@@ -49,18 +48,16 @@ main (void)
{ {
NiceAgent *agent; NiceAgent *agent;
NiceAddress addr; NiceAddress addr;
NiceUDPSocketFactory factory;
nice_address_init (&addr); nice_address_init (&addr);
g_type_init (); g_type_init ();
g_thread_init (NULL); g_thread_init (NULL);
nice_udp_fake_socket_factory_init (&factory);
if (!nice_address_set_from_string (&addr, "127.0.0.1")) if (!nice_address_set_from_string (&addr, "127.0.0.1"))
g_assert_not_reached (); g_assert_not_reached ();
agent = nice_agent_new (&factory, NULL, NICE_COMPATIBILITY_ID19); agent = nice_agent_new (NULL, NICE_COMPATIBILITY_ID19);
nice_agent_add_local_address (agent, &addr); nice_agent_add_local_address (agent, &addr);
g_assert (nice_agent_add_stream (agent, 1) == 1); g_assert (nice_agent_add_stream (agent, 1) == 1);
...@@ -76,7 +73,6 @@ main (void) ...@@ -76,7 +73,6 @@ main (void)
g_assert (NULL == agent->streams); g_assert (NULL == agent->streams);
g_object_unref (agent); g_object_unref (agent);
nice_udp_socket_factory_close (&factory);
return 0; return 0;
} }
......
...@@ -44,7 +44,6 @@ ...@@ -44,7 +44,6 @@
#include "agent.h" #include "agent.h"
#include "agent-priv.h" /* for testing purposes */ #include "agent-priv.h" /* for testing purposes */
#include "udp-bsd.h"
static NiceComponentState global_lagent_state = NICE_COMPONENT_STATE_LAST; static NiceComponentState global_lagent_state = NICE_COMPONENT_STATE_LAST;
static NiceComponentState global_ragent_state = NICE_COMPONENT_STATE_LAST; static NiceComponentState global_ragent_state = NICE_COMPONENT_STATE_LAST;
...@@ -474,7 +473,6 @@ static int run_safe_fallback_test (NiceAgent *lagent, NiceAgent *ragent, NiceAdd ...@@ -474,7 +473,6 @@ static int run_safe_fallback_test (NiceAgent *lagent, NiceAgent *ragent, NiceAdd
int main (void) int main (void)
{ {
NiceAgent *lagent, *ragent; /* agent's L and R */ NiceAgent *lagent, *ragent; /* agent's L and R */
NiceUDPSocketFactory udpfactory;
NiceAddress baseaddr; NiceAddress baseaddr;
int result; int result;
guint timer_id; guint timer_id;
...@@ -489,13 +487,9 @@ int main (void) ...@@ -489,13 +487,9 @@ int main (void)
* - no IPv6 support * - no IPv6 support
*/ */
nice_udp_bsd_socket_factory_init (&udpfactory);
/* step: create the agents L and R */ /* step: create the agents L and R */
lagent = nice_agent_new (&udpfactory, lagent = nice_agent_new (g_main_loop_get_context (global_mainloop), NICE_COMPATIBILITY_ID19);
g_main_loop_get_context (global_mainloop), NICE_COMPATIBILITY_ID19); ragent = nice_agent_new (g_main_loop_get_context (global_mainloop), NICE_COMPATIBILITY_ID19);
ragent = nice_agent_new (&udpfactory,
g_main_loop_get_context (global_mainloop), NICE_COMPATIBILITY_ID19);
...@@ -557,10 +551,8 @@ int main (void) ...@@ -557,10 +551,8 @@ int main (void)
g_object_unref (lagent); g_object_unref (lagent);
g_object_unref (ragent); g_object_unref (ragent);
nice_udp_socket_factory_close (&udpfactory); g_main_loop_unref (global_mainloop);
global_mainloop = NULL;
g_main_loop_unref (global_mainloop),
global_mainloop = NULL;
g_source_remove (timer_id); g_source_remove (timer_id);
......
...@@ -42,7 +42,6 @@ ...@@ -42,7 +42,6 @@
#include <string.h> #include <string.h>
#include "agent.h" #include "agent.h"
#include "udp-bsd.h"
static NiceComponentState global_lagent_state[2] = { NICE_COMPONENT_STATE_LAST, NICE_COMPONENT_STATE_LAST }; 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 }; static NiceComponentState global_ragent_state[2] = { NICE_COMPONENT_STATE_LAST, NICE_COMPONENT_STATE_LAST };
...@@ -721,7 +720,6 @@ static int run_full_test_control_conflict (NiceAgent *lagent, NiceAgent *ragent, ...@@ -721,7 +720,6 @@ static int run_full_test_control_conflict (NiceAgent *lagent, NiceAgent *ragent,
int main (void) int main (void)
{ {
NiceAgent *lagent, *ragent; /* agent's L and R */ NiceAgent *lagent, *ragent; /* agent's L and R */
NiceUDPSocketFactory udpfactory;
NiceAddress baseaddr; NiceAddress baseaddr;
int result; int result;
guint timer_id; guint timer_id;
...@@ -736,13 +734,9 @@ int main (void) ...@@ -736,13 +734,9 @@ int main (void)
* - no IPv6 support * - no IPv6 support
*/ */
nice_udp_bsd_socket_factory_init (&udpfactory);
/* step: create the agents L and R */ /* step: create the agents L and R */
lagent = nice_agent_new (&udpfactory, lagent = nice_agent_new (g_main_loop_get_context (global_mainloop), NICE_COMPATIBILITY_ID19);
g_main_loop_get_context (global_mainloop), NICE_COMPATIBILITY_ID19); ragent = nice_agent_new (g_main_loop_get_context (global_mainloop), NICE_COMPATIBILITY_ID19);
ragent = nice_agent_new (&udpfactory,
g_main_loop_get_context (global_mainloop), NICE_COMPATIBILITY_ID19);
/* step: add a timer to catch state changes triggered by signals */ /* step: add a timer to catch state changes triggered by signals */
timer_id = g_timeout_add (30000, timer_cb, NULL); timer_id = g_timeout_add (30000, timer_cb, NULL);
...@@ -785,13 +779,10 @@ int main (void) ...@@ -785,13 +779,10 @@ int main (void)
/* step: test setter/getter functions for properties */ /* step: test setter/getter functions for properties */
{ {
gpointer pointer;
guint max_checks = 0; guint max_checks = 0;
gchar *string = NULL; gchar *string = NULL;
guint port = 0; guint port = 0;
gboolean mode = FALSE; gboolean mode = FALSE;
g_object_get (G_OBJECT (lagent), "socket-factory", &pointer, NULL);
g_assert (pointer == (gpointer)&udpfactory);
g_object_get (G_OBJECT (lagent), "stun-server", &string, NULL); g_object_get (G_OBJECT (lagent), "stun-server", &string, NULL);
g_assert (stun_server == NULL || strcmp (string, stun_server) == 0); g_assert (stun_server == NULL || strcmp (string, stun_server) == 0);
g_free (string); g_free (string);
...@@ -905,10 +896,8 @@ int main (void) ...@@ -905,10 +896,8 @@ int main (void)
g_object_unref (lagent); g_object_unref (lagent);
g_object_unref (ragent); g_object_unref (ragent);
nice_udp_socket_factory_close (&udpfactory); g_main_loop_unref (global_mainloop);
global_mainloop = NULL;
g_main_loop_unref (global_mainloop),
global_mainloop = NULL;
g_source_remove (timer_id); g_source_remove (timer_id);
......
...@@ -68,7 +68,6 @@ main (void) ...@@ -68,7 +68,6 @@ main (void)
{ {
NiceAgent *agent; NiceAgent *agent;
NiceAddress addr; NiceAddress addr;
NiceUDPSocketFactory factory;
guint stream; guint stream;
nice_address_init (&addr); nice_address_init (&addr);
...@@ -76,9 +75,7 @@ main (void) ...@@ -76,9 +75,7 @@ main (void)
g_thread_init (NULL); g_thread_init (NULL);
loop = g_main_loop_new (NULL, FALSE); loop = g_main_loop_new (NULL, FALSE);
nice_udp_fake_socket_factory_init (&factory); agent = nice_agent_new (g_main_loop_get_context (loop), NICE_COMPATIBILITY_ID19);
agent = nice_agent_new (&factory,
g_main_loop_get_context (loop), NICE_COMPATIBILITY_ID19);
nice_address_set_ipv4 (&addr, 0x7f000001); nice_address_set_ipv4 (&addr, 0x7f000001);
nice_agent_add_local_address (agent, &addr); nice_agent_add_local_address (agent, &addr);
stream = nice_agent_add_stream (agent, 1); stream = nice_agent_add_stream (agent, 1);
...@@ -96,15 +93,14 @@ main (void) ...@@ -96,15 +93,14 @@ main (void)
candidates = nice_agent_get_local_candidates (agent, 1, 1); candidates = nice_agent_get_local_candidates (agent, 1, 1);
candidate = candidates->data; candidate = candidates->data;
sock = candidate->sockptr; sock = candidate->sockptr;
g_slist_free (candidates);
nice_udp_fake_socket_push_recv (sock, &addr, 6, "\x80hello"); nice_udp_socket_send (sock, &(candidate->addr), 6, "\x80hello");
g_slist_free (candidates);
} }
g_main_loop_run (loop); g_main_loop_run (loop);
g_object_unref (agent); g_object_unref (agent);
nice_udp_socket_factory_close (&factory);
return 0; return 0;
} }
...@@ -44,6 +44,8 @@ ...@@ -44,6 +44,8 @@
#include <unistd.h> #include <unistd.h>
#include <nice/nice.h> #include <nice/nice.h>
#include "udp.h"
static gboolean cb_called = FALSE; static gboolean cb_called = FALSE;
...@@ -71,7 +73,6 @@ main (void) ...@@ -71,7 +73,6 @@ main (void)
{ {
NiceAgent *agent; NiceAgent *agent;
NiceAddress addr; NiceAddress addr;
NiceUDPSocketFactory factory;
NiceUDPSocket *sock; NiceUDPSocket *sock;
gint pipe_fds[2]; gint pipe_fds[2];
GSList *fds = NULL; GSList *fds = NULL;
...@@ -88,8 +89,7 @@ main (void) ...@@ -88,8 +89,7 @@ main (void)
if (!nice_address_set_from_string (&addr, "127.0.0.1")) if (!nice_address_set_from_string (&addr, "127.0.0.1"))
g_assert_not_reached (); g_assert_not_reached ();
nice_udp_fake_socket_factory_init (&factory); agent = nice_agent_new (NULL, NICE_COMPATIBILITY_ID19);
agent = nice_agent_new (&factory, NULL, NICE_COMPATIBILITY_ID19);
nice_agent_add_local_address (agent, &addr); nice_agent_add_local_address (agent, &addr);
stream_id = nice_agent_add_stream (agent, 1); stream_id = nice_agent_add_stream (agent, 1);
nice_agent_gather_candidates (agent, stream_id); nice_agent_gather_candidates (agent, stream_id);
...@@ -101,6 +101,7 @@ main (void) ...@@ -101,6 +101,7 @@ main (void)
candidates = nice_agent_get_local_candidates (agent, stream_id, 1); candidates = nice_agent_get_local_candidates (agent, stream_id, 1);
candidate = candidates->data; candidate = candidates->data;
sock = candidate->sockptr; sock = candidate->sockptr;
addr = candidate->addr;
g_slist_free (candidates); g_slist_free (candidates);
} }
...@@ -131,7 +132,7 @@ main (void) ...@@ -131,7 +132,7 @@ main (void)
/* send fake data */ /* send fake data */
nice_udp_fake_socket_push_recv (sock, &addr, 7, "\x80lalala"); nice_udp_socket_send (sock, &addr, 7, "\x80lalala");
/* poll again */ /* poll again */
......
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
#include <string.h> #include <string.h>
#include "udp-fake.h" #include "udp.h"
#include "agent.h" #include "agent.h"
int int
...@@ -49,17 +49,14 @@ main (void) ...@@ -49,17 +49,14 @@ main (void)
{ {
NiceAgent *agent; NiceAgent *agent;
NiceAddress addr; NiceAddress addr;
NiceUDPSocketFactory factory;
guint stream_id; guint stream_id;
nice_address_init (&addr); nice_address_init (&addr);
g_type_init (); g_type_init ();
g_thread_init (NULL); g_thread_init (NULL);
nice_udp_fake_socket_factory_init (&factory);
/* set up agent */ /* set up agent */
agent = nice_agent_new (&factory, NULL, NICE_COMPATIBILITY_ID19); agent = nice_agent_new (NULL, NICE_COMPATIBILITY_ID19);
g_assert (nice_address_set_from_string (&addr, "192.168.0.1")); g_assert (nice_address_set_from_string (&addr, "192.168.0.1"));
nice_agent_add_local_address (agent, &addr); nice_agent_add_local_address (agent, &addr);
stream_id = nice_agent_add_stream (agent, 1); stream_id = nice_agent_add_stream (agent, 1);
...@@ -78,7 +75,7 @@ main (void) ...@@ -78,7 +75,7 @@ main (void)
candidate = candidates->data; candidate = candidates->data;
g_slist_free (candidates); g_slist_free (candidates);
sock = candidate->sockptr; sock = candidate->sockptr;
nice_udp_fake_socket_push_recv (sock, &addr, 7, "\x80lalala"); nice_udp_socket_send (sock, &candidate->addr, 7, "\x80lalala");
len = nice_agent_recv (agent, stream_id, len = nice_agent_recv (agent, stream_id,
candidate->component_id, 1024, buf); candidate->component_id, 1024, buf);
g_assert (len == 7); g_assert (len == 7);
...@@ -87,7 +84,6 @@ main (void) ...@@ -87,7 +84,6 @@ main (void)
/* clean up */ /* clean up */
g_object_unref (agent); g_object_unref (agent);
nice_udp_socket_factory_close (&factory);
return 0; return 0;
} }
......
...@@ -41,7 +41,6 @@ ...@@ -41,7 +41,6 @@
#include "agent.h" #include "agent.h"
#include "agent-priv.h" /* for testing purposes */ #include "agent-priv.h" /* for testing purposes */
#include "udp-bsd.h"
static NiceComponentState global_lagent_state = NICE_COMPONENT_STATE_LAST; static NiceComponentState global_lagent_state = NICE_COMPONENT_STATE_LAST;
static NiceComponentState global_ragent_state = NICE_COMPONENT_STATE_LAST; static NiceComponentState global_ragent_state = NICE_COMPONENT_STATE_LAST;
...@@ -379,7 +378,6 @@ static int run_restart_test (NiceAgent *lagent, NiceAgent *ragent, NiceAddress * ...@@ -379,7 +378,6 @@ static int run_restart_test (NiceAgent *lagent, NiceAgent *ragent, NiceAddress *
int main (void) int main (void)
{ {
NiceAgent *lagent, *ragent; /* agent's L and R */ NiceAgent *lagent, *ragent; /* agent's L and R */
NiceUDPSocketFactory udpfactory;
NiceAddress baseaddr; NiceAddress baseaddr;
int result; int result;
guint timer_id; guint timer_id;
...@@ -394,13 +392,10 @@ int main (void) ...@@ -394,13 +392,10 @@ int main (void)
* - no IPv6 support * - no IPv6 support
*/ */
nice_udp_bsd_socket_factory_init (&udpfactory);
/* step: create the agents L and R */ /* step: create the agents L and R */
lagent = nice_agent_new (&udpfactory, lagent = nice_agent_new (g_main_loop_get_context (global_mainloop), NICE_COMPATIBILITY_ID19);
g_main_loop_get_context (global_mainloop), NICE_COMPATIBILITY_ID19); ragent = nice_agent_new (g_main_loop_get_context (global_mainloop), NICE_COMPATIBILITY_ID19);
ragent = nice_agent_new (&udpfactory,
g_main_loop_get_context (global_mainloop), NICE_COMPATIBILITY_ID19);
/* step: add a timer to catch state changes triggered by signals */ /* step: add a timer to catch state changes triggered by signals */
...@@ -453,10 +448,9 @@ int main (void) ...@@ -453,10 +448,9 @@ int main (void)
g_object_unref (lagent); g_object_unref (lagent);
g_object_unref (ragent); g_object_unref (ragent);
nice_udp_socket_factory_close (&udpfactory);
g_main_loop_unref (global_mainloop), g_main_loop_unref (global_mainloop);
global_mainloop = NULL; global_mainloop = NULL;
g_source_remove (timer_id); g_source_remove (timer_id);
......
...@@ -42,7 +42,6 @@ ...@@ -42,7 +42,6 @@
#include <string.h> #include <string.h>
#include "agent.h" #include "agent.h"
#include "udp-bsd.h"
GMainLoop *error_loop; GMainLoop *error_loop;
...@@ -171,7 +170,6 @@ static void cb_component_state_changed (NiceAgent *agent, ...@@ -171,7 +170,6 @@ static void cb_component_state_changed (NiceAgent *agent,
int main (void) int main (void)
{ {
NiceAgent *lagent, *ragent; /* agent's L and R */ NiceAgent *lagent, *ragent; /* agent's L and R */
NiceUDPSocketFactory udpfactory;
NiceAddress baseaddr; NiceAddress baseaddr;
guint timer_id; guint timer_id;
const char *stun_server = NULL, *stun_server_port = NULL; const char *stun_server = NULL, *stun_server_port = NULL;
...@@ -198,11 +196,10 @@ int main (void) ...@@ -198,11 +196,10 @@ int main (void)
error_loop = g_main_loop_new (NULL, FALSE); error_loop = g_main_loop_new (NULL, FALSE);
nice_udp_bsd_socket_factory_init (&udpfactory);
/* step: create the agents L and R */ /* step: create the agents L and R */
lagent = nice_agent_new (&udpfactory, lmainctx, NICE_COMPATIBILITY_GOOGLE); lagent = nice_agent_new (lmainctx, NICE_COMPATIBILITY_MSN);
ragent = nice_agent_new (&udpfactory, rmainctx, NICE_COMPATIBILITY_GOOGLE); ragent = nice_agent_new (rmainctx, NICE_COMPATIBILITY_MSN);
g_object_set_data (G_OBJECT (lagent), "other-agent", ragent); g_object_set_data (G_OBJECT (lagent), "other-agent", ragent);
g_object_set_data (G_OBJECT (ragent), "other-agent", lagent); g_object_set_data (G_OBJECT (ragent), "other-agent", lagent);
...@@ -243,13 +240,10 @@ int main (void) ...@@ -243,13 +240,10 @@ int main (void)
/* step: test setter/getter functions for properties */ /* step: test setter/getter functions for properties */
{ {
gpointer pointer;
guint max_checks = 0; guint max_checks = 0;
gchar *string = NULL; gchar *string = NULL;
guint port = 0; guint port = 0;
gboolean mode = FALSE; gboolean mode = FALSE;
g_object_get (G_OBJECT (lagent), "socket-factory", &pointer, NULL);
g_assert (pointer == (gpointer)&udpfactory);
g_object_get (G_OBJECT (lagent), "stun-server", &string, NULL); g_object_get (G_OBJECT (lagent), "stun-server", &string, NULL);
g_assert (stun_server == NULL || strcmp (string, stun_server) == 0); g_assert (stun_server == NULL || strcmp (string, stun_server) == 0);
g_free (string); g_free (string);
...@@ -322,8 +316,6 @@ int main (void) ...@@ -322,8 +316,6 @@ int main (void)
g_object_unref (lagent); g_object_unref (lagent);
g_object_unref (ragent); g_object_unref (ragent);
nice_udp_socket_factory_close (&udpfactory);
g_main_loop_unref (lmainloop); g_main_loop_unref (lmainloop);
g_main_loop_unref (rmainloop); g_main_loop_unref (rmainloop);
g_main_loop_unref (ldmainloop); g_main_loop_unref (ldmainloop);
......
...@@ -40,7 +40,6 @@ ...@@ -40,7 +40,6 @@
#include <string.h> #include <string.h>
#include "udp-fake.h"
#include "agent.h" #include "agent.h"
#include "agent-priv.h" #include "agent-priv.h"
...@@ -50,7 +49,6 @@ main (void) ...@@ -50,7 +49,6 @@ main (void)
NiceAgent *agent; NiceAgent *agent;
NiceAddress addr_local, addr_remote; NiceAddress addr_local, addr_remote;
NiceCandidate *candidate; NiceCandidate *candidate;
NiceUDPSocketFactory factory;
GSList *candidates; GSList *candidates;
guint stream_id; guint stream_id;
...@@ -59,13 +57,12 @@ main (void) ...@@ -59,13 +57,12 @@ main (void)
g_type_init (); g_type_init ();
g_thread_init (NULL); g_thread_init (NULL);
nice_udp_fake_socket_factory_init (&factory);
g_assert (nice_address_set_from_string (&addr_local, "192.168.0.1")); g_assert (nice_address_set_from_string (&addr_local, "192.168.0.1"));
g_assert (nice_address_set_from_string (&addr_remote, "192.168.0.2")); g_assert (nice_address_set_from_string (&addr_remote, "192.168.0.2"));
nice_address_set_port (&addr_remote, 2345); nice_address_set_port (&addr_remote, 2345);
agent = nice_agent_new (&factory, NULL, NICE_COMPATIBILITY_ID19); agent = nice_agent_new ( NULL, NICE_COMPATIBILITY_ID19);
g_assert (agent->local_addresses == NULL); g_assert (agent->local_addresses == NULL);
...@@ -84,8 +81,9 @@ main (void) ...@@ -84,8 +81,9 @@ main (void)
candidates = nice_agent_get_local_candidates (agent, stream_id, 1); candidates = nice_agent_get_local_candidates (agent, stream_id, 1);
g_assert (g_slist_length (candidates) == 1); g_assert (g_slist_length (candidates) == 1);
candidate = candidates->data; candidate = candidates->data;
/* fake socket manager uses incremental port numbers starting at 1 */ /* socket manager uses random port number */
nice_address_set_port (&addr_local, 1); nice_address_set_port (&addr_local, 1);
nice_address_set_port (&(candidate->addr), 1);
g_assert (nice_address_equal (&(candidate->addr), &addr_local)); g_assert (nice_address_equal (&(candidate->addr), &addr_local));
g_assert (strncmp (candidate->foundation, "1", 1) == 0); g_assert (strncmp (candidate->foundation, "1", 1) == 0);
g_slist_free (candidates); g_slist_free (candidates);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment