summaryrefslogtreecommitdiff
path: root/udp
diff options
context:
space:
mode:
authorDafydd Harries <dafydd.harries@collabora.co.uk>2007-02-05 16:25:00 +0000
committerDafydd Harries <dafydd.harries@collabora.co.uk>2007-02-05 16:25:00 +0000
commit85e88fa0ea30a0632c3452605e3e5b41f5c713cb (patch)
tree042a3cb7bac3b2d66d94146bd2cb8a803a800824 /udp
parentebc37d94f105c19e1efc0cf21b7f6c7ecbe0c851 (diff)
downloadlibnice-85e88fa0ea30a0632c3452605e3e5b41f5c713cb.tar.gz
add extra test for BSD sockets
darcs-hash:20070205162552-c9803-ff0b7bcbce6668efaa473afeb0fc4f6882f81397.gz
Diffstat (limited to 'udp')
-rw-r--r--udp/Makefile.am6
-rw-r--r--udp/test-bsd.c44
2 files changed, 48 insertions, 2 deletions
diff --git a/udp/Makefile.am b/udp/Makefile.am
index e0239d5..b1fca04 100644
--- a/udp/Makefile.am
+++ b/udp/Makefile.am
@@ -21,16 +21,18 @@ udp_client_LDADD = $(COMMON_LDADD)
udp_echo_server_LDADD = $(COMMON_LDADD)
-check_PROGRAMS = test-fake
+check_PROGRAMS = test-fake test-bsd
test_fake_LDADD = $(COMMON_LDADD)
+test_bsd_LDADD = $(COMMON_LDADD)
+
test-echo.sh::
chmod +x $(srcdir)/$@
EXTRA_DIST = test-echo.sh
-TESTS = test-echo.sh test-fake
+TESTS = test-echo.sh $(check_PROGRAMS)
pkginclude_HEADERS = udp.h udp-fake.h udp-bsd.h
diff --git a/udp/test-bsd.c b/udp/test-bsd.c
new file mode 100644
index 0000000..58ec6f2
--- /dev/null
+++ b/udp/test-bsd.c
@@ -0,0 +1,44 @@
+
+#include <string.h>
+
+#include "udp-bsd.h"
+
+int
+main (void)
+{
+ NiceUDPSocketFactory factory;
+ NiceUDPSocket server;
+ NiceUDPSocket client;
+ NiceAddress tmp = {0,};
+ gchar buf[5];
+
+ nice_udp_bsd_socket_factory_init (&factory);
+
+ g_assert (nice_udp_socket_factory_make (&factory, &server, NULL));
+ // not bound to a particular interface
+ g_assert (server.addr.addr_ipv4 == 0);
+ // is bound to a particular port
+ g_assert (server.addr.port != 0);
+
+ g_assert (nice_udp_socket_factory_make (&factory, &client, NULL));
+ // not bound to a particular interface
+ g_assert (client.addr.addr_ipv4 == 0);
+ // is bound to a particular port
+ g_assert (client.addr.port != 0);
+
+ nice_udp_socket_send (&client, &server.addr, 5, "hello");
+ g_assert (5 == nice_udp_socket_recv (&server, &tmp, 5, buf));
+ g_assert (0 == strncmp (buf, "hello", 5));
+ g_assert (tmp.port == client.addr.port);
+
+ nice_udp_socket_send (&server, &client.addr, 5, "uryyb");
+ g_assert (5 == nice_udp_socket_recv (&client, &tmp, 5, buf));
+ g_assert (0 == strncmp (buf, "uryyb", 5));
+ g_assert (tmp.port == server.addr.port);
+
+ nice_udp_socket_close (&client);
+ nice_udp_socket_close (&server);
+ nice_udp_socket_factory_close (&factory);
+ return 0;
+}
+