2012-03-14 17:12:22 +00:00
|
|
|
/* GStreamer
|
|
|
|
*
|
|
|
|
* unit test for GstToc
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010, 2012 Alexander Saprykin <xelfium@gmail.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* ------- TOC -------
|
|
|
|
* / \
|
|
|
|
* edition1 edition2
|
|
|
|
* | |
|
|
|
|
* -chapter1 -chapter3
|
|
|
|
* -chapter2 |
|
|
|
|
* -subchapter1
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <gst/check/gstcheck.h>
|
|
|
|
|
|
|
|
#define ENTRY_ED1 "/edition1"
|
|
|
|
#define ENTRY_ED2 "/edition2"
|
|
|
|
#define ENTRY_ED3 "test-edition"
|
|
|
|
|
|
|
|
#define ENTRY_CH1 "/edition1/chapter1"
|
|
|
|
#define ENTRY_CH2 "/edition1/chapter2"
|
|
|
|
#define ENTRY_CH3 "/edition2/chapter3"
|
|
|
|
#define ENTRY_CH4 "/test-chapter"
|
|
|
|
|
|
|
|
#define ENTRY_SUB1 "/edition2/chapter3/subchapter1"
|
|
|
|
|
|
|
|
#define ENTRY_TAG "EntryTag"
|
|
|
|
#define TOC_TAG "TocTag"
|
|
|
|
|
|
|
|
#define TEST_UID "129537542"
|
|
|
|
|
|
|
|
#define CHECK_TOC_ENTRY(entry_c,type_c,uid_c) \
|
|
|
|
{ \
|
2012-07-03 16:45:05 +00:00
|
|
|
GstTagList *tags; \
|
2012-03-14 17:12:22 +00:00
|
|
|
gchar *tag_c; \
|
|
|
|
\
|
2012-07-03 16:45:05 +00:00
|
|
|
fail_unless_equals_string (gst_toc_entry_get_uid (entry_c), uid_c); \
|
|
|
|
fail_unless (gst_toc_entry_get_entry_type (entry_c) == type_c); \
|
2012-03-14 17:12:22 +00:00
|
|
|
\
|
2012-07-03 16:45:05 +00:00
|
|
|
tags = gst_toc_entry_get_tags (entry_c); \
|
|
|
|
fail_unless (tags != NULL); \
|
|
|
|
fail_unless (gst_tag_list_get_string (tags, \
|
|
|
|
GST_TAG_TITLE, &tag_c)); \
|
2012-03-14 17:12:22 +00:00
|
|
|
fail_unless_equals_string (tag_c, ENTRY_TAG); \
|
2012-04-10 10:16:50 +00:00
|
|
|
g_free (tag_c); \
|
2012-03-14 17:12:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define CHECK_TOC(toc_t) \
|
|
|
|
{ \
|
|
|
|
GstTocEntry *entry_t, *subentry_t; \
|
2012-07-03 16:45:05 +00:00
|
|
|
GstTagList *tags; \
|
|
|
|
GList *entries, *subentries, *subsubentries; \
|
2012-03-14 17:12:22 +00:00
|
|
|
gchar *tag_t; \
|
2012-04-10 10:16:50 +00:00
|
|
|
\
|
2012-03-14 17:12:22 +00:00
|
|
|
/* check TOC */ \
|
2012-07-03 16:45:05 +00:00
|
|
|
tags = gst_toc_get_tags (toc_t); \
|
|
|
|
fail_unless (tags != NULL); \
|
|
|
|
fail_unless (gst_tag_list_get_string (tags, \
|
|
|
|
GST_TAG_TITLE, &tag_t)); \
|
2012-03-14 17:12:22 +00:00
|
|
|
fail_unless_equals_string (tag_t, TOC_TAG); \
|
2012-04-10 10:16:50 +00:00
|
|
|
g_free (tag_t); \
|
2012-03-14 17:12:22 +00:00
|
|
|
\
|
2012-07-03 16:45:05 +00:00
|
|
|
entries = gst_toc_get_entries (toc_t); \
|
|
|
|
fail_unless_equals_int (g_list_length (entries), 2); \
|
2012-03-14 17:12:22 +00:00
|
|
|
/* check edition1 */ \
|
2012-07-03 16:45:05 +00:00
|
|
|
entry_t = g_list_nth_data (entries, 0); \
|
2012-03-14 17:12:22 +00:00
|
|
|
fail_if (entry_t == NULL); \
|
2012-07-03 16:45:05 +00:00
|
|
|
subentries = gst_toc_entry_get_sub_entries (entry_t); \
|
|
|
|
fail_unless_equals_int (g_list_length (subentries), 2); \
|
2012-03-14 17:12:22 +00:00
|
|
|
CHECK_TOC_ENTRY (entry_t, GST_TOC_ENTRY_TYPE_EDITION, ENTRY_ED1); \
|
|
|
|
/* check chapter1 */ \
|
2012-07-03 16:45:05 +00:00
|
|
|
subentry_t = g_list_nth_data (subentries, 0); \
|
2012-03-14 17:12:22 +00:00
|
|
|
fail_if (subentry_t == NULL); \
|
2012-07-03 16:45:05 +00:00
|
|
|
subsubentries = gst_toc_entry_get_sub_entries (subentry_t); \
|
|
|
|
fail_unless_equals_int (g_list_length (subsubentries), 0); \
|
2012-03-14 17:12:22 +00:00
|
|
|
CHECK_TOC_ENTRY (subentry_t, GST_TOC_ENTRY_TYPE_CHAPTER, ENTRY_CH1); \
|
|
|
|
/* check chapter2 */ \
|
2012-07-03 16:45:05 +00:00
|
|
|
subentry_t = g_list_nth_data (subentries, 1); \
|
2012-03-14 17:12:22 +00:00
|
|
|
fail_if (subentry_t == NULL); \
|
2012-07-03 16:45:05 +00:00
|
|
|
subsubentries = gst_toc_entry_get_sub_entries (subentry_t); \
|
|
|
|
fail_unless_equals_int (g_list_length (subsubentries), 0); \
|
2012-03-14 17:12:22 +00:00
|
|
|
CHECK_TOC_ENTRY (subentry_t, GST_TOC_ENTRY_TYPE_CHAPTER, ENTRY_CH2); \
|
|
|
|
/* check edition2 */ \
|
2012-07-03 16:45:05 +00:00
|
|
|
entry_t = g_list_nth_data (entries, 1); \
|
2012-03-14 17:12:22 +00:00
|
|
|
fail_if (entry_t == NULL); \
|
2012-07-03 16:45:05 +00:00
|
|
|
subentries = gst_toc_entry_get_sub_entries (entry_t); \
|
|
|
|
fail_unless_equals_int (g_list_length (subentries), 1); \
|
2012-03-14 17:12:22 +00:00
|
|
|
CHECK_TOC_ENTRY (entry_t, GST_TOC_ENTRY_TYPE_EDITION, ENTRY_ED2); \
|
|
|
|
/* check chapter3 */ \
|
2012-07-03 16:45:05 +00:00
|
|
|
subentry_t = g_list_nth_data (subentries, 0); \
|
2012-03-14 17:12:22 +00:00
|
|
|
fail_if (subentry_t == NULL); \
|
2012-07-03 16:45:05 +00:00
|
|
|
subsubentries = gst_toc_entry_get_sub_entries (subentry_t); \
|
|
|
|
fail_unless_equals_int (g_list_length (subsubentries), 1); \
|
2012-03-14 17:12:22 +00:00
|
|
|
CHECK_TOC_ENTRY (subentry_t, GST_TOC_ENTRY_TYPE_CHAPTER, ENTRY_CH3); \
|
|
|
|
/* check subchapter1 */ \
|
2012-07-03 16:45:05 +00:00
|
|
|
subentry_t = g_list_nth_data (subentries, 0); \
|
2012-03-14 17:12:22 +00:00
|
|
|
fail_if (subentry_t == NULL); \
|
2012-07-03 16:45:05 +00:00
|
|
|
subsubentries = gst_toc_entry_get_sub_entries (subentry_t); \
|
|
|
|
fail_unless_equals_int (g_list_length (subsubentries), 0); \
|
2012-03-14 17:12:22 +00:00
|
|
|
CHECK_TOC_ENTRY (subentry_t, GST_TOC_ENTRY_TYPE_CHAPTER, ENTRY_SUB1); \
|
|
|
|
}
|
|
|
|
|
2012-06-26 19:41:18 +00:00
|
|
|
/* This whole test is a bit pointless now that we just stuff a ref of
|
|
|
|
* the original TOC into the message/query/event */
|
2012-03-14 17:12:22 +00:00
|
|
|
GST_START_TEST (test_serializing)
|
|
|
|
{
|
|
|
|
GstToc *toc, *test_toc = NULL;
|
|
|
|
GstTocEntry *ed, *ch, *subch;
|
2012-07-03 16:45:05 +00:00
|
|
|
GstTagList *tags;
|
2012-03-14 17:12:22 +00:00
|
|
|
GstEvent *event;
|
|
|
|
GstMessage *message;
|
|
|
|
gboolean updated;
|
|
|
|
gchar *uid;
|
|
|
|
gint64 start = -1, stop = -1;
|
|
|
|
|
|
|
|
toc = gst_toc_new ();
|
|
|
|
fail_if (toc == NULL);
|
2012-07-03 16:45:05 +00:00
|
|
|
tags = gst_tag_list_new_empty ();
|
|
|
|
gst_tag_list_add (tags, GST_TAG_MERGE_APPEND, GST_TAG_TITLE, TOC_TAG, NULL);
|
|
|
|
gst_toc_set_tags (toc, tags);
|
2012-03-14 17:12:22 +00:00
|
|
|
|
|
|
|
/* create edition1 */
|
|
|
|
ed = gst_toc_entry_new (GST_TOC_ENTRY_TYPE_EDITION, ENTRY_ED1);
|
|
|
|
fail_if (ed == NULL);
|
2012-07-03 16:45:05 +00:00
|
|
|
tags = gst_tag_list_new_empty ();
|
|
|
|
gst_tag_list_add (tags, GST_TAG_MERGE_APPEND, GST_TAG_TITLE, ENTRY_TAG, NULL);
|
|
|
|
gst_toc_entry_set_tags (ed, tags);
|
2012-03-14 17:12:22 +00:00
|
|
|
|
|
|
|
CHECK_TOC_ENTRY (ed, GST_TOC_ENTRY_TYPE_EDITION, ENTRY_ED1);
|
|
|
|
|
|
|
|
/* append chapter1 to edition1 */
|
|
|
|
ch = gst_toc_entry_new (GST_TOC_ENTRY_TYPE_CHAPTER, ENTRY_CH1);
|
|
|
|
fail_if (ch == NULL);
|
2012-07-03 16:45:05 +00:00
|
|
|
tags = gst_tag_list_new_empty ();
|
|
|
|
gst_tag_list_add (tags, GST_TAG_MERGE_APPEND, GST_TAG_TITLE, ENTRY_TAG, NULL);
|
|
|
|
gst_toc_entry_set_tags (ch, tags);
|
2012-03-14 17:12:22 +00:00
|
|
|
|
|
|
|
CHECK_TOC_ENTRY (ch, GST_TOC_ENTRY_TYPE_CHAPTER, ENTRY_CH1);
|
|
|
|
|
2012-07-03 16:45:05 +00:00
|
|
|
gst_toc_entry_append_sub_entry (ed, ch);
|
|
|
|
fail_unless_equals_int (g_list_length (gst_toc_entry_get_sub_entries (ed)),
|
|
|
|
1);
|
2012-03-14 17:12:22 +00:00
|
|
|
|
|
|
|
/* append chapter2 to edition1 */
|
|
|
|
ch = gst_toc_entry_new (GST_TOC_ENTRY_TYPE_CHAPTER, ENTRY_CH2);
|
|
|
|
fail_if (ch == NULL);
|
2012-07-03 16:45:05 +00:00
|
|
|
tags = gst_tag_list_new_empty ();
|
|
|
|
gst_tag_list_add (tags, GST_TAG_MERGE_APPEND, GST_TAG_TITLE, ENTRY_TAG, NULL);
|
|
|
|
gst_toc_entry_set_tags (ch, tags);
|
2012-03-14 17:12:22 +00:00
|
|
|
|
|
|
|
CHECK_TOC_ENTRY (ch, GST_TOC_ENTRY_TYPE_CHAPTER, ENTRY_CH2);
|
|
|
|
|
2012-07-03 16:45:05 +00:00
|
|
|
gst_toc_entry_append_sub_entry (ed, ch);
|
|
|
|
fail_unless_equals_int (g_list_length (gst_toc_entry_get_sub_entries (ed)),
|
|
|
|
2);
|
2012-04-10 10:16:50 +00:00
|
|
|
|
2012-03-14 17:12:22 +00:00
|
|
|
/* append edition1 to the TOC */
|
2012-07-03 16:45:05 +00:00
|
|
|
gst_toc_append_entry (toc, ed);
|
|
|
|
fail_unless_equals_int (g_list_length (gst_toc_get_entries (toc)), 1);
|
2012-03-14 17:12:22 +00:00
|
|
|
|
|
|
|
/* test gst_toc_entry_find() */
|
|
|
|
ed = NULL;
|
|
|
|
ed = gst_toc_find_entry (toc, ENTRY_ED1);
|
|
|
|
|
|
|
|
fail_if (ed == NULL);
|
|
|
|
|
2012-04-10 10:16:50 +00:00
|
|
|
CHECK_TOC_ENTRY (ed, GST_TOC_ENTRY_TYPE_EDITION, ENTRY_ED1);
|
2012-03-14 17:12:22 +00:00
|
|
|
|
|
|
|
/* test info GstStructure */
|
2012-07-03 16:45:05 +00:00
|
|
|
gst_toc_entry_set_start_stop_times (ch, 100, 1000);
|
|
|
|
fail_if (!gst_toc_entry_get_start_stop_times (ch, &start, &stop));
|
2012-03-14 17:12:22 +00:00
|
|
|
fail_unless (start == 100);
|
|
|
|
fail_unless (stop == 1000);
|
|
|
|
|
|
|
|
/* create edition2 */
|
|
|
|
ed = gst_toc_entry_new (GST_TOC_ENTRY_TYPE_EDITION, ENTRY_ED2);
|
|
|
|
fail_if (ed == NULL);
|
2012-07-03 16:45:05 +00:00
|
|
|
tags = gst_tag_list_new_empty ();
|
|
|
|
gst_tag_list_add (tags, GST_TAG_MERGE_APPEND, GST_TAG_TITLE, ENTRY_TAG, NULL);
|
|
|
|
gst_toc_entry_set_tags (ed, tags);
|
2012-03-14 17:12:22 +00:00
|
|
|
|
|
|
|
CHECK_TOC_ENTRY (ed, GST_TOC_ENTRY_TYPE_EDITION, ENTRY_ED2);
|
|
|
|
|
|
|
|
/* create chapter3 */
|
|
|
|
ch = gst_toc_entry_new (GST_TOC_ENTRY_TYPE_CHAPTER, ENTRY_CH3);
|
|
|
|
fail_if (ch == NULL);
|
2012-07-03 16:45:05 +00:00
|
|
|
tags = gst_tag_list_new_empty ();
|
|
|
|
gst_tag_list_add (tags, GST_TAG_MERGE_APPEND, GST_TAG_TITLE, ENTRY_TAG, NULL);
|
|
|
|
gst_toc_entry_set_tags (ch, tags);
|
2012-03-14 17:12:22 +00:00
|
|
|
|
|
|
|
CHECK_TOC_ENTRY (ch, GST_TOC_ENTRY_TYPE_CHAPTER, ENTRY_CH3);
|
|
|
|
|
|
|
|
/* create subchapter1 */
|
|
|
|
subch = gst_toc_entry_new (GST_TOC_ENTRY_TYPE_CHAPTER, ENTRY_SUB1);
|
|
|
|
fail_if (subch == NULL);
|
2012-07-03 16:45:05 +00:00
|
|
|
tags = gst_tag_list_new_empty ();
|
|
|
|
gst_tag_list_add (tags, GST_TAG_MERGE_APPEND, GST_TAG_TITLE, ENTRY_TAG, NULL);
|
|
|
|
gst_toc_entry_set_tags (subch, tags);
|
2012-03-14 17:12:22 +00:00
|
|
|
|
|
|
|
CHECK_TOC_ENTRY (subch, GST_TOC_ENTRY_TYPE_CHAPTER, ENTRY_SUB1);
|
|
|
|
|
|
|
|
/* append subchapter1 to chapter3 */
|
2012-07-03 16:45:05 +00:00
|
|
|
gst_toc_entry_append_sub_entry (ch, subch);
|
|
|
|
fail_unless_equals_int (g_list_length (gst_toc_entry_get_sub_entries (ch)),
|
|
|
|
1);
|
2012-03-14 17:12:22 +00:00
|
|
|
|
|
|
|
/* append chapter3 to edition2 */
|
2012-07-03 16:45:05 +00:00
|
|
|
gst_toc_entry_append_sub_entry (ed, ch);
|
|
|
|
fail_unless_equals_int (g_list_length (gst_toc_entry_get_sub_entries (ed)),
|
|
|
|
1);
|
2012-03-14 17:12:22 +00:00
|
|
|
|
|
|
|
/* finally append edition2 to the TOC */
|
2012-07-03 16:45:05 +00:00
|
|
|
gst_toc_append_entry (toc, ed);
|
|
|
|
fail_unless_equals_int (g_list_length (gst_toc_get_entries (toc)), 2);
|
2012-03-14 17:12:22 +00:00
|
|
|
|
|
|
|
/* test gst_toc_copy() */
|
|
|
|
test_toc = gst_toc_copy (toc);
|
|
|
|
fail_if (test_toc == NULL);
|
|
|
|
CHECK_TOC (test_toc);
|
2012-06-24 19:10:34 +00:00
|
|
|
gst_toc_unref (test_toc);
|
2012-03-14 17:12:22 +00:00
|
|
|
test_toc = NULL;
|
|
|
|
|
|
|
|
/* check TOC event handling */
|
2012-06-06 13:45:11 +00:00
|
|
|
event = gst_event_new_toc (toc, TRUE);
|
2012-03-14 17:12:22 +00:00
|
|
|
fail_if (event == NULL);
|
|
|
|
fail_unless (event->type == GST_EVENT_TOC);
|
|
|
|
ASSERT_MINI_OBJECT_REFCOUNT (GST_MINI_OBJECT (event), "GstEvent", 1);
|
|
|
|
|
|
|
|
gst_event_parse_toc (event, &test_toc, &updated);
|
|
|
|
fail_unless (updated == TRUE);
|
|
|
|
fail_if (test_toc == NULL);
|
|
|
|
CHECK_TOC (test_toc);
|
2012-06-24 19:10:34 +00:00
|
|
|
gst_toc_unref (test_toc);
|
2012-03-14 17:12:22 +00:00
|
|
|
gst_event_unref (event);
|
|
|
|
updated = FALSE;
|
|
|
|
test_toc = NULL;
|
|
|
|
|
|
|
|
/* check TOC message handling */
|
|
|
|
message = gst_message_new_toc (NULL, toc, TRUE);
|
|
|
|
fail_if (message == NULL);
|
|
|
|
fail_unless (message->type == GST_MESSAGE_TOC);
|
|
|
|
ASSERT_MINI_OBJECT_REFCOUNT (GST_MINI_OBJECT (message), "GstMessage", 1);
|
|
|
|
|
|
|
|
gst_message_parse_toc (message, &test_toc, &updated);
|
|
|
|
fail_unless (updated == TRUE);
|
|
|
|
fail_if (test_toc == NULL);
|
|
|
|
CHECK_TOC (test_toc);
|
2012-06-24 19:10:34 +00:00
|
|
|
gst_toc_unref (test_toc);
|
2012-03-14 17:12:22 +00:00
|
|
|
gst_message_unref (message);
|
|
|
|
test_toc = NULL;
|
|
|
|
|
|
|
|
/* check TOC select event handling */
|
|
|
|
event = gst_event_new_toc_select (TEST_UID);
|
|
|
|
fail_if (event == NULL);
|
|
|
|
fail_unless (event->type == GST_EVENT_TOC_SELECT);
|
|
|
|
ASSERT_MINI_OBJECT_REFCOUNT (GST_MINI_OBJECT (event), "GstEvent", 1);
|
|
|
|
|
|
|
|
gst_event_parse_toc_select (event, &uid);
|
|
|
|
fail_unless_equals_string (uid, TEST_UID);
|
|
|
|
gst_event_unref (event);
|
|
|
|
g_free (uid);
|
|
|
|
|
2012-06-26 19:41:18 +00:00
|
|
|
/* FIXME: toc validation / verification should probably be done on the fly
|
|
|
|
* while creating it, and not when putting the toc in events or messages ? */
|
|
|
|
#if 0
|
2012-03-14 17:12:22 +00:00
|
|
|
/* that's wrong code, we should fail */
|
|
|
|
ch = gst_toc_entry_new (GST_TOC_ENTRY_TYPE_CHAPTER, ENTRY_CH4);
|
|
|
|
toc->entries = g_list_prepend (toc->entries, ch);
|
|
|
|
ASSERT_CRITICAL (message = gst_message_new_toc (NULL, toc, TRUE));
|
|
|
|
|
|
|
|
/* and yet another one */
|
|
|
|
toc->entries = g_list_remove (toc->entries, ch);
|
2012-06-24 19:10:34 +00:00
|
|
|
gst_toc_entry_unref (ch);
|
2012-03-14 17:12:22 +00:00
|
|
|
ed = gst_toc_entry_new (GST_TOC_ENTRY_TYPE_EDITION, ENTRY_ED3);
|
|
|
|
ch = (GstTocEntry *) (toc->entries->data);
|
|
|
|
ch->subentries = g_list_prepend (ch->subentries, ed);
|
|
|
|
ASSERT_WARNING (message = gst_message_new_toc (NULL, toc, TRUE));
|
2012-06-26 19:41:18 +00:00
|
|
|
#endif
|
2012-03-14 17:12:22 +00:00
|
|
|
|
2012-06-24 19:10:34 +00:00
|
|
|
gst_toc_unref (toc);
|
2012-03-14 17:12:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
|
|
|
static Suite *
|
|
|
|
gst_toc_suite (void)
|
|
|
|
{
|
|
|
|
Suite *s = suite_create ("GstToc");
|
|
|
|
TCase *tc_chain = tcase_create ("general");
|
|
|
|
|
|
|
|
suite_add_tcase (s, tc_chain);
|
|
|
|
tcase_add_test (tc_chain, test_serializing);
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_CHECK_MAIN (gst_toc);
|