From 7d7108f35d1a949e4abeffaf7a2ecbacf831d87e Mon Sep 17 00:00:00 2001 From: Seungha Yang Date: Wed, 22 Jan 2020 22:30:11 +0900 Subject: [PATCH] tests: audiosink: Test class extension struct Test a vfunc which belongs to GstAudioSinkExtension struct. Part-of: --- tests/check/libs/audiosink.c | 123 +++++++++++++++++++++++++++++++++++ tests/check/meson.build | 1 + 2 files changed, 124 insertions(+) create mode 100644 tests/check/libs/audiosink.c diff --git a/tests/check/libs/audiosink.c b/tests/check/libs/audiosink.c new file mode 100644 index 0000000000..c996d30f08 --- /dev/null +++ b/tests/check/libs/audiosink.c @@ -0,0 +1,123 @@ +/* GStreamer + * + * unit test for the audiosink base class + * + * Copyright (C) 2020 Seungha Yang + * + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include + +#define GST_TYPE_AUDIO_FOO_SINK (gst_audio_foo_sink_get_type()) +#define GST_AUDIO_FOO_SINK(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_AUDIO_FOO_SINK,GstAudioFooSink)) +#define GST_AUDIO_FOO_SINK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_AUDIO_FOO_SINK,GstAudioFooSinkClass)) +typedef struct _GstAudioFooSink GstAudioFooSink; +typedef struct _GstAudioFooSinkClass GstAudioFooSinkClass; + +static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink", + GST_PAD_SINK, + GST_PAD_ALWAYS, + GST_STATIC_CAPS (GST_AUDIO_CAPS_MAKE (GST_AUDIO_FORMATS_ALL))); + +struct _GstAudioFooSink +{ + GstAudioSink parent; + + guint num_clear_all_call; +}; + +struct _GstAudioFooSinkClass +{ + GstAudioSinkClass parent_class; +}; + +GType gst_audio_foo_sink_get_type (void); +G_DEFINE_TYPE (GstAudioFooSink, gst_audio_foo_sink, GST_TYPE_AUDIO_SINK); + +static void +gst_audio_foo_sink_clear_all (GstAudioSink * sink) +{ + GstAudioFooSink *self = GST_AUDIO_FOO_SINK (sink); + + self->num_clear_all_call++; +} + +static void +gst_audio_foo_sink_init (GstAudioFooSink * src) +{ +} + +static void +gst_audio_foo_sink_class_init (GstAudioFooSinkClass * klass) +{ + GstElementClass *element_class = GST_ELEMENT_CLASS (klass); + GstAudioSinkClass *audiosink_class = GST_AUDIO_SINK_CLASS (klass); + + gst_element_class_add_static_pad_template (element_class, &sink_template); + gst_element_class_set_metadata (element_class, + "AudioFooSink", "Sink/Audio", + "Audio Sink Unit Test element", "Foo Bar "); + + audiosink_class->extension->clear_all = gst_audio_foo_sink_clear_all; +} + +GST_START_TEST (test_class_extension) +{ + GstAudioFooSink *foosink = NULL; + GstAudioBaseSink *bsink; + GstAudioRingBuffer *ringbuffer; + + foosink = g_object_new (GST_TYPE_AUDIO_FOO_SINK, NULL); + fail_unless (foosink != NULL); + + /* change state to READY to prepare audio ringbuffer */ + fail_unless (gst_element_set_state (GST_ELEMENT (foosink), + GST_STATE_READY) == GST_STATE_CHANGE_SUCCESS); + + bsink = GST_AUDIO_BASE_SINK (foosink); + ringbuffer = bsink->ringbuffer; + fail_unless (ringbuffer != NULL); + + /* This will invoke GstAudioSink::clear_all method */ + gst_audio_ring_buffer_clear_all (ringbuffer); + fail_unless_equals_int (foosink->num_clear_all_call, 1); + + gst_element_set_state (GST_ELEMENT (foosink), GST_STATE_NULL); + gst_clear_object (&foosink); +} + +GST_END_TEST; + + +static Suite * +audiosink_suite (void) +{ + Suite *s = suite_create ("audiosink"); + TCase *tc_chain = tcase_create ("general"); + + suite_add_tcase (s, tc_chain); + tcase_add_test (tc_chain, test_class_extension); + + return s; +} + +GST_CHECK_MAIN (audiosink) diff --git a/tests/check/meson.build b/tests/check/meson.build index 81e8b45275..8309bbdd41 100644 --- a/tests/check/meson.build +++ b/tests/check/meson.build @@ -7,6 +7,7 @@ base_tests = [ [ 'libs/audiocdsrc.c' ], [ 'libs/audiodecoder.c' ], [ 'libs/audioencoder.c' ], + [ 'libs/audiosink.c' ], [ 'libs/baseaudiovisualizer.c' ], [ 'libs/discoverer.c' ], [ 'libs/fft.c' ],