5 * Copyright (C) 2010, 2012 Alexander Saprykin <xelfium@gmail.com>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
23 /* ------- TOC -------
32 #include <gst/check/gstcheck.h>
34 #define ENTRY_ED1 "/edition1"
35 #define ENTRY_ED2 "/edition2"
36 #define ENTRY_ED3 "test-edition"
38 #define ENTRY_CH1 "/edition1/chapter1"
39 #define ENTRY_CH2 "/edition1/chapter2"
40 #define ENTRY_CH3 "/edition2/chapter3"
41 #define ENTRY_CH4 "/test-chapter"
43 #define ENTRY_SUB1 "/edition2/chapter3/subchapter1"
45 #define ENTRY_TAG "EntryTag"
46 #define TOC_TAG "TocTag"
48 #define TEST_UID "129537542"
49 #define INFO_NAME "gst-toc-check"
50 #define INFO_FIELD "info-test"
51 #define INFO_TEXT_EN "info-text-entry"
52 #define INFO_TEXT_TOC "info-text-toc"
54 #define CHECK_TOC_ENTRY(entry_c,type_c,uid_c) \
58 GstStructure *struct_c; \
60 fail_unless_equals_string (entry_c->uid, uid_c); \
61 fail_unless (entry_c->type == type_c); \
62 fail_unless (entry_c->tags != NULL); \
63 fail_unless (entry_c->pads == NULL); \
65 fail_unless (entry_c->info != NULL); \
66 gst_structure_get (entry_c->info, INFO_NAME, GST_TYPE_STRUCTURE, \
68 fail_unless (struct_c != NULL); \
69 val = gst_structure_get_value (struct_c, INFO_FIELD); \
70 fail_unless (val != NULL); \
71 fail_unless_equals_string (g_value_get_string (val), INFO_TEXT_EN); \
73 fail_unless (gst_tag_list_get_string (entry_c->tags, \
74 GST_TAG_TITLE, &tag_c)); \
75 fail_unless_equals_string (tag_c, ENTRY_TAG); \
77 gst_structure_free (struct_c); \
80 #define CHECK_TOC(toc_t) \
82 GstTocEntry *entry_t, *subentry_t; \
85 GstStructure *struct_toc; \
88 fail_unless (g_list_length (toc_t->entries) == 2); \
89 fail_unless (toc_t->tags != NULL); \
90 fail_unless (gst_tag_list_get_string (toc_t->tags, \
91 GST_TAG_TITLE, &tag_t)); \
92 fail_unless_equals_string (tag_t, TOC_TAG); \
95 fail_unless (toc_t->info != NULL); \
96 gst_structure_get (toc_t->info, INFO_NAME, GST_TYPE_STRUCTURE, \
98 fail_unless (struct_toc != NULL); \
99 val = gst_structure_get_value (struct_toc, INFO_FIELD); \
100 fail_unless (val != NULL); \
101 fail_unless_equals_string (g_value_get_string (val), INFO_TEXT_TOC); \
102 gst_structure_free (struct_toc); \
104 /* check edition1 */ \
105 entry_t = g_list_nth_data (toc_t->entries, 0); \
106 fail_if (entry_t == NULL); \
107 fail_unless (g_list_length (entry_t->subentries) == 2); \
108 CHECK_TOC_ENTRY (entry_t, GST_TOC_ENTRY_TYPE_EDITION, ENTRY_ED1); \
109 /* check chapter1 */ \
110 subentry_t = g_list_nth_data (entry_t->subentries, 0); \
111 fail_if (subentry_t == NULL); \
112 fail_unless (g_list_length (subentry_t->subentries) == 0); \
113 CHECK_TOC_ENTRY (subentry_t, GST_TOC_ENTRY_TYPE_CHAPTER, ENTRY_CH1); \
114 /* check chapter2 */ \
115 subentry_t = g_list_nth_data (entry_t->subentries, 1); \
116 fail_if (subentry_t == NULL); \
117 fail_unless (g_list_length (subentry_t->subentries) == 0); \
118 CHECK_TOC_ENTRY (subentry_t, GST_TOC_ENTRY_TYPE_CHAPTER, ENTRY_CH2); \
119 /* check edition2 */ \
120 entry_t = g_list_nth_data (toc_t->entries, 1); \
121 fail_if (entry_t == NULL); \
122 fail_unless (g_list_length (entry_t->subentries) == 1); \
123 CHECK_TOC_ENTRY (entry_t, GST_TOC_ENTRY_TYPE_EDITION, ENTRY_ED2); \
124 /* check chapter3 */ \
125 subentry_t = g_list_nth_data (entry_t->subentries, 0); \
126 fail_if (subentry_t == NULL); \
127 fail_unless (g_list_length (subentry_t->subentries) == 1); \
128 CHECK_TOC_ENTRY (subentry_t, GST_TOC_ENTRY_TYPE_CHAPTER, ENTRY_CH3); \
129 /* check subchapter1 */ \
130 subentry_t = g_list_nth_data (subentry_t->subentries, 0); \
131 fail_if (subentry_t == NULL); \
132 fail_unless (g_list_length (subentry_t->subentries) == 0); \
133 CHECK_TOC_ENTRY (subentry_t, GST_TOC_ENTRY_TYPE_CHAPTER, ENTRY_SUB1); \
136 /* This whole test is a bit pointless now that we just stuff a ref of
137 * the original TOC into the message/query/event */
138 GST_START_TEST (test_serializing)
140 GstStructure *structure;
141 GstToc *toc, *test_toc = NULL;
142 GstTocEntry *ed, *ch, *subch;
148 gint64 start = -1, stop = -1;
150 toc = gst_toc_new ();
151 fail_if (toc == NULL);
152 gst_tag_list_add (toc->tags, GST_TAG_MERGE_APPEND, GST_TAG_TITLE,
155 gst_structure_new (INFO_NAME, INFO_FIELD, G_TYPE_STRING, INFO_TEXT_TOC,
157 gst_structure_set (toc->info, INFO_NAME, GST_TYPE_STRUCTURE, structure, NULL);
158 gst_structure_free (structure);
160 /* create edition1 */
161 ed = gst_toc_entry_new (GST_TOC_ENTRY_TYPE_EDITION, ENTRY_ED1);
162 fail_if (ed == NULL);
163 gst_tag_list_add (ed->tags, GST_TAG_MERGE_APPEND, GST_TAG_TITLE,
166 gst_structure_new (INFO_NAME, INFO_FIELD, G_TYPE_STRING, INFO_TEXT_EN,
168 gst_structure_set (ed->info, INFO_NAME, GST_TYPE_STRUCTURE, structure, NULL);
169 gst_structure_free (structure);
171 CHECK_TOC_ENTRY (ed, GST_TOC_ENTRY_TYPE_EDITION, ENTRY_ED1);
173 /* append chapter1 to edition1 */
174 ch = gst_toc_entry_new (GST_TOC_ENTRY_TYPE_CHAPTER, ENTRY_CH1);
175 fail_if (ch == NULL);
176 gst_tag_list_add (ch->tags, GST_TAG_MERGE_APPEND, GST_TAG_TITLE,
179 gst_structure_new (INFO_NAME, INFO_FIELD, G_TYPE_STRING, INFO_TEXT_EN,
181 gst_structure_set (ch->info, INFO_NAME, GST_TYPE_STRUCTURE, structure, NULL);
182 gst_structure_free (structure);
184 CHECK_TOC_ENTRY (ch, GST_TOC_ENTRY_TYPE_CHAPTER, ENTRY_CH1);
186 ed->subentries = g_list_append (ed->subentries, ch);
187 fail_unless (g_list_length (ed->subentries) == 1);
189 /* append chapter2 to edition1 */
190 ch = gst_toc_entry_new (GST_TOC_ENTRY_TYPE_CHAPTER, ENTRY_CH2);
191 fail_if (ch == NULL);
192 gst_tag_list_add (ch->tags, GST_TAG_MERGE_APPEND, GST_TAG_TITLE,
195 gst_structure_new (INFO_NAME, INFO_FIELD, G_TYPE_STRING, INFO_TEXT_EN,
197 gst_structure_set (ch->info, INFO_NAME, GST_TYPE_STRUCTURE, structure, NULL);
198 gst_structure_free (structure);
200 CHECK_TOC_ENTRY (ch, GST_TOC_ENTRY_TYPE_CHAPTER, ENTRY_CH2);
202 ed->subentries = g_list_append (ed->subentries, ch);
203 fail_unless (g_list_length (ed->subentries) == 2);
205 /* append edition1 to the TOC */
206 toc->entries = g_list_append (toc->entries, ed);
207 fail_unless (g_list_length (toc->entries) == 1);
209 /* test gst_toc_entry_find() */
211 ed = gst_toc_find_entry (toc, ENTRY_ED1);
213 fail_if (ed == NULL);
215 CHECK_TOC_ENTRY (ed, GST_TOC_ENTRY_TYPE_EDITION, ENTRY_ED1);
217 /* test info GstStructure */
218 gst_toc_entry_set_start_stop (ch, 100, 1000);
219 fail_if (!gst_toc_entry_get_start_stop (ch, &start, &stop));
220 fail_unless (start == 100);
221 fail_unless (stop == 1000);
223 /* create edition2 */
224 ed = gst_toc_entry_new (GST_TOC_ENTRY_TYPE_EDITION, ENTRY_ED2);
225 fail_if (ed == NULL);
226 gst_tag_list_add (ed->tags, GST_TAG_MERGE_APPEND, GST_TAG_TITLE,
229 gst_structure_new (INFO_NAME, INFO_FIELD, G_TYPE_STRING, INFO_TEXT_EN,
231 gst_structure_set (ed->info, INFO_NAME, GST_TYPE_STRUCTURE, structure, NULL);
232 gst_structure_free (structure);
234 CHECK_TOC_ENTRY (ed, GST_TOC_ENTRY_TYPE_EDITION, ENTRY_ED2);
236 /* create chapter3 */
237 ch = gst_toc_entry_new (GST_TOC_ENTRY_TYPE_CHAPTER, ENTRY_CH3);
238 fail_if (ch == NULL);
239 gst_tag_list_add (ch->tags, GST_TAG_MERGE_APPEND, GST_TAG_TITLE,
242 gst_structure_new (INFO_NAME, INFO_FIELD, G_TYPE_STRING, INFO_TEXT_EN,
244 gst_structure_set (ch->info, INFO_NAME, GST_TYPE_STRUCTURE, structure, NULL);
245 gst_structure_free (structure);
247 CHECK_TOC_ENTRY (ch, GST_TOC_ENTRY_TYPE_CHAPTER, ENTRY_CH3);
249 /* create subchapter1 */
250 subch = gst_toc_entry_new (GST_TOC_ENTRY_TYPE_CHAPTER, ENTRY_SUB1);
251 fail_if (subch == NULL);
252 gst_tag_list_add (subch->tags, GST_TAG_MERGE_APPEND, GST_TAG_TITLE,
255 gst_structure_new (INFO_NAME, INFO_FIELD, G_TYPE_STRING, INFO_TEXT_EN,
257 gst_structure_set (subch->info, INFO_NAME, GST_TYPE_STRUCTURE, structure,
259 gst_structure_free (structure);
261 CHECK_TOC_ENTRY (subch, GST_TOC_ENTRY_TYPE_CHAPTER, ENTRY_SUB1);
263 /* append subchapter1 to chapter3 */
264 ch->subentries = g_list_append (ch->subentries, subch);
265 fail_unless (g_list_length (ch->subentries) == 1);
267 /* append chapter3 to edition2 */
268 ed->subentries = g_list_append (ed->subentries, ch);
269 fail_unless (g_list_length (ed->subentries) == 1);
271 /* finally append edition2 to the TOC */
272 toc->entries = g_list_append (toc->entries, ed);
273 fail_unless (g_list_length (toc->entries) == 2);
275 /* test gst_toc_copy() */
276 test_toc = gst_toc_copy (toc);
277 fail_if (test_toc == NULL);
278 CHECK_TOC (test_toc);
279 gst_toc_unref (test_toc);
282 /* check TOC event handling */
283 event = gst_event_new_toc (toc, TRUE);
284 fail_if (event == NULL);
285 fail_unless (event->type == GST_EVENT_TOC);
286 ASSERT_MINI_OBJECT_REFCOUNT (GST_MINI_OBJECT (event), "GstEvent", 1);
288 gst_event_parse_toc (event, &test_toc, &updated);
289 fail_unless (updated == TRUE);
290 fail_if (test_toc == NULL);
291 CHECK_TOC (test_toc);
292 gst_toc_unref (test_toc);
293 gst_event_unref (event);
297 /* check TOC message handling */
298 message = gst_message_new_toc (NULL, toc, TRUE);
299 fail_if (message == NULL);
300 fail_unless (message->type == GST_MESSAGE_TOC);
301 ASSERT_MINI_OBJECT_REFCOUNT (GST_MINI_OBJECT (message), "GstMessage", 1);
303 gst_message_parse_toc (message, &test_toc, &updated);
304 fail_unless (updated == TRUE);
305 fail_if (test_toc == NULL);
306 CHECK_TOC (test_toc);
307 gst_toc_unref (test_toc);
308 gst_message_unref (message);
311 /* check TOC select event handling */
312 event = gst_event_new_toc_select (TEST_UID);
313 fail_if (event == NULL);
314 fail_unless (event->type == GST_EVENT_TOC_SELECT);
315 ASSERT_MINI_OBJECT_REFCOUNT (GST_MINI_OBJECT (event), "GstEvent", 1);
317 gst_event_parse_toc_select (event, &uid);
318 fail_unless_equals_string (uid, TEST_UID);
319 gst_event_unref (event);
322 /* check TOC query handling */
323 query = gst_query_new_toc ();
324 fail_if (query == NULL);
325 gst_query_set_toc (query, toc, TEST_UID);
326 fail_unless (query->type == GST_QUERY_TOC);
327 ASSERT_MINI_OBJECT_REFCOUNT (GST_MINI_OBJECT (query), "GstQuery", 1);
329 gst_query_parse_toc (query, &test_toc, &uid);
330 fail_unless_equals_string (uid, TEST_UID);
331 fail_if (test_toc == NULL);
332 CHECK_TOC (test_toc);
333 gst_toc_unref (test_toc);
334 gst_query_unref (query);
337 /* FIXME: toc validation / verification should probably be done on the fly
338 * while creating it, and not when putting the toc in events or messages ? */
340 /* that's wrong code, we should fail */
341 ch = gst_toc_entry_new (GST_TOC_ENTRY_TYPE_CHAPTER, ENTRY_CH4);
342 toc->entries = g_list_prepend (toc->entries, ch);
343 ASSERT_CRITICAL (message = gst_message_new_toc (NULL, toc, TRUE));
345 /* and yet another one */
346 toc->entries = g_list_remove (toc->entries, ch);
347 gst_toc_entry_unref (ch);
348 ed = gst_toc_entry_new (GST_TOC_ENTRY_TYPE_EDITION, ENTRY_ED3);
349 ch = (GstTocEntry *) (toc->entries->data);
350 ch->subentries = g_list_prepend (ch->subentries, ed);
351 ASSERT_WARNING (message = gst_message_new_toc (NULL, toc, TRUE));
362 Suite *s = suite_create ("GstToc");
363 TCase *tc_chain = tcase_create ("general");
365 suite_add_tcase (s, tc_chain);
366 tcase_add_test (tc_chain, test_serializing);
371 GST_CHECK_MAIN (gst_toc);