Commit 7adc1e65 authored by Dafydd Harries's avatar Dafydd Harries

add test for nice_agent_poll_read

darcs-hash:20070208141242-c9803-90539751108f409bc2da2dd2517bdb6cc58f7ff0.gz
parent eae437db
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
include $(top_srcdir)/common.mk include $(top_srcdir)/common.mk
AM_CFLAGS = -Wall -Werror \ AM_CFLAGS = -Wall -Werror \
-I $(top_srcdir) \
-I $(top_srcdir)/address \ -I $(top_srcdir)/address \
-I $(top_srcdir)/random \ -I $(top_srcdir)/random \
-I $(top_srcdir)/udp \ -I $(top_srcdir)/udp \
...@@ -32,7 +33,8 @@ check_PROGRAMS = \ ...@@ -32,7 +33,8 @@ check_PROGRAMS = \
test-recv \ test-recv \
test-send \ test-send \
test-stun \ test-stun \
test-priority test-priority \
test-poll
TESTS = $(check_PROGRAMS) TESTS = $(check_PROGRAMS)
...@@ -48,5 +50,7 @@ test_stun_LDADD = $(COMMON_LDADD) ...@@ -48,5 +50,7 @@ test_stun_LDADD = $(COMMON_LDADD)
test_priority_LDADD = $(COMMON_LDADD) test_priority_LDADD = $(COMMON_LDADD)
test_poll_LDADD = $(COMMON_LDADD)
pkginclude_HEADERS = agent.h candidate.h event.h pkginclude_HEADERS = agent.h candidate.h event.h
#include <string.h>
#include <unistd.h>
#include <nice/nice.h>
static gboolean cb_called = FALSE;
void
handle_recv (
NiceAgent *agent,
guint stream_id,
guint component_id,
guint len,
gchar *buf,
gpointer data)
{
g_assert (cb_called == FALSE);
g_assert (stream_id == 1);
g_assert (component_id == 1);
g_assert (len == 7);
g_assert (0 == strncmp (buf, "\x80lalala", 7));
cb_called = TRUE;
}
int
main (void)
{
NiceAgent *agent;
NiceAddress addr = {0,};
NiceUDPSocketFactory factory;
NiceCandidate *candidate;
NiceUDPSocket *sock;
gint pipe_fds[2];
GSList *fds = NULL;
GSList *readable;
/* set up agent */
if (!nice_address_set_ipv4_from_string (&addr, "127.0.0.1"))
g_assert_not_reached ();
nice_udp_fake_socket_factory_init (&factory);
agent = nice_agent_new (&factory);
nice_agent_add_local_address (agent, &addr);
nice_agent_add_stream (agent, handle_recv, NULL);
candidate = agent->local_candidates->data;
sock = &candidate->sock;
/* set up pipe and fd list */
if (pipe (pipe_fds) != 0)
g_assert_not_reached ();
write (pipe_fds[1], "hello", 5);
fds = g_slist_append (fds, GUINT_TO_POINTER (pipe_fds[0]));
/* poll */
readable = nice_agent_poll_read (agent, fds);
g_assert (g_slist_length (readable) == 1);
g_assert (GPOINTER_TO_UINT (readable->data) == pipe_fds[0]);
g_slist_free (readable);
g_assert (cb_called == FALSE);
{
gchar buf[1024];
g_assert (5 == read (pipe_fds[0], buf, 1024));
g_assert (0 == strncmp (buf, "hello", 5));
}
/* send fake data */
nice_udp_fake_socket_push_recv (sock, &addr, 7, "\x80lalala");
/* poll again */
readable = nice_agent_poll_read (agent, fds);
g_assert (cb_called == TRUE);
g_assert (readable == NULL);
/* clean up */
g_slist_free (fds);
nice_agent_free (agent);
return 0;
}
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