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

Port libnice tests to match new API

parent 6056277b
......@@ -41,7 +41,6 @@
#include "agent.h"
#include "agent-priv.h"
#include "udp-fake.h"
#include <string.h>
int
......@@ -49,18 +48,16 @@ main (void)
{
NiceAgent *agent;
NiceAddress addr;
NiceUDPSocketFactory factory;
nice_address_init (&addr);
g_type_init ();
g_thread_init (NULL);
nice_udp_fake_socket_factory_init (&factory);
if (!nice_address_set_from_string (&addr, "127.0.0.1"))
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);
g_assert (nice_agent_add_stream (agent, 1) == 1);
......@@ -76,7 +73,6 @@ main (void)
g_assert (NULL == agent->streams);
g_object_unref (agent);
nice_udp_socket_factory_close (&factory);
return 0;
}
......
......@@ -44,7 +44,6 @@
#include "agent.h"
#include "agent-priv.h" /* for testing purposes */
#include "udp-bsd.h"
static NiceComponentState global_lagent_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
int main (void)
{
NiceAgent *lagent, *ragent; /* agent's L and R */
NiceUDPSocketFactory udpfactory;
NiceAddress baseaddr;
int result;
guint timer_id;
......@@ -489,13 +487,9 @@ int main (void)
* - no IPv6 support
*/
nice_udp_bsd_socket_factory_init (&udpfactory);
/* step: create the agents L and R */
lagent = nice_agent_new (&udpfactory,
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);
lagent = nice_agent_new (g_main_loop_get_context (global_mainloop), NICE_COMPATIBILITY_ID19);
ragent = nice_agent_new (g_main_loop_get_context (global_mainloop), NICE_COMPATIBILITY_ID19);
......@@ -557,10 +551,8 @@ int main (void)
g_object_unref (lagent);
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);
......
......@@ -42,7 +42,6 @@
#include <string.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_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,
int main (void)
{
NiceAgent *lagent, *ragent; /* agent's L and R */
NiceUDPSocketFactory udpfactory;
NiceAddress baseaddr;
int result;
guint timer_id;
......@@ -736,13 +734,9 @@ int main (void)
* - no IPv6 support
*/
nice_udp_bsd_socket_factory_init (&udpfactory);
/* step: create the agents L and R */
lagent = nice_agent_new (&udpfactory,
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);
lagent = nice_agent_new (g_main_loop_get_context (global_mainloop), NICE_COMPATIBILITY_ID19);
ragent = nice_agent_new (g_main_loop_get_context (global_mainloop), NICE_COMPATIBILITY_ID19);
/* step: add a timer to catch state changes triggered by signals */
timer_id = g_timeout_add (30000, timer_cb, NULL);
......@@ -785,13 +779,10 @@ int main (void)
/* step: test setter/getter functions for properties */
{
gpointer pointer;
guint max_checks = 0;
gchar *string = NULL;
guint port = 0;
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_assert (stun_server == NULL || strcmp (string, stun_server) == 0);
g_free (string);
......@@ -905,10 +896,8 @@ int main (void)
g_object_unref (lagent);
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);
......
......@@ -68,7 +68,6 @@ main (void)
{
NiceAgent *agent;
NiceAddress addr;
NiceUDPSocketFactory factory;
guint stream;
nice_address_init (&addr);
......@@ -76,9 +75,7 @@ main (void)
g_thread_init (NULL);
loop = g_main_loop_new (NULL, FALSE);
nice_udp_fake_socket_factory_init (&factory);
agent = nice_agent_new (&factory,
g_main_loop_get_context (loop), NICE_COMPATIBILITY_ID19);
agent = nice_agent_new (g_main_loop_get_context (loop), NICE_COMPATIBILITY_ID19);
nice_address_set_ipv4 (&addr, 0x7f000001);
nice_agent_add_local_address (agent, &addr);
stream = nice_agent_add_stream (agent, 1);
......@@ -96,15 +93,14 @@ main (void)
candidates = nice_agent_get_local_candidates (agent, 1, 1);
candidate = candidates->data;
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_object_unref (agent);
nice_udp_socket_factory_close (&factory);
return 0;
}
......@@ -44,6 +44,8 @@
#include <unistd.h>
#include <nice/nice.h>
#include "udp.h"
static gboolean cb_called = FALSE;
......@@ -71,7 +73,6 @@ main (void)
{
NiceAgent *agent;
NiceAddress addr;
NiceUDPSocketFactory factory;
NiceUDPSocket *sock;
gint pipe_fds[2];
GSList *fds = NULL;
......@@ -88,8 +89,7 @@ main (void)
if (!nice_address_set_from_string (&addr, "127.0.0.1"))
g_assert_not_reached ();
nice_udp_fake_socket_factory_init (&factory);
agent = nice_agent_new (&factory, NULL, NICE_COMPATIBILITY_ID19);
agent = nice_agent_new (NULL, NICE_COMPATIBILITY_ID19);
nice_agent_add_local_address (agent, &addr);
stream_id = nice_agent_add_stream (agent, 1);
nice_agent_gather_candidates (agent, stream_id);
......@@ -101,6 +101,7 @@ main (void)
candidates = nice_agent_get_local_candidates (agent, stream_id, 1);
candidate = candidates->data;
sock = candidate->sockptr;
addr = candidate->addr;
g_slist_free (candidates);
}
......@@ -131,7 +132,7 @@ main (void)
/* send fake data */
nice_udp_fake_socket_push_recv (sock, &addr, 7, "\x80lalala");
nice_udp_socket_send (sock, &addr, 7, "\x80lalala");
/* poll again */
......
......@@ -41,7 +41,7 @@
#include <string.h>
#include "udp-fake.h"
#include "udp.h"
#include "agent.h"
int
......@@ -49,17 +49,14 @@ main (void)
{
NiceAgent *agent;
NiceAddress addr;
NiceUDPSocketFactory factory;
guint stream_id;
nice_address_init (&addr);
g_type_init ();
g_thread_init (NULL);
nice_udp_fake_socket_factory_init (&factory);
/* 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"));
nice_agent_add_local_address (agent, &addr);
stream_id = nice_agent_add_stream (agent, 1);
......@@ -78,7 +75,7 @@ main (void)
candidate = candidates->data;
g_slist_free (candidates);
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,
candidate->component_id, 1024, buf);
g_assert (len == 7);
......@@ -87,7 +84,6 @@ main (void)
/* clean up */
g_object_unref (agent);
nice_udp_socket_factory_close (&factory);
return 0;
}
......
......@@ -41,7 +41,6 @@
#include "agent.h"
#include "agent-priv.h" /* for testing purposes */
#include "udp-bsd.h"
static NiceComponentState global_lagent_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 *
int main (void)
{
NiceAgent *lagent, *ragent; /* agent's L and R */
NiceUDPSocketFactory udpfactory;
NiceAddress baseaddr;
int result;
guint timer_id;
......@@ -394,13 +392,10 @@ int main (void)
* - no IPv6 support
*/
nice_udp_bsd_socket_factory_init (&udpfactory);
/* step: create the agents L and R */
lagent = nice_agent_new (&udpfactory,
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);
lagent = nice_agent_new (g_main_loop_get_context (global_mainloop), NICE_COMPATIBILITY_ID19);
ragent = nice_agent_new (g_main_loop_get_context (global_mainloop), NICE_COMPATIBILITY_ID19);
/* step: add a timer to catch state changes triggered by signals */
......@@ -453,10 +448,9 @@ int main (void)
g_object_unref (lagent);
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);
......
......@@ -42,7 +42,6 @@
#include <string.h>
#include "agent.h"
#include "udp-bsd.h"
GMainLoop *error_loop;
......@@ -171,7 +170,6 @@ static void cb_component_state_changed (NiceAgent *agent,
int main (void)
{
NiceAgent *lagent, *ragent; /* agent's L and R */
NiceUDPSocketFactory udpfactory;
NiceAddress baseaddr;
guint timer_id;
const char *stun_server = NULL, *stun_server_port = NULL;
......@@ -198,11 +196,10 @@ int main (void)
error_loop = g_main_loop_new (NULL, FALSE);
nice_udp_bsd_socket_factory_init (&udpfactory);
/* step: create the agents L and R */
lagent = nice_agent_new (&udpfactory, lmainctx, NICE_COMPATIBILITY_GOOGLE);
ragent = nice_agent_new (&udpfactory, rmainctx, NICE_COMPATIBILITY_GOOGLE);
lagent = nice_agent_new (lmainctx, NICE_COMPATIBILITY_MSN);
ragent = nice_agent_new (rmainctx, NICE_COMPATIBILITY_MSN);
g_object_set_data (G_OBJECT (lagent), "other-agent", ragent);
g_object_set_data (G_OBJECT (ragent), "other-agent", lagent);
......@@ -243,13 +240,10 @@ int main (void)
/* step: test setter/getter functions for properties */
{
gpointer pointer;
guint max_checks = 0;
gchar *string = NULL;
guint port = 0;
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_assert (stun_server == NULL || strcmp (string, stun_server) == 0);
g_free (string);
......@@ -322,8 +316,6 @@ int main (void)
g_object_unref (lagent);
g_object_unref (ragent);
nice_udp_socket_factory_close (&udpfactory);
g_main_loop_unref (lmainloop);
g_main_loop_unref (rmainloop);
g_main_loop_unref (ldmainloop);
......
......@@ -40,7 +40,6 @@
#include <string.h>
#include "udp-fake.h"
#include "agent.h"
#include "agent-priv.h"
......@@ -50,7 +49,6 @@ main (void)
NiceAgent *agent;
NiceAddress addr_local, addr_remote;
NiceCandidate *candidate;
NiceUDPSocketFactory factory;
GSList *candidates;
guint stream_id;
......@@ -59,13 +57,12 @@ main (void)
g_type_init ();
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_remote, "192.168.0.2"));
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);
......@@ -84,8 +81,9 @@ main (void)
candidates = nice_agent_get_local_candidates (agent, stream_id, 1);
g_assert (g_slist_length (candidates) == 1);
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 (&(candidate->addr), 1);
g_assert (nice_address_equal (&(candidate->addr), &addr_local));
g_assert (strncmp (candidate->foundation, "1", 1) == 0);
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