tests/check/: use the new macro
[platform/upstream/gstreamer.git] / tests / check / gst / gsttag.c
1 /*
2  * Copyright (C) 2003 Benjamin Otte <in7y118@public.uni-hamburg.de>
3  *
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.
8  *
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.
13  *
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.
17  */
18
19 #include <gst/check/gstcheck.h>
20
21 #include <string.h>
22
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"
29
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"
36
37 /* checks that a tag contains the given values and not more values */
38 static void
39 check_tags (const GstTagList * list, const gchar * tag, gchar * value, ...)
40 {
41   va_list args;
42   gchar *str;
43   guint i = 0;
44
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);
49     g_free (str);
50
51     value = va_arg (args, gchar *);
52     i++;
53   }
54   fail_unless (i == gst_tag_list_get_tag_size (list, tag));
55   va_end (args);
56 }
57
58 #define NEW_LIST_FIXED(mode)                                    \
59 G_STMT_START {                                                  \
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);          \
64 } G_STMT_END;
65
66 #define NEW_LIST_UNFIXED(mode)                                  \
67 G_STMT_START {                                                  \
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);      \
72 } G_STMT_END;
73
74 #define NEW_LISTS_FIXED(mode)                                   \
75 G_STMT_START {                                                  \
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);               \
86 } G_STMT_END;
87
88 #define NEW_LISTS_UNFIXED(mode)                                 \
89 G_STMT_START {                                                  \
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);               \
100 } G_STMT_END;
101
102
103 GST_START_TEST (test_merge)
104 {
105   GstTagList *list = NULL, *list2 = NULL, *merge = NULL;
106
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);
113
114   /* check additions */
115
116   /* unfixed */
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);
129
130   /* fixed */
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);
143
144   /* check merging */
145   /* unfixed */
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);
158
159   /* fixed */
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);
172
173   /* clean up */
174   if (list)
175     gst_tag_list_free (list);
176   if (list2)
177     gst_tag_list_free (list2);
178   if (merge)
179     gst_tag_list_free (merge);
180 }
181
182 GST_END_TEST
183 GST_START_TEST (test_date_tags)
184 {
185   GstTagList *tag_list, *tag_list2;
186   GDate *date, *date2;
187   gchar *str;
188
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);
192
193   str = gst_structure_to_string (tag_list);
194   fail_if (str == NULL);
195   fail_if (strstr (str, "2005-10-14") == NULL);
196
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);
201   g_free (str);
202
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);
210   g_date_free (date2);
211
212   gst_tag_list_free (tag_list);
213   g_date_free (date);
214 }
215
216 GST_END_TEST;
217
218 Suite *
219 gst_tag_suite (void)
220 {
221   Suite *s = suite_create ("GstTag");
222   TCase *tc_chain = tcase_create ("general");
223
224   suite_add_tcase (s, tc_chain);
225   tcase_add_test (tc_chain, test_merge);
226   tcase_add_test (tc_chain, test_date_tags);
227
228   return s;
229 }
230
231 GST_CHECK_MAIN (gst_tag);