Fix a couple of Windows 2Gig file size issues.
[flac.git] / src / test_libFLAC / format.c
blob5e881721126f53d13405b203ddbec246b58256f4
1 /* test_libFLAC - Unit tester for libFLAC
2 * Copyright (C) 2004,2005,2006,2007,2008,2009 Josh Coalson
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.
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.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #if HAVE_CONFIG_H
20 # include <config.h>
21 #endif
23 #include "FLAC/assert.h"
24 #include "FLAC/format.h"
25 #include "format.h"
26 #include <stdio.h>
28 static const char *true_false_string_[2] = { "false", "true" };
30 static struct {
31 unsigned rate;
32 FLAC__bool valid;
33 FLAC__bool subset;
34 } SAMPLE_RATES[] = {
35 { 0 , false, false },
36 { 1 , true , true },
37 { 9 , true , true },
38 { 10 , true , true },
39 { 4000 , true , true },
40 { 8000 , true , true },
41 { 11025 , true , true },
42 { 12000 , true , true },
43 { 16000 , true , true },
44 { 22050 , true , true },
45 { 24000 , true , true },
46 { 32000 , true , true },
47 { 32768 , true , true },
48 { 44100 , true , true },
49 { 48000 , true , true },
50 { 65000 , true , true },
51 { 65535 , true , true },
52 { 65536 , true , false },
53 { 65540 , true , true },
54 { 65550 , true , true },
55 { 65555 , true , false },
56 { 66000 , true , true },
57 { 66001 , true , false },
58 { 96000 , true , true },
59 { 100000 , true , true },
60 { 100001 , true , false },
61 { 192000 , true , true },
62 { 500000 , true , true },
63 { 500001 , true , false },
64 { 500010 , true , true },
65 { 655349 , true , false },
66 { 655350 , true , true },
67 { 655351 , false, false },
68 { 655360 , false, false },
69 { 700000 , false, false },
70 { 700010 , false, false },
71 { 1000000, false, false },
72 { 1100000, false, false }
75 static struct {
76 const char *string;
77 FLAC__bool valid;
78 } VCENTRY_NAMES[] = {
79 { "" , true },
80 { "a" , true },
81 { "=" , false },
82 { "a=" , false },
83 { "\x01", false },
84 { "\x1f", false },
85 { "\x7d", true },
86 { "\x7e", false },
87 { "\xff", false }
90 static struct {
91 unsigned length;
92 const FLAC__byte *string;
93 FLAC__bool valid;
94 } VCENTRY_VALUES[] = {
95 { 0, (const FLAC__byte*)"" , true },
96 { 1, (const FLAC__byte*)"" , true },
97 { 1, (const FLAC__byte*)"\x01" , true },
98 { 1, (const FLAC__byte*)"\x7f" , true },
99 { 1, (const FLAC__byte*)"\x80" , false },
100 { 1, (const FLAC__byte*)"\x81" , false },
101 { 1, (const FLAC__byte*)"\xc0" , false },
102 { 1, (const FLAC__byte*)"\xe0" , false },
103 { 1, (const FLAC__byte*)"\xf0" , false },
104 { 2, (const FLAC__byte*)"\xc0\x41" , false },
105 { 2, (const FLAC__byte*)"\xc1\x41" , false },
106 { 2, (const FLAC__byte*)"\xc0\x85" , false }, /* non-shortest form */
107 { 2, (const FLAC__byte*)"\xc1\x85" , false }, /* non-shortest form */
108 { 2, (const FLAC__byte*)"\xc2\x85" , true },
109 { 2, (const FLAC__byte*)"\xe0\x41" , false },
110 { 2, (const FLAC__byte*)"\xe1\x41" , false },
111 { 2, (const FLAC__byte*)"\xe0\x85" , false },
112 { 2, (const FLAC__byte*)"\xe1\x85" , false },
113 { 3, (const FLAC__byte*)"\xe0\x85\x41", false },
114 { 3, (const FLAC__byte*)"\xe1\x85\x41", false },
115 { 3, (const FLAC__byte*)"\xe0\x85\x80", false }, /* non-shortest form */
116 { 3, (const FLAC__byte*)"\xe0\x95\x80", false }, /* non-shortest form */
117 { 3, (const FLAC__byte*)"\xe0\xa5\x80", true },
118 { 3, (const FLAC__byte*)"\xe1\x85\x80", true },
119 { 3, (const FLAC__byte*)"\xe1\x95\x80", true },
120 { 3, (const FLAC__byte*)"\xe1\xa5\x80", true }
123 static struct {
124 const FLAC__byte *string;
125 FLAC__bool valid;
126 } VCENTRY_VALUES_NT[] = {
127 { (const FLAC__byte*)"" , true },
128 { (const FLAC__byte*)"\x01" , true },
129 { (const FLAC__byte*)"\x7f" , true },
130 { (const FLAC__byte*)"\x80" , false },
131 { (const FLAC__byte*)"\x81" , false },
132 { (const FLAC__byte*)"\xc0" , false },
133 { (const FLAC__byte*)"\xe0" , false },
134 { (const FLAC__byte*)"\xf0" , false },
135 { (const FLAC__byte*)"\xc0\x41" , false },
136 { (const FLAC__byte*)"\xc1\x41" , false },
137 { (const FLAC__byte*)"\xc0\x85" , false }, /* non-shortest form */
138 { (const FLAC__byte*)"\xc1\x85" , false }, /* non-shortest form */
139 { (const FLAC__byte*)"\xc2\x85" , true },
140 { (const FLAC__byte*)"\xe0\x41" , false },
141 { (const FLAC__byte*)"\xe1\x41" , false },
142 { (const FLAC__byte*)"\xe0\x85" , false },
143 { (const FLAC__byte*)"\xe1\x85" , false },
144 { (const FLAC__byte*)"\xe0\x85\x41", false },
145 { (const FLAC__byte*)"\xe1\x85\x41", false },
146 { (const FLAC__byte*)"\xe0\x85\x80", false }, /* non-shortest form */
147 { (const FLAC__byte*)"\xe0\x95\x80", false }, /* non-shortest form */
148 { (const FLAC__byte*)"\xe0\xa5\x80", true },
149 { (const FLAC__byte*)"\xe1\x85\x80", true },
150 { (const FLAC__byte*)"\xe1\x95\x80", true },
151 { (const FLAC__byte*)"\xe1\xa5\x80", true }
154 static struct {
155 unsigned length;
156 const FLAC__byte *string;
157 FLAC__bool valid;
158 } VCENTRIES[] = {
159 { 0, (const FLAC__byte*)"" , false },
160 { 1, (const FLAC__byte*)"a" , false },
161 { 1, (const FLAC__byte*)"=" , true },
162 { 2, (const FLAC__byte*)"a=" , true },
163 { 2, (const FLAC__byte*)"\x01=" , false },
164 { 2, (const FLAC__byte*)"\x1f=" , false },
165 { 2, (const FLAC__byte*)"\x7d=" , true },
166 { 2, (const FLAC__byte*)"\x7e=" , false },
167 { 2, (const FLAC__byte*)"\xff=" , false },
168 { 3, (const FLAC__byte*)"a=\x01" , true },
169 { 3, (const FLAC__byte*)"a=\x7f" , true },
170 { 3, (const FLAC__byte*)"a=\x80" , false },
171 { 3, (const FLAC__byte*)"a=\x81" , false },
172 { 3, (const FLAC__byte*)"a=\xc0" , false },
173 { 3, (const FLAC__byte*)"a=\xe0" , false },
174 { 3, (const FLAC__byte*)"a=\xf0" , false },
175 { 4, (const FLAC__byte*)"a=\xc0\x41" , false },
176 { 4, (const FLAC__byte*)"a=\xc1\x41" , false },
177 { 4, (const FLAC__byte*)"a=\xc0\x85" , false }, /* non-shortest form */
178 { 4, (const FLAC__byte*)"a=\xc1\x85" , false }, /* non-shortest form */
179 { 4, (const FLAC__byte*)"a=\xc2\x85" , true },
180 { 4, (const FLAC__byte*)"a=\xe0\x41" , false },
181 { 4, (const FLAC__byte*)"a=\xe1\x41" , false },
182 { 4, (const FLAC__byte*)"a=\xe0\x85" , false },
183 { 4, (const FLAC__byte*)"a=\xe1\x85" , false },
184 { 5, (const FLAC__byte*)"a=\xe0\x85\x41", false },
185 { 5, (const FLAC__byte*)"a=\xe1\x85\x41", false },
186 { 5, (const FLAC__byte*)"a=\xe0\x85\x80", false }, /* non-shortest form */
187 { 5, (const FLAC__byte*)"a=\xe0\x95\x80", false }, /* non-shortest form */
188 { 5, (const FLAC__byte*)"a=\xe0\xa5\x80", true },
189 { 5, (const FLAC__byte*)"a=\xe1\x85\x80", true },
190 { 5, (const FLAC__byte*)"a=\xe1\x95\x80", true },
191 { 5, (const FLAC__byte*)"a=\xe1\xa5\x80", true }
194 FLAC__bool test_format(void)
196 unsigned i;
198 printf("\n+++ libFLAC unit test: format\n\n");
200 for(i = 0; i < sizeof(SAMPLE_RATES)/sizeof(SAMPLE_RATES[0]); i++) {
201 printf("testing FLAC__format_sample_rate_is_valid(%u)... ", SAMPLE_RATES[i].rate);
202 if(FLAC__format_sample_rate_is_valid(SAMPLE_RATES[i].rate) != SAMPLE_RATES[i].valid) {
203 printf("FAILED, expected %s, got %s\n", true_false_string_[SAMPLE_RATES[i].valid], true_false_string_[!SAMPLE_RATES[i].valid]);
204 return false;
206 printf("OK\n");
209 for(i = 0; i < sizeof(SAMPLE_RATES)/sizeof(SAMPLE_RATES[0]); i++) {
210 printf("testing FLAC__format_sample_rate_is_subset(%u)... ", SAMPLE_RATES[i].rate);
211 if(FLAC__format_sample_rate_is_subset(SAMPLE_RATES[i].rate) != SAMPLE_RATES[i].subset) {
212 printf("FAILED, expected %s, got %s\n", true_false_string_[SAMPLE_RATES[i].subset], true_false_string_[!SAMPLE_RATES[i].subset]);
213 return false;
215 printf("OK\n");
218 for(i = 0; i < sizeof(VCENTRY_NAMES)/sizeof(VCENTRY_NAMES[0]); i++) {
219 printf("testing FLAC__format_vorbiscomment_entry_name_is_legal(\"%s\")... ", VCENTRY_NAMES[i].string);
220 if(FLAC__format_vorbiscomment_entry_name_is_legal(VCENTRY_NAMES[i].string) != VCENTRY_NAMES[i].valid) {
221 printf("FAILED, expected %s, got %s\n", true_false_string_[VCENTRY_NAMES[i].valid], true_false_string_[!VCENTRY_NAMES[i].valid]);
222 return false;
224 printf("OK\n");
227 for(i = 0; i < sizeof(VCENTRY_VALUES)/sizeof(VCENTRY_VALUES[0]); i++) {
228 printf("testing FLAC__format_vorbiscomment_entry_value_is_legal(\"%s\", %u)... ", VCENTRY_VALUES[i].string, VCENTRY_VALUES[i].length);
229 if(FLAC__format_vorbiscomment_entry_value_is_legal(VCENTRY_VALUES[i].string, VCENTRY_VALUES[i].length) != VCENTRY_VALUES[i].valid) {
230 printf("FAILED, expected %s, got %s\n", true_false_string_[VCENTRY_VALUES[i].valid], true_false_string_[!VCENTRY_VALUES[i].valid]);
231 return false;
233 printf("OK\n");
236 for(i = 0; i < sizeof(VCENTRY_VALUES_NT)/sizeof(VCENTRY_VALUES_NT[0]); i++) {
237 printf("testing FLAC__format_vorbiscomment_entry_value_is_legal(\"%s\", -1)... ", VCENTRY_VALUES_NT[i].string);
238 if(FLAC__format_vorbiscomment_entry_value_is_legal(VCENTRY_VALUES_NT[i].string, (unsigned)(-1)) != VCENTRY_VALUES_NT[i].valid) {
239 printf("FAILED, expected %s, got %s\n", true_false_string_[VCENTRY_VALUES_NT[i].valid], true_false_string_[!VCENTRY_VALUES_NT[i].valid]);
240 return false;
242 printf("OK\n");
245 for(i = 0; i < sizeof(VCENTRIES)/sizeof(VCENTRIES[0]); i++) {
246 printf("testing FLAC__format_vorbiscomment_entry_is_legal(\"%s\", %u)... ", VCENTRIES[i].string, VCENTRIES[i].length);
247 if(FLAC__format_vorbiscomment_entry_is_legal(VCENTRIES[i].string, VCENTRIES[i].length) != VCENTRIES[i].valid) {
248 printf("FAILED, expected %s, got %s\n", true_false_string_[VCENTRIES[i].valid], true_false_string_[!VCENTRIES[i].valid]);
249 return false;
251 printf("OK\n");
254 printf("\nPASSED!\n");
255 return true;