3 * Copyright (C) 2008 Sebastian Dröge <slomo@circular-chaos.org>
5 * xingmux.c: Unit test for the xingmux element
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public License
9 * as published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 #include <gst/base/gstbasetransform.h>
25 #include <gst/check/gstcheck.h>
29 #include "xingmux_testdata.h"
31 /* For ease of programming we use globals to keep refs for our floating
32 * src and sink pads we create; otherwise we always have to do get_pad,
33 * get_peer, and then remove references in every test function */
34 GstPad *mysrcpad, *mysinkpad;
36 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
39 GST_STATIC_CAPS ("audio/mpeg, " "mpegversion = (int) 1," "layer = (int) 3")
41 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
44 GST_STATIC_CAPS ("audio/mpeg, " "mpegversion = (int) 1," "layer = (int) 3")
52 GST_DEBUG ("setup_xingmux");
53 xingmux = gst_check_setup_element ("xingmux");
54 mysrcpad = gst_check_setup_src_pad (xingmux, &srctemplate, NULL);
55 mysinkpad = gst_check_setup_sink_pad (xingmux, &sinktemplate, NULL);
56 gst_pad_set_active (mysrcpad, TRUE);
57 gst_pad_set_active (mysinkpad, TRUE);
63 cleanup_xingmux (GstElement * xingmux)
65 GST_DEBUG ("cleanup_xingmux");
67 g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL);
68 g_list_free (buffers);
71 gst_pad_set_active (mysrcpad, FALSE);
72 gst_pad_set_active (mysinkpad, FALSE);
73 gst_check_teardown_src_pad (xingmux);
74 gst_check_teardown_sink_pad (xingmux);
75 gst_check_teardown_element (xingmux);
78 GST_START_TEST (test_xing_remux)
83 const guint8 *verify_data;
85 xingmux = setup_xingmux ();
87 fail_unless (gst_element_set_state (xingmux,
88 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
89 "could not set to playing");
91 inbuffer = gst_buffer_new_and_alloc (sizeof (test_xing));
92 memcpy (GST_BUFFER_DATA (inbuffer), test_xing, sizeof (test_xing));
94 gst_buffer_set_caps (inbuffer, GST_PAD_CAPS (mysrcpad));
95 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
97 /* pushing gives away my reference ... */
98 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
99 fail_unless (gst_pad_push_event (mysrcpad, gst_event_new_eos ()));
100 /* ... and puts a new buffer on the global list */
101 fail_unless_equals_int (g_list_length (buffers), 93);
103 verify_data = test_xing;
104 for (it = buffers; it != NULL; it = it->next) {
105 GstBuffer *outbuffer = (GstBuffer *) it->data;
110 /* Empty Xing header, should be the same as input data until the "Xing" marker
111 * and zeroes afterwards. */
112 fail_unless (memcmp (test_xing, GST_BUFFER_DATA (outbuffer), 25) == 0);
113 for (j = 26; j < GST_BUFFER_SIZE (outbuffer); j++)
114 fail_unless (GST_BUFFER_DATA (outbuffer)[j] == 0);
115 verify_data += GST_BUFFER_SIZE (outbuffer);
116 } else if (it->next != NULL) {
117 /* Should contain the raw MP3 data without changes */
118 fail_unless (memcmp (verify_data, GST_BUFFER_DATA (outbuffer),
119 GST_BUFFER_SIZE (outbuffer)) == 0);
120 verify_data += GST_BUFFER_SIZE (outbuffer);
122 /* Last buffer is the rewrite of the first buffer and should be exactly the same
123 * as the old Xing header we had */
124 fail_unless (memcmp (test_xing, GST_BUFFER_DATA (outbuffer),
125 GST_BUFFER_SIZE (outbuffer)) == 0);
130 cleanup_xingmux (xingmux);
138 Suite *s = suite_create ("xingmux");
139 TCase *tc_chain = tcase_create ("general");
141 suite_add_tcase (s, tc_chain);
142 tcase_add_test (tc_chain, test_xing_remux);
148 main (int argc, char **argv)
152 Suite *s = xingmux_suite ();
153 SRunner *sr = srunner_create (s);
155 gst_check_init (&argc, &argv);
157 srunner_run_all (sr, CK_NORMAL);
158 nf = srunner_ntests_failed (sr);