From 5b0ec93e99a091c9708df83a0f645593d3b31da8 Mon Sep 17 00:00:00 2001 From: William Manley Date: Mon, 3 Nov 2014 01:08:27 +0000 Subject: [PATCH] tests: Add TCP pipelines test There don't seem to be any unit tests for the socket handling elements. As I am about to attempt some refactorings I've added some basic tests which exercise some of the happy-paths in tcpclientsrc, tcpserversrc, tcpserversink and tcpclientsink. They should let me know if I've caused serious breakage. They are far from exhaustive but are sufficient for me to have caught a few memory-leaks in the existing code. https://bugzilla.gnome.org/show_bug.cgi?id=739544 --- tests/check/Makefile.am | 8 ++ tests/check/pipelines/.gitignore | 1 + tests/check/pipelines/tcp.c | 153 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 162 insertions(+) create mode 100644 tests/check/pipelines/tcp.c diff --git a/tests/check/Makefile.am b/tests/check/Makefile.am index d2eb6c5..9a3d639 100644 --- a/tests/check/Makefile.am +++ b/tests/check/Makefile.am @@ -164,7 +164,11 @@ check_audiorate = endif if USE_PLUGIN_TCP +if USE_PLUGIN_APP +check_tcp = elements/multifdsink elements/multisocketsink pipelines/tcp +else check_tcp = elements/multifdsink elements/multisocketsink +endif else check_tcp = endif @@ -590,6 +594,10 @@ libs_videoencoder_LDADD = \ elements_multisocketsink_CFLAGS = $(GIO_CFLAGS) $(AM_CFLAGS) elements_multisocketsink_LDADD = $(GIO_LIBS) $(LDADD) +pipelines_tcp_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GIO_CFLAGS) $(AM_CFLAGS) +pipelines_tcp_LDADD = $(GST_PLUGINS_BASE_LIBS) $(GIO_LIBS) $(LDADD) \ + $(top_builddir)/gst-libs/gst/app/libgstapp-@GST_API_VERSION@.la + pipelines_gio_CFLAGS = $(GIO_CFLAGS) $(AM_CFLAGS) pipelines_gio_LDADD = $(GIO_LIBS) $(LDADD) diff --git a/tests/check/pipelines/.gitignore b/tests/check/pipelines/.gitignore index 6219548..128a50e 100644 --- a/tests/check/pipelines/.gitignore +++ b/tests/check/pipelines/.gitignore @@ -3,6 +3,7 @@ basetime capsfilter-renegotiation gio simple-launch-lines +tcp theoraenc vorbisdec vorbisenc diff --git a/tests/check/pipelines/tcp.c b/tests/check/pipelines/tcp.c new file mode 100644 index 0000000..18c01db --- /dev/null +++ b/tests/check/pipelines/tcp.c @@ -0,0 +1,153 @@ +/* GStreamer + * + * Copyright (C) 2014 William Manley + * + * 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., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include +#include +#include +#include + +typedef struct +{ + GstElement *sink; + GstElement *src; + + GstPipeline *sink_pipeline; + GstPipeline *src_pipeline; + GstAppSrc *sink_src; + GstAppSink *src_sink; +} SymmetryTest; + +static void +symmetry_test_setup (SymmetryTest * st, GstElement * sink, GstElement * src) +{ + GstCaps *caps; + st->sink = sink; + g_object_set (sink, "sync", FALSE, NULL); + st->src = src; + + st->sink_pipeline = GST_PIPELINE (gst_pipeline_new (NULL)); + st->src_pipeline = GST_PIPELINE (gst_pipeline_new (NULL)); + + st->sink_src = GST_APP_SRC (gst_element_factory_make ("appsrc", NULL)); + fail_unless (st->sink_src != NULL); + caps = gst_caps_from_string ("application/x-gst-check"); + gst_app_src_set_caps (st->sink_src, caps); + gst_caps_unref (caps); + + gst_bin_add_many (GST_BIN (st->sink_pipeline), GST_ELEMENT (st->sink_src), + st->sink, NULL); + fail_unless (gst_element_link_many (GST_ELEMENT (st->sink_src), st->sink, + NULL)); + + st->src_sink = GST_APP_SINK (gst_element_factory_make ("appsink", NULL)); + fail_unless (st->src_sink != NULL); + gst_bin_add_many (GST_BIN (st->src_pipeline), st->src, + GST_ELEMENT (st->src_sink), NULL); + fail_unless (gst_element_link_many (st->src, GST_ELEMENT (st->src_sink), + NULL)); + + gst_element_set_state (GST_ELEMENT (st->sink_pipeline), GST_STATE_PLAYING); + gst_element_set_state (GST_ELEMENT (st->src_pipeline), GST_STATE_PLAYING); +} + +static void +symmetry_test_teardown (SymmetryTest * st) +{ + fail_unless (gst_element_set_state (GST_ELEMENT (st->sink_pipeline), + GST_STATE_NULL) != GST_STATE_CHANGE_FAILURE); + fail_unless (gst_element_set_state (GST_ELEMENT (st->src_pipeline), + GST_STATE_NULL) != GST_STATE_CHANGE_FAILURE); + + gst_object_unref (st->sink_pipeline); + gst_object_unref (st->src_pipeline); + + memset (st, 0, sizeof (*st)); +} + +static void +symmetry_test_assert_passthrough (SymmetryTest * st, GstBuffer * in) +{ + gpointer copy; + gsize data_size; + GstSample *out; + + gst_buffer_extract_dup (in, 0, -1, ©, &data_size); + + fail_unless (gst_app_src_push_buffer (st->sink_src, in) == GST_FLOW_OK); + in = NULL; + out = gst_app_sink_pull_sample (st->src_sink); + fail_unless (out != NULL); + + fail_unless (gst_buffer_get_size (gst_sample_get_buffer (out)) == data_size); + fail_unless (gst_buffer_memcmp (gst_sample_get_buffer (out), 0, copy, + data_size) == 0); + g_free (copy); + gst_sample_unref (out); +} + + +GST_START_TEST (test_that_tcpclientsink_and_tcpserversrc_are_symmetrical) +{ + SymmetryTest st = { 0 }; + GstElement *serversrc = gst_check_setup_element ("tcpserversrc"); + + gst_element_set_state (serversrc, GST_STATE_PAUSED); + symmetry_test_setup (&st, gst_check_setup_element ("tcpclientsink"), + serversrc); + + symmetry_test_assert_passthrough (&st, + gst_buffer_new_wrapped (g_strdup ("hello"), 5)); + + symmetry_test_teardown (&st); +} + +GST_END_TEST; + + +GST_START_TEST (test_that_tcpserversink_and_tcpclientsrc_are_symmetrical) +{ + SymmetryTest st = { 0 }; + + symmetry_test_setup (&st, gst_check_setup_element ("tcpserversink"), + gst_check_setup_element ("tcpclientsrc")); + + symmetry_test_assert_passthrough (&st, + gst_buffer_new_wrapped (g_strdup ("hello"), 5)); + symmetry_test_teardown (&st); +} + +GST_END_TEST; + +static Suite * +socketintegrationtest_suite (void) +{ + Suite *s = suite_create ("socketintegrationtest"); + TCase *tc_chain = tcase_create ("general"); + + suite_add_tcase (s, tc_chain); + tcase_add_test (tc_chain, + test_that_tcpclientsink_and_tcpserversrc_are_symmetrical); + tcase_add_test (tc_chain, + test_that_tcpserversink_and_tcpclientsrc_are_symmetrical); + + return s; +} + +GST_CHECK_MAIN (socketintegrationtest); -- 2.7.4