[0.11] gst-plugins-good: udpsrc: add unit test that sends 0-size packet

Sebastian Dröge slomo at kemper.freedesktop.org
Tue Jan 10 05:33:26 PST 2012


Module: gst-plugins-good
Branch: 0.11
Commit: b744ad03ccf85cfe34f00866964fc97fad385975
URL:    http://cgit.freedesktop.org/gstreamer/gst-plugins-good/commit/?id=b744ad03ccf85cfe34f00866964fc97fad385975

Author: Tim-Philipp Müller <tim.muller at collabora.co.uk>
Date:   Tue Dec 27 11:49:10 2011 +0000

udpsrc: add unit test that sends 0-size packet

https://bugzilla.gnome.org/show_bug.cgi?id=666644

---

 tests/check/Makefile.am       |    4 ++
 tests/check/elements/udpsrc.c |  120 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 124 insertions(+), 0 deletions(-)

diff --git a/tests/check/Makefile.am b/tests/check/Makefile.am
index 27dde40..d16e985 100644
--- a/tests/check/Makefile.am
+++ b/tests/check/Makefile.am
@@ -147,6 +147,7 @@ check_PROGRAMS = \
 	elements/shapewipe \
 	elements/spectrum \
 	elements/udpsink \
+	elements/udpsrc \
 	elements/videocrop \
 	elements/videofilter \
 	elements/y4menc \
@@ -261,6 +262,9 @@ elements_sunaudio_LDADD = \
 	$(GST_PLUGINS_BASE_LIBS) -lgstinterfaces- at GST_MAJORMINOR@ \
 	$(LDADD)
 
+elements_udpsrc_CFLAGS = $(AM_CFLAGS) $(GIO_CFLAGS)
+elements_udpsrc_LDADD = $(LDADD) $(GIO_LIBS)
+
 elements_videocrop_LDADD = $(GST_BASE_LIBS) $(LDADD)
 elements_videocrop_CFLAGS = $(GST_BASE_CFLAGS) $(CFLAGS) $(AM_CFLAGS)
 
diff --git a/tests/check/elements/udpsrc.c b/tests/check/elements/udpsrc.c
new file mode 100644
index 0000000..d84334a
--- /dev/null
+++ b/tests/check/elements/udpsrc.c
@@ -0,0 +1,120 @@
+/* GStreamer UDP source unit tests
+ * Copyright (C) 2011 Tim-Philipp Müller <tim centricular net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#include <gst/check/gstcheck.h>
+#include <gio/gio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
+    GST_PAD_SINK,
+    GST_PAD_ALWAYS,
+    GST_STATIC_CAPS_ANY);
+
+GST_START_TEST (test_udpsrc_empty_packet)
+{
+  GstElement *udpsrc;
+  GSocket *socket;
+  GstPad *sinkpad;
+  int port = 0;
+
+  udpsrc = gst_check_setup_element ("udpsrc");
+  fail_unless (udpsrc != NULL);
+  g_object_set (udpsrc, "port", 0, NULL);
+
+  sinkpad = gst_check_setup_sink_pad_by_name (udpsrc, &sinktemplate, "src");
+  fail_unless (sinkpad != NULL);
+  gst_pad_set_active (sinkpad, TRUE);
+
+  gst_element_set_state (udpsrc, GST_STATE_PLAYING);
+  g_object_get (udpsrc, "port", &port, NULL);
+  GST_INFO ("udpsrc port = %d", port);
+
+  socket = g_socket_new (G_SOCKET_FAMILY_IPV4, G_SOCKET_TYPE_DATAGRAM,
+      G_SOCKET_PROTOCOL_UDP, NULL);
+
+  if (socket != NULL) {
+    GSocketAddress *sa;
+    GInetAddress *ia;
+    gchar *s;
+
+    ia = g_inet_address_new_loopback (G_SOCKET_FAMILY_IPV4);
+    s = g_inet_address_to_string (ia);
+    GST_LOG ("inet address %s", s);
+    g_free (s);
+    sa = g_inet_socket_address_new (ia, port);
+
+    if (g_socket_send_to (socket, sa, "HeLL0", 0, NULL, NULL) == 0) {
+      GST_INFO ("sent 0 bytes");
+      if (g_socket_send_to (socket, sa, "HeLL0", 6, NULL, NULL) == 6) {
+        GstBuffer *buf;
+        guint len;
+
+        GST_INFO ("sent 6 bytes");
+
+        g_usleep (G_USEC_PER_SEC / 2);
+
+        len = g_list_length (buffers);
+        GST_INFO ("%u buffers", len);
+        fail_unless (len == 1 || len == 2);
+
+        /* last buffer should be our HeLL0 string */
+        buf = GST_BUFFER (g_list_nth_data (buffers, len - 1));
+        fail_unless_equals_int (GST_BUFFER_SIZE (buf), 6);
+        fail_unless_equals_string ((gchar *) GST_BUFFER_DATA (buf), "HeLL0");
+
+        /* if there's another buffer, it should be 0 bytes */
+        if (len == 2) {
+          buf = GST_BUFFER (g_list_nth_data (buffers, 0));
+          fail_unless_equals_int (GST_BUFFER_SIZE (buf), 0);
+        }
+      } else {
+        GST_WARNING ("send_to(6 bytes) failed");
+      }
+    } else {
+      GST_WARNING ("send_to(0 bytes) failed");
+    }
+
+    g_object_unref (sa);
+    g_object_unref (ia);
+  } else {
+    GST_WARNING ("Could not create IPv4 UDP socket for unit test");
+  }
+
+  gst_element_set_state (udpsrc, GST_STATE_NULL);
+
+  gst_check_teardown_pad_by_name (udpsrc, "src");
+  gst_check_teardown_element (udpsrc);
+
+  g_object_unref (socket);
+}
+
+GST_END_TEST;
+
+static Suite *
+udpsrc_suite (void)
+{
+  Suite *s = suite_create ("udpsrc");
+  TCase *tc_chain = tcase_create ("udpsrc");
+
+  suite_add_tcase (s, tc_chain);
+  tcase_add_test (tc_chain, test_udpsrc_empty_packet);
+  return s;
+}
+
+GST_CHECK_MAIN (udpsrc)



More information about the gstreamer-commits mailing list