convert C prototypes for functions with no args from () to (void)
[platform/upstream/flac.git] / src / test_libFLAC / format.c
1 /* test_libFLAC - Unit tester for libFLAC
2  * Copyright (C) 2004,2005,2006  Josh Coalson
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program 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
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17  */
18
19 #if HAVE_CONFIG_H
20 #  include <config.h>
21 #endif
22
23 #include "FLAC/assert.h"
24 #include "FLAC/format.h"
25 #include <stdio.h>
26
27 static const char *true_false_string_[2] = { "false", "true" };
28
29 static struct {
30         unsigned rate;
31         FLAC__bool valid;
32 } SAMPLE_RATES[] = {
33         { 0      , false },
34         { 1      , true  },
35         { 9      , true  },
36         { 10     , true  },
37         { 4000   , true  },
38         { 8000   , true  },
39         { 11025  , true  },
40         { 12000  , true  },
41         { 16000  , true  },
42         { 22050  , true  },
43         { 24000  , true  },
44         { 32000  , true  },
45         { 32768  , true  },
46         { 44100  , true  },
47         { 48000  , true  },
48         { 65000  , true  },
49         { 65535  , true  },
50         { 65536  , false },
51         { 65540  , true  },
52         { 65550  , true  },
53         { 65555  , false },
54         { 66000  , true  },
55         { 66001  , false },
56         { 96000  , true  },
57         { 100000 , true  },
58         { 100001 , false },
59         { 192000 , true  },
60         { 500000 , true  },
61         { 500001 , false },
62         { 500010 , true  },
63         { 700000 , false },
64         { 700010 , false },
65         { 1000000, false },
66         { 1100000, false }
67 };
68
69 static struct {
70         const char *string;
71         FLAC__bool valid;
72 } VCENTRY_NAMES[] = {
73         { ""    , true  },
74         { "a"   , true  },
75         { "="   , false },
76         { "a="  , false },
77         { "\x01", false },
78         { "\x1f", false },
79         { "\x7d", true  },
80         { "\x7e", false },
81         { "\xff", false }
82 };
83
84 static struct {
85         unsigned length;
86         const FLAC__byte *string;
87         FLAC__bool valid;
88 } VCENTRY_VALUES[] = {
89         { 0, (const FLAC__byte*)""            , true  },
90         { 1, (const FLAC__byte*)""            , true  },
91         { 1, (const FLAC__byte*)"\x01"        , true  },
92         { 1, (const FLAC__byte*)"\x7f"        , true  },
93         { 1, (const FLAC__byte*)"\x80"        , false },
94         { 1, (const FLAC__byte*)"\x81"        , false },
95         { 1, (const FLAC__byte*)"\xc0"        , false },
96         { 1, (const FLAC__byte*)"\xe0"        , false },
97         { 1, (const FLAC__byte*)"\xf0"        , false },
98         { 2, (const FLAC__byte*)"\xc0\x41"    , false },
99         { 2, (const FLAC__byte*)"\xc1\x41"    , false },
100         { 2, (const FLAC__byte*)"\xc0\x85"    , false }, /* non-shortest form */
101         { 2, (const FLAC__byte*)"\xc1\x85"    , false }, /* non-shortest form */
102         { 2, (const FLAC__byte*)"\xc2\x85"    , true  },
103         { 2, (const FLAC__byte*)"\xe0\x41"    , false },
104         { 2, (const FLAC__byte*)"\xe1\x41"    , false },
105         { 2, (const FLAC__byte*)"\xe0\x85"    , false },
106         { 2, (const FLAC__byte*)"\xe1\x85"    , false },
107         { 3, (const FLAC__byte*)"\xe0\x85\x41", false },
108         { 3, (const FLAC__byte*)"\xe1\x85\x41", false },
109         { 3, (const FLAC__byte*)"\xe0\x85\x80", false }, /* non-shortest form */
110         { 3, (const FLAC__byte*)"\xe0\x95\x80", false }, /* non-shortest form */
111         { 3, (const FLAC__byte*)"\xe0\xa5\x80", true  },
112         { 3, (const FLAC__byte*)"\xe1\x85\x80", true  },
113         { 3, (const FLAC__byte*)"\xe1\x95\x80", true  },
114         { 3, (const FLAC__byte*)"\xe1\xa5\x80", true  }
115 };
116
117 static struct {
118         const FLAC__byte *string;
119         FLAC__bool valid;
120 } VCENTRY_VALUES_NT[] = {
121         { (const FLAC__byte*)""            , true  },
122         { (const FLAC__byte*)"\x01"        , true  },
123         { (const FLAC__byte*)"\x7f"        , true  },
124         { (const FLAC__byte*)"\x80"        , false },
125         { (const FLAC__byte*)"\x81"        , false },
126         { (const FLAC__byte*)"\xc0"        , false },
127         { (const FLAC__byte*)"\xe0"        , false },
128         { (const FLAC__byte*)"\xf0"        , false },
129         { (const FLAC__byte*)"\xc0\x41"    , false },
130         { (const FLAC__byte*)"\xc1\x41"    , false },
131         { (const FLAC__byte*)"\xc0\x85"    , false }, /* non-shortest form */
132         { (const FLAC__byte*)"\xc1\x85"    , false }, /* non-shortest form */
133         { (const FLAC__byte*)"\xc2\x85"    , true  },
134         { (const FLAC__byte*)"\xe0\x41"    , false },
135         { (const FLAC__byte*)"\xe1\x41"    , false },
136         { (const FLAC__byte*)"\xe0\x85"    , false },
137         { (const FLAC__byte*)"\xe1\x85"    , false },
138         { (const FLAC__byte*)"\xe0\x85\x41", false },
139         { (const FLAC__byte*)"\xe1\x85\x41", false },
140         { (const FLAC__byte*)"\xe0\x85\x80", false }, /* non-shortest form */
141         { (const FLAC__byte*)"\xe0\x95\x80", false }, /* non-shortest form */
142         { (const FLAC__byte*)"\xe0\xa5\x80", true  },
143         { (const FLAC__byte*)"\xe1\x85\x80", true  },
144         { (const FLAC__byte*)"\xe1\x95\x80", true  },
145         { (const FLAC__byte*)"\xe1\xa5\x80", true  }
146 };
147
148 static struct {
149         unsigned length;
150         const FLAC__byte *string;
151         FLAC__bool valid;
152 } VCENTRIES[] = {
153         { 0, (const FLAC__byte*)""              , false },
154         { 1, (const FLAC__byte*)"a"             , false },
155         { 1, (const FLAC__byte*)"="             , true  },
156         { 2, (const FLAC__byte*)"a="            , true  },
157         { 2, (const FLAC__byte*)"\x01="         , false },
158         { 2, (const FLAC__byte*)"\x1f="         , false },
159         { 2, (const FLAC__byte*)"\x7d="         , true  },
160         { 2, (const FLAC__byte*)"\x7e="         , false },
161         { 2, (const FLAC__byte*)"\xff="         , false },
162         { 3, (const FLAC__byte*)"a=\x01"        , true  },
163         { 3, (const FLAC__byte*)"a=\x7f"        , true  },
164         { 3, (const FLAC__byte*)"a=\x80"        , false },
165         { 3, (const FLAC__byte*)"a=\x81"        , false },
166         { 3, (const FLAC__byte*)"a=\xc0"        , false },
167         { 3, (const FLAC__byte*)"a=\xe0"        , false },
168         { 3, (const FLAC__byte*)"a=\xf0"        , false },
169         { 4, (const FLAC__byte*)"a=\xc0\x41"    , false },
170         { 4, (const FLAC__byte*)"a=\xc1\x41"    , false },
171         { 4, (const FLAC__byte*)"a=\xc0\x85"    , false }, /* non-shortest form */
172         { 4, (const FLAC__byte*)"a=\xc1\x85"    , false }, /* non-shortest form */
173         { 4, (const FLAC__byte*)"a=\xc2\x85"    , true  },
174         { 4, (const FLAC__byte*)"a=\xe0\x41"    , false },
175         { 4, (const FLAC__byte*)"a=\xe1\x41"    , false },
176         { 4, (const FLAC__byte*)"a=\xe0\x85"    , false },
177         { 4, (const FLAC__byte*)"a=\xe1\x85"    , false },
178         { 5, (const FLAC__byte*)"a=\xe0\x85\x41", false },
179         { 5, (const FLAC__byte*)"a=\xe1\x85\x41", false },
180         { 5, (const FLAC__byte*)"a=\xe0\x85\x80", false }, /* non-shortest form */
181         { 5, (const FLAC__byte*)"a=\xe0\x95\x80", false }, /* non-shortest form */
182         { 5, (const FLAC__byte*)"a=\xe0\xa5\x80", true  },
183         { 5, (const FLAC__byte*)"a=\xe1\x85\x80", true  },
184         { 5, (const FLAC__byte*)"a=\xe1\x95\x80", true  },
185         { 5, (const FLAC__byte*)"a=\xe1\xa5\x80", true  }
186 };
187
188 FLAC__bool test_format(void)
189 {
190         unsigned i;
191
192         printf("\n+++ libFLAC unit test: format\n\n");
193
194         for(i = 0; i < sizeof(SAMPLE_RATES)/sizeof(SAMPLE_RATES[0]); i++) {
195                 printf("testing FLAC__format_sample_rate_is_valid(%u)... ", SAMPLE_RATES[i].rate);
196                 if(FLAC__format_sample_rate_is_valid(SAMPLE_RATES[i].rate) != SAMPLE_RATES[i].valid) {
197                         printf("FAILED, expected %s, got %s\n", true_false_string_[SAMPLE_RATES[i].valid], true_false_string_[!SAMPLE_RATES[i].valid]);
198                         return false;
199                 }
200                 printf("OK\n");
201         }
202
203         for(i = 0; i < sizeof(VCENTRY_NAMES)/sizeof(VCENTRY_NAMES[0]); i++) {
204                 printf("testing FLAC__format_vorbiscomment_entry_name_is_legal(\"%s\")... ", VCENTRY_NAMES[i].string);
205                 if(FLAC__format_vorbiscomment_entry_name_is_legal(VCENTRY_NAMES[i].string) != VCENTRY_NAMES[i].valid) {
206                         printf("FAILED, expected %s, got %s\n", true_false_string_[VCENTRY_NAMES[i].valid], true_false_string_[!VCENTRY_NAMES[i].valid]);
207                         return false;
208                 }
209                 printf("OK\n");
210         }
211
212         for(i = 0; i < sizeof(VCENTRY_VALUES)/sizeof(VCENTRY_VALUES[0]); i++) {
213                 printf("testing FLAC__format_vorbiscomment_entry_value_is_legal(\"%s\", %u)... ", VCENTRY_VALUES[i].string, VCENTRY_VALUES[i].length);
214                 if(FLAC__format_vorbiscomment_entry_value_is_legal(VCENTRY_VALUES[i].string, VCENTRY_VALUES[i].length) != VCENTRY_VALUES[i].valid) {
215                         printf("FAILED, expected %s, got %s\n", true_false_string_[VCENTRY_VALUES[i].valid], true_false_string_[!VCENTRY_VALUES[i].valid]);
216                         return false;
217                 }
218                 printf("OK\n");
219         }
220
221         for(i = 0; i < sizeof(VCENTRY_VALUES_NT)/sizeof(VCENTRY_VALUES_NT[0]); i++) {
222                 printf("testing FLAC__format_vorbiscomment_entry_value_is_legal(\"%s\", -1)... ", VCENTRY_VALUES_NT[i].string);
223                 if(FLAC__format_vorbiscomment_entry_value_is_legal(VCENTRY_VALUES_NT[i].string, (unsigned)(-1)) != VCENTRY_VALUES_NT[i].valid) {
224                         printf("FAILED, expected %s, got %s\n", true_false_string_[VCENTRY_VALUES_NT[i].valid], true_false_string_[!VCENTRY_VALUES_NT[i].valid]);
225                         return false;
226                 }
227                 printf("OK\n");
228         }
229
230         for(i = 0; i < sizeof(VCENTRIES)/sizeof(VCENTRIES[0]); i++) {
231                 printf("testing FLAC__format_vorbiscomment_entry_is_legal(\"%s\", %u)... ", VCENTRIES[i].string, VCENTRIES[i].length);
232                 if(FLAC__format_vorbiscomment_entry_is_legal(VCENTRIES[i].string, VCENTRIES[i].length) != VCENTRIES[i].valid) {
233                         printf("FAILED, expected %s, got %s\n", true_false_string_[VCENTRIES[i].valid], true_false_string_[!VCENTRIES[i].valid]);
234                         return false;
235                 }
236                 printf("OK\n");
237         }
238
239         printf("\nPASSED!\n");
240         return true;
241 }