1 /* EasyTAG - tag editor for audio files
2  * Copyright (C) 2014-2015 David King <amigadave@amigadave.com>
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the Free
6  * Software Foundation; either version 2 of the License, or (at your option)
7  * any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc., 51
16  * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18 
19 #include "config.h"
20 
21 #include "file_description.h"
22 
23 static void
file_description_get_extension(void)24 file_description_get_extension (void)
25 {
26     gsize i;
27     static const struct
28     {
29         const gchar *filename;
30         const gchar *extension;
31     } filenames[] =
32     {
33         { "test.mp3", ".mp3" },
34         { "test.mp4.mp3", ".mp3" },
35         { "test.mp4mp3", ".mp4mp3" },
36         { "test.", "." },
37         { "test", NULL },
38         { "test.Mp4", ".Mp4" }
39     };
40 
41     for (i = 0; i < G_N_ELEMENTS (filenames); i++)
42     {
43         const gchar *extension;
44         extension = ET_Get_File_Extension (filenames[i].filename);
45         g_assert_cmpstr (extension, ==, filenames[i].extension);
46     }
47 }
48 
49 static void
file_description_get_file_description(void)50 file_description_get_file_description (void)
51 {
52     gsize i;
53     static const struct
54     {
55         const gchar *filename;
56         ET_File_Type file_type;
57         ET_Tag_Type tag_type;
58     } filenames[] =
59     {
60 #ifdef ENABLE_MP3
61         { "test.mp3", MP3_FILE, ID3_TAG },
62         { "test.mp4.mp3", MP3_FILE, ID3_TAG },
63         { "test.mp2", MP2_FILE, ID3_TAG },
64 #else /* !ENABLE_MP3 */
65         { "test.mp3", UNKNOWN_FILE, UNKNOWN_TAG },
66         { "test.mp4.mp3", UNKNOWN_FILE, UNKNOWN_TAG },
67         { "test.mp2", UNKNOWN_FILE, UNKNOWN_TAG },
68 #endif /* !ENABLE_MP3 */
69         { "test.mp4mp3", UNKNOWN_FILE, UNKNOWN_TAG },
70         { "test.", UNKNOWN_FILE, UNKNOWN_TAG },
71         { "test", UNKNOWN_FILE, UNKNOWN_TAG },
72 #ifdef ENABLE_MP4
73         { "test.Mp4", MP4_FILE, MP4_TAG },
74         { "test.mp4", MP4_FILE, MP4_TAG },
75         { "test.m4a", MP4_FILE, MP4_TAG },
76         { "test.m4p", MP4_FILE, MP4_TAG },
77         { "test.m4v", MP4_FILE, MP4_TAG },
78         { "test.aac", MP4_FILE, MP4_TAG },
79 #else /* !ENABLE_MP4 */
80         { "test.Mp4", UNKNOWN_FILE, UNKNOWN_TAG },
81         { "test.mp4", UNKNOWN_FILE, UNKNOWN_TAG },
82         { "test.m4a", UNKNOWN_FILE, UNKNOWN_TAG },
83         { "test.m4p", UNKNOWN_FILE, UNKNOWN_TAG },
84         { "test.m4v", UNKNOWN_FILE, UNKNOWN_TAG },
85 #endif /* ENABLE_MP4 */
86         { "test.mpeg", UNKNOWN_FILE, UNKNOWN_TAG },
87 #ifdef ENABLE_OPUS
88         { "test.opus", OPUS_FILE, OPUS_TAG },
89 #else /* !ENABLE_OPUS */
90         { "test.opus", UNKNOWN_FILE, UNKNOWN_TAG },
91 #endif /* !ENABLE_OPUS */
92 #ifdef ENABLE_OGG
93         { "test.ogg", OGG_FILE, OGG_TAG },
94         { "test.oga", OGG_FILE, OGG_TAG },
95 #else /* !ENABLE_OGG */
96         { "test.ogg", UNKNOWN_FILE, UNKNOWN_TAG },
97         { "test.oga", UNKNOWN_FILE, UNKNOWN_TAG },
98 #endif /* !ENABLE_OGG */
99 #ifdef ENABLE_SPEEX
100         { "test.spx", SPEEX_FILE, OGG_TAG },
101 #else /* !ENABLE_SPEEX */
102         { "test.spx", UNKNOWN_FILE, UNKNOWN_TAG },
103 #endif
104         { "test.dsf", UNKNOWN_FILE, UNKNOWN_TAG },
105 #ifdef ENABLE_FLAC
106         { "test.flac", FLAC_FILE, FLAC_TAG },
107         { "test.fla", FLAC_FILE, FLAC_TAG },
108 #else /* !ENABLE_FLAC */
109         { "test.flac", UNKNOWN_FILE, UNKNOWN_TAG },
110         { "test.fla", UNKNOWN_FILE, UNKNOWN_TAG },
111 #endif /* !ENABLE_FLAC */
112         { "test.mpc", MPC_FILE, APE_TAG },
113         { "test.mp+", MPC_FILE, APE_TAG },
114         { "test.mpp", MPC_FILE, APE_TAG },
115         { "test.ape", MAC_FILE, APE_TAG },
116         { "test.mac", MAC_FILE, APE_TAG },
117         { "test.ofr", OFR_FILE, APE_TAG },
118         { "test.ofs", OFR_FILE, APE_TAG },
119 #ifdef ENABLE_WAVPACK
120         { "test.wv", WAVPACK_FILE, WAVPACK_TAG },
121 #else /* !ENABLE_WAVPACK */
122         { "test.wv", UNKNOWN_FILE, UNKNOWN_TAG },
123 #endif /* !ENABLE_WAVPACK */
124         { "test.wvc", UNKNOWN_FILE, UNKNOWN_TAG }
125     };
126 
127     for (i = 0; i < G_N_ELEMENTS (filenames); i++)
128     {
129         const ET_File_Description *description;
130         description = ET_Get_File_Description (filenames[i].filename);
131         g_assert_cmpint (description->FileType, ==, filenames[i].file_type);
132         g_assert_cmpint (description->TagType, ==, filenames[i].tag_type);
133     }
134 }
135 
136 static void
file_description_is_supported(void)137 file_description_is_supported (void)
138 {
139     gsize i;
140     static const struct
141     {
142         const gchar *filename;
143         gboolean supported;
144     } filenames[] =
145     {
146 #ifdef ENABLE_MP3
147         { "test.mp3", TRUE },
148         { "test.mp4.mp3", TRUE },
149         { "test.mp2", TRUE },
150 #else /* !ENABLE_MP3 */
151         { "test.mp3", FALSE },
152         { "test.mp4.mp3", FALSE },
153         { "test.mp2", FALSE },
154 #endif /* !ENABLE_MP3 */
155         { "test.mp4mp3", FALSE },
156         { "test.", FALSE },
157         { "test", FALSE },
158         { "test.mpeg", FALSE },
159 #ifdef ENABLE_OPUS
160         { "test.opus", TRUE },
161 #else /* !ENABLE_OPUS */
162         { "test.opus", FALSE },
163 #endif /* !ENABLE_OPUS */
164 #ifdef ENABLE_OGG
165         { "test.ogg", TRUE },
166         { "test.oga", TRUE },
167 #else /* !ENABLE_OGG */
168         { "test.ogg", FALSE },
169         { "test.oga", FALSE },
170 #endif /* !ENABLE_OGG */
171 #ifdef ENABLE_SPEEX
172         { "test.spx", TRUE },
173 #else /* !ENABLE_SPEEX */
174         { "test.spx", FALSE },
175 #endif /* !ENABLE_SPEEX */
176 #ifdef ENABLE_FLAC
177         { "test.flac", TRUE },
178         { "test.fla", TRUE },
179 #else /* !ENABLE_FLAC */
180         { "test.flac", FALSE },
181         { "test.fla", FALSE },
182 #endif /* !ENABLE_FLAC */
183         { "test.mpc", TRUE },
184         { "test.mp+", TRUE },
185         { "test.mpp", TRUE },
186         { "test.ape", TRUE },
187         { "test.mac", TRUE },
188         { "test.ofr", TRUE },
189         { "test.ofs", TRUE },
190 #ifdef ENABLE_MP4
191         { "test.mp4", TRUE },
192         { "test.m4a", TRUE },
193         { "test.m4p", TRUE },
194         { "test.m4v", TRUE },
195 #else /* !ENABLE_MP4 */
196         { "test.mp4", FALSE },
197         { "test.m4a", FALSE },
198         { "test.m4p", FALSE },
199         { "test.m4v", FALSE },
200 #endif /* !ENABLE_MP4 */
201 #ifdef ENABLE_WAVPACK
202         { "test.wv", TRUE },
203 #else /* !ENABLE_WAVPACK */
204         { "test.wv", FALSE },
205 #endif /* !ENABLE_WAVPACK */
206         { "test.wvc", FALSE }
207     };
208 
209     for (i = 0; i < G_N_ELEMENTS (filenames); i++)
210     {
211         gboolean supported;
212         supported = et_file_is_supported (filenames[i].filename);
213         g_assert (supported == filenames[i].supported);
214     }
215 }
216 
217 int
main(int argc,char ** argv)218 main (int argc, char** argv)
219 {
220     g_test_init (&argc, &argv, NULL);
221 
222     g_test_add_func ("/file_description/get_extension",
223                      file_description_get_extension);
224     g_test_add_func ("/file_description/get_file_description",
225                      file_description_get_file_description);
226     g_test_add_func ("/file_description/is_supported",
227                      file_description_is_supported);
228 
229     return g_test_run ();
230 }
231