1 /* GStreamer MulawDec unit tests
2 *
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Library General Public
5 * License as published by the Free Software Foundation; either
6 * version 2 of the License, or (at your option) any later version.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Library General Public License for more details.
12 *
13 * You should have received a copy of the GNU Library General Public
14 * License along with this library; if not, write to the
15 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
16 * Boston, MA 02110-1301, USA.
17 */
18 #ifdef HAVE_CONFIG_H
19 #include "config.h"
20 #endif
21
22 #include <gst/check/gstcheck.h>
23 #include <gst/audio/audio.h>
24 #include <string.h>
25
26 static GstPad *mysrcpad, *mysinkpad;
27 static GstElement *mulawdec = NULL;
28
29 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
30 GST_PAD_SINK,
31 GST_PAD_ALWAYS,
32 GST_STATIC_CAPS ("audio/x-raw,"
33 "format = (string) " GST_AUDIO_NE (S16) ", "
34 "rate = (int) 8000, "
35 "channels = (int) 1, " "layout = (string)interleaved")
36 );
37
38 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
39 GST_PAD_SRC,
40 GST_PAD_ALWAYS,
41 GST_STATIC_CAPS ("audio/x-mulaw," "rate = (int) 8000," "channels = (int) 1")
42 );
43
44 static void
mulawdec_setup(void)45 mulawdec_setup (void)
46 {
47 GstCaps *src_caps;
48
49 src_caps =
50 gst_caps_from_string ("audio/x-mulaw," "rate = (int) 8000,"
51 "channels = (int) 1");
52
53 GST_DEBUG ("%s", __FUNCTION__);
54
55 mulawdec = gst_check_setup_element ("mulawdec");
56
57 mysrcpad = gst_check_setup_src_pad (mulawdec, &srctemplate);
58 mysinkpad = gst_check_setup_sink_pad (mulawdec, &sinktemplate);
59
60 gst_pad_set_active (mysrcpad, TRUE);
61 gst_pad_set_active (mysinkpad, TRUE);
62
63 gst_check_setup_events (mysrcpad, mulawdec, src_caps, GST_FORMAT_TIME);
64
65 gst_caps_unref (src_caps);
66 }
67
68 static void
buffer_unref(void * buffer,void * user_data)69 buffer_unref (void *buffer, void *user_data)
70 {
71 gst_buffer_unref (GST_BUFFER (buffer));
72 }
73
74 static void
mulawdec_teardown(void)75 mulawdec_teardown (void)
76 {
77 /* free decoded buffers */
78 g_list_foreach (buffers, buffer_unref, NULL);
79 g_list_free (buffers);
80 buffers = NULL;
81
82 gst_pad_set_active (mysrcpad, FALSE);
83 gst_pad_set_active (mysinkpad, FALSE);
84 gst_check_teardown_src_pad (mulawdec);
85 gst_check_teardown_sink_pad (mulawdec);
86 gst_check_teardown_element (mulawdec);
87 mulawdec = NULL;
88 }
89
GST_START_TEST(test_one_buffer)90 GST_START_TEST (test_one_buffer)
91 {
92 GstBuffer *buffer;
93 gint buf_size = 4096;
94 guint8 *dp;
95
96 fail_unless (gst_element_set_state (mulawdec, GST_STATE_PLAYING) ==
97 GST_STATE_CHANGE_SUCCESS, "could not change state to playing");
98
99 buffer = gst_buffer_new ();
100 dp = g_malloc0 (buf_size);
101 gst_buffer_append_memory (buffer,
102 gst_memory_new_wrapped (0, dp, buf_size, 0, buf_size, dp, g_free));
103 ASSERT_BUFFER_REFCOUNT (buffer, "buffer", 1);
104
105 fail_unless (gst_pad_push (mysrcpad, buffer) == GST_FLOW_OK);
106
107 fail_unless (g_list_length (buffers) == 1);
108 fail_unless (gst_buffer_get_size (GST_BUFFER (g_list_first (buffers)->data)));
109 }
110
111 GST_END_TEST;
112
113 static Suite *
mulawdec_suite(void)114 mulawdec_suite (void)
115 {
116 Suite *s = suite_create ("mulawdec");
117 TCase *tc_chain = tcase_create ("mulawdec");
118
119 tcase_add_checked_fixture (tc_chain, mulawdec_setup, mulawdec_teardown);
120
121 suite_add_tcase (s, tc_chain);
122 tcase_add_test (tc_chain, test_one_buffer);
123 return s;
124 }
125
126 GST_CHECK_MAIN (mulawdec)
127