1 /* GStreamer unit tests for id3demux
3 * Copyright (C) 2007 Tim-Philipp Müller <tim centricular net>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
21 #include <gst/check/gstcheck.h>
25 typedef void (CheckTagsFunc) (const GstTagList * tags, const gchar * file);
28 pad_added_cb (GstElement * id3demux, GstPad * pad, GstBin * pipeline)
32 sink = gst_bin_get_by_name (pipeline, "fakesink");
33 fail_unless (gst_element_link (id3demux, sink));
34 gst_object_unref (sink);
36 gst_element_set_state (sink, GST_STATE_PAUSED);
39 static GstBusSyncReply
40 error_cb (GstBus * bus, GstMessage * msg, gpointer user_data)
42 if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR) {
43 const gchar *file = (const gchar *) user_data;
47 gst_message_parse_error (msg, &err, &dbg);
48 g_error ("ERROR for %s: %s\n%s\n", file, err->message, dbg);
55 read_tags_from_file (const gchar * file, gboolean push_mode)
57 GstStateChangeReturn state_ret;
58 GstTagList *tags = NULL;
60 GstElement *src, *sep, *sink, *id3demux, *pipeline;
64 pipeline = gst_pipeline_new ("pipeline");
65 fail_unless (pipeline != NULL, "Failed to create pipeline!");
67 bus = gst_element_get_bus (pipeline);
69 /* kids, don't use a sync handler for this at home, really; we do because
70 * we just want to abort and nothing else */
71 gst_bus_set_sync_handler (bus, error_cb, (gpointer) file);
73 src = gst_element_factory_make ("filesrc", "filesrc");
74 fail_unless (src != NULL, "Failed to create 'filesrc' element!");
77 sep = gst_element_factory_make ("queue", "queue");
78 fail_unless (sep != NULL, "Failed to create 'queue' element");
80 sep = gst_element_factory_make ("identity", "identity");
81 fail_unless (sep != NULL, "Failed to create 'identity' element");
84 id3demux = gst_element_factory_make ("id3demux", "id3demux");
85 fail_unless (id3demux != NULL, "Failed to create 'id3demux' element!");
87 sink = gst_element_factory_make ("fakesink", "fakesink");
88 fail_unless (sink != NULL, "Failed to create 'fakesink' element!");
90 gst_bin_add_many (GST_BIN (pipeline), src, sep, id3demux, sink, NULL);
92 fail_unless (gst_element_link (src, sep));
93 fail_unless (gst_element_link (sep, id3demux));
95 /* can't link id3demux and sink yet, do that later */
96 g_signal_connect (id3demux, "pad-added", G_CALLBACK (pad_added_cb), pipeline);
98 path = g_build_filename (GST_TEST_FILES_PATH, file, NULL);
99 GST_LOG ("reading file '%s'", path);
100 g_object_set (src, "location", path, NULL);
102 state_ret = gst_element_set_state (pipeline, GST_STATE_PAUSED);
103 fail_unless (state_ret != GST_STATE_CHANGE_FAILURE);
105 if (state_ret == GST_STATE_CHANGE_ASYNC) {
106 GST_LOG ("waiting for pipeline to reach PAUSED state");
107 state_ret = gst_element_get_state (pipeline, NULL, NULL, -1);
108 fail_unless_equals_int (state_ret, GST_STATE_CHANGE_SUCCESS);
111 GST_LOG ("PAUSED, let's retrieve our tags");
113 msg = gst_bus_poll (bus, GST_MESSAGE_TAG, -1);
114 fail_unless (msg != NULL, "Expected TAG message on bus! (%s)", file);
116 gst_message_parse_tag (msg, &tags);
117 fail_unless (tags != NULL, "TAG message did not contain taglist! (%s)", file);
119 gst_message_unref (msg);
120 gst_object_unref (bus);
122 fail_unless_equals_int (gst_element_set_state (pipeline, GST_STATE_NULL),
123 GST_STATE_CHANGE_SUCCESS);
124 gst_object_unref (pipeline);
128 GST_INFO ("%s: tags = %" GST_PTR_FORMAT, file, tags);
133 run_check_for_file (const gchar * filename, CheckTagsFunc * check_func)
137 /* first, pull-based */
138 tags = read_tags_from_file (filename, FALSE);
139 fail_unless (tags != NULL, "Failed to extract tags from '%s'", filename);
140 check_func (tags, filename);
141 gst_tag_list_free (tags);
143 /* FIXME: need to fix id3demux for short content in push mode */
145 /* now try push-based */
146 tags = read_tags_from_file (filename, TRUE);
147 fail_unless (tags != NULL, "Failed to extract tags from '%s'", filename);
148 check_func (tags, filename);
149 gst_tag_list_free (tags);
154 check_date_1977_06_23 (const GstTagList * tags, const gchar * file)
158 gst_tag_list_get_date (tags, GST_TAG_DATE, &date);
159 fail_unless (date != NULL, "Tags from %s should contain a GST_TAG_DATE tag");
160 fail_unless_equals_int (g_date_get_year (date), 1977);
161 fail_unless_equals_int (g_date_get_month (date), 6);
162 fail_unless_equals_int (g_date_get_day (date), 23);
166 GST_START_TEST (test_tdat_tyer)
168 run_check_for_file ("id3-407349-1.tag", check_date_1977_06_23);
169 run_check_for_file ("id3-407349-2.tag", check_date_1977_06_23);
175 check_wcop (const GstTagList * tags, const gchar * file)
177 gchar *copyright = NULL;
180 fail_unless (gst_tag_list_get_string (tags, GST_TAG_LICENSE_URI, &uri));
181 fail_unless (uri != NULL);
182 fail_unless_equals_string (uri,
183 "http://creativecommons.org/licenses/by/3.0/");
186 fail_unless (gst_tag_list_get_string (tags, GST_TAG_COPYRIGHT, ©right));
187 fail_unless (copyright != NULL);
188 fail_unless_equals_string (copyright,
189 " Steadman. Licensed to the public under http://creativecommons.org/licenses/by/3.0/ verify at http://test.com");
193 GST_START_TEST (test_wcop)
195 run_check_for_file ("id3-447000-wcop.tag", check_wcop);
201 check_unsync_v23 (const GstTagList * tags, const gchar * file)
205 gchar *artist = NULL;
207 fail_unless (gst_tag_list_get_string (tags, GST_TAG_TITLE, &title));
208 fail_unless (title != NULL);
209 fail_unless_equals_string (title, "ARTIST"); /* sic */
212 fail_unless (gst_tag_list_get_string (tags, GST_TAG_ALBUM, &album));
213 fail_unless (album != NULL);
214 fail_unless_equals_string (album, "Album");
217 fail_unless (gst_tag_list_get_string (tags, GST_TAG_ARTIST, &artist));
218 fail_unless (artist != NULL);
219 fail_unless_equals_string (artist, "藝人");
223 GST_START_TEST (test_unsync_v23)
225 run_check_for_file ("id3-577468-unsynced-tag.tag", check_unsync_v23);
231 check_unsync_v24 (const GstTagList * tags, const gchar * file)
237 gchar *artist = NULL;
239 fail_unless (gst_tag_list_get_string (tags, GST_TAG_TITLE, &title));
240 fail_unless (title != NULL);
241 fail_unless_equals_string (title, "Starlight");
244 fail_unless (gst_tag_list_get_string (tags, GST_TAG_ALBUM, &album));
245 fail_unless (album != NULL);
246 fail_unless_equals_string (album, "L'albumRockVol.4 CD1");
249 fail_unless (gst_tag_list_get_string (tags, GST_TAG_ARTIST, &artist));
250 fail_unless (artist != NULL);
251 fail_unless_equals_string (artist, "Muse");
254 val = gst_tag_list_get_value_index (tags, GST_TAG_IMAGE, 0);
255 fail_unless (val != NULL);
256 fail_unless (GST_VALUE_HOLDS_BUFFER (val));
257 buf = gst_value_get_buffer (val);
258 fail_unless (buf != NULL);
259 fail_unless (GST_BUFFER_CAPS (buf) != NULL);
260 fail_unless_equals_int (GST_BUFFER_SIZE (buf), 38022);
261 /* check for jpeg start/end markers */
262 fail_unless_equals_int (GST_BUFFER_DATA (buf)[0], 0xff);
263 fail_unless_equals_int (GST_BUFFER_DATA (buf)[1], 0xd8);
264 fail_unless_equals_int (GST_BUFFER_DATA (buf)[38020], 0xff);
265 fail_unless_equals_int (GST_BUFFER_DATA (buf)[38021], 0xd9);
268 GST_START_TEST (test_unsync_v24)
270 run_check_for_file ("id3-588148-unsynced-v24.tag", check_unsync_v24);
276 id3demux_suite (void)
278 Suite *s = suite_create ("id3demux");
279 TCase *tc_chain = tcase_create ("general");
281 suite_add_tcase (s, tc_chain);
282 tcase_add_test (tc_chain, test_tdat_tyer);
283 tcase_add_test (tc_chain, test_wcop);
284 tcase_add_test (tc_chain, test_unsync_v23);
285 tcase_add_test (tc_chain, test_unsync_v24);
290 GST_CHECK_MAIN (id3demux)