1 /* test_libFLAC - Unit tester for libFLAC
2 * Copyright (C) 2004 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
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.
19 #include "FLAC/assert.h"
20 #include "FLAC/format.h"
23 static const char *true_false_string_[2] = { "false", "true" };
82 const FLAC__byte *string;
84 } VCENTRY_VALUES[] = {
85 { 0, (const FLAC__byte*)"", true },
86 { 1, (const FLAC__byte*)"", true },
87 { 1, (const FLAC__byte*)"\x01", true },
88 { 1, (const FLAC__byte*)"\x7f", true },
89 { 1, (const FLAC__byte*)"\x80", false },
90 { 1, (const FLAC__byte*)"\x81", false },
91 { 1, (const FLAC__byte*)"\xc0", false },
92 { 1, (const FLAC__byte*)"\xe0", false },
93 { 1, (const FLAC__byte*)"\xf0", false },
94 { 2, (const FLAC__byte*)"\xc0\x41", false },
95 { 2, (const FLAC__byte*)"\xc1\x41", false },
96 { 2, (const FLAC__byte*)"\xc0\x85", true },
97 { 2, (const FLAC__byte*)"\xc1\x85", true },
98 { 2, (const FLAC__byte*)"\xe0\x41", false },
99 { 2, (const FLAC__byte*)"\xe1\x41", false },
100 { 2, (const FLAC__byte*)"\xe0\x85", false },
101 { 2, (const FLAC__byte*)"\xe1\x85", false },
102 { 3, (const FLAC__byte*)"\xe0\x85\x41", false },
103 { 3, (const FLAC__byte*)"\xe1\x85\x41", false },
104 { 3, (const FLAC__byte*)"\xe0\x85\x80", true },
105 { 3, (const FLAC__byte*)"\xe1\x85\x80", true }
109 const FLAC__byte *string;
111 } VCENTRY_VALUES_NT[] = {
112 { (FLAC__byte*)"", true },
113 { (FLAC__byte*)"\x01", true },
114 { (FLAC__byte*)"\x7f", true },
115 { (FLAC__byte*)"\x80", false },
116 { (FLAC__byte*)"\x81", false },
117 { (FLAC__byte*)"\xc0", false },
118 { (FLAC__byte*)"\xe0", false },
119 { (FLAC__byte*)"\xf0", false },
120 { (FLAC__byte*)"\xc0\x41", false },
121 { (FLAC__byte*)"\xc1\x41", false },
122 { (FLAC__byte*)"\xc0\x85", true },
123 { (FLAC__byte*)"\xc1\x85", true },
124 { (FLAC__byte*)"\xe0\x41", false },
125 { (FLAC__byte*)"\xe1\x41", false },
126 { (FLAC__byte*)"\xe0\x85", false },
127 { (FLAC__byte*)"\xe1\x85", false },
128 { (FLAC__byte*)"\xe0\x85\x41", false },
129 { (FLAC__byte*)"\xe1\x85\x41", false },
130 { (FLAC__byte*)"\xe0\x85\x80", true },
131 { (FLAC__byte*)"\xe1\x85\x80", true }
136 const FLAC__byte *string;
139 { 0, (const FLAC__byte*)"", false },
140 { 1, (const FLAC__byte*)"a", false },
141 { 1, (const FLAC__byte*)"=", true },
142 { 2, (const FLAC__byte*)"a=", true },
143 { 2, (const FLAC__byte*)"\x01=", false },
144 { 2, (const FLAC__byte*)"\x1f=", false },
145 { 2, (const FLAC__byte*)"\x7d=", true },
146 { 2, (const FLAC__byte*)"\x7e=", false },
147 { 2, (const FLAC__byte *)"\xff=", false },
148 { 3, (const FLAC__byte*)"a=\x01", true },
149 { 3, (const FLAC__byte*)"a=\x7f", true },
150 { 3, (const FLAC__byte*)"a=\x80", false },
151 { 3, (const FLAC__byte*)"a=\x81", false },
152 { 3, (const FLAC__byte*)"a=\xc0", false },
153 { 3, (const FLAC__byte*)"a=\xe0", false },
154 { 3, (const FLAC__byte*)"a=\xf0", false },
155 { 4, (const FLAC__byte*)"a=\xc0\x41", false },
156 { 4, (const FLAC__byte*)"a=\xc1\x41", false },
157 { 4, (const FLAC__byte*)"a=\xc0\x85", true },
158 { 4, (const FLAC__byte*)"a=\xc1\x85", true },
159 { 4, (const FLAC__byte*)"a=\xe0\x41", false },
160 { 4, (const FLAC__byte*)"a=\xe1\x41", false },
161 { 4, (const FLAC__byte*)"a=\xe0\x85", false },
162 { 4, (const FLAC__byte*)"a=\xe1\x85", false },
163 { 5, (const FLAC__byte*)"a=\xe0\x85\x41", false },
164 { 5, (const FLAC__byte*)"a=\xe1\x85\x41", false },
165 { 5, (const FLAC__byte*)"a=\xe0\x85\x80", true },
166 { 5, (const FLAC__byte*)"a=\xe1\x85\x80", true }
169 FLAC__bool test_format()
173 printf("\n+++ libFLAC unit test: format\n\n");
175 for(i = 0; i < sizeof(SAMPLE_RATES)/sizeof(SAMPLE_RATES[0]); i++) {
176 printf("testing FLAC__format_sample_rate_is_valid(%u)... ", SAMPLE_RATES[i].rate);
177 if(FLAC__format_sample_rate_is_valid(SAMPLE_RATES[i].rate) != SAMPLE_RATES[i].valid) {
178 printf("FAILED, expected %s, got %s\n", true_false_string_[SAMPLE_RATES[i].valid], true_false_string_[!SAMPLE_RATES[i].valid]);
184 for(i = 0; i < sizeof(VCENTRY_NAMES)/sizeof(VCENTRY_NAMES[0]); i++) {
185 printf("testing FLAC__format_vorbiscomment_entry_name_is_legal(\"%s\")... ", VCENTRY_NAMES[i].string);
186 if(FLAC__format_vorbiscomment_entry_name_is_legal(VCENTRY_NAMES[i].string) != VCENTRY_NAMES[i].valid) {
187 printf("FAILED, expected %s, got %s\n", true_false_string_[VCENTRY_NAMES[i].valid], true_false_string_[!VCENTRY_NAMES[i].valid]);
193 for(i = 0; i < sizeof(VCENTRY_VALUES)/sizeof(VCENTRY_VALUES[0]); i++) {
194 printf("testing FLAC__format_vorbiscomment_entry_value_is_legal(\"%s\", %u)... ", VCENTRY_VALUES[i].string, VCENTRY_VALUES[i].length);
195 if(FLAC__format_vorbiscomment_entry_value_is_legal(VCENTRY_VALUES[i].string, VCENTRY_VALUES[i].length) != VCENTRY_VALUES[i].valid) {
196 printf("FAILED, expected %s, got %s\n", true_false_string_[VCENTRY_VALUES[i].valid], true_false_string_[!VCENTRY_VALUES[i].valid]);
202 for(i = 0; i < sizeof(VCENTRY_VALUES_NT)/sizeof(VCENTRY_VALUES_NT[0]); i++) {
203 printf("testing FLAC__format_vorbiscomment_entry_value_is_legal(\"%s\", -1)... ", VCENTRY_VALUES_NT[i].string);
204 if(FLAC__format_vorbiscomment_entry_value_is_legal(VCENTRY_VALUES_NT[i].string, (unsigned)(-1)) != VCENTRY_VALUES_NT[i].valid) {
205 printf("FAILED, expected %s, got %s\n", true_false_string_[VCENTRY_VALUES_NT[i].valid], true_false_string_[!VCENTRY_VALUES_NT[i].valid]);
211 for(i = 0; i < sizeof(VCENTRIES)/sizeof(VCENTRIES[0]); i++) {
212 printf("testing FLAC__format_vorbiscomment_entry_is_legal(\"%s\", %u)... ", VCENTRIES[i].string, VCENTRIES[i].length);
213 if(FLAC__format_vorbiscomment_entry_is_legal(VCENTRIES[i].string, VCENTRIES[i].length) != VCENTRIES[i].valid) {
214 printf("FAILED, expected %s, got %s\n", true_false_string_[VCENTRIES[i].valid], true_false_string_[!VCENTRIES[i].valid]);
220 printf("\nPASSED!\n");