2 * Copyright (C) 2003 Benjamin Otte <in7y118@public.uni-hamburg.de>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public
15 * License along with this library; if not, write to the Free
16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 #include <gst/check/gstcheck.h>
23 /* multiple artists are possible */
24 #define UTAG GST_TAG_ARTIST
25 #define UNFIXED1 "Britney Spears"
26 #define UNFIXED2 "Evanescence"
27 #define UNFIXED3 "AC/DC"
28 #define UNFIXED4 "The Prodigy"
30 /* license is fixed */
31 #define FTAG GST_TAG_LICENSE
32 #define FIXED1 "Lesser General Public License"
33 #define FIXED2 "Microsoft End User License Agreement"
34 #define FIXED3 "Mozilla Public License"
35 #define FIXED4 "Public Domain"
37 /* checks that a tag contains the given values and not more values */
39 check_tags (const GstTagList * list, const gchar * tag, gchar * value, ...)
45 va_start (args, value);
46 while (value != NULL) {
47 fail_unless (gst_tag_list_get_string_index (list, tag, i, &str));
48 fail_unless (strcmp (value, str) == 0);
51 value = va_arg (args, gchar *);
54 fail_unless (i == gst_tag_list_get_tag_size (list, tag));
58 #define NEW_LIST_FIXED(mode) \
60 if (list) gst_tag_list_free (list); \
61 list = gst_tag_list_new (); \
62 gst_tag_list_add (list, mode, FTAG, FIXED1, FTAG, FIXED2, \
63 FTAG, FIXED3, FTAG, FIXED4, NULL); \
66 #define NEW_LIST_UNFIXED(mode) \
68 if (list) gst_tag_list_free (list); \
69 list = gst_tag_list_new (); \
70 gst_tag_list_add (list, mode, UTAG, UNFIXED1, UTAG, UNFIXED2, \
71 UTAG, UNFIXED3, UTAG, UNFIXED4, NULL); \
74 #define NEW_LISTS_FIXED(mode) \
76 if (list) gst_tag_list_free (list); \
77 list = gst_tag_list_new (); \
78 gst_tag_list_add (list, GST_TAG_MERGE_APPEND, FTAG, FIXED1, \
79 FTAG, FIXED2, NULL); \
80 if (list2) gst_tag_list_free (list2); \
81 list2 = gst_tag_list_new (); \
82 gst_tag_list_add (list2, GST_TAG_MERGE_APPEND, FTAG, FIXED3, \
83 FTAG, FIXED4, NULL); \
84 if (merge) gst_tag_list_free (merge); \
85 merge = gst_tag_list_merge (list, list2, mode); \
88 #define NEW_LISTS_UNFIXED(mode) \
90 if (list) gst_tag_list_free (list); \
91 list = gst_tag_list_new (); \
92 gst_tag_list_add (list, GST_TAG_MERGE_APPEND, UTAG, UNFIXED1, \
93 UTAG, UNFIXED2, NULL); \
94 if (list2) gst_tag_list_free (list2); \
95 list2 = gst_tag_list_new (); \
96 gst_tag_list_add (list2, GST_TAG_MERGE_APPEND, UTAG, UNFIXED3,\
97 UTAG, UNFIXED4, NULL); \
98 if (merge) gst_tag_list_free (merge); \
99 merge = gst_tag_list_merge (list, list2, mode); \
103 GST_START_TEST (test_merge)
105 GstTagList *list = NULL, *list2 = NULL, *merge = NULL;
107 /* make sure the assumptions work */
108 fail_unless (gst_tag_is_fixed (FTAG));
109 fail_unless (!gst_tag_is_fixed (UTAG));
110 /* we check string here only */
111 fail_unless (gst_tag_get_type (FTAG) == G_TYPE_STRING);
112 fail_unless (gst_tag_get_type (UTAG) == G_TYPE_STRING);
114 /* check additions */
117 NEW_LIST_UNFIXED (GST_TAG_MERGE_REPLACE_ALL);
118 check_tags (list, UTAG, UNFIXED4, NULL);
119 NEW_LIST_UNFIXED (GST_TAG_MERGE_REPLACE);
120 check_tags (list, UTAG, UNFIXED4, NULL);
121 NEW_LIST_UNFIXED (GST_TAG_MERGE_PREPEND);
122 check_tags (list, UTAG, UNFIXED4, UNFIXED3, UNFIXED2, UNFIXED1, NULL);
123 NEW_LIST_UNFIXED (GST_TAG_MERGE_APPEND);
124 check_tags (list, UTAG, UNFIXED1, UNFIXED2, UNFIXED3, UNFIXED4, NULL);
125 NEW_LIST_UNFIXED (GST_TAG_MERGE_KEEP);
126 check_tags (list, UTAG, UNFIXED1, NULL);
127 NEW_LIST_UNFIXED (GST_TAG_MERGE_KEEP_ALL);
128 check_tags (list, UTAG, NULL);
131 NEW_LIST_FIXED (GST_TAG_MERGE_REPLACE_ALL);
132 check_tags (list, FTAG, FIXED4, NULL);
133 NEW_LIST_FIXED (GST_TAG_MERGE_REPLACE);
134 check_tags (list, FTAG, FIXED4, NULL);
135 NEW_LIST_FIXED (GST_TAG_MERGE_PREPEND);
136 check_tags (list, FTAG, FIXED4, NULL);
137 NEW_LIST_FIXED (GST_TAG_MERGE_APPEND);
138 check_tags (list, FTAG, FIXED1, NULL);
139 NEW_LIST_FIXED (GST_TAG_MERGE_KEEP);
140 check_tags (list, FTAG, FIXED1, NULL);
141 NEW_LIST_FIXED (GST_TAG_MERGE_KEEP_ALL);
142 check_tags (list, FTAG, NULL);
146 NEW_LISTS_UNFIXED (GST_TAG_MERGE_REPLACE_ALL);
147 check_tags (merge, UTAG, UNFIXED3, UNFIXED4, NULL);
148 NEW_LISTS_UNFIXED (GST_TAG_MERGE_REPLACE);
149 check_tags (merge, UTAG, UNFIXED3, UNFIXED4, NULL);
150 NEW_LISTS_UNFIXED (GST_TAG_MERGE_PREPEND);
151 check_tags (merge, UTAG, UNFIXED3, UNFIXED4, UNFIXED1, UNFIXED2, NULL);
152 NEW_LISTS_UNFIXED (GST_TAG_MERGE_APPEND);
153 check_tags (merge, UTAG, UNFIXED1, UNFIXED2, UNFIXED3, UNFIXED4, NULL);
154 NEW_LISTS_UNFIXED (GST_TAG_MERGE_KEEP);
155 check_tags (merge, UTAG, UNFIXED1, UNFIXED2, NULL);
156 NEW_LISTS_UNFIXED (GST_TAG_MERGE_KEEP_ALL);
157 check_tags (merge, UTAG, UNFIXED1, UNFIXED2, NULL);
160 NEW_LISTS_FIXED (GST_TAG_MERGE_REPLACE_ALL);
161 check_tags (merge, FTAG, FIXED3, NULL);
162 NEW_LISTS_FIXED (GST_TAG_MERGE_REPLACE);
163 check_tags (merge, FTAG, FIXED3, NULL);
164 NEW_LISTS_FIXED (GST_TAG_MERGE_PREPEND);
165 check_tags (merge, FTAG, FIXED3, NULL);
166 NEW_LISTS_FIXED (GST_TAG_MERGE_APPEND);
167 check_tags (merge, FTAG, FIXED1, NULL);
168 NEW_LISTS_FIXED (GST_TAG_MERGE_KEEP);
169 check_tags (merge, FTAG, FIXED1, NULL);
170 NEW_LISTS_FIXED (GST_TAG_MERGE_KEEP_ALL);
171 check_tags (merge, FTAG, FIXED1, NULL);
175 gst_tag_list_free (list);
177 gst_tag_list_free (list2);
179 gst_tag_list_free (merge);
183 GST_START_TEST (test_date_tags)
185 GstTagList *tag_list, *tag_list2;
189 date = g_date_new_dmy (14, 10, 2005);
190 tag_list = gst_tag_list_new ();
191 gst_tag_list_add (tag_list, GST_TAG_MERGE_APPEND, GST_TAG_DATE, date, NULL);
193 str = gst_structure_to_string (tag_list);
194 fail_if (str == NULL);
195 fail_if (strstr (str, "2005-10-14") == NULL);
197 tag_list2 = gst_structure_from_string (str, NULL);
198 fail_if (tag_list2 == NULL);
199 fail_if (!gst_tag_list_get_date (tag_list2, GST_TAG_DATE, &date2));
200 gst_tag_list_free (tag_list2);
203 fail_if (g_date_compare (date, date2) != 0);
204 fail_if (g_date_get_day (date) != 14);
205 fail_if (g_date_get_month (date) != 10);
206 fail_if (g_date_get_year (date) != 2005);
207 fail_if (g_date_get_day (date2) != 14);
208 fail_if (g_date_get_month (date2) != 10);
209 fail_if (g_date_get_year (date2) != 2005);
212 gst_tag_list_free (tag_list);
221 Suite *s = suite_create ("GstTag");
222 TCase *tc_chain = tcase_create ("general");
224 suite_add_tcase (s, tc_chain);
225 tcase_add_test (tc_chain, test_merge);
226 tcase_add_test (tc_chain, test_date_tags);
231 GST_CHECK_MAIN (gst_tag);