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")
53 GST_DEBUG ("setup_xingmux");
54 xingmux = gst_check_setup_element ("xingmux");
55 mysrcpad = gst_check_setup_src_pad (xingmux, &srctemplate);
56 mysinkpad = gst_check_setup_sink_pad (xingmux, &sinktemplate);
57 gst_pad_set_active (mysrcpad, TRUE);
58 gst_pad_set_active (mysinkpad, TRUE);
60 caps = gst_caps_new_simple ("audio/mpeg",
61 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 3, NULL);
62 gst_check_setup_events (mysrcpad, xingmux, caps, GST_FORMAT_TIME);
63 gst_caps_unref (caps);
69 cleanup_xingmux (GstElement * xingmux)
71 GST_DEBUG ("cleanup_xingmux");
73 g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL);
74 g_list_free (buffers);
77 gst_pad_set_active (mysrcpad, FALSE);
78 gst_pad_set_active (mysinkpad, FALSE);
79 gst_check_teardown_src_pad (xingmux);
80 gst_check_teardown_sink_pad (xingmux);
81 gst_check_teardown_element (xingmux);
84 GST_START_TEST (test_xing_remux)
89 const guint8 *verify_data;
91 xingmux = setup_xingmux ();
93 fail_unless (gst_element_set_state (xingmux,
94 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
95 "could not set to playing");
97 inbuffer = gst_buffer_new_and_alloc (sizeof (test_xing));
98 gst_buffer_fill (inbuffer, 0, test_xing, sizeof (test_xing));
100 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
102 /* pushing gives away my reference ... */
103 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
104 fail_unless (gst_pad_push_event (mysrcpad, gst_event_new_eos ()));
105 /* ... and puts a new buffer on the global list */
106 fail_unless_equals_int (g_list_length (buffers), 93);
108 verify_data = test_xing;
109 for (it = buffers; it != NULL; it = it->next) {
110 GstBuffer *outbuffer = (GstBuffer *) it->data;
113 gst_buffer_map (outbuffer, &map, GST_MAP_READ);
118 /* Empty Xing header, should be the same as input data until the "Xing" marker
119 * and zeroes afterwards. */
120 fail_unless (memcmp (map.data, test_xing, 25) == 0);
121 for (j = 26; j < map.size; j++)
122 fail_unless (map.data[j] == 0);
123 verify_data += map.size;
124 } else if (it->next != NULL) {
125 /* Should contain the raw MP3 data without changes */
126 fail_unless (memcmp (map.data, verify_data, map.size) == 0);
127 verify_data += map.size;
129 /* Last buffer is the rewrite of the first buffer and should be exactly the same
130 * as the old Xing header we had */
131 fail_unless (memcmp (test_xing, map.data, map.size) == 0);
133 gst_buffer_unmap (outbuffer, &map);
137 cleanup_xingmux (xingmux);
145 Suite *s = suite_create ("xingmux");
146 TCase *tc_chain = tcase_create ("general");
148 suite_add_tcase (s, tc_chain);
149 tcase_add_test (tc_chain, test_xing_remux);
154 GST_CHECK_MAIN (xingmux);