4 * unit test for amrnbenc
6 * Copyright (C) 2006 Thomas Vander Stichele <thomas at apestaart dot org>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
24 #include <gst/check/gstcheck.h>
25 #include <gst/audio/audio.h>
27 #define SRC_CAPS "audio/x-raw, format = (string)" GST_AUDIO_NE (S16) ", " \
28 "layout = (string) interleaved, channels = (int) 1, rate = (int) 8000"
29 #define SINK_CAPS "audio/AMR"
31 static GstPad *srcpad, *sinkpad;
33 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
36 GST_STATIC_CAPS (SINK_CAPS)
39 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
42 GST_STATIC_CAPS (SRC_CAPS)
46 buffer_unref (void *buffer, void *user_data)
48 gst_buffer_unref (GST_BUFFER (buffer));
58 GST_DEBUG ("setup_amrnbenc");
60 amrnbenc = gst_check_setup_element ("amrnbenc");
61 srcpad = gst_check_setup_src_pad (amrnbenc, &srctemplate);
62 sinkpad = gst_check_setup_sink_pad (amrnbenc, &sinktemplate);
63 gst_pad_set_active (srcpad, TRUE);
64 gst_pad_set_active (sinkpad, TRUE);
67 gst_element_set_bus (amrnbenc, bus);
69 fail_unless (gst_element_set_state (amrnbenc,
70 GST_STATE_PLAYING) != GST_STATE_CHANGE_FAILURE,
71 "could not set to playing");
73 caps = gst_caps_from_string (SRC_CAPS);
74 gst_check_setup_events (srcpad, amrnbenc, caps, GST_FORMAT_TIME);
75 gst_caps_unref (caps);
82 cleanup_amrnbenc (GstElement * amrnbenc)
86 /* free encoded buffers */
87 g_list_foreach (buffers, buffer_unref, NULL);
88 g_list_free (buffers);
91 bus = GST_ELEMENT_BUS (amrnbenc);
92 gst_bus_set_flushing (bus, TRUE);
93 gst_object_unref (bus);
95 GST_DEBUG ("cleanup_amrnbenc");
96 gst_pad_set_active (srcpad, FALSE);
97 gst_pad_set_active (sinkpad, FALSE);
98 gst_check_teardown_src_pad (amrnbenc);
99 gst_check_teardown_sink_pad (amrnbenc);
100 gst_check_teardown_element (amrnbenc);
103 /* push a random block of audio of the given size */
105 push_data (gint size, GstFlowReturn expected_return)
110 buffer = gst_buffer_new_and_alloc (size);
111 /* make valgrind happier */
112 gst_buffer_memset (buffer, 0, 0, size);
114 res = gst_pad_push (srcpad, buffer);
115 fail_unless (res == expected_return,
116 "pushing audio returned %d (%s) not %d (%s)", res,
117 gst_flow_get_name (res), expected_return,
118 gst_flow_get_name (expected_return));
121 GST_START_TEST (test_enc)
123 GstElement *amrnbenc;
125 amrnbenc = setup_amrnbenc ();
126 push_data (1000, GST_FLOW_OK);
128 cleanup_amrnbenc (amrnbenc);
136 Suite *s = suite_create ("amrnbenc");
137 TCase *tc_chain = tcase_create ("general");
139 suite_add_tcase (s, tc_chain);
140 tcase_add_test (tc_chain, test_enc);
144 GST_CHECK_MAIN (amrnbenc);