Merge remote-tracking branch 'origin/master' into 0.11
[platform/upstream/gstreamer.git] / tests / check / libs / tag.c
1 /* GStreamer
2  *
3  * unit tests for the tag support library
4  *
5  * Copyright (C) 2006-2011 Tim-Philipp Müller <tim centricular net>
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., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, 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/base/gstbytewriter.h>
31 #include <string.h>
32 #include <locale.h>
33
34 GST_START_TEST (test_parse_extended_comment)
35 {
36   gchar *key, *val, *lang;
37
38   /* first check the g_return_val_if_fail conditions */
39   ASSERT_CRITICAL (gst_tag_parse_extended_comment (NULL, NULL, NULL, NULL,
40           FALSE));
41   ASSERT_CRITICAL (gst_tag_parse_extended_comment ("\377\000", NULL, NULL, NULL,
42           FALSE));
43
44   key = val = lang = NULL;
45   fail_unless (gst_tag_parse_extended_comment ("a=b", &key, &lang, &val,
46           FALSE) == TRUE);
47   fail_unless (key != NULL);
48   fail_unless (lang == NULL);
49   fail_unless (val != NULL);
50   fail_unless_equals_string (key, "a");
51   fail_unless_equals_string (val, "b");
52   g_free (key);
53   g_free (lang);
54   g_free (val);
55
56   key = val = lang = NULL;
57   fail_unless (gst_tag_parse_extended_comment ("a[l]=b", &key, &lang, &val,
58           FALSE) == TRUE);
59   fail_unless (key != NULL);
60   fail_unless (lang != NULL);
61   fail_unless (val != NULL);
62   fail_unless_equals_string (key, "a");
63   fail_unless_equals_string (lang, "l");
64   fail_unless_equals_string (val, "b");
65   g_free (key);
66   g_free (lang);
67   g_free (val);
68
69   key = val = lang = NULL;
70   fail_unless (gst_tag_parse_extended_comment ("foo=bar", &key, &lang, &val,
71           FALSE) == TRUE);
72   fail_unless (key != NULL);
73   fail_unless (lang == NULL);
74   fail_unless (val != NULL);
75   fail_unless_equals_string (key, "foo");
76   fail_unless_equals_string (val, "bar");
77   g_free (key);
78   g_free (lang);
79   g_free (val);
80
81   key = val = lang = NULL;
82   fail_unless (gst_tag_parse_extended_comment ("foo[fr]=bar", &key, &lang, &val,
83           FALSE) == TRUE);
84   fail_unless (key != NULL);
85   fail_unless (lang != NULL);
86   fail_unless (val != NULL);
87   fail_unless_equals_string (key, "foo");
88   fail_unless_equals_string (lang, "fr");
89   fail_unless_equals_string (val, "bar");
90   g_free (key);
91   g_free (lang);
92   g_free (val);
93
94   key = val = lang = NULL;
95   fail_unless (gst_tag_parse_extended_comment ("foo=[fr]bar", &key, &lang, &val,
96           FALSE) == TRUE);
97   fail_unless (key != NULL);
98   fail_unless (lang == NULL);
99   fail_unless (val != NULL);
100   fail_unless_equals_string (key, "foo");
101   fail_unless_equals_string (val, "[fr]bar");
102   g_free (key);
103   g_free (lang);
104   g_free (val);
105
106   /* test NULL for output locations */
107   fail_unless (gst_tag_parse_extended_comment ("foo[fr]=bar", NULL, NULL, NULL,
108           FALSE) == TRUE);
109
110   /* test strict mode (key must be specified) */
111   fail_unless (gst_tag_parse_extended_comment ("foo[fr]=bar", NULL, NULL, NULL,
112           TRUE) == TRUE);
113   fail_unless (gst_tag_parse_extended_comment ("foo=bar", NULL, NULL, NULL,
114           TRUE) == TRUE);
115   fail_unless (gst_tag_parse_extended_comment ("foobar", NULL, NULL, NULL,
116           TRUE) == FALSE);
117
118   /* test non-strict mode (if there's no key, that's fine too) */
119   fail_unless (gst_tag_parse_extended_comment ("foobar", NULL, NULL, NULL,
120           FALSE) == TRUE);
121   fail_unless (gst_tag_parse_extended_comment ("[fr]bar", NULL, NULL, NULL,
122           FALSE) == TRUE);
123
124   key = val = lang = NULL;
125   fail_unless (gst_tag_parse_extended_comment ("[fr]bar", &key, &lang, &val,
126           FALSE) == TRUE);
127   fail_unless (key == NULL);
128   fail_unless (lang == NULL);
129   fail_unless (val != NULL);
130   fail_unless_equals_string (val, "[fr]bar");
131   g_free (key);
132   g_free (lang);
133   g_free (val);
134 }
135
136 GST_END_TEST;
137
138 #define ASSERT_TAG_LIST_HAS_STRING(list,field,string)                      \
139   {                                                                        \
140     gboolean got_match = FALSE;                                            \
141     guint i, size;                                                         \
142                                                                            \
143     fail_unless (gst_tag_list_get_tag_size (list,field) > 0);              \
144     size = gst_tag_list_get_tag_size (list,field);                         \
145     for (i = 0; i < size; ++i) {                                           \
146       gchar *___s = NULL;                                                  \
147                                                                            \
148       fail_unless (gst_tag_list_get_string_index (list, field, i, &___s)); \
149       fail_unless (___s != NULL);                                          \
150       if (g_str_equal (___s, string)) {                                    \
151         got_match = TRUE;                                                  \
152         g_free (___s);                                                     \
153         break;                                                             \
154       }                                                                    \
155       g_free (___s);                                                       \
156     }                                                                      \
157     fail_unless (got_match);                                               \
158   }
159
160 #define ASSERT_TAG_LIST_HAS_UINT(list,field,num)                           \
161   {                                                                        \
162     guint ___n;                                                            \
163                                                                            \
164     fail_unless (gst_tag_list_get_tag_size (list,field) > 0);              \
165     fail_unless (gst_tag_list_get_tag_size (list,field) == 1);             \
166     fail_unless (gst_tag_list_get_uint_index (list, field, 0, &___n));     \
167     fail_unless_equals_int (___n, num);                                    \
168   }
169
170 #define MATCH_DOUBLE(p1, p2) ((p1 < p2 + 1e-6) && (p2 < p1 + 1e-6))
171 #define ASSERT_TAG_LIST_HAS_DOUBLE(list,field,d)                           \
172   {                                                                        \
173     gdouble ___d;                                                          \
174                                                                            \
175     fail_unless (gst_tag_list_get_tag_size (list,field) > 0);              \
176     fail_unless (gst_tag_list_get_tag_size (list,field) == 1);             \
177     fail_unless (gst_tag_list_get_double_index (list, field, 0, &___d));   \
178     fail_unless (MATCH_DOUBLE (d, ___d),                                   \
179         "%f does not match expected %f", ___d, d);                         \
180   }
181
182 GST_START_TEST (test_musicbrainz_tag_registration)
183 {
184   GstTagList *list;
185
186   gst_tag_register_musicbrainz_tags ();
187
188   list = gst_tag_list_new_empty ();
189
190   /* musicbrainz tags aren't registered yet */
191   gst_vorbis_tag_add (list, "MUSICBRAINZ_TRACKID", "123456");
192   gst_vorbis_tag_add (list, "MUSICBRAINZ_ARTISTID", "234567");
193   gst_vorbis_tag_add (list, "MUSICBRAINZ_ALBUMID", "345678");
194   gst_vorbis_tag_add (list, "MUSICBRAINZ_ALBUMARTISTID", "4567890");
195   gst_vorbis_tag_add (list, "MUSICBRAINZ_TRMID", "5678901");
196   /* MUSICBRAINZ_SORTNAME = GST_TAG_ARTIST_SORTNAME now */
197   gst_vorbis_tag_add (list, "MUSICBRAINZ_SORTNAME", "Five, 678901");
198
199   ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_MUSICBRAINZ_TRACKID, "123456");
200   ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_MUSICBRAINZ_ARTISTID, "234567");
201   ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_MUSICBRAINZ_ALBUMID, "345678");
202   ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_MUSICBRAINZ_ALBUMARTISTID,
203       "4567890");
204   ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_MUSICBRAINZ_TRMID, "5678901");
205   ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_ARTIST_SORTNAME, "Five, 678901");
206
207   gst_tag_list_free (list);
208 }
209
210 GST_END_TEST;
211
212 /* is there an easier way to compare two structures / tagslists? */
213 static gboolean
214 taglists_are_equal (const GstTagList * list_1, const GstTagList * list_2)
215 {
216   GstCaps *c_list_1 = gst_caps_new_empty ();
217   GstCaps *c_list_2 = gst_caps_new_empty ();
218   gboolean ret;
219
220   gst_caps_append_structure (c_list_1,
221       gst_structure_copy ((GstStructure *) list_1));
222   gst_caps_append_structure (c_list_2,
223       gst_structure_copy ((GstStructure *) list_2));
224
225   ret = gst_caps_is_equal (c_list_2, c_list_1);
226
227   gst_caps_unref (c_list_1);
228   gst_caps_unref (c_list_2);
229
230   return ret;
231 }
232
233 GST_START_TEST (test_vorbis_tags)
234 {
235   GstTagList *list;
236
237   list = gst_tag_list_new_empty ();
238
239   /* NULL pointers aren't allowed */
240   ASSERT_CRITICAL (gst_vorbis_tag_add (NULL, "key", "value"));
241   ASSERT_CRITICAL (gst_vorbis_tag_add (list, NULL, "value"));
242   ASSERT_CRITICAL (gst_vorbis_tag_add (list, "key", NULL));
243
244   /* must be UTF-8 */
245   ASSERT_CRITICAL (gst_vorbis_tag_add (list, "key", "v\377lue"));
246   ASSERT_CRITICAL (gst_vorbis_tag_add (list, "k\377y", "value"));
247
248   /* key can't have a '=' in it */
249   ASSERT_CRITICAL (gst_vorbis_tag_add (list, "k=y", "value"));
250   ASSERT_CRITICAL (gst_vorbis_tag_add (list, "key=", "value"));
251
252   /* should be allowed in values though */
253   gst_vorbis_tag_add (list, "keeey", "va=ue");
254
255   /* add some tags */
256   gst_vorbis_tag_add (list, "TITLE", "Too");
257   gst_vorbis_tag_add (list, "ALBUM", "Aoo");
258   gst_vorbis_tag_add (list, "ARTIST", "Alboo");
259   gst_vorbis_tag_add (list, "PERFORMER", "Perfoo");
260   gst_vorbis_tag_add (list, "COPYRIGHT", "Copyfoo");
261   gst_vorbis_tag_add (list, "DESCRIPTION", "Descoo");
262   gst_vorbis_tag_add (list, "LICENSE", "Licoo");
263   gst_vorbis_tag_add (list, "LICENSE",
264       "http://creativecommons.org/licenses/by/3.0/");
265   gst_vorbis_tag_add (list, "LOCATION", "Bristol, UK");
266   gst_vorbis_tag_add (list, "ORGANIZATION", "Orgoo");
267   gst_vorbis_tag_add (list, "GENRE", "Goo");
268   gst_vorbis_tag_add (list, "CONTACT", "Coo");
269   gst_vorbis_tag_add (list, "COMMENT", "Stroodle is good");
270   gst_vorbis_tag_add (list, "COMMENT", "Peroxysulfid stroodles the brain");
271
272   gst_vorbis_tag_add (list, "TRACKNUMBER", "5");
273   gst_vorbis_tag_add (list, "TRACKTOTAL", "77");
274   gst_vorbis_tag_add (list, "DISCNUMBER", "1");
275   gst_vorbis_tag_add (list, "DISCTOTAL", "2");
276   gst_vorbis_tag_add (list, "DATE", "1954-12-31");
277
278   ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_TITLE, "Too");
279   ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_ALBUM, "Aoo");
280   ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_ARTIST, "Alboo");
281   ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_PERFORMER, "Perfoo");
282   ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_COPYRIGHT, "Copyfoo");
283   ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_DESCRIPTION, "Descoo");
284   ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_LICENSE, "Licoo");
285   ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_LICENSE_URI,
286       "http://creativecommons.org/licenses/by/3.0/");
287   ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_GEO_LOCATION_NAME, "Bristol, UK");
288   ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_ORGANIZATION, "Orgoo");
289   ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_GENRE, "Goo");
290   ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_CONTACT, "Coo");
291   ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_COMMENT,
292       "Peroxysulfid stroodles the brain");
293   ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_COMMENT, "Stroodle is good");
294   ASSERT_TAG_LIST_HAS_UINT (list, GST_TAG_TRACK_NUMBER, 5);
295   ASSERT_TAG_LIST_HAS_UINT (list, GST_TAG_TRACK_COUNT, 77);
296   ASSERT_TAG_LIST_HAS_UINT (list, GST_TAG_ALBUM_VOLUME_NUMBER, 1);
297   ASSERT_TAG_LIST_HAS_UINT (list, GST_TAG_ALBUM_VOLUME_COUNT, 2);
298
299   {
300     GDate *date = NULL;
301
302     fail_unless (gst_tag_list_get_date (list, GST_TAG_DATE, &date));
303     fail_unless (date != NULL);
304     fail_unless (g_date_get_day (date) == 31);
305     fail_unless (g_date_get_month (date) == G_DATE_DECEMBER);
306     fail_unless (g_date_get_year (date) == 1954);
307
308     g_date_free (date);
309   }
310
311   /* unknown vorbis comments should go into a GST_TAG_EXTENDED_COMMENT */
312   gst_vorbis_tag_add (list, "CoEdSub_ID", "98172AF-973-10-B");
313   ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_EXTENDED_COMMENT,
314       "CoEdSub_ID=98172AF-973-10-B");
315   gst_vorbis_tag_add (list, "RuBuWuHash", "1337BA42F91");
316   ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_EXTENDED_COMMENT,
317       "RuBuWuHash=1337BA42F91");
318
319   gst_vorbis_tag_add (list, "REPLAYGAIN_REFERENCE_LOUDNESS", "89.");
320   ASSERT_TAG_LIST_HAS_DOUBLE (list, GST_TAG_REFERENCE_LEVEL, 89.);
321   gst_vorbis_tag_add (list, "REPLAYGAIN_TRACK_GAIN", "+12.36");
322   ASSERT_TAG_LIST_HAS_DOUBLE (list, GST_TAG_TRACK_GAIN, +12.36);
323   gst_vorbis_tag_add (list, "REPLAYGAIN_TRACK_PEAK", "0.96349");
324   ASSERT_TAG_LIST_HAS_DOUBLE (list, GST_TAG_TRACK_PEAK, 0.96349);
325   gst_vorbis_tag_add (list, "REPLAYGAIN_ALBUM_GAIN", "+10.12");
326   ASSERT_TAG_LIST_HAS_DOUBLE (list, GST_TAG_ALBUM_GAIN, +10.12);
327   /* now check that we can parse floating point numbers with any separator
328    * (',' or '.') regardless of the current locale */
329   gst_vorbis_tag_add (list, "REPLAYGAIN_ALBUM_PEAK", "0,98107");
330   ASSERT_TAG_LIST_HAS_DOUBLE (list, GST_TAG_ALBUM_PEAK, 0.98107);
331   gst_vorbis_tag_add (list, "LICENSE", "http://foo.com/license-1.html");
332
333   /* make sure we can convert back and forth without loss */
334   {
335     GstTagList *new_list, *even_newer_list;
336     GstBuffer *buf, *buf2;
337     gchar *vendor_id = NULL;
338
339     buf = gst_tag_list_to_vorbiscomment_buffer (list,
340         (const guint8 *) "\003vorbis", 7, "libgstunittest");
341     fail_unless (buf != NULL);
342     new_list = gst_tag_list_from_vorbiscomment_buffer (buf,
343         (const guint8 *) "\003vorbis", 7, &vendor_id);
344     fail_unless (new_list != NULL);
345     fail_unless (vendor_id != NULL);
346     g_free (vendor_id);
347     vendor_id = NULL;
348
349     GST_LOG ("new_list = %" GST_PTR_FORMAT, new_list);
350     fail_unless (taglists_are_equal (list, new_list));
351
352     buf2 = gst_tag_list_to_vorbiscomment_buffer (new_list,
353         (const guint8 *) "\003vorbis", 7, "libgstunittest");
354     fail_unless (buf2 != NULL);
355     even_newer_list = gst_tag_list_from_vorbiscomment_buffer (buf2,
356         (const guint8 *) "\003vorbis", 7, &vendor_id);
357     fail_unless (even_newer_list != NULL);
358     fail_unless (vendor_id != NULL);
359     g_free (vendor_id);
360     vendor_id = NULL;
361
362     GST_LOG ("even_newer_list = %" GST_PTR_FORMAT, even_newer_list);
363     fail_unless (taglists_are_equal (new_list, even_newer_list));
364
365     gst_tag_list_free (new_list);
366     gst_tag_list_free (even_newer_list);
367     gst_buffer_unref (buf);
368     gst_buffer_unref (buf2);
369   }
370
371   /* there can only be one language per taglist ... */
372   gst_tag_list_free (list);
373   list = gst_tag_list_new_empty ();
374   gst_vorbis_tag_add (list, "LANGUAGE", "fr");
375   ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_LANGUAGE_CODE, "fr");
376
377   gst_tag_list_free (list);
378   list = gst_tag_list_new_empty ();
379   gst_vorbis_tag_add (list, "LANGUAGE", "[fr]");
380   ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_LANGUAGE_CODE, "fr");
381
382   gst_tag_list_free (list);
383   list = gst_tag_list_new_empty ();
384   gst_vorbis_tag_add (list, "LANGUAGE", "French [fr]");
385   ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_LANGUAGE_CODE, "fr");
386
387   gst_tag_list_free (list);
388   list = gst_tag_list_new_empty ();
389   gst_vorbis_tag_add (list, "LANGUAGE", "[eng] English");
390   ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_LANGUAGE_CODE, "eng");
391
392   gst_tag_list_free (list);
393   list = gst_tag_list_new_empty ();
394   gst_vorbis_tag_add (list, "LANGUAGE", "eng");
395   ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_LANGUAGE_CODE, "eng");
396
397   gst_tag_list_free (list);
398   list = gst_tag_list_new_empty ();
399   gst_vorbis_tag_add (list, "LANGUAGE", "[eng]");
400   ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_LANGUAGE_CODE, "eng");
401
402   /* free-form *sigh* */
403   gst_tag_list_free (list);
404   list = gst_tag_list_new_empty ();
405   gst_vorbis_tag_add (list, "LANGUAGE", "English");
406   ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_LANGUAGE_CODE, "English");
407
408   /* now, while we still have a taglist, test _to_vorbiscomment_buffer() */
409   {
410     GstBuffer *buf1, *buf2;
411     guint8 *data1, *data2;
412     gsize size1, size2;
413
414     ASSERT_CRITICAL (gst_tag_list_to_vorbiscomment_buffer (NULL,
415             (const guint8 *) "x", 1, "x"));
416
417     buf1 = gst_tag_list_to_vorbiscomment_buffer (list, NULL, 0, NULL);
418     fail_unless (buf1 != NULL);
419
420     buf2 = gst_tag_list_to_vorbiscomment_buffer (list,
421         (const guint8 *) "foo", 3, NULL);
422     fail_unless (buf2 != NULL);
423
424     data1 = gst_buffer_map (buf1, &size1, NULL, GST_MAP_READ);
425     data2 = gst_buffer_map (buf2, &size2, NULL, GST_MAP_READ);
426
427     fail_unless (memcmp (data1, data2 + 3, size1) == 0);
428
429     gst_buffer_unmap (buf2, data2, size2);
430     gst_buffer_unmap (buf1, data1, size1);
431
432     gst_buffer_unref (buf1);
433     gst_buffer_unref (buf2);
434   }
435
436   gst_tag_list_free (list);
437
438   /* make sure gst_tag_list_from_vorbiscomment_buffer() works with an
439    * empty ID (for Speex) */
440   {
441     const guint8 speex_comments_buf1[] = { 0x03, 0x00, 0x00, 0x00, 'f', 'o',
442       'o', 0x00, 0x00, 0x00, 0x00
443     };
444     GstBuffer *buf;
445     gchar *vendor = NULL;
446
447     buf = gst_buffer_new ();
448     gst_buffer_take_memory (buf, -1,
449         gst_memory_new_wrapped (GST_MEMORY_FLAG_READONLY,
450             (gpointer) speex_comments_buf1, NULL,
451             sizeof (speex_comments_buf1), 0, sizeof (speex_comments_buf1)));
452
453     /* make sure it doesn't memcmp over the end of the buffer */
454     fail_unless (gst_tag_list_from_vorbiscomment_buffer (buf,
455             (const guint8 *) "averylongstringbrownfoxjumpoverthefence", 39,
456             &vendor) == NULL);
457     fail_unless (vendor == NULL);
458
459     /* make sure it bails out if the ID doesn't match */
460     fail_unless (gst_tag_list_from_vorbiscomment_buffer (buf,
461             (guint8 *) "short", 4, &vendor) == NULL);
462     fail_unless (vendor == NULL);
463
464     /* now read properly */
465     list = gst_tag_list_from_vorbiscomment_buffer (buf, NULL, 0, &vendor);
466     fail_unless (vendor != NULL);
467     fail_unless_equals_string (vendor, "foo");
468     fail_unless (list != NULL);
469     fail_unless (gst_structure_n_fields ((GstStructure *) list) == 0);
470     g_free (vendor);
471     gst_tag_list_free (list);
472
473     /* now again without vendor */
474     list = gst_tag_list_from_vorbiscomment_buffer (buf, NULL, 0, NULL);
475     fail_unless (list != NULL);
476     fail_unless (gst_structure_n_fields ((GstStructure *) list) == 0);
477     gst_tag_list_free (list);
478
479     gst_buffer_unref (buf);
480   }
481
482   /* the same with an ID */
483   {
484     const guint8 vorbis_comments_buf[] = { 0x03, 'v', 'o', 'r', 'b', 'i', 's',
485       0x03, 0x00, 0x00, 0x00, 'f', 'o', 'o', 0x01, 0x00, 0x00, 0x00,
486       strlen ("ARTIST=foo bar"), 0x00, 0x00, 0x00, 'A', 'R', 'T', 'I', 'S',
487       'T', '=', 'f', 'o', 'o', ' ', 'b', 'a', 'r'
488     };
489     GstBuffer *buf;
490     gchar *vendor = NULL;
491
492     buf = gst_buffer_new ();
493     gst_buffer_take_memory (buf, -1,
494         gst_memory_new_wrapped (GST_MEMORY_FLAG_READONLY,
495             (gpointer) vorbis_comments_buf, NULL,
496             sizeof (vorbis_comments_buf), 0, sizeof (vorbis_comments_buf)));
497
498     /* make sure it doesn't memcmp over the end of the buffer */
499     fail_unless (gst_tag_list_from_vorbiscomment_buffer (buf,
500             (const guint8 *) "averylongstringbrownfoxjumpoverthefence", 39,
501             &vendor) == NULL);
502     fail_unless (vendor == NULL);
503
504     /* make sure it bails out if the ID doesn't match */
505     fail_unless (gst_tag_list_from_vorbiscomment_buffer (buf,
506             (guint8 *) "short", 4, &vendor) == NULL);
507     fail_unless (vendor == NULL);
508
509     /* now read properly */
510     list = gst_tag_list_from_vorbiscomment_buffer (buf,
511         (guint8 *) "\003vorbis", 7, &vendor);
512     fail_unless (vendor != NULL);
513     fail_unless_equals_string (vendor, "foo");
514     fail_unless (list != NULL);
515     fail_unless (gst_structure_n_fields ((GstStructure *) list) == 1);
516     ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_ARTIST, "foo bar");
517     g_free (vendor);
518     gst_tag_list_free (list);
519
520     /* now again without vendor */
521     list = gst_tag_list_from_vorbiscomment_buffer (buf,
522         (guint8 *) "\003vorbis", 7, NULL);
523     fail_unless (list != NULL);
524     fail_unless (gst_structure_n_fields ((GstStructure *) list) == 1);
525     ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_ARTIST, "foo bar");
526     gst_tag_list_free (list);
527
528     gst_buffer_unref (buf);
529   }
530
531   /* check date with time */
532   {
533     GDate *date = NULL;
534
535     list = gst_tag_list_new_empty ();
536     gst_vorbis_tag_add (list, "DATE", "2006-09-25 22:02:38");
537
538     fail_unless (gst_tag_list_get_date_index (list, GST_TAG_DATE, 0, &date));
539     fail_unless (date != NULL);
540     fail_unless (g_date_get_day (date) == 25);
541     fail_unless (g_date_get_month (date) == G_DATE_SEPTEMBER);
542     fail_unless (g_date_get_year (date) == 2006);
543
544     g_date_free (date);
545     gst_tag_list_free (list);
546   }
547
548   /* check date with month/day of 00-00 */
549   {
550     GDate *date = NULL;
551
552     list = gst_tag_list_new_empty ();
553     gst_vorbis_tag_add (list, "DATE", "1992-00-00");
554
555     fail_unless (gst_tag_list_get_date_index (list, GST_TAG_DATE, 0, &date));
556     fail_unless (date != NULL);
557     fail_unless (g_date_get_year (date) == 1992);
558
559     g_date_free (date);
560     gst_tag_list_free (list);
561   }
562
563   /* check date with valid month, but day of 00 */
564   {
565     GDate *date = NULL;
566
567     list = gst_tag_list_new_empty ();
568     gst_vorbis_tag_add (list, "DATE", "1992-05-00");
569
570     fail_unless (gst_tag_list_get_date_index (list, GST_TAG_DATE, 0, &date));
571     fail_unless (date != NULL);
572     fail_unless (g_date_get_year (date) == 1992);
573     fail_unless (g_date_get_month (date) == G_DATE_MAY);
574
575     g_date_free (date);
576     gst_tag_list_free (list);
577   }
578 }
579
580 GST_END_TEST;
581
582 GST_START_TEST (test_id3_tags)
583 {
584   guint i;
585
586   fail_unless (gst_tag_id3_genre_count () > 0);
587
588   for (i = 0; i < gst_tag_id3_genre_count (); ++i) {
589     const gchar *genre;
590
591     genre = gst_tag_id3_genre_get (i);
592     GST_LOG ("genre: %s", genre);
593     fail_unless (genre != NULL);
594   }
595
596   {
597     /* TODO: GstTagList *gst_tag_list_new_from_id3v1 (const guint8 *data) */
598   }
599
600   /* gst_tag_from_id3_tag */
601   fail_unless (gst_tag_from_id3_tag ("TALB") != NULL);
602   ASSERT_CRITICAL (gst_tag_from_id3_tag (NULL));
603   fail_unless (gst_tag_from_id3_tag ("R2D2") == NULL);
604   fail_unless_equals_string (gst_tag_from_id3_tag ("WCOP"),
605       GST_TAG_COPYRIGHT_URI);
606
607   /* gst_tag_from_id3_user_tag */
608   ASSERT_CRITICAL (gst_tag_from_id3_user_tag (NULL, "foo"));
609   ASSERT_CRITICAL (gst_tag_from_id3_user_tag ("foo", NULL));
610   fail_unless (gst_tag_from_id3_user_tag ("R2D2", "R2D2") == NULL);
611
612   /* gst_tag_to_id3_tag */
613   ASSERT_CRITICAL (gst_tag_to_id3_tag (NULL));
614   fail_unless (gst_tag_to_id3_tag ("R2D2") == NULL);
615   fail_unless (gst_tag_to_id3_tag (GST_TAG_ARTIST) != NULL);
616   fail_unless_equals_string (gst_tag_to_id3_tag (GST_TAG_COPYRIGHT_URI),
617       "WCOP");
618
619   fail_unless (GST_TYPE_TAG_IMAGE_TYPE != 0);
620   fail_unless (g_type_name (GST_TYPE_TAG_IMAGE_TYPE) != NULL);
621 }
622
623 GST_END_TEST;
624
625
626 GST_START_TEST (test_id3v1_utf8_tag)
627 {
628   const guint8 id3v1[128] = {
629     /* marker */
630     'T', 'A', 'G',
631     /* title (30 bytes) */
632     'D', 0xc3, 0xad, 'v', 'k', 'a', ' ', 's',
633     ' ', 'p', 'e', 'r', 'l', 'a', 'm', 'i',
634     ' ', 'v', 'e', ' ', 'v', 'l', 'a', 's',
635     'e', 'c', 'h', 0, 0, 0,
636     /* artist (30 bytes) */
637     'A', 'l', 'e', 0xc5, 0xa1, ' ', 'B', 'r', 'i', 'c', 'h', 't', 'a',
638     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
639     /* album (30 bytes) */
640     'B', 'e', 's', 't', ' ', 'o', 'f', ' ', '(', 'P', 'r', 'o', 's', 't',
641     0xc4, 0x9b, ' ', 0xc3, 0xba, 0xc5, 0xbe, 'a', 's', 'n', 0xc3, 0xbd, ')',
642     0, 0, 0,
643     /* year (4 bytes) */
644     '2', '0', '0', '0',
645     /* comment (28 bytes) */
646     '-', '-', '-', ' ', 0xc4, 0x8d, 'e', 's', 'k', 0xc3, 0xa9, ' ', 'p',
647     0xc3, 0xad, 's', 'n', 'i', 0xc4, 0x8d, 'k', 'y', ' ', '-', '-', '-',
648     0, 0,
649     /* track number */
650     0, 0,
651     /* genre */
652     0x11
653   };
654   GstTagList *tags;
655   GDate *d;
656   gchar *s;
657
658   /* set this, to make sure UTF-8 strings are really interpreted properly
659    * as UTF-8, regardless of the locale set */
660   g_setenv ("GST_ID3V1_TAG_ENCODING", "WINDOWS-1250", TRUE);
661
662   tags = gst_tag_list_new_from_id3v1 (id3v1);
663   fail_unless (tags != NULL);
664
665   GST_LOG ("Got tags: %" GST_PTR_FORMAT, tags);
666
667   s = NULL;
668   fail_unless (gst_tag_list_get_string (tags, GST_TAG_TITLE, &s));
669   fail_unless (s != NULL);
670   fail_unless_equals_string (s, "Dívka s perlami ve vlasech");
671   g_free (s);
672
673   s = NULL;
674   fail_unless (gst_tag_list_get_string (tags, GST_TAG_ARTIST, &s));
675   fail_unless (s != NULL);
676   fail_unless_equals_string (s, "Aleš Brichta");
677   g_free (s);
678
679   s = NULL;
680   fail_unless (gst_tag_list_get_string (tags, GST_TAG_ALBUM, &s));
681   fail_unless (s != NULL);
682   fail_unless_equals_string (s, "Best of (Prostě úžasný)");
683   g_free (s);
684
685   d = NULL;
686   fail_unless (gst_tag_list_get_date (tags, GST_TAG_DATE, &d));
687   fail_unless (d != NULL);
688   fail_unless_equals_int (g_date_get_year (d), 2000);
689   g_date_free (d);
690   d = NULL;
691
692   gst_tag_list_free (tags);
693
694   g_unsetenv ("GST_ID3V1_TAG_ENCODING");
695 }
696
697 GST_END_TEST;
698
699 GST_START_TEST (test_language_utils)
700 {
701   gchar **lang_codes, **c;
702
703 #define ASSERT_STRINGS_EQUAL fail_unless_equals_string
704
705   lang_codes = gst_tag_get_language_codes ();
706   fail_unless (lang_codes != NULL);
707   fail_unless (*lang_codes != NULL);
708
709   for (c = lang_codes; c != NULL && *c != NULL; ++c) {
710     const gchar *lang_name, *c1, *c2t, *c2b;
711
712     lang_name = gst_tag_get_language_name (*c);
713     fail_unless (lang_name != NULL);
714     fail_unless (g_utf8_validate (lang_name, -1, NULL));
715
716     c1 = gst_tag_get_language_code_iso_639_1 (*c);
717     fail_unless (c1 != NULL);
718     fail_unless (g_utf8_validate (c1, -1, NULL));
719
720     c2t = gst_tag_get_language_code_iso_639_2T (*c);
721     fail_unless (c2t != NULL);
722     fail_unless (g_utf8_validate (c2t, -1, NULL));
723
724     c2b = gst_tag_get_language_code_iso_639_2B (*c);
725     fail_unless (c2b != NULL);
726     fail_unless (g_utf8_validate (c2b, -1, NULL));
727
728     ASSERT_STRINGS_EQUAL (gst_tag_get_language_code_iso_639_1 (*c), *c);
729     ASSERT_STRINGS_EQUAL (gst_tag_get_language_code_iso_639_1 (c2t), *c);
730     ASSERT_STRINGS_EQUAL (gst_tag_get_language_code_iso_639_1 (c2b), *c);
731
732     GST_DEBUG ("[%s] %s %s %s : %s\n", *c, c1, c2t, c2b, lang_name);
733
734   }
735   g_strfreev (lang_codes);
736
737   fail_unless (gst_tag_get_language_name ("de") != NULL);
738   fail_unless (gst_tag_get_language_name ("deu") != NULL);
739   fail_unless (gst_tag_get_language_name ("ger") != NULL);
740   fail_unless_equals_string (gst_tag_get_language_name ("deu"),
741       gst_tag_get_language_name ("ger"));
742   fail_unless_equals_string (gst_tag_get_language_name ("de"),
743       gst_tag_get_language_name ("ger"));
744   fail_unless (gst_tag_get_language_name ("de") !=
745       gst_tag_get_language_name ("fr"));
746
747   ASSERT_STRINGS_EQUAL (gst_tag_get_language_code ("deu"), "de");
748   ASSERT_STRINGS_EQUAL (gst_tag_get_language_code ("de"), "de");
749   ASSERT_STRINGS_EQUAL (gst_tag_get_language_code ("ger"), "de");
750
751   ASSERT_STRINGS_EQUAL (gst_tag_get_language_code_iso_639_1 ("deu"), "de");
752   ASSERT_STRINGS_EQUAL (gst_tag_get_language_code_iso_639_1 ("de"), "de");
753   ASSERT_STRINGS_EQUAL (gst_tag_get_language_code_iso_639_1 ("ger"), "de");
754
755   ASSERT_STRINGS_EQUAL (gst_tag_get_language_code_iso_639_2T ("de"), "deu");
756   ASSERT_STRINGS_EQUAL (gst_tag_get_language_code_iso_639_2T ("deu"), "deu");
757   ASSERT_STRINGS_EQUAL (gst_tag_get_language_code_iso_639_2T ("ger"), "deu");
758
759   ASSERT_STRINGS_EQUAL (gst_tag_get_language_code_iso_639_2B ("de"), "ger");
760   ASSERT_STRINGS_EQUAL (gst_tag_get_language_code_iso_639_2B ("deu"), "ger");
761   ASSERT_STRINGS_EQUAL (gst_tag_get_language_code_iso_639_2B ("ger"), "ger");
762 }
763
764 GST_END_TEST;
765
766 #define SPECIFIC_L "http://creativecommons.org/licenses/by-nc-sa/2.5/scotland/"
767 #define GENERIC_L "http://creativecommons.org/licenses/by/1.0/"
768 #define DERIVED_L "http://creativecommons.org/licenses/sampling+/1.0/tw/"
769
770 GST_START_TEST (test_license_utils)
771 {
772   GHashTable *ht;
773   GError *err = NULL;
774   gchar **liblicense_refs, **r;
775   gchar **lrefs, **l;
776   gchar *path, *data = NULL;
777   gsize data_len;
778
779   gst_debug_set_threshold_for_name ("tag-licenses", GST_LEVEL_NONE);
780
781   /* test jurisdiction-specific license */
782   fail_unless_equals_int (gst_tag_get_license_flags (SPECIFIC_L), 0x01010703);
783   fail_unless_equals_string (gst_tag_get_license_nick (SPECIFIC_L),
784       "CC BY-NC-SA 2.5 SCOTLAND");
785   fail_unless_equals_string (gst_tag_get_license_version (SPECIFIC_L), "2.5");
786   fail_unless_equals_string (gst_tag_get_license_jurisdiction (SPECIFIC_L),
787       "scotland");
788
789   g_setenv ("GST_TAG_LICENSE_TRANSLATIONS_LANG", "C", TRUE);
790   fail_unless_equals_string (gst_tag_get_license_title (SPECIFIC_L),
791       "Attribution-NonCommercial-ShareAlike");
792   fail_unless (gst_tag_get_license_description (SPECIFIC_L) == NULL);
793
794   /* test generic license */
795   fail_unless_equals_int (gst_tag_get_license_flags (GENERIC_L), 0x01000307);
796   fail_unless_equals_string (gst_tag_get_license_nick (GENERIC_L), "CC BY 1.0");
797   fail_unless_equals_string (gst_tag_get_license_version (GENERIC_L), "1.0");
798   fail_unless (gst_tag_get_license_jurisdiction (GENERIC_L) == NULL);
799
800   g_setenv ("GST_TAG_LICENSE_TRANSLATIONS_LANG", "C", TRUE);
801   fail_unless_equals_string (gst_tag_get_license_title (GENERIC_L),
802       "Attribution");
803   fail_unless_equals_string (gst_tag_get_license_description (GENERIC_L),
804       "You must attribute the work in the manner specified by the author or licensor.");
805
806 #ifdef ENABLE_NLS
807   g_setenv ("GST_TAG_LICENSE_TRANSLATIONS_LANG", "fr", TRUE);
808   fail_unless_equals_string (gst_tag_get_license_title (GENERIC_L),
809       "Paternité");
810   fail_unless_equals_string (gst_tag_get_license_description (GENERIC_L),
811       "L'offrant autorise les autres à reproduire, distribuer et communiquer cette création au public. En échange, les personnes qui acceptent ce contrat doivent citer le nom de l'auteur original.");
812 #endif
813
814   /* test derived (for a certain jurisdiction) license */
815   fail_unless_equals_int (gst_tag_get_license_flags (DERIVED_L), 0x0100030d);
816   fail_unless_equals_string (gst_tag_get_license_nick (DERIVED_L),
817       "CC SAMPLING+ 1.0 TW");
818   fail_unless_equals_string (gst_tag_get_license_version (DERIVED_L), "1.0");
819   fail_unless_equals_string (gst_tag_get_license_jurisdiction (DERIVED_L),
820       "tw");
821
822   g_setenv ("GST_TAG_LICENSE_TRANSLATIONS_LANG", "C", TRUE);
823   fail_unless_equals_string (gst_tag_get_license_title (DERIVED_L),
824       "Sampling Plus");
825   fail_unless_equals_string (gst_tag_get_license_description (GENERIC_L),
826       "You must attribute the work in the manner specified by the author or licensor.");
827
828   /* test all we know about */
829   lrefs = gst_tag_get_licenses ();
830   fail_unless (lrefs != NULL);
831   fail_unless (*lrefs != NULL);
832
833   GST_INFO ("%d licenses", g_strv_length (lrefs));
834   fail_unless (g_strv_length (lrefs) >= 376);
835
836   ht = g_hash_table_new (g_str_hash, g_str_equal);
837
838   for (l = lrefs; l != NULL && *l != NULL; ++l) {
839     const gchar *ref, *nick, *title, *desc G_GNUC_UNUSED;
840
841     ref = (const gchar *) *l;
842     nick = gst_tag_get_license_nick (ref);
843     title = gst_tag_get_license_title (ref);
844     desc = gst_tag_get_license_description (ref);
845     fail_unless (nick != NULL, "no nick for license '%s'", ref);
846     fail_unless (title != NULL, "no title for license '%s'", ref);
847     GST_LOG ("ref: %s [nick %s]", ref, (nick) ? nick : "none");
848     GST_TRACE ("    %s : %s", title, (desc) ? desc : "(no description)");
849
850     /* make sure the list contains no duplicates */
851     fail_if (g_hash_table_lookup (ht, (gpointer) ref) != NULL);
852     g_hash_table_insert (ht, (gpointer) ref, (gpointer) "meep");
853   }
854   g_hash_table_destroy (ht);
855
856   /* trailing slash shouldn't make a difference */
857   fail_unless_equals_int (gst_tag_get_license_flags
858       ("http://creativecommons.org/licenses/by-nd/1.0/"),
859       gst_tag_get_license_flags
860       ("http://creativecommons.org/licenses/by-nd/1.0"));
861   fail_unless_equals_string (gst_tag_get_license_nick
862       ("http://creativecommons.org/licenses/by-nd/1.0/"),
863       gst_tag_get_license_nick
864       ("http://creativecommons.org/licenses/by-nd/1.0"));
865   fail_unless_equals_int (gst_tag_get_license_flags
866       ("http://creativecommons.org/licenses/by-nd/2.5/ca/"),
867       gst_tag_get_license_flags
868       ("http://creativecommons.org/licenses/by-nd/2.5/ca"));
869   fail_unless_equals_string (gst_tag_get_license_nick
870       ("http://creativecommons.org/licenses/by-nd/2.5/ca/"),
871       gst_tag_get_license_nick
872       ("http://creativecommons.org/licenses/by-nd/2.5/ca"));
873
874   /* unknown licenses */
875   fail_unless (gst_tag_get_license_nick
876       ("http://creativecommons.org/licenses/by-nd/25/ca/") == NULL);
877   fail_unless (gst_tag_get_license_flags
878       ("http://creativecommons.org/licenses/by-nd/25/ca") == 0);
879   fail_unless (gst_tag_get_license_jurisdiction
880       ("http://creativecommons.org/licenses/by-nd/25/ca/") == NULL);
881   fail_unless (gst_tag_get_license_jurisdiction
882       ("http://creativecommons.org/licenses/by-nd/25/ca") == NULL);
883   fail_unless (gst_tag_get_license_title
884       ("http://creativecommons.org/licenses/by-nd/25/ca") == NULL);
885   fail_unless (gst_tag_get_license_jurisdiction
886       ("http://creativecommons.org/licenses/by-nd/25/ca") == NULL);
887
888   /* unknown prefixes even */
889   fail_unless (gst_tag_get_license_nick
890       ("http://copycats.org/licenses/by-nd/2.5/ca/") == NULL);
891   fail_unless (gst_tag_get_license_flags
892       ("http://copycats.org/licenses/by-nd/2.5/ca") == 0);
893   fail_unless (gst_tag_get_license_jurisdiction
894       ("http://copycats.org/licenses/by-nd/2.5/ca/") == NULL);
895   fail_unless (gst_tag_get_license_title
896       ("http://copycats.org/licenses/by-nd/2.5/ca/") == NULL);
897   fail_unless (gst_tag_get_license_description
898       ("http://copycats.org/licenses/by-nd/2.5/ca/") == NULL);
899
900   /* read list of liblicense refs from file */
901   path = g_build_filename (GST_TEST_FILES_PATH, "license-uris", NULL);
902   GST_LOG ("reading file '%s'", path);
903   if (!g_file_get_contents (path, &data, &data_len, &err)) {
904     g_error ("error loading test file: %s", err->message);
905   }
906
907   while (data_len > 0 && data[data_len - 1] == '\n') {
908     data[--data_len] = '\0';
909   }
910
911   liblicense_refs = g_strsplit (data, "\n", -1);
912   g_free (data);
913   g_free (path);
914
915   fail_unless (g_strv_length (lrefs) >= g_strv_length (liblicense_refs));
916
917   for (r = liblicense_refs; r != NULL && *r != NULL; ++r) {
918     GstTagLicenseFlags flags;
919     const gchar *version, *nick, *jur;
920     const gchar *ref = *r;
921
922     GST_LOG ("liblicense ref: %s", ref);
923
924     version = gst_tag_get_license_version (ref);
925     if (strstr (ref, "publicdomain") != NULL)
926       fail_unless (version == NULL);
927     else
928       fail_unless (version != NULL, "expected version for license %s", ref);
929
930     flags = gst_tag_get_license_flags (ref);
931     fail_unless (flags != 0, "expected non-zero flags for license %s", ref);
932
933     nick = gst_tag_get_license_nick (ref);
934     fail_unless (nick != NULL, "expected nick for license %s", ref);
935
936     jur = gst_tag_get_license_jurisdiction (ref);
937     if (g_str_has_suffix (ref, "de/")) {
938       fail_unless_equals_string (jur, "de");
939     } else if (g_str_has_suffix (ref, "scotland")) {
940       fail_unless_equals_string (jur, "scotland");
941     } else if (g_str_has_suffix (ref, ".0") || g_str_has_suffix (ref, ".1")) {
942       fail_unless (jur == NULL);
943     }
944   }
945
946   g_strfreev (liblicense_refs);
947   g_strfreev (lrefs);
948 }
949
950 GST_END_TEST;
951
952 GST_START_TEST (test_xmp_formatting)
953 {
954   GstTagList *list;
955   GstBuffer *buf;
956   const gchar *text;
957   gsize len;
958
959   /* test data */
960   list = gst_tag_list_new (GST_TAG_TITLE, "test title",
961       GST_TAG_DESCRIPTION, "test decription",
962       GST_TAG_KEYWORDS, "keyword1", GST_TAG_KEYWORDS, "keyword2", NULL);
963
964   buf = gst_tag_list_to_xmp_buffer (list, FALSE);
965   fail_unless (buf != NULL);
966
967   text = gst_buffer_map (buf, &len, NULL, GST_MAP_READ);
968
969   /* check the content */
970   fail_unless (g_strrstr_len (text, len, "<?xpacket begin") == text);
971   fail_unless (g_strrstr_len (text, len, ">test title<") != NULL);
972   fail_unless (g_strrstr_len (text, len, ">test decription<") != NULL);
973   fail_unless (g_strrstr_len (text, len, ">keyword1<") != NULL);
974   fail_unless (g_strrstr_len (text, len, ">keyword2<") != NULL);
975   fail_unless (g_strrstr_len (text, len, "<?xpacket end") != NULL);
976   gst_buffer_unmap (buf, (gpointer) text, len);
977
978   gst_buffer_unref (buf);
979   gst_tag_list_free (list);
980 }
981
982 GST_END_TEST;
983
984
985 GST_START_TEST (test_xmp_parsing)
986 {
987   GstTagList *list;
988   GstBuffer *buf;
989   guint i, j, result_size;
990   gchar *text;
991   const gchar *xmp_header =
992       "<?xpacket begin=\"\xEF\xBB\xBF\" id=\"W5M0MpCehiHzreSzNTczkc9d\"?>"
993       "<x:xmpmeta xmlns:x=\"adobe:ns:meta/\" x:xmptk=\"GStreamer\">"
994       "<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\">";
995
996   /* We used to write an extra trailing \n after the footer, keep compatibility
997    * with our old generated media by checking that it still can be parsed */
998   const gchar *xmp_footers[] = {
999     "</rdf:RDF>" "</x:xmpmeta>" "<?xpacket end=\"r\"?>",
1000     "</rdf:RDF>" "</x:xmpmeta>" "<?xpacket end=\"r\"?>\n",
1001     NULL
1002   };
1003
1004   struct
1005   {
1006     const gchar *xmp_data;
1007     gint result_size;
1008     gint result_test;
1009   } test_data[] = {
1010     {
1011     "", -1, -1}, {
1012     "<rdf:Description rdf:about=\"\" />", 0, -1}, {
1013     "<rdf:Description rdf:about=\"\"></rdf:Description>", 0, -1}, {
1014     "<rdf:Description    rdf:about=\"\"    ></rdf:Description>", 0, -1}, {
1015     "<rdf:Description rdf:about=\"\"><dc:description>test</dc:description></rdf:Description>",
1016           1, 0}, {
1017     "<rdf:Description rdf:about=\"\" dc:description=\"test\"></rdf:Description>",
1018           1, 0}, {
1019     NULL, -1, -1}
1020   };
1021
1022   /* test data */
1023   j = 0;
1024   i = 0;
1025   while (xmp_footers[j]) {
1026     while (test_data[i].xmp_data) {
1027       gsize len;
1028
1029       GST_DEBUG ("trying test-data %u", i);
1030
1031       text =
1032           g_strconcat (xmp_header, test_data[i].xmp_data, xmp_footers[j], NULL);
1033
1034       buf = gst_buffer_new ();
1035       len = strlen (text) + 1;
1036       gst_buffer_take_memory (buf, -1,
1037           gst_memory_new_wrapped (0, text, NULL, len, 0, len));
1038
1039       list = gst_tag_list_from_xmp_buffer (buf);
1040       if (test_data[i].result_size >= 0) {
1041         fail_unless (list != NULL);
1042
1043         result_size = gst_structure_n_fields ((GstStructure *) list);
1044         fail_unless (result_size == test_data[i].result_size);
1045
1046         /* check the taglist content */
1047         switch (test_data[i].result_test) {
1048           case 0:
1049             ASSERT_TAG_LIST_HAS_STRING (list, "description", "test");
1050             break;
1051           default:
1052             break;
1053         }
1054       }
1055       if (list)
1056         gst_tag_list_free (list);
1057
1058       gst_buffer_unref (buf);
1059       g_free (text);
1060       i++;
1061     }
1062     j++;
1063   }
1064 }
1065
1066 GST_END_TEST;
1067
1068 static void
1069 do_xmp_tag_serialization_deserialization (GstTagList * taglist,
1070     const gchar ** schemas)
1071 {
1072   GstTagList *taglist2;
1073   GstBuffer *buf;
1074
1075   buf = gst_tag_list_to_xmp_buffer_full (taglist, TRUE, schemas);
1076   taglist2 = gst_tag_list_from_xmp_buffer (buf);
1077
1078   fail_unless (gst_tag_list_is_equal (taglist, taglist2));
1079
1080   gst_buffer_unref (buf);
1081   gst_tag_list_free (taglist2);
1082 }
1083
1084 static void
1085 do_simple_xmp_tag_serialization_deserialization (const gchar * gsttag,
1086     GValue * value)
1087 {
1088   GstTagList *taglist = gst_tag_list_new_empty ();
1089
1090   gst_tag_list_add_value (taglist, GST_TAG_MERGE_REPLACE, gsttag, value);
1091
1092   do_xmp_tag_serialization_deserialization (taglist, NULL);
1093   gst_tag_list_free (taglist);
1094 }
1095
1096 GST_START_TEST (test_xmp_tags_serialization_deserialization)
1097 {
1098   GValue value = { 0 };
1099   GDate *date;
1100   GstDateTime *datetime;
1101
1102   gst_tag_register_musicbrainz_tags ();
1103
1104   g_value_init (&value, G_TYPE_STRING);
1105   g_value_set_static_string (&value, "my string");
1106   do_simple_xmp_tag_serialization_deserialization (GST_TAG_ARTIST, &value);
1107   do_simple_xmp_tag_serialization_deserialization (GST_TAG_COPYRIGHT, &value);
1108   do_simple_xmp_tag_serialization_deserialization (GST_TAG_DESCRIPTION, &value);
1109   do_simple_xmp_tag_serialization_deserialization (GST_TAG_KEYWORDS, &value);
1110   do_simple_xmp_tag_serialization_deserialization (GST_TAG_TITLE, &value);
1111   do_simple_xmp_tag_serialization_deserialization (GST_TAG_VIDEO_CODEC, &value);
1112   do_simple_xmp_tag_serialization_deserialization (GST_TAG_GEO_LOCATION_COUNTRY,
1113       &value);
1114   do_simple_xmp_tag_serialization_deserialization (GST_TAG_GEO_LOCATION_CITY,
1115       &value);
1116   do_simple_xmp_tag_serialization_deserialization
1117       (GST_TAG_GEO_LOCATION_SUBLOCATION, &value);
1118   do_simple_xmp_tag_serialization_deserialization (GST_TAG_DEVICE_MANUFACTURER,
1119       &value);
1120   do_simple_xmp_tag_serialization_deserialization (GST_TAG_DEVICE_MODEL,
1121       &value);
1122   do_simple_xmp_tag_serialization_deserialization (GST_TAG_APPLICATION_NAME,
1123       &value);
1124
1125   g_value_set_static_string (&value, "rotate-0");
1126   do_simple_xmp_tag_serialization_deserialization (GST_TAG_IMAGE_ORIENTATION,
1127       &value);
1128   g_value_set_static_string (&value, "flip-rotate-0");
1129   do_simple_xmp_tag_serialization_deserialization (GST_TAG_IMAGE_ORIENTATION,
1130       &value);
1131   g_value_set_static_string (&value, "rotate-180");
1132   do_simple_xmp_tag_serialization_deserialization (GST_TAG_IMAGE_ORIENTATION,
1133       &value);
1134   g_value_set_static_string (&value, "flip-rotate-180");
1135   do_simple_xmp_tag_serialization_deserialization (GST_TAG_IMAGE_ORIENTATION,
1136       &value);
1137   g_value_set_static_string (&value, "flip-rotate-270");
1138   do_simple_xmp_tag_serialization_deserialization (GST_TAG_IMAGE_ORIENTATION,
1139       &value);
1140   g_value_set_static_string (&value, "rotate-90");
1141   do_simple_xmp_tag_serialization_deserialization (GST_TAG_IMAGE_ORIENTATION,
1142       &value);
1143   g_value_set_static_string (&value, "flip-rotate-90");
1144   do_simple_xmp_tag_serialization_deserialization (GST_TAG_IMAGE_ORIENTATION,
1145       &value);
1146   g_value_set_static_string (&value, "rotate-270");
1147   do_simple_xmp_tag_serialization_deserialization (GST_TAG_IMAGE_ORIENTATION,
1148       &value);
1149
1150   g_value_unset (&value);
1151   g_value_init (&value, G_TYPE_DOUBLE);
1152
1153   g_value_set_double (&value, 0.0);
1154   do_simple_xmp_tag_serialization_deserialization
1155       (GST_TAG_GEO_LOCATION_LATITUDE, &value);
1156   do_simple_xmp_tag_serialization_deserialization
1157       (GST_TAG_GEO_LOCATION_LONGITUDE, &value);
1158   g_value_set_double (&value, 10.5);
1159   do_simple_xmp_tag_serialization_deserialization
1160       (GST_TAG_GEO_LOCATION_LATITUDE, &value);
1161   do_simple_xmp_tag_serialization_deserialization
1162       (GST_TAG_GEO_LOCATION_LONGITUDE, &value);
1163   g_value_set_double (&value, -32.375);
1164   do_simple_xmp_tag_serialization_deserialization
1165       (GST_TAG_GEO_LOCATION_LATITUDE, &value);
1166   do_simple_xmp_tag_serialization_deserialization
1167       (GST_TAG_GEO_LOCATION_LONGITUDE, &value);
1168
1169   g_value_set_double (&value, 0);
1170   do_simple_xmp_tag_serialization_deserialization
1171       (GST_TAG_GEO_LOCATION_ELEVATION, &value);
1172   g_value_set_double (&value, 100);
1173   do_simple_xmp_tag_serialization_deserialization
1174       (GST_TAG_GEO_LOCATION_ELEVATION, &value);
1175   g_value_set_double (&value, 500.25);
1176   do_simple_xmp_tag_serialization_deserialization
1177       (GST_TAG_GEO_LOCATION_ELEVATION, &value);
1178   g_value_set_double (&value, -12.75);
1179   do_simple_xmp_tag_serialization_deserialization
1180       (GST_TAG_GEO_LOCATION_ELEVATION, &value);
1181
1182   g_value_set_double (&value, 0.0);
1183   do_simple_xmp_tag_serialization_deserialization
1184       (GST_TAG_GEO_LOCATION_MOVEMENT_SPEED, &value);
1185   g_value_set_double (&value, 10.0);
1186   do_simple_xmp_tag_serialization_deserialization
1187       (GST_TAG_GEO_LOCATION_MOVEMENT_SPEED, &value);
1188   g_value_set_double (&value, 786.125);
1189   do_simple_xmp_tag_serialization_deserialization
1190       (GST_TAG_GEO_LOCATION_MOVEMENT_SPEED, &value);
1191   g_value_set_double (&value, -2.5);
1192   do_simple_xmp_tag_serialization_deserialization
1193       (GST_TAG_GEO_LOCATION_MOVEMENT_SPEED, &value);
1194
1195   g_value_set_double (&value, 0.0);
1196   do_simple_xmp_tag_serialization_deserialization
1197       (GST_TAG_GEO_LOCATION_MOVEMENT_DIRECTION, &value);
1198   g_value_set_double (&value, 180.0);
1199   do_simple_xmp_tag_serialization_deserialization
1200       (GST_TAG_GEO_LOCATION_MOVEMENT_DIRECTION, &value);
1201   g_value_set_double (&value, 359.99);
1202   do_simple_xmp_tag_serialization_deserialization
1203       (GST_TAG_GEO_LOCATION_MOVEMENT_DIRECTION, &value);
1204
1205   g_value_set_double (&value, 0.0);
1206   do_simple_xmp_tag_serialization_deserialization
1207       (GST_TAG_GEO_LOCATION_CAPTURE_DIRECTION, &value);
1208   g_value_set_double (&value, 90.0);
1209   do_simple_xmp_tag_serialization_deserialization
1210       (GST_TAG_GEO_LOCATION_CAPTURE_DIRECTION, &value);
1211   g_value_set_double (&value, 359.99);
1212   do_simple_xmp_tag_serialization_deserialization
1213       (GST_TAG_GEO_LOCATION_CAPTURE_DIRECTION, &value);
1214
1215   g_value_set_double (&value, 0.0);
1216   do_simple_xmp_tag_serialization_deserialization
1217       (GST_TAG_CAPTURING_EXPOSURE_COMPENSATION, &value);
1218   g_value_set_double (&value, 1.0);
1219   do_simple_xmp_tag_serialization_deserialization
1220       (GST_TAG_CAPTURING_EXPOSURE_COMPENSATION, &value);
1221   g_value_set_double (&value, -2.5);
1222   do_simple_xmp_tag_serialization_deserialization
1223       (GST_TAG_CAPTURING_EXPOSURE_COMPENSATION, &value);
1224   g_value_unset (&value);
1225
1226   g_value_init (&value, GST_TYPE_DATE);
1227   date = g_date_new_dmy (22, 3, 2010);
1228   gst_value_set_date (&value, date);
1229   g_date_free (date);
1230   do_simple_xmp_tag_serialization_deserialization (GST_TAG_DATE, &value);
1231   g_value_unset (&value);
1232
1233   g_value_init (&value, G_TYPE_UINT);
1234   g_value_set_uint (&value, 0);
1235   do_simple_xmp_tag_serialization_deserialization (GST_TAG_USER_RATING, &value);
1236   g_value_set_uint (&value, 100);
1237   do_simple_xmp_tag_serialization_deserialization (GST_TAG_USER_RATING, &value);
1238   g_value_set_uint (&value, 22);
1239   do_simple_xmp_tag_serialization_deserialization (GST_TAG_USER_RATING, &value);
1240   g_value_unset (&value);
1241
1242   g_value_init (&value, GST_TYPE_DATE_TIME);
1243   datetime = gst_date_time_new (0, 2010, 6, 22, 12, 5, 10);
1244   g_value_set_boxed (&value, datetime);
1245   gst_date_time_unref (datetime);
1246   do_simple_xmp_tag_serialization_deserialization (GST_TAG_DATE_TIME, &value);
1247   datetime = gst_date_time_new (0, 2010, 6, 22, 12, 5, 10.000125);
1248   g_value_set_boxed (&value, datetime);
1249   gst_date_time_unref (datetime);
1250   do_simple_xmp_tag_serialization_deserialization (GST_TAG_DATE_TIME, &value);
1251   datetime = gst_date_time_new (0, 2010, 6, 22, 12, 5, 10.000001);
1252   g_value_set_boxed (&value, datetime);
1253   gst_date_time_unref (datetime);
1254   do_simple_xmp_tag_serialization_deserialization (GST_TAG_DATE_TIME, &value);
1255   datetime = gst_date_time_new (0, 2010, 6, 22, 12, 5, 10.123456);
1256   g_value_set_boxed (&value, datetime);
1257   gst_date_time_unref (datetime);
1258   do_simple_xmp_tag_serialization_deserialization (GST_TAG_DATE_TIME, &value);
1259   datetime = gst_date_time_new (-3, 2010, 6, 22, 12, 5, 10.123456);
1260   g_value_set_boxed (&value, datetime);
1261   gst_date_time_unref (datetime);
1262   do_simple_xmp_tag_serialization_deserialization (GST_TAG_DATE_TIME, &value);
1263   datetime = gst_date_time_new (5, 2010, 6, 22, 12, 5, 10.123456);
1264   g_value_set_boxed (&value, datetime);
1265   gst_date_time_unref (datetime);
1266   do_simple_xmp_tag_serialization_deserialization (GST_TAG_DATE_TIME, &value);
1267   datetime = gst_date_time_new_local_time (2010, 12, 2, 12, 5, 10.000043);
1268   g_value_set_boxed (&value, datetime);
1269   gst_date_time_unref (datetime);
1270   do_simple_xmp_tag_serialization_deserialization (GST_TAG_DATE_TIME, &value);
1271   g_value_unset (&value);
1272 }
1273
1274 GST_END_TEST;
1275
1276
1277 GST_START_TEST (test_xmp_compound_tags)
1278 {
1279   const gchar *schemas[] = { "Iptc4xmpExt", NULL };
1280   GstTagList *taglist = gst_tag_list_new_empty ();
1281
1282   gst_tag_list_add (taglist, GST_TAG_MERGE_APPEND, GST_TAG_KEYWORDS, "k1",
1283       GST_TAG_KEYWORDS, "k2", GST_TAG_TITLE, "title", GST_TAG_KEYWORDS, "k3",
1284       NULL);
1285   do_xmp_tag_serialization_deserialization (taglist, NULL);
1286   gst_tag_list_free (taglist);
1287
1288   taglist = gst_tag_list_new_empty ();
1289   gst_tag_list_add (taglist, GST_TAG_MERGE_APPEND, GST_TAG_GEO_LOCATION_COUNTRY,
1290       "Brazil", GST_TAG_GEO_LOCATION_CITY, "Campina Grande", NULL);
1291   do_xmp_tag_serialization_deserialization (taglist, schemas);
1292   gst_tag_list_free (taglist);
1293 }
1294
1295 GST_END_TEST;
1296
1297
1298 GST_START_TEST (test_exif_parsing)
1299 {
1300   GstTagList *taglist;
1301   GstBuffer *buf;
1302   GstByteWriter writer;
1303   const gchar *str = NULL;
1304
1305   gst_byte_writer_init (&writer);
1306
1307   /* write the IFD */
1308   /* 1 entry */
1309   gst_byte_writer_put_uint16_le (&writer, 1);
1310
1311   /* copyright tag */
1312   /* tag id */
1313   gst_byte_writer_put_uint16_le (&writer, 0x8298);
1314   /* tag type */
1315   gst_byte_writer_put_uint16_le (&writer, 0x2);
1316   /* count */
1317   gst_byte_writer_put_uint32_le (&writer, strlen ("my copyright") + 1);
1318   /* offset */
1319   gst_byte_writer_put_uint32_le (&writer, 8 + 14);
1320
1321   /* data */
1322   gst_byte_writer_put_string (&writer, "my copyright");
1323
1324   buf = gst_byte_writer_reset_and_get_buffer (&writer);
1325
1326   taglist = gst_tag_list_from_exif_buffer (buf, G_LITTLE_ENDIAN, 8);
1327
1328   fail_unless (gst_tag_list_get_tag_size (taglist, GST_TAG_COPYRIGHT) == 1);
1329   gst_tag_list_peek_string_index (taglist, GST_TAG_COPYRIGHT, 0, &str);
1330   fail_unless_equals_string (str, "my copyright");
1331
1332   gst_tag_list_free (taglist);
1333   gst_buffer_unref (buf);
1334 }
1335
1336 GST_END_TEST;
1337
1338
1339 static void
1340 do_exif_tag_serialization_deserialization (GstTagList * taglist)
1341 {
1342   GstTagList *taglist2;
1343   GstBuffer *buf;
1344
1345   /* LE */
1346   buf = gst_tag_list_to_exif_buffer (taglist, G_LITTLE_ENDIAN, 0);
1347   taglist2 = gst_tag_list_from_exif_buffer (buf, G_LITTLE_ENDIAN, 0);
1348   gst_buffer_unref (buf);
1349
1350   fail_unless (gst_tag_list_is_equal (taglist, taglist2));
1351   gst_tag_list_free (taglist2);
1352
1353   /* BE */
1354   buf = gst_tag_list_to_exif_buffer (taglist, G_BIG_ENDIAN, 0);
1355   taglist2 = gst_tag_list_from_exif_buffer (buf, G_BIG_ENDIAN, 0);
1356   gst_buffer_unref (buf);
1357
1358   fail_unless (gst_tag_list_is_equal (taglist, taglist2));
1359   gst_tag_list_free (taglist2);
1360
1361   /* APP1 */
1362   buf = gst_tag_list_to_exif_buffer_with_tiff_header (taglist);
1363   taglist2 = gst_tag_list_from_exif_buffer_with_tiff_header (buf);
1364   gst_buffer_unref (buf);
1365
1366   fail_unless (gst_tag_list_is_equal (taglist, taglist2));
1367   gst_tag_list_free (taglist2);
1368 }
1369
1370 static void
1371 do_simple_exif_tag_serialization_deserialization (const gchar * gsttag,
1372     GValue * value)
1373 {
1374   GstTagList *taglist = gst_tag_list_new_empty ();
1375
1376   gst_tag_list_add_value (taglist, GST_TAG_MERGE_REPLACE, gsttag, value);
1377   do_exif_tag_serialization_deserialization (taglist);
1378
1379   gst_tag_list_free (taglist);
1380 }
1381
1382 /*
1383  * Adds tags from multiple ifd tables and tries serializing them
1384  */
1385 GST_START_TEST (test_exif_multiple_tags)
1386 {
1387   GstTagList *taglist;
1388   GstDateTime *datetime;
1389   GValue value = { 0 };
1390
1391   gst_tag_register_musicbrainz_tags ();
1392
1393   taglist = gst_tag_list_new (GST_TAG_ARTIST, "artist",
1394       GST_TAG_DEVICE_MANUFACTURER, "make",
1395       GST_TAG_DEVICE_MODEL, "model", GST_TAG_GEO_LOCATION_LATITUDE, 45.5,
1396       GST_TAG_GEO_LOCATION_LONGITUDE, -10.25,
1397       GST_TAG_IMAGE_HORIZONTAL_PPI, 300.0,
1398       GST_TAG_IMAGE_VERTICAL_PPI, 300.0, NULL);
1399
1400   g_value_init (&value, GST_TYPE_DATE_TIME);
1401   datetime = gst_date_time_new_local_time (2010, 6, 22, 12, 5, 10);
1402   g_value_set_boxed (&value, datetime);
1403   gst_date_time_unref (datetime);
1404   gst_tag_list_add_value (taglist, GST_TAG_MERGE_APPEND, GST_TAG_DATE_TIME,
1405       &value);
1406   g_value_unset (&value);
1407
1408   do_exif_tag_serialization_deserialization (taglist);
1409
1410   gst_tag_list_free (taglist);
1411 }
1412
1413 GST_END_TEST;
1414
1415
1416 GST_START_TEST (test_exif_tags_serialization_deserialization)
1417 {
1418   GValue value = { 0 };
1419   GstDateTime *datetime = NULL;
1420   GstBuffer *buf = NULL;
1421   gint i;
1422   GstTagList *taglist;
1423   guint8 *data;
1424
1425   gst_tag_register_musicbrainz_tags ();
1426
1427   g_value_init (&value, G_TYPE_STRING);
1428   g_value_set_static_string (&value, "my string");
1429   do_simple_exif_tag_serialization_deserialization (GST_TAG_COPYRIGHT, &value);
1430   g_value_set_static_string (&value, "ty");
1431   do_simple_exif_tag_serialization_deserialization (GST_TAG_ARTIST, &value);
1432   g_value_set_static_string (&value, "Company Software 1.2b (info)");
1433   do_simple_exif_tag_serialization_deserialization (GST_TAG_APPLICATION_NAME,
1434       &value);
1435
1436   /* non ascii chars */
1437   g_value_set_static_string (&value, "AaÄäEeËëIiÏïOoÖöUuÜü");
1438   do_simple_exif_tag_serialization_deserialization (GST_TAG_ARTIST, &value);
1439   g_value_set_static_string (&value, "Äë");
1440   do_simple_exif_tag_serialization_deserialization (GST_TAG_ARTIST, &value);
1441
1442   /* image orientation tests */
1443   g_value_set_static_string (&value, "rotate-0");
1444   do_simple_exif_tag_serialization_deserialization (GST_TAG_IMAGE_ORIENTATION,
1445       &value);
1446   g_value_set_static_string (&value, "flip-rotate-0");
1447   do_simple_exif_tag_serialization_deserialization (GST_TAG_IMAGE_ORIENTATION,
1448       &value);
1449   g_value_set_static_string (&value, "rotate-180");
1450   do_simple_exif_tag_serialization_deserialization (GST_TAG_IMAGE_ORIENTATION,
1451       &value);
1452   g_value_set_static_string (&value, "flip-rotate-180");
1453   do_simple_exif_tag_serialization_deserialization (GST_TAG_IMAGE_ORIENTATION,
1454       &value);
1455   g_value_set_static_string (&value, "flip-rotate-270");
1456   do_simple_exif_tag_serialization_deserialization (GST_TAG_IMAGE_ORIENTATION,
1457       &value);
1458   g_value_set_static_string (&value, "rotate-90");
1459   do_simple_exif_tag_serialization_deserialization (GST_TAG_IMAGE_ORIENTATION,
1460       &value);
1461   g_value_set_static_string (&value, "flip-rotate-90");
1462   do_simple_exif_tag_serialization_deserialization (GST_TAG_IMAGE_ORIENTATION,
1463       &value);
1464   g_value_set_static_string (&value, "rotate-270");
1465   do_simple_exif_tag_serialization_deserialization (GST_TAG_IMAGE_ORIENTATION,
1466       &value);
1467
1468   /* exposure program */
1469   g_value_set_static_string (&value, "undefined");
1470   do_simple_exif_tag_serialization_deserialization
1471       (GST_TAG_CAPTURING_EXPOSURE_PROGRAM, &value);
1472   g_value_set_static_string (&value, "manual");
1473   do_simple_exif_tag_serialization_deserialization
1474       (GST_TAG_CAPTURING_EXPOSURE_PROGRAM, &value);
1475   g_value_set_static_string (&value, "normal");
1476   do_simple_exif_tag_serialization_deserialization
1477       (GST_TAG_CAPTURING_EXPOSURE_PROGRAM, &value);
1478   g_value_set_static_string (&value, "aperture-priority");
1479   do_simple_exif_tag_serialization_deserialization
1480       (GST_TAG_CAPTURING_EXPOSURE_PROGRAM, &value);
1481   g_value_set_static_string (&value, "shutter-priority");
1482   do_simple_exif_tag_serialization_deserialization
1483       (GST_TAG_CAPTURING_EXPOSURE_PROGRAM, &value);
1484   g_value_set_static_string (&value, "creative");
1485   do_simple_exif_tag_serialization_deserialization
1486       (GST_TAG_CAPTURING_EXPOSURE_PROGRAM, &value);
1487   g_value_set_static_string (&value, "action");
1488   do_simple_exif_tag_serialization_deserialization
1489       (GST_TAG_CAPTURING_EXPOSURE_PROGRAM, &value);
1490   g_value_set_static_string (&value, "portrait");
1491   do_simple_exif_tag_serialization_deserialization
1492       (GST_TAG_CAPTURING_EXPOSURE_PROGRAM, &value);
1493   g_value_set_static_string (&value, "landscape");
1494   do_simple_exif_tag_serialization_deserialization
1495       (GST_TAG_CAPTURING_EXPOSURE_PROGRAM, &value);
1496
1497   /* exposure mode */
1498   g_value_set_static_string (&value, "auto-exposure");
1499   do_simple_exif_tag_serialization_deserialization
1500       (GST_TAG_CAPTURING_EXPOSURE_MODE, &value);
1501   g_value_set_static_string (&value, "manual-exposure");
1502   do_simple_exif_tag_serialization_deserialization
1503       (GST_TAG_CAPTURING_EXPOSURE_MODE, &value);
1504   g_value_set_static_string (&value, "auto-bracket");
1505   do_simple_exif_tag_serialization_deserialization
1506       (GST_TAG_CAPTURING_EXPOSURE_MODE, &value);
1507
1508   /* scene capture type */
1509   g_value_set_static_string (&value, "standard");
1510   do_simple_exif_tag_serialization_deserialization
1511       (GST_TAG_CAPTURING_SCENE_CAPTURE_TYPE, &value);
1512   g_value_set_static_string (&value, "portrait");
1513   do_simple_exif_tag_serialization_deserialization
1514       (GST_TAG_CAPTURING_SCENE_CAPTURE_TYPE, &value);
1515   g_value_set_static_string (&value, "landscape");
1516   do_simple_exif_tag_serialization_deserialization
1517       (GST_TAG_CAPTURING_SCENE_CAPTURE_TYPE, &value);
1518   g_value_set_static_string (&value, "night-scene");
1519   do_simple_exif_tag_serialization_deserialization
1520       (GST_TAG_CAPTURING_SCENE_CAPTURE_TYPE, &value);
1521
1522   g_value_set_static_string (&value, "none");
1523   do_simple_exif_tag_serialization_deserialization
1524       (GST_TAG_CAPTURING_GAIN_ADJUSTMENT, &value);
1525   g_value_set_static_string (&value, "high-gain-up");
1526   do_simple_exif_tag_serialization_deserialization
1527       (GST_TAG_CAPTURING_GAIN_ADJUSTMENT, &value);
1528   g_value_set_static_string (&value, "low-gain-up");
1529   do_simple_exif_tag_serialization_deserialization
1530       (GST_TAG_CAPTURING_GAIN_ADJUSTMENT, &value);
1531   g_value_set_static_string (&value, "high-gain-down");
1532   do_simple_exif_tag_serialization_deserialization
1533       (GST_TAG_CAPTURING_GAIN_ADJUSTMENT, &value);
1534   g_value_set_static_string (&value, "low-gain-down");
1535   do_simple_exif_tag_serialization_deserialization
1536       (GST_TAG_CAPTURING_GAIN_ADJUSTMENT, &value);
1537
1538   g_value_set_static_string (&value, "auto");
1539   do_simple_exif_tag_serialization_deserialization
1540       (GST_TAG_CAPTURING_WHITE_BALANCE, &value);
1541   g_value_set_static_string (&value, "manual");
1542   do_simple_exif_tag_serialization_deserialization
1543       (GST_TAG_CAPTURING_WHITE_BALANCE, &value);
1544
1545   g_value_set_static_string (&value, "normal");
1546   do_simple_exif_tag_serialization_deserialization (GST_TAG_CAPTURING_CONTRAST,
1547       &value);
1548   g_value_set_static_string (&value, "hard");
1549   do_simple_exif_tag_serialization_deserialization (GST_TAG_CAPTURING_CONTRAST,
1550       &value);
1551   g_value_set_static_string (&value, "soft");
1552   do_simple_exif_tag_serialization_deserialization (GST_TAG_CAPTURING_CONTRAST,
1553       &value);
1554
1555   g_value_set_static_string (&value, "normal");
1556   do_simple_exif_tag_serialization_deserialization
1557       (GST_TAG_CAPTURING_SATURATION, &value);
1558   g_value_set_static_string (&value, "low-saturation");
1559   do_simple_exif_tag_serialization_deserialization
1560       (GST_TAG_CAPTURING_SATURATION, &value);
1561   g_value_set_static_string (&value, "high-saturation");
1562   do_simple_exif_tag_serialization_deserialization
1563       (GST_TAG_CAPTURING_SATURATION, &value);
1564
1565   g_value_set_static_string (&value, "normal");
1566   do_simple_exif_tag_serialization_deserialization (GST_TAG_CAPTURING_SHARPNESS,
1567       &value);
1568   g_value_set_static_string (&value, "hard");
1569   do_simple_exif_tag_serialization_deserialization (GST_TAG_CAPTURING_SHARPNESS,
1570       &value);
1571   g_value_set_static_string (&value, "soft");
1572   do_simple_exif_tag_serialization_deserialization (GST_TAG_CAPTURING_SHARPNESS,
1573       &value);
1574
1575   g_value_set_static_string (&value, "unknown");
1576   do_simple_exif_tag_serialization_deserialization
1577       (GST_TAG_CAPTURING_METERING_MODE, &value);
1578   g_value_set_static_string (&value, "average");
1579   do_simple_exif_tag_serialization_deserialization
1580       (GST_TAG_CAPTURING_METERING_MODE, &value);
1581   g_value_set_static_string (&value, "center-weighted-average");
1582   do_simple_exif_tag_serialization_deserialization
1583       (GST_TAG_CAPTURING_METERING_MODE, &value);
1584   g_value_set_static_string (&value, "spot");
1585   do_simple_exif_tag_serialization_deserialization
1586       (GST_TAG_CAPTURING_METERING_MODE, &value);
1587   g_value_set_static_string (&value, "multi-spot");
1588   do_simple_exif_tag_serialization_deserialization
1589       (GST_TAG_CAPTURING_METERING_MODE, &value);
1590   g_value_set_static_string (&value, "pattern");
1591   do_simple_exif_tag_serialization_deserialization
1592       (GST_TAG_CAPTURING_METERING_MODE, &value);
1593   g_value_set_static_string (&value, "partial");
1594   do_simple_exif_tag_serialization_deserialization
1595       (GST_TAG_CAPTURING_METERING_MODE, &value);
1596   g_value_set_static_string (&value, "other");
1597   do_simple_exif_tag_serialization_deserialization
1598       (GST_TAG_CAPTURING_METERING_MODE, &value);
1599
1600   g_value_set_static_string (&value, "dsc");
1601   do_simple_exif_tag_serialization_deserialization (GST_TAG_CAPTURING_SOURCE,
1602       &value);
1603   g_value_set_static_string (&value, "other");
1604   do_simple_exif_tag_serialization_deserialization (GST_TAG_CAPTURING_SOURCE,
1605       &value);
1606   g_value_set_static_string (&value, "transparent-scanner");
1607   do_simple_exif_tag_serialization_deserialization (GST_TAG_CAPTURING_SOURCE,
1608       &value);
1609   g_value_set_static_string (&value, "reflex-scanner");
1610   do_simple_exif_tag_serialization_deserialization (GST_TAG_CAPTURING_SOURCE,
1611       &value);
1612   g_value_unset (&value);
1613
1614   g_value_init (&value, G_TYPE_DOUBLE);
1615   g_value_set_double (&value, 30.5);
1616   do_simple_exif_tag_serialization_deserialization
1617       (GST_TAG_GEO_LOCATION_LATITUDE, &value);
1618   g_value_set_double (&value, -12.125);
1619   do_simple_exif_tag_serialization_deserialization
1620       (GST_TAG_GEO_LOCATION_LATITUDE, &value);
1621   g_value_set_double (&value, 0);
1622   do_simple_exif_tag_serialization_deserialization
1623       (GST_TAG_GEO_LOCATION_LONGITUDE, &value);
1624   g_value_set_double (&value, 65.0);
1625   do_simple_exif_tag_serialization_deserialization
1626       (GST_TAG_GEO_LOCATION_LONGITUDE, &value);
1627   g_value_set_double (&value, -0.75);
1628   do_simple_exif_tag_serialization_deserialization
1629       (GST_TAG_GEO_LOCATION_LONGITUDE, &value);
1630
1631   g_value_set_double (&value, 0.0);
1632   do_simple_exif_tag_serialization_deserialization
1633       (GST_TAG_GEO_LOCATION_CAPTURE_DIRECTION, &value);
1634   g_value_set_double (&value, 180.5);
1635   do_simple_exif_tag_serialization_deserialization
1636       (GST_TAG_GEO_LOCATION_CAPTURE_DIRECTION, &value);
1637   g_value_set_double (&value, 0.12345);
1638   do_simple_exif_tag_serialization_deserialization
1639       (GST_TAG_GEO_LOCATION_MOVEMENT_DIRECTION, &value);
1640   g_value_set_double (&value, 359.9);
1641   do_simple_exif_tag_serialization_deserialization
1642       (GST_TAG_GEO_LOCATION_MOVEMENT_DIRECTION, &value);
1643
1644   g_value_set_double (&value, 0.0);
1645   do_simple_exif_tag_serialization_deserialization
1646       (GST_TAG_GEO_LOCATION_ELEVATION, &value);
1647   g_value_set_double (&value, 321.456);
1648   do_simple_exif_tag_serialization_deserialization
1649       (GST_TAG_GEO_LOCATION_ELEVATION, &value);
1650   g_value_set_double (&value, -12.56);
1651   do_simple_exif_tag_serialization_deserialization
1652       (GST_TAG_GEO_LOCATION_ELEVATION, &value);
1653
1654   g_value_set_double (&value, 0);
1655   do_simple_exif_tag_serialization_deserialization
1656       (GST_TAG_GEO_LOCATION_MOVEMENT_SPEED, &value);
1657   g_value_set_double (&value, 100 / 3.6);
1658   do_simple_exif_tag_serialization_deserialization
1659       (GST_TAG_GEO_LOCATION_MOVEMENT_SPEED, &value);
1660
1661   g_value_set_double (&value, 0);
1662   do_simple_exif_tag_serialization_deserialization
1663       (GST_TAG_GEO_LOCATION_HORIZONTAL_ERROR, &value);
1664   g_value_set_double (&value, 50.25);
1665   do_simple_exif_tag_serialization_deserialization
1666       (GST_TAG_GEO_LOCATION_HORIZONTAL_ERROR, &value);
1667
1668   g_value_set_double (&value, 0);
1669   do_simple_exif_tag_serialization_deserialization
1670       (GST_TAG_CAPTURING_DIGITAL_ZOOM_RATIO, &value);
1671   g_value_set_double (&value, 2.5);
1672   do_simple_exif_tag_serialization_deserialization
1673       (GST_TAG_CAPTURING_DIGITAL_ZOOM_RATIO, &value);
1674   g_value_set_double (&value, 8.75);
1675   do_simple_exif_tag_serialization_deserialization
1676       (GST_TAG_CAPTURING_DIGITAL_ZOOM_RATIO, &value);
1677
1678   g_value_set_double (&value, 20.0);
1679   do_simple_exif_tag_serialization_deserialization
1680       (GST_TAG_CAPTURING_FOCAL_LENGTH, &value);
1681   g_value_set_double (&value, 5.5);
1682   do_simple_exif_tag_serialization_deserialization
1683       (GST_TAG_CAPTURING_FOCAL_LENGTH, &value);
1684
1685   g_value_set_double (&value, 16);
1686   do_simple_exif_tag_serialization_deserialization
1687       (GST_TAG_CAPTURING_FOCAL_RATIO, &value);
1688   g_value_set_double (&value, 2.7);
1689   do_simple_exif_tag_serialization_deserialization
1690       (GST_TAG_CAPTURING_FOCAL_LENGTH, &value);
1691
1692   g_value_set_double (&value, 96.0);
1693   do_simple_exif_tag_serialization_deserialization
1694       (GST_TAG_IMAGE_HORIZONTAL_PPI, &value);
1695   g_value_set_double (&value, 300.0);
1696   do_simple_exif_tag_serialization_deserialization
1697       (GST_TAG_IMAGE_HORIZONTAL_PPI, &value);
1698   g_value_set_double (&value, 87.5);
1699   do_simple_exif_tag_serialization_deserialization
1700       (GST_TAG_IMAGE_VERTICAL_PPI, &value);
1701   g_value_set_double (&value, 600.0);
1702   do_simple_exif_tag_serialization_deserialization
1703       (GST_TAG_IMAGE_VERTICAL_PPI, &value);
1704
1705   g_value_set_double (&value, 0.0);
1706   do_simple_exif_tag_serialization_deserialization
1707       (GST_TAG_CAPTURING_EXPOSURE_COMPENSATION, &value);
1708   g_value_set_double (&value, 1.0);
1709   do_simple_exif_tag_serialization_deserialization
1710       (GST_TAG_CAPTURING_EXPOSURE_COMPENSATION, &value);
1711   g_value_set_double (&value, -2.5);
1712   do_simple_exif_tag_serialization_deserialization
1713       (GST_TAG_CAPTURING_EXPOSURE_COMPENSATION, &value);
1714   g_value_unset (&value);
1715
1716   g_value_init (&value, G_TYPE_INT);
1717   g_value_set_int (&value, 400);
1718   do_simple_exif_tag_serialization_deserialization
1719       (GST_TAG_CAPTURING_ISO_SPEED, &value);
1720   g_value_set_int (&value, 1600);
1721   do_simple_exif_tag_serialization_deserialization
1722       (GST_TAG_CAPTURING_ISO_SPEED, &value);
1723   g_value_unset (&value);
1724
1725   g_value_init (&value, GST_TYPE_DATE_TIME);
1726   datetime = gst_date_time_new_local_time (2010, 6, 22, 12, 5, 10);
1727   g_value_set_boxed (&value, datetime);
1728   gst_date_time_unref (datetime);
1729   do_simple_exif_tag_serialization_deserialization (GST_TAG_DATE_TIME, &value);
1730   g_value_unset (&value);
1731
1732   g_value_init (&value, GST_TYPE_BUFFER);
1733   buf = gst_buffer_new_and_alloc (1024);
1734   data = gst_buffer_map (buf, NULL, NULL, GST_MAP_WRITE);
1735   for (i = 0; i < 1024; i++)
1736     data[i] = i % 255;
1737   gst_buffer_unmap (buf, data, 1024);
1738   gst_value_set_buffer (&value, buf);
1739   gst_buffer_unref (buf);
1740   do_simple_exif_tag_serialization_deserialization (GST_TAG_APPLICATION_DATA,
1741       &value);
1742   g_value_unset (&value);
1743
1744   g_value_init (&value, GST_TYPE_FRACTION);
1745   gst_value_set_fraction (&value, 1, 1);
1746   do_simple_exif_tag_serialization_deserialization
1747       (GST_TAG_CAPTURING_SHUTTER_SPEED, &value);
1748   gst_value_set_fraction (&value, 1, 30);
1749   do_simple_exif_tag_serialization_deserialization
1750       (GST_TAG_CAPTURING_SHUTTER_SPEED, &value);
1751   gst_value_set_fraction (&value, 1, 200);
1752   do_simple_exif_tag_serialization_deserialization
1753       (GST_TAG_CAPTURING_SHUTTER_SPEED, &value);
1754   gst_value_set_fraction (&value, 1, 8000);
1755   do_simple_exif_tag_serialization_deserialization
1756       (GST_TAG_CAPTURING_SHUTTER_SPEED, &value);
1757   g_value_unset (&value);
1758
1759   /* flash is a little bit more tricky, because 2 tags are merged into 1 in
1760    * exif */
1761   taglist = gst_tag_list_new (GST_TAG_CAPTURING_FLASH_FIRED, FALSE,
1762       GST_TAG_CAPTURING_FLASH_MODE, "auto", NULL);
1763   do_exif_tag_serialization_deserialization (taglist);
1764   gst_tag_list_free (taglist);
1765
1766   taglist = gst_tag_list_new (GST_TAG_CAPTURING_FLASH_FIRED, TRUE,
1767       GST_TAG_CAPTURING_FLASH_MODE, "auto", NULL);
1768   do_exif_tag_serialization_deserialization (taglist);
1769   gst_tag_list_free (taglist);
1770
1771   taglist = gst_tag_list_new (GST_TAG_CAPTURING_FLASH_FIRED, FALSE,
1772       GST_TAG_CAPTURING_FLASH_MODE, "never", NULL);
1773   do_exif_tag_serialization_deserialization (taglist);
1774   gst_tag_list_free (taglist);
1775
1776   taglist = gst_tag_list_new (GST_TAG_CAPTURING_FLASH_FIRED, TRUE,
1777       GST_TAG_CAPTURING_FLASH_MODE, "always", NULL);
1778   do_exif_tag_serialization_deserialization (taglist);
1779   gst_tag_list_free (taglist);
1780 }
1781
1782 GST_END_TEST;
1783
1784 static Suite *
1785 tag_suite (void)
1786 {
1787   Suite *s = suite_create ("tag support library");
1788   TCase *tc_chain = tcase_create ("general");
1789
1790   suite_add_tcase (s, tc_chain);
1791   tcase_add_test (tc_chain, test_musicbrainz_tag_registration);
1792   tcase_add_test (tc_chain, test_parse_extended_comment);
1793   tcase_add_test (tc_chain, test_vorbis_tags);
1794   tcase_add_test (tc_chain, test_id3_tags);
1795   tcase_add_test (tc_chain, test_id3v1_utf8_tag);
1796   tcase_add_test (tc_chain, test_language_utils);
1797   tcase_add_test (tc_chain, test_license_utils);
1798   tcase_add_test (tc_chain, test_xmp_formatting);
1799   tcase_add_test (tc_chain, test_xmp_parsing);
1800   tcase_add_test (tc_chain, test_xmp_tags_serialization_deserialization);
1801   tcase_add_test (tc_chain, test_xmp_compound_tags);
1802   tcase_add_test (tc_chain, test_exif_parsing);
1803   tcase_add_test (tc_chain, test_exif_tags_serialization_deserialization);
1804   tcase_add_test (tc_chain, test_exif_multiple_tags);
1805   return s;
1806 }
1807
1808 int
1809 main (int argc, char **argv)
1810 {
1811   int nf;
1812
1813   Suite *s = tag_suite ();
1814   SRunner *sr = srunner_create (s);
1815
1816   gst_check_init (&argc, &argv);
1817
1818   srunner_run_all (sr, CK_NORMAL);
1819   nf = srunner_ntests_failed (sr);
1820   srunner_free (sr);
1821
1822   return nf;
1823 }