1 /* test_libFLAC - Unit tester for libFLAC
2 * Copyright (C) 2002 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.
20 #include "file_utils.h"
21 #include "FLAC/assert.h"
22 #include "FLAC/file_encoder.h"
23 #include "FLAC/seekable_stream_encoder.h"
24 #include "FLAC/stream_encoder.h"
25 #include "share/grabbag.h"
30 static FLAC__StreamMetadata streaminfo_, padding_, seektable_, application1_, application2_, vorbiscomment_, cuesheet_;
31 static FLAC__StreamMetadata *metadata_sequence_[] = { &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_ };
32 static const unsigned num_metadata_ = 6;
33 static const char *flacfilename_ = "metadata.flac";
35 static FLAC__bool die_s_(const char *msg, const FLAC__StreamEncoder *encoder)
37 FLAC__StreamEncoderState state = FLAC__stream_encoder_get_state(encoder);
40 printf("FAILED, %s", msg);
44 printf(", state = %u (%s)\n", (unsigned)state, FLAC__StreamEncoderStateString[state]);
45 if(state == FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR) {
46 FLAC__StreamDecoderState dstate = FLAC__stream_encoder_get_verify_decoder_state(encoder);
47 printf(" verify decoder state = %u (%s)\n", (unsigned)dstate, FLAC__StreamDecoderStateString[dstate]);
53 static FLAC__bool die_ss_(const char *msg, const FLAC__SeekableStreamEncoder *encoder)
55 FLAC__SeekableStreamEncoderState state = FLAC__seekable_stream_encoder_get_state(encoder);
58 printf("FAILED, %s", msg);
62 printf(", state = %u (%s)\n", (unsigned)state, FLAC__SeekableStreamEncoderStateString[state]);
63 if(state == FLAC__SEEKABLE_STREAM_ENCODER_STREAM_ENCODER_ERROR) {
64 FLAC__StreamEncoderState state_ = FLAC__seekable_stream_encoder_get_stream_encoder_state(encoder);
65 printf(" stream encoder state = %u (%s)\n", (unsigned)state_, FLAC__StreamEncoderStateString[state_]);
66 if(state_ == FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR) {
67 FLAC__StreamDecoderState dstate = FLAC__seekable_stream_encoder_get_verify_decoder_state(encoder);
68 printf(" verify decoder state = %u (%s)\n", (unsigned)dstate, FLAC__StreamDecoderStateString[dstate]);
75 static FLAC__bool die_f_(const char *msg, const FLAC__FileEncoder *encoder)
77 FLAC__FileEncoderState state = FLAC__file_encoder_get_state(encoder);
80 printf("FAILED, %s", msg);
84 printf(", state = %u (%s)\n", (unsigned)state, FLAC__FileEncoderStateString[state]);
85 if(state == FLAC__FILE_ENCODER_SEEKABLE_STREAM_ENCODER_ERROR) {
86 FLAC__SeekableStreamEncoderState state_ = FLAC__file_encoder_get_seekable_stream_encoder_state(encoder);
87 printf(" seekable stream encoder state = %u (%s)\n", (unsigned)state_, FLAC__SeekableStreamEncoderStateString[state_]);
88 if(state_ == FLAC__SEEKABLE_STREAM_ENCODER_STREAM_ENCODER_ERROR) {
89 FLAC__StreamEncoderState state__ = FLAC__file_encoder_get_stream_encoder_state(encoder);
90 printf(" stream encoder state = %u (%s)\n", (unsigned)state__, FLAC__StreamEncoderStateString[state__]);
91 if(state__ == FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR) {
92 FLAC__StreamDecoderState dstate = FLAC__file_encoder_get_verify_decoder_state(encoder);
93 printf(" verify decoder state = %u (%s)\n", (unsigned)dstate, FLAC__StreamDecoderStateString[dstate]);
101 static void *malloc_or_die_(size_t size)
103 void *x = malloc(size);
105 fprintf(stderr, "ERROR: out of memory allocating %u bytes\n", (unsigned)size);
111 static void init_metadata_blocks_()
114 most of the actual numbers and data in the blocks don't matter,
115 we just want to make sure the encoder encodes them correctly
117 remember, the metadata interface gets tested after the encoders,
118 so we do all the metadata manipulation here without it.
121 /* min/max_framesize and md5sum don't get written at first, so we have to leave them 0 */
122 streaminfo_.is_last = false;
123 streaminfo_.type = FLAC__METADATA_TYPE_STREAMINFO;
124 streaminfo_.length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH;
125 streaminfo_.data.stream_info.min_blocksize = 576;
126 streaminfo_.data.stream_info.max_blocksize = 576;
127 streaminfo_.data.stream_info.min_framesize = 0;
128 streaminfo_.data.stream_info.max_framesize = 0;
129 streaminfo_.data.stream_info.sample_rate = 44100;
130 streaminfo_.data.stream_info.channels = 1;
131 streaminfo_.data.stream_info.bits_per_sample = 8;
132 streaminfo_.data.stream_info.total_samples = 0;
133 memset(streaminfo_.data.stream_info.md5sum, 0, 16);
135 padding_.is_last = false;
136 padding_.type = FLAC__METADATA_TYPE_PADDING;
137 padding_.length = 1234;
139 seektable_.is_last = false;
140 seektable_.type = FLAC__METADATA_TYPE_SEEKTABLE;
141 seektable_.data.seek_table.num_points = 2;
142 seektable_.length = seektable_.data.seek_table.num_points * FLAC__STREAM_METADATA_SEEKPOINT_LENGTH;
143 seektable_.data.seek_table.points = malloc_or_die_(seektable_.data.seek_table.num_points * sizeof(FLAC__StreamMetadata_SeekPoint));
144 seektable_.data.seek_table.points[0].sample_number = 0;
145 seektable_.data.seek_table.points[0].stream_offset = 0;
146 seektable_.data.seek_table.points[0].frame_samples = streaminfo_.data.stream_info.min_blocksize;
147 seektable_.data.seek_table.points[1].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
148 seektable_.data.seek_table.points[1].stream_offset = 1000;
149 seektable_.data.seek_table.points[1].frame_samples = streaminfo_.data.stream_info.min_blocksize;
151 application1_.is_last = false;
152 application1_.type = FLAC__METADATA_TYPE_APPLICATION;
153 application1_.length = 8;
154 memcpy(application1_.data.application.id, "\xfe\xdc\xba\x98", 4);
155 application1_.data.application.data = malloc_or_die_(4);
156 memcpy(application1_.data.application.data, "\xf0\xe1\xd2\xc3", 4);
158 application2_.is_last = false;
159 application2_.type = FLAC__METADATA_TYPE_APPLICATION;
160 application2_.length = 4;
161 memcpy(application2_.data.application.id, "\x76\x54\x32\x10", 4);
162 application2_.data.application.data = 0;
164 vorbiscomment_.is_last = false;
165 vorbiscomment_.type = FLAC__METADATA_TYPE_VORBIS_COMMENT;
166 vorbiscomment_.length = (4 + 8) + 4 + (4 + 5) + (4 + 0);
167 vorbiscomment_.data.vorbis_comment.vendor_string.length = 8;
168 vorbiscomment_.data.vorbis_comment.vendor_string.entry = malloc_or_die_(8);
169 memcpy(vorbiscomment_.data.vorbis_comment.vendor_string.entry, "flac 1.x", 8);
170 vorbiscomment_.data.vorbis_comment.num_comments = 2;
171 vorbiscomment_.data.vorbis_comment.comments = malloc_or_die_(vorbiscomment_.data.vorbis_comment.num_comments * sizeof(FLAC__StreamMetadata_VorbisComment_Entry));
172 vorbiscomment_.data.vorbis_comment.comments[0].length = 5;
173 vorbiscomment_.data.vorbis_comment.comments[0].entry = malloc_or_die_(5);
174 memcpy(vorbiscomment_.data.vorbis_comment.comments[0].entry, "ab=cd", 5);
175 vorbiscomment_.data.vorbis_comment.comments[1].length = 0;
176 vorbiscomment_.data.vorbis_comment.comments[1].entry = 0;
178 cuesheet_.is_last = true;
179 cuesheet_.type = FLAC__METADATA_TYPE_CUESHEET;
183 FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN +
184 FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN +
185 FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN +
186 FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN +
187 FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN
191 FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN +
192 FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN +
193 FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN +
194 FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN +
195 FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN +
196 FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN +
197 FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN
201 FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN +
202 FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN +
203 FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN
206 memset(cuesheet_.data.cue_sheet.media_catalog_number, 0, sizeof(cuesheet_.data.cue_sheet.media_catalog_number));
207 cuesheet_.data.cue_sheet.media_catalog_number[0] = 'j';
208 cuesheet_.data.cue_sheet.media_catalog_number[1] = 'C';
209 cuesheet_.data.cue_sheet.lead_in = 2 * 44100;
210 cuesheet_.data.cue_sheet.is_cd = true;
211 cuesheet_.data.cue_sheet.num_tracks = 3;
212 cuesheet_.data.cue_sheet.tracks = malloc_or_die_(cuesheet_.data.cue_sheet.num_tracks * sizeof(FLAC__StreamMetadata_CueSheet_Track));
213 cuesheet_.data.cue_sheet.tracks[0].offset = 0;
214 cuesheet_.data.cue_sheet.tracks[0].number = 1;
215 memcpy(cuesheet_.data.cue_sheet.tracks[0].isrc, "ACBDE1234567", sizeof(cuesheet_.data.cue_sheet.tracks[0].isrc));
216 cuesheet_.data.cue_sheet.tracks[0].type = 0;
217 cuesheet_.data.cue_sheet.tracks[0].pre_emphasis = 1;
218 cuesheet_.data.cue_sheet.tracks[0].num_indices = 2;
219 cuesheet_.data.cue_sheet.tracks[0].indices = malloc_or_die_(cuesheet_.data.cue_sheet.tracks[0].num_indices * sizeof(FLAC__StreamMetadata_CueSheet_Index));
220 cuesheet_.data.cue_sheet.tracks[0].indices[0].offset = 0;
221 cuesheet_.data.cue_sheet.tracks[0].indices[0].number = 0;
222 cuesheet_.data.cue_sheet.tracks[0].indices[1].offset = 123 * 588;
223 cuesheet_.data.cue_sheet.tracks[0].indices[1].number = 1;
224 cuesheet_.data.cue_sheet.tracks[1].offset = 1234 * 588;
225 cuesheet_.data.cue_sheet.tracks[1].number = 2;
226 memcpy(cuesheet_.data.cue_sheet.tracks[1].isrc, "ACBDE7654321", sizeof(cuesheet_.data.cue_sheet.tracks[1].isrc));
227 cuesheet_.data.cue_sheet.tracks[1].type = 1;
228 cuesheet_.data.cue_sheet.tracks[1].pre_emphasis = 0;
229 cuesheet_.data.cue_sheet.tracks[1].num_indices = 1;
230 cuesheet_.data.cue_sheet.tracks[1].indices = malloc_or_die_(cuesheet_.data.cue_sheet.tracks[1].num_indices * sizeof(FLAC__StreamMetadata_CueSheet_Index));
231 cuesheet_.data.cue_sheet.tracks[1].indices[0].offset = 0;
232 cuesheet_.data.cue_sheet.tracks[1].indices[0].number = 1;
233 cuesheet_.data.cue_sheet.tracks[2].offset = 12345 * 588;
234 cuesheet_.data.cue_sheet.tracks[2].number = 170;
235 cuesheet_.data.cue_sheet.tracks[2].num_indices = 0;
238 static void free_metadata_blocks_()
240 free(seektable_.data.seek_table.points);
241 free(application1_.data.application.data);
242 free(vorbiscomment_.data.vorbis_comment.vendor_string.entry);
243 free(vorbiscomment_.data.vorbis_comment.comments[0].entry);
244 free(vorbiscomment_.data.vorbis_comment.comments);
245 free(cuesheet_.data.cue_sheet.tracks[0].indices);
246 free(cuesheet_.data.cue_sheet.tracks[1].indices);
247 free(cuesheet_.data.cue_sheet.tracks);
250 static FLAC__StreamEncoderWriteStatus stream_encoder_write_callback_(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data)
252 (void)encoder, (void)buffer, (void)bytes, (void)samples, (void)current_frame, (void)client_data;
253 return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
256 static void stream_encoder_metadata_callback_(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetadata *metadata, void *client_data)
258 (void)encoder, (void)metadata, (void)client_data;
261 static FLAC__bool test_stream_encoder()
263 FLAC__StreamEncoder *encoder;
264 FLAC__StreamEncoderState state;
265 FLAC__StreamDecoderState dstate;
266 FLAC__int32 samples[1024];
267 FLAC__int32 *samples_array[1] = { samples };
270 printf("\n+++ libFLAC unit test: FLAC__StreamEncoder\n\n");
272 printf("testing FLAC__stream_encoder_new()... ");
273 encoder = FLAC__stream_encoder_new();
275 printf("FAILED, returned NULL\n");
280 printf("testing FLAC__stream_encoder_set_verify()... ");
281 if(!FLAC__stream_encoder_set_verify(encoder, true))
282 return die_s_("returned false", encoder);
285 printf("testing FLAC__stream_encoder_set_streamable_subset()... ");
286 if(!FLAC__stream_encoder_set_streamable_subset(encoder, true))
287 return die_s_("returned false", encoder);
290 printf("testing FLAC__stream_encoder_set_do_mid_side_stereo()... ");
291 if(!FLAC__stream_encoder_set_do_mid_side_stereo(encoder, false))
292 return die_s_("returned false", encoder);
295 printf("testing FLAC__stream_encoder_set_loose_mid_side_stereo()... ");
296 if(!FLAC__stream_encoder_set_loose_mid_side_stereo(encoder, false))
297 return die_s_("returned false", encoder);
300 printf("testing FLAC__stream_encoder_set_channels()... ");
301 if(!FLAC__stream_encoder_set_channels(encoder, streaminfo_.data.stream_info.channels))
302 return die_s_("returned false", encoder);
305 printf("testing FLAC__stream_encoder_set_bits_per_sample()... ");
306 if(!FLAC__stream_encoder_set_bits_per_sample(encoder, streaminfo_.data.stream_info.bits_per_sample))
307 return die_s_("returned false", encoder);
310 printf("testing FLAC__stream_encoder_set_sample_rate()... ");
311 if(!FLAC__stream_encoder_set_sample_rate(encoder, streaminfo_.data.stream_info.sample_rate))
312 return die_s_("returned false", encoder);
315 printf("testing FLAC__stream_encoder_set_blocksize()... ");
316 if(!FLAC__stream_encoder_set_blocksize(encoder, streaminfo_.data.stream_info.min_blocksize))
317 return die_s_("returned false", encoder);
320 printf("testing FLAC__stream_encoder_set_max_lpc_order()... ");
321 if(!FLAC__stream_encoder_set_max_lpc_order(encoder, 0))
322 return die_s_("returned false", encoder);
325 printf("testing FLAC__stream_encoder_set_qlp_coeff_precision()... ");
326 if(!FLAC__stream_encoder_set_qlp_coeff_precision(encoder, 0))
327 return die_s_("returned false", encoder);
330 printf("testing FLAC__stream_encoder_set_do_qlp_coeff_prec_search()... ");
331 if(!FLAC__stream_encoder_set_do_qlp_coeff_prec_search(encoder, false))
332 return die_s_("returned false", encoder);
335 printf("testing FLAC__stream_encoder_set_do_escape_coding()... ");
336 if(!FLAC__stream_encoder_set_do_escape_coding(encoder, false))
337 return die_s_("returned false", encoder);
340 printf("testing FLAC__stream_encoder_set_do_exhaustive_model_search()... ");
341 if(!FLAC__stream_encoder_set_do_exhaustive_model_search(encoder, false))
342 return die_s_("returned false", encoder);
345 printf("testing FLAC__stream_encoder_set_min_residual_partition_order()... ");
346 if(!FLAC__stream_encoder_set_min_residual_partition_order(encoder, 0))
347 return die_s_("returned false", encoder);
350 printf("testing FLAC__stream_encoder_set_max_residual_partition_order()... ");
351 if(!FLAC__stream_encoder_set_max_residual_partition_order(encoder, 0))
352 return die_s_("returned false", encoder);
355 printf("testing FLAC__stream_encoder_set_rice_parameter_search_dist()... ");
356 if(!FLAC__stream_encoder_set_rice_parameter_search_dist(encoder, 0))
357 return die_s_("returned false", encoder);
360 printf("testing FLAC__stream_encoder_set_total_samples_estimate()... ");
361 if(!FLAC__stream_encoder_set_total_samples_estimate(encoder, streaminfo_.data.stream_info.total_samples))
362 return die_s_("returned false", encoder);
365 printf("testing FLAC__stream_encoder_set_metadata()... ");
366 if(!FLAC__stream_encoder_set_metadata(encoder, metadata_sequence_, num_metadata_))
367 return die_s_("returned false", encoder);
370 printf("testing FLAC__stream_encoder_set_write_callback()... ");
371 if(!FLAC__stream_encoder_set_write_callback(encoder, stream_encoder_write_callback_))
372 return die_s_("returned false", encoder);
375 printf("testing FLAC__stream_encoder_set_metadata_callback()... ");
376 if(!FLAC__stream_encoder_set_metadata_callback(encoder, stream_encoder_metadata_callback_))
377 return die_s_("returned false", encoder);
380 printf("testing FLAC__stream_encoder_set_client_data()... ");
381 if(!FLAC__stream_encoder_set_client_data(encoder, 0))
382 return die_s_("returned false", encoder);
385 printf("testing FLAC__stream_encoder_init()... ");
386 if(FLAC__stream_encoder_init(encoder) != FLAC__STREAM_ENCODER_OK)
387 return die_s_(0, encoder);
390 printf("testing FLAC__stream_encoder_get_state()... ");
391 state = FLAC__stream_encoder_get_state(encoder);
392 printf("returned state = %u (%s)... OK\n", (unsigned)state, FLAC__StreamEncoderStateString[state]);
394 printf("testing FLAC__stream_encoder_get_verify_decoder_state()... ");
395 dstate = FLAC__stream_encoder_get_verify_decoder_state(encoder);
396 printf("returned state = %u (%s)... OK\n", (unsigned)dstate, FLAC__StreamDecoderStateString[dstate]);
399 FLAC__uint64 absolute_sample;
400 unsigned frame_number;
403 FLAC__int32 expected;
406 printf("testing FLAC__stream_encoder_get_verify_decoder_error_stats()... ");
407 FLAC__stream_encoder_get_verify_decoder_error_stats(encoder, &absolute_sample, &frame_number, &channel, &sample, &expected, &got);
411 printf("testing FLAC__stream_encoder_get_verify()... ");
412 if(FLAC__stream_encoder_get_verify(encoder) != true) {
413 printf("FAILED, expected true, got false\n");
418 printf("testing FLAC__stream_encoder_get_streamable_subset()... ");
419 if(FLAC__stream_encoder_get_streamable_subset(encoder) != true) {
420 printf("FAILED, expected true, got false\n");
425 printf("testing FLAC__stream_encoder_get_do_mid_side_stereo()... ");
426 if(FLAC__stream_encoder_get_do_mid_side_stereo(encoder) != false) {
427 printf("FAILED, expected false, got true\n");
432 printf("testing FLAC__stream_encoder_get_loose_mid_side_stereo()... ");
433 if(FLAC__stream_encoder_get_loose_mid_side_stereo(encoder) != false) {
434 printf("FAILED, expected false, got true\n");
439 printf("testing FLAC__stream_encoder_get_channels()... ");
440 if(FLAC__stream_encoder_get_channels(encoder) != streaminfo_.data.stream_info.channels) {
441 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.channels, FLAC__stream_encoder_get_channels(encoder));
446 printf("testing FLAC__stream_encoder_get_bits_per_sample()... ");
447 if(FLAC__stream_encoder_get_bits_per_sample(encoder) != streaminfo_.data.stream_info.bits_per_sample) {
448 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.bits_per_sample, FLAC__stream_encoder_get_bits_per_sample(encoder));
453 printf("testing FLAC__stream_encoder_get_sample_rate()... ");
454 if(FLAC__stream_encoder_get_sample_rate(encoder) != streaminfo_.data.stream_info.sample_rate) {
455 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.sample_rate, FLAC__stream_encoder_get_sample_rate(encoder));
460 printf("testing FLAC__stream_encoder_get_blocksize()... ");
461 if(FLAC__stream_encoder_get_blocksize(encoder) != streaminfo_.data.stream_info.min_blocksize) {
462 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.min_blocksize, FLAC__stream_encoder_get_blocksize(encoder));
467 printf("testing FLAC__stream_encoder_get_max_lpc_order()... ");
468 if(FLAC__stream_encoder_get_max_lpc_order(encoder) != 0) {
469 printf("FAILED, expected %u, got %u\n", 0, FLAC__stream_encoder_get_max_lpc_order(encoder));
474 printf("testing FLAC__stream_encoder_get_qlp_coeff_precision()... ");
475 (void)FLAC__stream_encoder_get_qlp_coeff_precision(encoder);
476 /* we asked the encoder to auto select this so we accept anything */
479 printf("testing FLAC__stream_encoder_get_do_qlp_coeff_prec_search()... ");
480 if(FLAC__stream_encoder_get_do_qlp_coeff_prec_search(encoder) != false) {
481 printf("FAILED, expected false, got true\n");
486 printf("testing FLAC__stream_encoder_get_do_escape_coding()... ");
487 if(FLAC__stream_encoder_get_do_escape_coding(encoder) != false) {
488 printf("FAILED, expected false, got true\n");
493 printf("testing FLAC__stream_encoder_get_do_exhaustive_model_search()... ");
494 if(FLAC__stream_encoder_get_do_exhaustive_model_search(encoder) != false) {
495 printf("FAILED, expected false, got true\n");
500 printf("testing FLAC__stream_encoder_get_min_residual_partition_order()... ");
501 if(FLAC__stream_encoder_get_min_residual_partition_order(encoder) != 0) {
502 printf("FAILED, expected %u, got %u\n", 0, FLAC__stream_encoder_get_min_residual_partition_order(encoder));
507 printf("testing FLAC__stream_encoder_get_max_residual_partition_order()... ");
508 if(FLAC__stream_encoder_get_max_residual_partition_order(encoder) != 0) {
509 printf("FAILED, expected %u, got %u\n", 0, FLAC__stream_encoder_get_max_residual_partition_order(encoder));
514 printf("testing FLAC__stream_encoder_get_rice_parameter_search_dist()... ");
515 if(FLAC__stream_encoder_get_rice_parameter_search_dist(encoder) != 0) {
516 printf("FAILED, expected %u, got %u\n", 0, FLAC__stream_encoder_get_rice_parameter_search_dist(encoder));
521 printf("testing FLAC__stream_encoder_get_total_samples_estimate()... ");
522 if(FLAC__stream_encoder_get_total_samples_estimate(encoder) != streaminfo_.data.stream_info.total_samples) {
523 printf("FAILED, expected %llu, got %llu\n", streaminfo_.data.stream_info.total_samples, FLAC__stream_encoder_get_total_samples_estimate(encoder));
528 /* init the dummy sample buffer */
529 for(i = 0; i < sizeof(samples) / sizeof(FLAC__int32); i++)
532 printf("testing FLAC__stream_encoder_process()... ");
533 if(!FLAC__stream_encoder_process(encoder, (const FLAC__int32 * const *)samples_array, sizeof(samples) / sizeof(FLAC__int32)))
534 return die_s_("returned false", encoder);
537 printf("testing FLAC__stream_encoder_process_interleaved()... ");
538 if(!FLAC__stream_encoder_process_interleaved(encoder, samples, sizeof(samples) / sizeof(FLAC__int32)))
539 return die_s_("returned false", encoder);
542 printf("testing FLAC__stream_encoder_finish()... ");
543 FLAC__stream_encoder_finish(encoder);
546 printf("testing FLAC__stream_encoder_delete()... ");
547 FLAC__stream_encoder_delete(encoder);
550 printf("\nPASSED!\n");
555 FLAC__SeekableStreamEncoderSeekStatus seekable_stream_encoder_seek_callback_(const FLAC__SeekableStreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data)
557 (void)encoder, (void)absolute_byte_offset, (void)client_data;
558 return FLAC__SEEKABLE_STREAM_ENCODER_SEEK_STATUS_OK;
561 FLAC__StreamEncoderWriteStatus seekable_stream_encoder_write_callback_(const FLAC__SeekableStreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data)
563 (void)encoder, (void)buffer, (void)bytes, (void)samples, (void)current_frame, (void)client_data;
564 return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
567 static FLAC__bool test_seekable_stream_encoder()
569 FLAC__SeekableStreamEncoder *encoder;
570 FLAC__SeekableStreamEncoderState state;
571 FLAC__StreamEncoderState state_;
572 FLAC__StreamDecoderState dstate;
573 FLAC__int32 samples[1024];
574 FLAC__int32 *samples_array[1] = { samples };
577 printf("\n+++ libFLAC unit test: FLAC__SeekableStreamEncoder\n\n");
579 printf("testing FLAC__seekable_stream_encoder_new()... ");
580 encoder = FLAC__seekable_stream_encoder_new();
582 printf("FAILED, returned NULL\n");
587 printf("testing FLAC__seekable_stream_encoder_set_verify()... ");
588 if(!FLAC__seekable_stream_encoder_set_verify(encoder, true))
589 return die_ss_("returned false", encoder);
592 printf("testing FLAC__seekable_stream_encoder_set_streamable_subset()... ");
593 if(!FLAC__seekable_stream_encoder_set_streamable_subset(encoder, true))
594 return die_ss_("returned false", encoder);
597 printf("testing FLAC__seekable_stream_encoder_set_do_mid_side_stereo()... ");
598 if(!FLAC__seekable_stream_encoder_set_do_mid_side_stereo(encoder, false))
599 return die_ss_("returned false", encoder);
602 printf("testing FLAC__seekable_stream_encoder_set_loose_mid_side_stereo()... ");
603 if(!FLAC__seekable_stream_encoder_set_loose_mid_side_stereo(encoder, false))
604 return die_ss_("returned false", encoder);
607 printf("testing FLAC__seekable_stream_encoder_set_channels()... ");
608 if(!FLAC__seekable_stream_encoder_set_channels(encoder, streaminfo_.data.stream_info.channels))
609 return die_ss_("returned false", encoder);
612 printf("testing FLAC__seekable_stream_encoder_set_bits_per_sample()... ");
613 if(!FLAC__seekable_stream_encoder_set_bits_per_sample(encoder, streaminfo_.data.stream_info.bits_per_sample))
614 return die_ss_("returned false", encoder);
617 printf("testing FLAC__seekable_stream_encoder_set_sample_rate()... ");
618 if(!FLAC__seekable_stream_encoder_set_sample_rate(encoder, streaminfo_.data.stream_info.sample_rate))
619 return die_ss_("returned false", encoder);
622 printf("testing FLAC__seekable_stream_encoder_set_blocksize()... ");
623 if(!FLAC__seekable_stream_encoder_set_blocksize(encoder, streaminfo_.data.stream_info.min_blocksize))
624 return die_ss_("returned false", encoder);
627 printf("testing FLAC__seekable_stream_encoder_set_max_lpc_order()... ");
628 if(!FLAC__seekable_stream_encoder_set_max_lpc_order(encoder, 0))
629 return die_ss_("returned false", encoder);
632 printf("testing FLAC__seekable_stream_encoder_set_qlp_coeff_precision()... ");
633 if(!FLAC__seekable_stream_encoder_set_qlp_coeff_precision(encoder, 0))
634 return die_ss_("returned false", encoder);
637 printf("testing FLAC__seekable_stream_encoder_set_do_qlp_coeff_prec_search()... ");
638 if(!FLAC__seekable_stream_encoder_set_do_qlp_coeff_prec_search(encoder, false))
639 return die_ss_("returned false", encoder);
642 printf("testing FLAC__seekable_stream_encoder_set_do_escape_coding()... ");
643 if(!FLAC__seekable_stream_encoder_set_do_escape_coding(encoder, false))
644 return die_ss_("returned false", encoder);
647 printf("testing FLAC__seekable_stream_encoder_set_do_exhaustive_model_search()... ");
648 if(!FLAC__seekable_stream_encoder_set_do_exhaustive_model_search(encoder, false))
649 return die_ss_("returned false", encoder);
652 printf("testing FLAC__seekable_stream_encoder_set_min_residual_partition_order()... ");
653 if(!FLAC__seekable_stream_encoder_set_min_residual_partition_order(encoder, 0))
654 return die_ss_("returned false", encoder);
657 printf("testing FLAC__seekable_stream_encoder_set_max_residual_partition_order()... ");
658 if(!FLAC__seekable_stream_encoder_set_max_residual_partition_order(encoder, 0))
659 return die_ss_("returned false", encoder);
662 printf("testing FLAC__seekable_stream_encoder_set_rice_parameter_search_dist()... ");
663 if(!FLAC__seekable_stream_encoder_set_rice_parameter_search_dist(encoder, 0))
664 return die_ss_("returned false", encoder);
667 printf("testing FLAC__seekable_stream_encoder_set_total_samples_estimate()... ");
668 if(!FLAC__seekable_stream_encoder_set_total_samples_estimate(encoder, streaminfo_.data.stream_info.total_samples))
669 return die_ss_("returned false", encoder);
672 printf("testing FLAC__seekable_stream_encoder_set_metadata()... ");
673 if(!FLAC__seekable_stream_encoder_set_metadata(encoder, metadata_sequence_, num_metadata_))
674 return die_ss_("returned false", encoder);
677 printf("testing FLAC__seekable_stream_encoder_set_seek_callback()... ");
678 if(!FLAC__seekable_stream_encoder_set_seek_callback(encoder, seekable_stream_encoder_seek_callback_))
679 return die_ss_("returned false", encoder);
682 printf("testing FLAC__seekable_stream_encoder_set_write_callback()... ");
683 if(!FLAC__seekable_stream_encoder_set_write_callback(encoder, seekable_stream_encoder_write_callback_))
684 return die_ss_("returned false", encoder);
687 printf("testing FLAC__seekable_stream_encoder_set_client_data()... ");
688 if(!FLAC__seekable_stream_encoder_set_client_data(encoder, 0))
689 return die_ss_("returned false", encoder);
692 printf("testing FLAC__seekable_stream_encoder_init()... ");
693 if(FLAC__seekable_stream_encoder_init(encoder) != FLAC__SEEKABLE_STREAM_ENCODER_OK)
694 return die_ss_(0, encoder);
697 printf("testing FLAC__seekable_stream_encoder_get_state()... ");
698 state = FLAC__seekable_stream_encoder_get_state(encoder);
699 printf("returned state = %u (%s)... OK\n", (unsigned)state, FLAC__SeekableStreamEncoderStateString[state]);
701 printf("testing FLAC__seekable_stream_encoder_get_stream_encoder_state()... ");
702 state_ = FLAC__seekable_stream_encoder_get_stream_encoder_state(encoder);
703 printf("returned state = %u (%s)... OK\n", (unsigned)state_, FLAC__StreamEncoderStateString[state_]);
705 printf("testing FLAC__seekable_stream_encoder_get_verify_decoder_state()... ");
706 dstate = FLAC__seekable_stream_encoder_get_verify_decoder_state(encoder);
707 printf("returned state = %u (%s)... OK\n", (unsigned)dstate, FLAC__StreamDecoderStateString[dstate]);
710 FLAC__uint64 absolute_sample;
711 unsigned frame_number;
714 FLAC__int32 expected;
717 printf("testing FLAC__seekable_stream_encoder_get_verify_decoder_error_stats()... ");
718 FLAC__seekable_stream_encoder_get_verify_decoder_error_stats(encoder, &absolute_sample, &frame_number, &channel, &sample, &expected, &got);
722 printf("testing FLAC__seekable_stream_encoder_get_verify()... ");
723 if(FLAC__seekable_stream_encoder_get_verify(encoder) != true) {
724 printf("FAILED, expected true, got false\n");
729 printf("testing FLAC__seekable_stream_encoder_get_streamable_subset()... ");
730 if(FLAC__seekable_stream_encoder_get_streamable_subset(encoder) != true) {
731 printf("FAILED, expected true, got false\n");
736 printf("testing FLAC__seekable_stream_encoder_get_do_mid_side_stereo()... ");
737 if(FLAC__seekable_stream_encoder_get_do_mid_side_stereo(encoder) != false) {
738 printf("FAILED, expected false, got true\n");
743 printf("testing FLAC__seekable_stream_encoder_get_loose_mid_side_stereo()... ");
744 if(FLAC__seekable_stream_encoder_get_loose_mid_side_stereo(encoder) != false) {
745 printf("FAILED, expected false, got true\n");
750 printf("testing FLAC__seekable_stream_encoder_get_channels()... ");
751 if(FLAC__seekable_stream_encoder_get_channels(encoder) != streaminfo_.data.stream_info.channels) {
752 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.channels, FLAC__seekable_stream_encoder_get_channels(encoder));
757 printf("testing FLAC__seekable_stream_encoder_get_bits_per_sample()... ");
758 if(FLAC__seekable_stream_encoder_get_bits_per_sample(encoder) != streaminfo_.data.stream_info.bits_per_sample) {
759 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.bits_per_sample, FLAC__seekable_stream_encoder_get_bits_per_sample(encoder));
764 printf("testing FLAC__seekable_stream_encoder_get_sample_rate()... ");
765 if(FLAC__seekable_stream_encoder_get_sample_rate(encoder) != streaminfo_.data.stream_info.sample_rate) {
766 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.sample_rate, FLAC__seekable_stream_encoder_get_sample_rate(encoder));
771 printf("testing FLAC__seekable_stream_encoder_get_blocksize()... ");
772 if(FLAC__seekable_stream_encoder_get_blocksize(encoder) != streaminfo_.data.stream_info.min_blocksize) {
773 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.min_blocksize, FLAC__seekable_stream_encoder_get_blocksize(encoder));
778 printf("testing FLAC__seekable_stream_encoder_get_max_lpc_order()... ");
779 if(FLAC__seekable_stream_encoder_get_max_lpc_order(encoder) != 0) {
780 printf("FAILED, expected %u, got %u\n", 0, FLAC__seekable_stream_encoder_get_max_lpc_order(encoder));
785 printf("testing FLAC__seekable_stream_encoder_get_qlp_coeff_precision()... ");
786 (void)FLAC__seekable_stream_encoder_get_qlp_coeff_precision(encoder);
787 /* we asked the encoder to auto select this so we accept anything */
790 printf("testing FLAC__seekable_stream_encoder_get_do_qlp_coeff_prec_search()... ");
791 if(FLAC__seekable_stream_encoder_get_do_qlp_coeff_prec_search(encoder) != false) {
792 printf("FAILED, expected false, got true\n");
797 printf("testing FLAC__seekable_stream_encoder_get_do_escape_coding()... ");
798 if(FLAC__seekable_stream_encoder_get_do_escape_coding(encoder) != false) {
799 printf("FAILED, expected false, got true\n");
804 printf("testing FLAC__seekable_stream_encoder_get_do_exhaustive_model_search()... ");
805 if(FLAC__seekable_stream_encoder_get_do_exhaustive_model_search(encoder) != false) {
806 printf("FAILED, expected false, got true\n");
811 printf("testing FLAC__seekable_stream_encoder_get_min_residual_partition_order()... ");
812 if(FLAC__seekable_stream_encoder_get_min_residual_partition_order(encoder) != 0) {
813 printf("FAILED, expected %u, got %u\n", 0, FLAC__seekable_stream_encoder_get_min_residual_partition_order(encoder));
818 printf("testing FLAC__seekable_stream_encoder_get_max_residual_partition_order()... ");
819 if(FLAC__seekable_stream_encoder_get_max_residual_partition_order(encoder) != 0) {
820 printf("FAILED, expected %u, got %u\n", 0, FLAC__seekable_stream_encoder_get_max_residual_partition_order(encoder));
825 printf("testing FLAC__seekable_stream_encoder_get_rice_parameter_search_dist()... ");
826 if(FLAC__seekable_stream_encoder_get_rice_parameter_search_dist(encoder) != 0) {
827 printf("FAILED, expected %u, got %u\n", 0, FLAC__seekable_stream_encoder_get_rice_parameter_search_dist(encoder));
832 printf("testing FLAC__seekable_stream_encoder_get_total_samples_estimate()... ");
833 if(FLAC__seekable_stream_encoder_get_total_samples_estimate(encoder) != streaminfo_.data.stream_info.total_samples) {
834 printf("FAILED, expected %llu, got %llu\n", streaminfo_.data.stream_info.total_samples, FLAC__seekable_stream_encoder_get_total_samples_estimate(encoder));
839 /* init the dummy sample buffer */
840 for(i = 0; i < sizeof(samples) / sizeof(FLAC__int32); i++)
843 printf("testing FLAC__seekable_stream_encoder_process()... ");
844 if(!FLAC__seekable_stream_encoder_process(encoder, (const FLAC__int32 * const *)samples_array, sizeof(samples) / sizeof(FLAC__int32)))
845 return die_ss_("returned false", encoder);
848 printf("testing FLAC__seekable_stream_encoder_process_interleaved()... ");
849 if(!FLAC__seekable_stream_encoder_process_interleaved(encoder, samples, sizeof(samples) / sizeof(FLAC__int32)))
850 return die_ss_("returned false", encoder);
853 printf("testing FLAC__seekable_stream_encoder_finish()... ");
854 FLAC__seekable_stream_encoder_finish(encoder);
857 printf("testing FLAC__seekable_stream_encoder_delete()... ");
858 FLAC__seekable_stream_encoder_delete(encoder);
861 printf("\nPASSED!\n");
866 static void file_encoder_progress_callback_(const FLAC__FileEncoder *encoder, FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate, void *client_data)
868 (void)encoder, (void)bytes_written, (void)samples_written, (void)frames_written, (void)total_frames_estimate, (void)client_data;
871 static FLAC__bool test_file_encoder()
873 FLAC__FileEncoder *encoder;
874 FLAC__FileEncoderState state;
875 FLAC__SeekableStreamEncoderState state_;
876 FLAC__StreamEncoderState state__;
877 FLAC__StreamDecoderState dstate;
878 FLAC__int32 samples[1024];
879 FLAC__int32 *samples_array[1] = { samples };
882 printf("\n+++ libFLAC unit test: FLAC__FileEncoder\n\n");
884 printf("testing FLAC__file_encoder_new()... ");
885 encoder = FLAC__file_encoder_new();
887 printf("FAILED, returned NULL\n");
892 printf("testing FLAC__file_encoder_set_verify()... ");
893 if(!FLAC__file_encoder_set_verify(encoder, true))
894 return die_f_("returned false", encoder);
897 printf("testing FLAC__file_encoder_set_streamable_subset()... ");
898 if(!FLAC__file_encoder_set_streamable_subset(encoder, true))
899 return die_f_("returned false", encoder);
902 printf("testing FLAC__file_encoder_set_do_mid_side_stereo()... ");
903 if(!FLAC__file_encoder_set_do_mid_side_stereo(encoder, false))
904 return die_f_("returned false", encoder);
907 printf("testing FLAC__file_encoder_set_loose_mid_side_stereo()... ");
908 if(!FLAC__file_encoder_set_loose_mid_side_stereo(encoder, false))
909 return die_f_("returned false", encoder);
912 printf("testing FLAC__file_encoder_set_channels()... ");
913 if(!FLAC__file_encoder_set_channels(encoder, streaminfo_.data.stream_info.channels))
914 return die_f_("returned false", encoder);
917 printf("testing FLAC__file_encoder_set_bits_per_sample()... ");
918 if(!FLAC__file_encoder_set_bits_per_sample(encoder, streaminfo_.data.stream_info.bits_per_sample))
919 return die_f_("returned false", encoder);
922 printf("testing FLAC__file_encoder_set_sample_rate()... ");
923 if(!FLAC__file_encoder_set_sample_rate(encoder, streaminfo_.data.stream_info.sample_rate))
924 return die_f_("returned false", encoder);
927 printf("testing FLAC__file_encoder_set_blocksize()... ");
928 if(!FLAC__file_encoder_set_blocksize(encoder, streaminfo_.data.stream_info.min_blocksize))
929 return die_f_("returned false", encoder);
932 printf("testing FLAC__file_encoder_set_max_lpc_order()... ");
933 if(!FLAC__file_encoder_set_max_lpc_order(encoder, 0))
934 return die_f_("returned false", encoder);
937 printf("testing FLAC__file_encoder_set_qlp_coeff_precision()... ");
938 if(!FLAC__file_encoder_set_qlp_coeff_precision(encoder, 0))
939 return die_f_("returned false", encoder);
942 printf("testing FLAC__file_encoder_set_do_qlp_coeff_prec_search()... ");
943 if(!FLAC__file_encoder_set_do_qlp_coeff_prec_search(encoder, false))
944 return die_f_("returned false", encoder);
947 printf("testing FLAC__file_encoder_set_do_escape_coding()... ");
948 if(!FLAC__file_encoder_set_do_escape_coding(encoder, false))
949 return die_f_("returned false", encoder);
952 printf("testing FLAC__file_encoder_set_do_exhaustive_model_search()... ");
953 if(!FLAC__file_encoder_set_do_exhaustive_model_search(encoder, false))
954 return die_f_("returned false", encoder);
957 printf("testing FLAC__file_encoder_set_min_residual_partition_order()... ");
958 if(!FLAC__file_encoder_set_min_residual_partition_order(encoder, 0))
959 return die_f_("returned false", encoder);
962 printf("testing FLAC__file_encoder_set_max_residual_partition_order()... ");
963 if(!FLAC__file_encoder_set_max_residual_partition_order(encoder, 0))
964 return die_f_("returned false", encoder);
967 printf("testing FLAC__file_encoder_set_rice_parameter_search_dist()... ");
968 if(!FLAC__file_encoder_set_rice_parameter_search_dist(encoder, 0))
969 return die_f_("returned false", encoder);
972 printf("testing FLAC__file_encoder_set_total_samples_estimate()... ");
973 if(!FLAC__file_encoder_set_total_samples_estimate(encoder, streaminfo_.data.stream_info.total_samples))
974 return die_f_("returned false", encoder);
977 printf("testing FLAC__file_encoder_set_metadata()... ");
978 if(!FLAC__file_encoder_set_metadata(encoder, metadata_sequence_, num_metadata_))
979 return die_f_("returned false", encoder);
982 printf("testing FLAC__file_encoder_set_filename()... ");
983 if(!FLAC__file_encoder_set_filename(encoder, flacfilename_))
984 return die_f_("returned false", encoder);
987 printf("testing FLAC__file_encoder_set_progress_callback()... ");
988 if(!FLAC__file_encoder_set_progress_callback(encoder, file_encoder_progress_callback_))
989 return die_f_("returned false", encoder);
992 printf("testing FLAC__file_encoder_set_client_data()... ");
993 if(!FLAC__file_encoder_set_client_data(encoder, 0))
994 return die_f_("returned false", encoder);
997 printf("testing FLAC__file_encoder_init()... ");
998 if(FLAC__file_encoder_init(encoder) != FLAC__FILE_ENCODER_OK)
999 return die_f_(0, encoder);
1002 printf("testing FLAC__file_encoder_get_state()... ");
1003 state = FLAC__file_encoder_get_state(encoder);
1004 printf("returned state = %u (%s)... OK\n", (unsigned)state, FLAC__FileEncoderStateString[state]);
1006 printf("testing FLAC__file_encoder_get_seekable_stream_encoder_state()... ");
1007 state_ = FLAC__file_encoder_get_seekable_stream_encoder_state(encoder);
1008 printf("returned state = %u (%s)... OK\n", (unsigned)state_, FLAC__SeekableStreamEncoderStateString[state_]);
1010 printf("testing FLAC__file_encoder_get_stream_encoder_state()... ");
1011 state__ = FLAC__file_encoder_get_stream_encoder_state(encoder);
1012 printf("returned state = %u (%s)... OK\n", (unsigned)state__, FLAC__StreamEncoderStateString[state__]);
1014 printf("testing FLAC__file_encoder_get_verify_decoder_state()... ");
1015 dstate = FLAC__file_encoder_get_verify_decoder_state(encoder);
1016 printf("returned state = %u (%s)... OK\n", (unsigned)dstate, FLAC__StreamDecoderStateString[dstate]);
1019 FLAC__uint64 absolute_sample;
1020 unsigned frame_number;
1023 FLAC__int32 expected;
1026 printf("testing FLAC__file_encoder_get_verify_decoder_error_stats()... ");
1027 FLAC__file_encoder_get_verify_decoder_error_stats(encoder, &absolute_sample, &frame_number, &channel, &sample, &expected, &got);
1031 printf("testing FLAC__file_encoder_get_verify()... ");
1032 if(FLAC__file_encoder_get_verify(encoder) != true) {
1033 printf("FAILED, expected true, got false\n");
1038 printf("testing FLAC__file_encoder_get_streamable_subset()... ");
1039 if(FLAC__file_encoder_get_streamable_subset(encoder) != true) {
1040 printf("FAILED, expected true, got false\n");
1045 printf("testing FLAC__file_encoder_get_do_mid_side_stereo()... ");
1046 if(FLAC__file_encoder_get_do_mid_side_stereo(encoder) != false) {
1047 printf("FAILED, expected false, got true\n");
1052 printf("testing FLAC__file_encoder_get_loose_mid_side_stereo()... ");
1053 if(FLAC__file_encoder_get_loose_mid_side_stereo(encoder) != false) {
1054 printf("FAILED, expected false, got true\n");
1059 printf("testing FLAC__file_encoder_get_channels()... ");
1060 if(FLAC__file_encoder_get_channels(encoder) != streaminfo_.data.stream_info.channels) {
1061 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.channels, FLAC__file_encoder_get_channels(encoder));
1066 printf("testing FLAC__file_encoder_get_bits_per_sample()... ");
1067 if(FLAC__file_encoder_get_bits_per_sample(encoder) != streaminfo_.data.stream_info.bits_per_sample) {
1068 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.bits_per_sample, FLAC__file_encoder_get_bits_per_sample(encoder));
1073 printf("testing FLAC__file_encoder_get_sample_rate()... ");
1074 if(FLAC__file_encoder_get_sample_rate(encoder) != streaminfo_.data.stream_info.sample_rate) {
1075 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.sample_rate, FLAC__file_encoder_get_sample_rate(encoder));
1080 printf("testing FLAC__file_encoder_get_blocksize()... ");
1081 if(FLAC__file_encoder_get_blocksize(encoder) != streaminfo_.data.stream_info.min_blocksize) {
1082 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.min_blocksize, FLAC__file_encoder_get_blocksize(encoder));
1087 printf("testing FLAC__file_encoder_get_max_lpc_order()... ");
1088 if(FLAC__file_encoder_get_max_lpc_order(encoder) != 0) {
1089 printf("FAILED, expected %u, got %u\n", 0, FLAC__file_encoder_get_max_lpc_order(encoder));
1094 printf("testing FLAC__file_encoder_get_qlp_coeff_precision()... ");
1095 (void)FLAC__file_encoder_get_qlp_coeff_precision(encoder);
1096 /* we asked the encoder to auto select this so we accept anything */
1099 printf("testing FLAC__file_encoder_get_do_qlp_coeff_prec_search()... ");
1100 if(FLAC__file_encoder_get_do_qlp_coeff_prec_search(encoder) != false) {
1101 printf("FAILED, expected false, got true\n");
1106 printf("testing FLAC__file_encoder_get_do_escape_coding()... ");
1107 if(FLAC__file_encoder_get_do_escape_coding(encoder) != false) {
1108 printf("FAILED, expected false, got true\n");
1113 printf("testing FLAC__file_encoder_get_do_exhaustive_model_search()... ");
1114 if(FLAC__file_encoder_get_do_exhaustive_model_search(encoder) != false) {
1115 printf("FAILED, expected false, got true\n");
1120 printf("testing FLAC__file_encoder_get_min_residual_partition_order()... ");
1121 if(FLAC__file_encoder_get_min_residual_partition_order(encoder) != 0) {
1122 printf("FAILED, expected %u, got %u\n", 0, FLAC__file_encoder_get_min_residual_partition_order(encoder));
1127 printf("testing FLAC__file_encoder_get_max_residual_partition_order()... ");
1128 if(FLAC__file_encoder_get_max_residual_partition_order(encoder) != 0) {
1129 printf("FAILED, expected %u, got %u\n", 0, FLAC__file_encoder_get_max_residual_partition_order(encoder));
1134 printf("testing FLAC__file_encoder_get_rice_parameter_search_dist()... ");
1135 if(FLAC__file_encoder_get_rice_parameter_search_dist(encoder) != 0) {
1136 printf("FAILED, expected %u, got %u\n", 0, FLAC__file_encoder_get_rice_parameter_search_dist(encoder));
1141 printf("testing FLAC__file_encoder_get_total_samples_estimate()... ");
1142 if(FLAC__file_encoder_get_total_samples_estimate(encoder) != streaminfo_.data.stream_info.total_samples) {
1143 printf("FAILED, expected %llu, got %llu\n", streaminfo_.data.stream_info.total_samples, FLAC__file_encoder_get_total_samples_estimate(encoder));
1148 /* init the dummy sample buffer */
1149 for(i = 0; i < sizeof(samples) / sizeof(FLAC__int32); i++)
1152 printf("testing FLAC__file_encoder_process()... ");
1153 if(!FLAC__file_encoder_process(encoder, (const FLAC__int32 * const *)samples_array, sizeof(samples) / sizeof(FLAC__int32)))
1154 return die_f_("returned false", encoder);
1157 printf("testing FLAC__file_encoder_process_interleaved()... ");
1158 if(!FLAC__file_encoder_process_interleaved(encoder, samples, sizeof(samples) / sizeof(FLAC__int32)))
1159 return die_f_("returned false", encoder);
1162 printf("testing FLAC__file_encoder_finish()... ");
1163 FLAC__file_encoder_finish(encoder);
1166 printf("testing FLAC__file_encoder_delete()... ");
1167 FLAC__file_encoder_delete(encoder);
1170 printf("\nPASSED!\n");
1175 FLAC__bool test_encoders()
1177 init_metadata_blocks_();
1179 if(!test_stream_encoder())
1182 if(!test_seekable_stream_encoder())
1185 if(!test_file_encoder())
1188 (void) grabbag__file_remove_file(flacfilename_);
1189 free_metadata_blocks_();