1 /* GStreamer
2 *
3 * unit tests for xmp config library
4 *
5 * Copyright (C) 2011 Thiago Santos <thiago.sousa.santos@collabora.co.uk>
6 *
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.
11 *
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.
16 *
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., 51 Franklin St, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21 */
22
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26
27 #include <gst/check/gstcheck.h>
28
29 #include <gst/tag/tag.h>
30 #include <gst/tag/xmpwriter.h>
31
32 #include <string.h>
33
34 #define TEST_ELEMENT_TYPE (test_element_get_type())
35
36 typedef struct TestElement TestElement;
37 typedef struct TestElementClass TestElementClass;
38
39 struct TestElement
40 {
41 GstElement parent;
42 };
43
44 struct TestElementClass
45 {
46 GstElementClass parent_class;
47 };
48
49 GType test_element_get_type (void);
50
51 static void init_interface (GType type);
52
53 G_DEFINE_TYPE_WITH_CODE (TestElement, test_element, GST_TYPE_ELEMENT,
54 init_interface (g_define_type_id));
55
56 static void
init_interface(GType type)57 init_interface (GType type)
58 {
59 static const GInterfaceInfo tagxmpwriter_info = {
60 NULL,
61 NULL,
62 NULL,
63 };
64
65 g_type_add_interface_static (type, GST_TYPE_TAG_XMP_WRITER,
66 &tagxmpwriter_info);
67 }
68
69 static void
test_element_class_init(TestElementClass * klass)70 test_element_class_init (TestElementClass * klass)
71 {
72 }
73
74 static void
test_element_init(TestElement * this)75 test_element_init (TestElement * this)
76 {
77 }
78
79 static gboolean
gst_buffer_equals(GstBuffer * buf_a,GstBuffer * buf_b)80 gst_buffer_equals (GstBuffer * buf_a, GstBuffer * buf_b)
81 {
82 gboolean res;
83 GstMapInfo map1, map2;
84
85 gst_buffer_map (buf_a, &map1, GST_MAP_READ);
86 gst_buffer_map (buf_b, &map2, GST_MAP_READ);
87
88 if (map1.size == map2.size) {
89 res = memcmp (map1.data, map2.data, map1.size) == 0;
90 } else {
91 res = FALSE;
92 }
93 gst_buffer_unmap (buf_a, &map1);
94 gst_buffer_unmap (buf_b, &map2);
95
96 return res;
97 }
98
99 static GstTagList *
create_taglist(void)100 create_taglist (void)
101 {
102 return gst_tag_list_new (GST_TAG_ARTIST, "artist",
103 GST_TAG_TITLE, "title", GST_TAG_COPYRIGHT, "copyright", NULL);
104 }
105
GST_START_TEST(test_no_xmp)106 GST_START_TEST (test_no_xmp)
107 {
108 GstTagList *taglist = create_taglist ();
109 GstElement *test_element =
110 (GstElement *) g_object_new (TEST_ELEMENT_TYPE, NULL);
111
112 gst_tag_xmp_writer_remove_all_schemas (GST_TAG_XMP_WRITER (test_element));
113
114 fail_unless (gst_tag_xmp_writer_tag_list_to_xmp_buffer (GST_TAG_XMP_WRITER
115 (test_element), taglist, TRUE) == NULL);
116
117 gst_object_unref (test_element);
118 gst_tag_list_unref (taglist);
119 }
120
121 GST_END_TEST;
122
123
GST_START_TEST(test_default)124 GST_START_TEST (test_default)
125 {
126 GstTagList *taglist = create_taglist ();
127 GstElement *test_element =
128 (GstElement *) g_object_new (TEST_ELEMENT_TYPE, NULL);
129 GstBuffer *buf;
130 GstBuffer *buf2;
131
132 buf =
133 gst_tag_xmp_writer_tag_list_to_xmp_buffer (GST_TAG_XMP_WRITER
134 (test_element), taglist, TRUE);
135 buf2 = gst_tag_list_to_xmp_buffer (taglist, TRUE, NULL);
136 fail_unless (gst_buffer_equals (buf, buf2));
137
138 gst_object_unref (test_element);
139 gst_buffer_unref (buf);
140 gst_buffer_unref (buf2);
141 gst_tag_list_unref (taglist);
142 }
143
144 GST_END_TEST;
145
146
GST_START_TEST(test_disable)147 GST_START_TEST (test_disable)
148 {
149 GstTagList *taglist;
150 GstTagList *taglist2;
151 GstElement *test_element =
152 (GstElement *) g_object_new (TEST_ELEMENT_TYPE, NULL);
153 GstBuffer *buf;
154 const gchar *str;
155
156 taglist = gst_tag_list_new (GST_TAG_ARTIST, "artist", NULL);
157
158 /* add a tag that is mapped on xmp schema (as of Mar, 21th 2011) */
159 gst_tag_list_add (taglist, GST_TAG_MERGE_REPLACE, GST_TAG_USER_RATING, 5,
160 NULL);
161
162 buf =
163 gst_tag_xmp_writer_tag_list_to_xmp_buffer (GST_TAG_XMP_WRITER
164 (test_element), taglist, TRUE);
165 taglist2 = gst_tag_list_from_xmp_buffer (buf);
166 fail_unless (gst_tag_list_is_equal (taglist, taglist2));
167 gst_tag_list_unref (taglist2);
168 gst_buffer_unref (buf);
169
170 gst_tag_xmp_writer_remove_schema (GST_TAG_XMP_WRITER (test_element), "xap");
171 buf =
172 gst_tag_xmp_writer_tag_list_to_xmp_buffer (GST_TAG_XMP_WRITER
173 (test_element), taglist, TRUE);
174 taglist2 = gst_tag_list_from_xmp_buffer (buf);
175
176 /* artist should be there, but rating shouldn't */
177 fail_unless (gst_tag_list_peek_string_index (taglist2, GST_TAG_ARTIST, 0,
178 &str));
179 fail_unless (gst_tag_list_get_value_index (taglist2, GST_TAG_USER_RATING,
180 0) == NULL);
181
182 gst_tag_list_unref (taglist2);
183 gst_buffer_unref (buf);
184
185 gst_object_unref (test_element);
186 gst_tag_list_unref (taglist);
187 }
188
189 GST_END_TEST;
190
191
192 static Suite *
xmp_config_suite(void)193 xmp_config_suite (void)
194 {
195 Suite *s = suite_create ("xmpconfig interface");
196 TCase *tc_chain = tcase_create ("configuration");
197
198 suite_add_tcase (s, tc_chain);
199 tcase_add_test (tc_chain, test_no_xmp);
200 tcase_add_test (tc_chain, test_default);
201 tcase_add_test (tc_chain, test_disable);
202
203 return s;
204 }
205
206 GST_CHECK_MAIN (xmp_config);
207