3 * unit tests for xmp config library
5 * Copyright (C) 2011 Thiago Santos <thiago.sousa.santos@collabora.co.uk>
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.
27 #include <gst/check/gstcheck.h>
29 #include <gst/tag/tag.h>
30 #include <gst/tag/xmpwriter.h>
34 #define TEST_ELEMENT_TYPE (test_element_get_type())
36 typedef struct TestElement TestElement;
37 typedef struct TestElementClass TestElementClass;
44 struct TestElementClass
46 GstElementClass parent_class;
49 GType test_element_get_type (void);
51 static void init_interface (GType type);
53 GST_BOILERPLATE_FULL (TestElement, test_element, GstElement, GST_TYPE_ELEMENT,
57 init_interface (GType type)
59 static const GInterfaceInfo tagxmpwriter_info = {
65 g_type_add_interface_static (type, GST_TYPE_TAG_XMP_WRITER,
70 test_element_base_init (gpointer klass)
75 test_element_class_init (TestElementClass * klass)
80 test_element_init (TestElement * this, TestElementClass * klass)
85 tag_list_equals (GstTagList * taglist, GstTagList * taglist2)
87 const gchar *name_sent, *name_recv;
88 const GValue *value_sent, *value_recv;
96 fail_unless (taglist2 != NULL);
97 n_recv = gst_structure_n_fields (taglist2);
98 n_sent = gst_structure_n_fields (taglist);
99 fail_unless (n_recv == n_sent);
100 fail_unless (n_sent > 0);
102 /* FIXME: compare taglist values */
103 for (i = 0; i < n_sent; i++) {
104 name_sent = gst_structure_nth_field_name (taglist, i);
105 value_sent = gst_structure_get_value (taglist, name_sent);
107 for (j = 0; j < n_recv; j++) {
108 name_recv = gst_structure_nth_field_name (taglist2, j);
109 if (!strcmp (name_sent, name_recv)) {
110 value_recv = gst_structure_get_value (taglist2, name_recv);
111 comparison = gst_value_compare (value_sent, value_recv);
112 if (comparison != GST_VALUE_EQUAL) {
113 gchar *vs = g_strdup_value_contents (value_sent);
114 gchar *vr = g_strdup_value_contents (value_recv);
115 GST_DEBUG ("sent = %s:'%s', recv = %s:'%s'",
116 G_VALUE_TYPE_NAME (value_sent), vs,
117 G_VALUE_TYPE_NAME (value_recv), vr);
121 if (comparison != GST_VALUE_EQUAL &&
122 G_VALUE_HOLDS (value_sent, G_TYPE_DOUBLE)) {
126 /* add some tolerance for doubles */
127 vs = g_value_get_double (value_sent);
128 vr = g_value_get_double (value_recv);
129 if (vr >= vs - 0.001 && vr <= vs + 0.001)
130 comparison = GST_VALUE_EQUAL;
132 fail_unless (comparison == GST_VALUE_EQUAL,
133 "tag item %s has been received with different type or value",
139 fail_unless (found, "tag item %s is lost", name_sent);
144 gst_buffer_equals (GstBuffer * buf_a, GstBuffer * buf_b)
146 if (GST_BUFFER_SIZE (buf_a) != GST_BUFFER_SIZE (buf_b))
149 return memcmp (GST_BUFFER_DATA (buf_a), GST_BUFFER_DATA (buf_b),
150 GST_BUFFER_SIZE (buf_a)) == 0;
154 create_taglist (void)
156 return gst_tag_list_new_full (GST_TAG_ARTIST, "artist",
157 GST_TAG_TITLE, "title", GST_TAG_COPYRIGHT, "copyright", NULL);
160 GST_START_TEST (test_no_xmp)
162 GstTagList *taglist = create_taglist ();
163 GstElement *test_element =
164 (GstElement *) g_object_new (TEST_ELEMENT_TYPE, NULL);
166 gst_tag_xmp_writer_remove_all_schemas (GST_TAG_XMP_WRITER (test_element));
168 fail_unless (gst_tag_xmp_writer_tag_list_to_xmp_buffer (GST_TAG_XMP_WRITER
169 (test_element), taglist, TRUE) == NULL);
171 gst_object_unref (test_element);
172 gst_tag_list_free (taglist);
178 GST_START_TEST (test_default)
180 GstTagList *taglist = create_taglist ();
181 GstElement *test_element =
182 (GstElement *) g_object_new (TEST_ELEMENT_TYPE, NULL);
187 gst_tag_xmp_writer_tag_list_to_xmp_buffer (GST_TAG_XMP_WRITER
188 (test_element), taglist, TRUE);
189 buf2 = gst_tag_list_to_xmp_buffer (taglist, TRUE);
190 fail_unless (gst_buffer_equals (buf, buf2));
192 gst_object_unref (test_element);
193 gst_buffer_unref (buf);
194 gst_buffer_unref (buf2);
195 gst_tag_list_free (taglist);
201 GST_START_TEST (test_disable)
204 GstTagList *taglist2;
205 GstElement *test_element =
206 (GstElement *) g_object_new (TEST_ELEMENT_TYPE, NULL);
210 taglist = gst_tag_list_new_full (GST_TAG_ARTIST, "artist", NULL);
212 /* add a tag that is mapped on xmp schema (as of Mar, 21th 2011) */
213 gst_tag_list_add (taglist, GST_TAG_MERGE_REPLACE, GST_TAG_USER_RATING, 5,
217 gst_tag_xmp_writer_tag_list_to_xmp_buffer (GST_TAG_XMP_WRITER
218 (test_element), taglist, TRUE);
219 taglist2 = gst_tag_list_from_xmp_buffer (buf);
220 tag_list_equals (taglist, taglist2);
221 gst_tag_list_free (taglist2);
222 gst_buffer_unref (buf);
224 gst_tag_xmp_writer_remove_schema (GST_TAG_XMP_WRITER (test_element), "xap");
226 gst_tag_xmp_writer_tag_list_to_xmp_buffer (GST_TAG_XMP_WRITER
227 (test_element), taglist, TRUE);
228 taglist2 = gst_tag_list_from_xmp_buffer (buf);
230 /* artist should be there, but rating shouldn't */
231 fail_unless (gst_tag_list_peek_string_index (taglist2, GST_TAG_ARTIST, 0,
233 fail_unless (gst_tag_list_get_value_index (taglist2, GST_TAG_USER_RATING,
236 gst_tag_list_free (taglist2);
237 gst_buffer_unref (buf);
239 gst_object_unref (test_element);
240 gst_tag_list_free (taglist);
247 xmp_config_suite (void)
249 Suite *s = suite_create ("xmpconfig interface");
250 TCase *tc_chain = tcase_create ("configuration");
252 suite_add_tcase (s, tc_chain);
253 tcase_add_test (tc_chain, test_no_xmp);
254 tcase_add_test (tc_chain, test_default);
255 tcase_add_test (tc_chain, test_disable);
261 main (int argc, char **argv)
265 Suite *s = xmp_config_suite ();
266 SRunner *sr = srunner_create (s);
268 gst_check_init (&argc, &argv);
270 srunner_run_all (sr, CK_NORMAL);
271 nf = srunner_ntests_failed (sr);