From 52a29f5bb43f9b6de9e000016842d45c6aa3248a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim-Philipp=20M=C3=BCller?= Date: Fri, 12 Jan 2007 10:53:54 +0000 Subject: [PATCH] tests/check/: Add minimal unit test for beforementioned GstTagSetter bug. Original commit message from CVS: * tests/check/Makefile.am: * tests/check/gst/.cvsignore: * tests/check/gst/gsttagsetter.c: (gst_dummy_enc_add_interfaces), (gst_dummy_enc_base_init), (gst_dummy_enc_class_init), (gst_dummy_enc_init), (tag_list_foreach), (tag_setter_list_length), (GST_START_TEST), (gst_tag_setter_suite): Add minimal unit test for beforementioned GstTagSetter bug. --- ChangeLog | 12 ++- tests/check/Makefile.am | 1 + tests/check/gst/.gitignore | 1 + tests/check/gst/gsttagsetter.c | 132 +++++++++++++++++++++++++++++++++ 4 files changed, 145 insertions(+), 1 deletion(-) create mode 100644 tests/check/gst/gsttagsetter.c diff --git a/ChangeLog b/ChangeLog index bad8ce5d06..4027857ac1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,14 @@ -2007-01-11 Tim-Philipp Müller +2007-01-12 Tim-Philipp Müller + + * tests/check/Makefile.am: + * tests/check/gst/.cvsignore: + * tests/check/gst/gsttagsetter.c: (gst_dummy_enc_add_interfaces), + (gst_dummy_enc_base_init), (gst_dummy_enc_class_init), + (gst_dummy_enc_init), (tag_list_foreach), (tag_setter_list_length), + (GST_START_TEST), (gst_tag_setter_suite): + Add minimal unit test for beforementioned GstTagSetter bug. + +2007-01-12 Tim-Philipp Müller Patch by: René Stadler diff --git a/tests/check/Makefile.am b/tests/check/Makefile.am index 32b745978c..6b258269ee 100644 --- a/tests/check/Makefile.am +++ b/tests/check/Makefile.am @@ -79,6 +79,7 @@ check_PROGRAMS = \ gst/gstsystemclock \ gst/gststructure \ gst/gsttag \ + gst/gsttagsetter \ gst/gsttask \ gst/gstvalue \ $(LOADSAVE_CHECKS) \ diff --git a/tests/check/gst/.gitignore b/tests/check/gst/.gitignore index 860bb22ac8..f3809f6391 100644 --- a/tests/check/gst/.gitignore +++ b/tests/check/gst/.gitignore @@ -21,6 +21,7 @@ gstsegment gststructure gstsystemclock gsttag +gsttagsetter gstutils gstvalue gstquery diff --git a/tests/check/gst/gsttagsetter.c b/tests/check/gst/gsttagsetter.c new file mode 100644 index 0000000000..95318477dd --- /dev/null +++ b/tests/check/gst/gsttagsetter.c @@ -0,0 +1,132 @@ +/* GStreamer GstTagSetter interface unit tests + * Copyright (C) 2007 Tim-Philipp Müller + * + * 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. + */ + +#include +#include +#include + +/* some minimal GstTagSetter object */ +#define GST_TYPE_DUMMY_ENC gst_dummy_enc_get_type() + +typedef GstElement GstDummyEnc; +typedef GstElementClass GstDummyEncClass; + +static void gst_dummy_enc_add_interfaces (GType enc_type); + +GST_BOILERPLATE_FULL (GstDummyEnc, gst_dummy_enc, GstElement, + GST_TYPE_ELEMENT, gst_dummy_enc_add_interfaces); + +static void +gst_dummy_enc_add_interfaces (GType enc_type) +{ + static const GInterfaceInfo tag_setter_info = { NULL, NULL, NULL }; + + g_type_add_interface_static (enc_type, GST_TYPE_TAG_SETTER, &tag_setter_info); +} + +static void +gst_dummy_enc_base_init (gpointer g_class) +{ +} + +static void +gst_dummy_enc_class_init (GstDummyEncClass * klass) +{ +} + +static void +gst_dummy_enc_init (GstDummyEnc * enc, GstDummyEncClass * klass) +{ +} + +static void +tag_list_foreach (const GstTagList * taglist, const gchar * tag, guint * p_num) +{ + guint tag_size; + + tag_size = gst_tag_list_get_tag_size (taglist, tag); + GST_LOG ("%u+%u tag = %s", *p_num, tag_size, tag); + *p_num += tag_size; +} + +static guint +tag_setter_list_length (GstTagSetter * setter) +{ + guint len = 0; + + gst_tag_list_foreach (gst_tag_setter_get_tag_list (setter), + (GstTagForeachFunc) tag_list_foreach, &len); + return len; +} + +#define assert_tag_setter_list_length(setter,len) \ + fail_unless_equals_int (tag_setter_list_length(setter), len); + +GST_START_TEST (test_merge) +{ + GstTagSetter *setter; + GstTagList *list1, *list2; + GstElement *enc; + + enc = g_object_new (GST_TYPE_DUMMY_ENC, NULL); + fail_unless (enc != NULL); + + setter = GST_TAG_SETTER (enc); + + list1 = gst_tag_list_new (); + gst_tag_list_add (list1, GST_TAG_MERGE_APPEND, GST_TAG_ARTIST, "artist1", + NULL); + gst_tag_setter_merge_tags (setter, list1, GST_TAG_MERGE_APPEND); + assert_tag_setter_list_length (setter, 1); + + list2 = gst_tag_list_new (); + gst_tag_list_add (list2, GST_TAG_MERGE_APPEND, GST_TAG_ARTIST, "artist2", + GST_TAG_TITLE, "title1", NULL); + gst_tag_setter_merge_tags (setter, list2, GST_TAG_MERGE_APPEND); + assert_tag_setter_list_length (setter, 3); + + gst_tag_setter_merge_tags (setter, list2, GST_TAG_MERGE_REPLACE_ALL); + assert_tag_setter_list_length (setter, 2); + + gst_tag_setter_merge_tags (setter, list1, GST_TAG_MERGE_REPLACE_ALL); + assert_tag_setter_list_length (setter, 1); + + gst_tag_setter_add_tags (setter, GST_TAG_MERGE_APPEND, GST_TAG_ALBUM, "xyz", + NULL); + assert_tag_setter_list_length (setter, 2); + + gst_tag_list_free (list2); + gst_tag_list_free (list1); + + g_object_unref (enc); +} + +GST_END_TEST static Suite * +gst_tag_setter_suite (void) +{ + Suite *s = suite_create ("GstTagSetter"); + TCase *tc_chain = tcase_create ("general"); + + suite_add_tcase (s, tc_chain); + tcase_add_test (tc_chain, test_merge); + + return s; +} + +GST_CHECK_MAIN (gst_tag_setter);