1 | /* |
---|
2 | * Copyright (C) 2003 Benjamin Otte <in7y118@public.uni-hamburg.de> |
---|
3 | * |
---|
4 | * parse1.c: Test various parsing stuff |
---|
5 | * |
---|
6 | * This library is free software; you can redistribute it and/or |
---|
7 | * modify it under the terms of the GNU General Public |
---|
8 | * License as published by the Free Software Foundation; either |
---|
9 | * version 2 of the License, or (at your option) any later version. |
---|
10 | * |
---|
11 | * This library is distributed in the hope that it will be useful, |
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
14 | * General Public License for more details. |
---|
15 | * |
---|
16 | * You should have received a copy of the GNU General Public |
---|
17 | * License along with this library; if not, write to the Free |
---|
18 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
19 | */ |
---|
20 | |
---|
21 | #include <gst/gst.h> |
---|
22 | |
---|
23 | #include <string.h> |
---|
24 | |
---|
25 | |
---|
26 | /* multiple artists are possible */ |
---|
27 | #define UTAG GST_TAG_ARTIST |
---|
28 | #define UNFIXED1 "Britney Spears" |
---|
29 | #define UNFIXED2 "Evanescene" |
---|
30 | #define UNFIXED3 "AC/DC" |
---|
31 | #define UNFIXED4 "The Prodigy" |
---|
32 | |
---|
33 | /* license is fixed */ |
---|
34 | #define FTAG GST_TAG_LICENSE |
---|
35 | #define FIXED1 "Lesser General Public License" |
---|
36 | #define FIXED2 "Microsoft End User License Agreement" |
---|
37 | #define FIXED3 "Mozilla Public License" |
---|
38 | #define FIXED4 "Public Domain" |
---|
39 | |
---|
40 | /* checks that a tag contains the given values and not more values */ |
---|
41 | static void |
---|
42 | check (const GstTagList * list, const gchar * tag, gchar * value, ...) |
---|
43 | { |
---|
44 | va_list args; |
---|
45 | gchar *str; |
---|
46 | guint i = 0; |
---|
47 | |
---|
48 | va_start (args, value); |
---|
49 | while (value != NULL) { |
---|
50 | g_assert (gst_tag_list_get_string_index (list, tag, i, &str)); |
---|
51 | g_assert (strcmp (value, str) == 0); |
---|
52 | g_free (str); |
---|
53 | |
---|
54 | value = va_arg (args, gchar *); |
---|
55 | i++; |
---|
56 | } |
---|
57 | g_assert (i == gst_tag_list_get_tag_size (list, tag)); |
---|
58 | va_end (args); |
---|
59 | } |
---|
60 | |
---|
61 | #define NEW_LIST_FIXED(mode) G_STMT_START{ \ |
---|
62 | if (list) gst_tag_list_free (list);\ |
---|
63 | list = gst_tag_list_new (); \ |
---|
64 | gst_tag_list_add (list, mode, FTAG, FIXED1, FTAG, FIXED2, FTAG, FIXED3, FTAG, FIXED4, NULL); \ |
---|
65 | }G_STMT_END |
---|
66 | #define NEW_LIST_UNFIXED(mode) G_STMT_START{ \ |
---|
67 | if (list) gst_tag_list_free (list);\ |
---|
68 | list = gst_tag_list_new (); \ |
---|
69 | gst_tag_list_add (list, mode, UTAG, UNFIXED1, UTAG, UNFIXED2, UTAG, UNFIXED3, UTAG, UNFIXED4, NULL);\ |
---|
70 | }G_STMT_END |
---|
71 | #define NEW_LISTS_FIXED(mode) G_STMT_START{ \ |
---|
72 | if (list) gst_tag_list_free (list);\ |
---|
73 | list = gst_tag_list_new (); \ |
---|
74 | gst_tag_list_add (list, GST_TAG_MERGE_APPEND, FTAG, FIXED1, FTAG, FIXED2, NULL); \ |
---|
75 | if (list2) gst_tag_list_free (list2);\ |
---|
76 | list2 = gst_tag_list_new (); \ |
---|
77 | gst_tag_list_add (list2, GST_TAG_MERGE_APPEND, FTAG, FIXED3, FTAG, FIXED4, NULL); \ |
---|
78 | if (merge) gst_tag_list_free (merge);\ |
---|
79 | merge = gst_tag_list_merge (list, list2, mode); \ |
---|
80 | }G_STMT_END |
---|
81 | #define NEW_LISTS_UNFIXED(mode) G_STMT_START{ \ |
---|
82 | if (list) gst_tag_list_free (list);\ |
---|
83 | list = gst_tag_list_new (); \ |
---|
84 | gst_tag_list_add (list, GST_TAG_MERGE_APPEND, UTAG, UNFIXED1, UTAG, UNFIXED2, NULL); \ |
---|
85 | if (list2) gst_tag_list_free (list2);\ |
---|
86 | list2 = gst_tag_list_new (); \ |
---|
87 | gst_tag_list_add (list2, GST_TAG_MERGE_APPEND, UTAG, UNFIXED3, UTAG, UNFIXED4, NULL); \ |
---|
88 | if (merge) gst_tag_list_free (merge);\ |
---|
89 | merge = gst_tag_list_merge (list, list2, mode); \ |
---|
90 | }G_STMT_END |
---|
91 | gint |
---|
92 | main (gint argc, gchar * argv[]) |
---|
93 | { |
---|
94 | GstTagList *list = NULL, *list2 = NULL, *merge = NULL; |
---|
95 | |
---|
96 | gst_init (&argc, &argv); |
---|
97 | |
---|
98 | /* make sure the assumptions work */ |
---|
99 | g_assert (gst_tag_is_fixed (FTAG)); |
---|
100 | g_assert (!gst_tag_is_fixed (UTAG)); |
---|
101 | /* we check string here only */ |
---|
102 | g_assert (gst_tag_get_type (FTAG) == G_TYPE_STRING); |
---|
103 | g_assert (gst_tag_get_type (UTAG) == G_TYPE_STRING); |
---|
104 | |
---|
105 | /* check additions */ |
---|
106 | /* unfixed */ |
---|
107 | NEW_LIST_UNFIXED (GST_TAG_MERGE_REPLACE_ALL); |
---|
108 | check (list, UTAG, UNFIXED4, NULL); |
---|
109 | NEW_LIST_UNFIXED (GST_TAG_MERGE_REPLACE); |
---|
110 | check (list, UTAG, UNFIXED4, NULL); |
---|
111 | NEW_LIST_UNFIXED (GST_TAG_MERGE_PREPEND); |
---|
112 | check (list, UTAG, UNFIXED4, UNFIXED3, UNFIXED2, UNFIXED1, NULL); |
---|
113 | NEW_LIST_UNFIXED (GST_TAG_MERGE_APPEND); |
---|
114 | check (list, UTAG, UNFIXED1, UNFIXED2, UNFIXED3, UNFIXED4, NULL); |
---|
115 | NEW_LIST_UNFIXED (GST_TAG_MERGE_KEEP); |
---|
116 | check (list, UTAG, UNFIXED1, NULL); |
---|
117 | NEW_LIST_UNFIXED (GST_TAG_MERGE_KEEP_ALL); |
---|
118 | check (list, UTAG, NULL); |
---|
119 | /* fixed */ |
---|
120 | NEW_LIST_FIXED (GST_TAG_MERGE_REPLACE_ALL); |
---|
121 | check (list, FTAG, FIXED4, NULL); |
---|
122 | NEW_LIST_FIXED (GST_TAG_MERGE_REPLACE); |
---|
123 | check (list, FTAG, FIXED4, NULL); |
---|
124 | NEW_LIST_FIXED (GST_TAG_MERGE_PREPEND); |
---|
125 | check (list, FTAG, FIXED4, NULL); |
---|
126 | NEW_LIST_FIXED (GST_TAG_MERGE_APPEND); |
---|
127 | check (list, FTAG, FIXED1, NULL); |
---|
128 | NEW_LIST_FIXED (GST_TAG_MERGE_KEEP); |
---|
129 | check (list, FTAG, FIXED1, NULL); |
---|
130 | NEW_LIST_FIXED (GST_TAG_MERGE_KEEP_ALL); |
---|
131 | check (list, FTAG, NULL); |
---|
132 | |
---|
133 | /* check merging */ |
---|
134 | /* unfixed */ |
---|
135 | NEW_LISTS_UNFIXED (GST_TAG_MERGE_REPLACE_ALL); |
---|
136 | check (merge, UTAG, UNFIXED3, UNFIXED4, NULL); |
---|
137 | NEW_LISTS_UNFIXED (GST_TAG_MERGE_REPLACE); |
---|
138 | check (merge, UTAG, UNFIXED3, UNFIXED4, NULL); |
---|
139 | NEW_LISTS_UNFIXED (GST_TAG_MERGE_PREPEND); |
---|
140 | check (merge, UTAG, UNFIXED3, UNFIXED4, UNFIXED1, UNFIXED2, NULL); |
---|
141 | NEW_LISTS_UNFIXED (GST_TAG_MERGE_APPEND); |
---|
142 | check (merge, UTAG, UNFIXED1, UNFIXED2, UNFIXED3, UNFIXED4, NULL); |
---|
143 | NEW_LISTS_UNFIXED (GST_TAG_MERGE_KEEP); |
---|
144 | check (merge, UTAG, UNFIXED1, UNFIXED2, NULL); |
---|
145 | NEW_LISTS_UNFIXED (GST_TAG_MERGE_KEEP_ALL); |
---|
146 | check (merge, UTAG, UNFIXED1, UNFIXED2, NULL); |
---|
147 | /* fixed */ |
---|
148 | NEW_LISTS_FIXED (GST_TAG_MERGE_REPLACE_ALL); |
---|
149 | check (merge, FTAG, FIXED3, NULL); |
---|
150 | NEW_LISTS_FIXED (GST_TAG_MERGE_REPLACE); |
---|
151 | check (merge, FTAG, FIXED3, NULL); |
---|
152 | NEW_LISTS_FIXED (GST_TAG_MERGE_PREPEND); |
---|
153 | check (merge, FTAG, FIXED3, NULL); |
---|
154 | NEW_LISTS_FIXED (GST_TAG_MERGE_APPEND); |
---|
155 | check (merge, FTAG, FIXED1, NULL); |
---|
156 | NEW_LISTS_FIXED (GST_TAG_MERGE_KEEP); |
---|
157 | check (merge, FTAG, FIXED1, NULL); |
---|
158 | NEW_LISTS_FIXED (GST_TAG_MERGE_KEEP_ALL); |
---|
159 | check (merge, FTAG, FIXED1, NULL); |
---|
160 | |
---|
161 | return 0; |
---|
162 | } |
---|