1 /* test_libFLAC - Unit tester for libFLAC
2 * Copyright (C) 2002,2003 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 "metadata_utils.h"
22 #include "FLAC/assert.h"
23 #include "FLAC/file_encoder.h"
24 #include "FLAC/seekable_stream_encoder.h"
25 #include "FLAC/stream_encoder.h"
26 #include "share/grabbag.h"
31 static FLAC__StreamMetadata streaminfo_, padding_, seektable_, application1_, application2_, vorbiscomment_, cuesheet_, unknown_;
32 static FLAC__StreamMetadata *metadata_sequence_[] = { &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &unknown_ };
33 static const unsigned num_metadata_ = sizeof(metadata_sequence_) / sizeof(metadata_sequence_[0]);
34 static const char *flacfilename_ = "metadata.flac";
36 static FLAC__bool die_s_(const char *msg, const FLAC__StreamEncoder *encoder)
38 FLAC__StreamEncoderState state = FLAC__stream_encoder_get_state(encoder);
41 printf("FAILED, %s", msg);
45 printf(", state = %u (%s)\n", (unsigned)state, FLAC__StreamEncoderStateString[state]);
46 if(state == FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR) {
47 FLAC__StreamDecoderState dstate = FLAC__stream_encoder_get_verify_decoder_state(encoder);
48 printf(" verify decoder state = %u (%s)\n", (unsigned)dstate, FLAC__StreamDecoderStateString[dstate]);
54 static FLAC__bool die_ss_(const char *msg, const FLAC__SeekableStreamEncoder *encoder)
56 FLAC__SeekableStreamEncoderState state = FLAC__seekable_stream_encoder_get_state(encoder);
59 printf("FAILED, %s", msg);
63 printf(", state = %u (%s)\n", (unsigned)state, FLAC__SeekableStreamEncoderStateString[state]);
64 if(state == FLAC__SEEKABLE_STREAM_ENCODER_STREAM_ENCODER_ERROR) {
65 FLAC__StreamEncoderState state_ = FLAC__seekable_stream_encoder_get_stream_encoder_state(encoder);
66 printf(" stream encoder state = %u (%s)\n", (unsigned)state_, FLAC__StreamEncoderStateString[state_]);
67 if(state_ == FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR) {
68 FLAC__StreamDecoderState dstate = FLAC__seekable_stream_encoder_get_verify_decoder_state(encoder);
69 printf(" verify decoder state = %u (%s)\n", (unsigned)dstate, FLAC__StreamDecoderStateString[dstate]);
76 static FLAC__bool die_f_(const char *msg, const FLAC__FileEncoder *encoder)
78 FLAC__FileEncoderState state = FLAC__file_encoder_get_state(encoder);
81 printf("FAILED, %s", msg);
85 printf(", state = %u (%s)\n", (unsigned)state, FLAC__FileEncoderStateString[state]);
86 if(state == FLAC__FILE_ENCODER_SEEKABLE_STREAM_ENCODER_ERROR) {
87 FLAC__SeekableStreamEncoderState state_ = FLAC__file_encoder_get_seekable_stream_encoder_state(encoder);
88 printf(" seekable stream encoder state = %u (%s)\n", (unsigned)state_, FLAC__SeekableStreamEncoderStateString[state_]);
89 if(state_ == FLAC__SEEKABLE_STREAM_ENCODER_STREAM_ENCODER_ERROR) {
90 FLAC__StreamEncoderState state__ = FLAC__file_encoder_get_stream_encoder_state(encoder);
91 printf(" stream encoder state = %u (%s)\n", (unsigned)state__, FLAC__StreamEncoderStateString[state__]);
92 if(state__ == FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR) {
93 FLAC__StreamDecoderState dstate = FLAC__file_encoder_get_verify_decoder_state(encoder);
94 printf(" verify decoder state = %u (%s)\n", (unsigned)dstate, FLAC__StreamDecoderStateString[dstate]);
102 static void init_metadata_blocks_()
104 mutils__init_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &unknown_);
107 static void free_metadata_blocks_()
109 mutils__free_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &unknown_);
112 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)
114 (void)encoder, (void)buffer, (void)bytes, (void)samples, (void)current_frame, (void)client_data;
115 return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
118 static void stream_encoder_metadata_callback_(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetadata *metadata, void *client_data)
120 (void)encoder, (void)metadata, (void)client_data;
123 static FLAC__bool test_stream_encoder()
125 FLAC__StreamEncoder *encoder;
126 FLAC__StreamEncoderState state;
127 FLAC__StreamDecoderState dstate;
128 FLAC__int32 samples[1024];
129 FLAC__int32 *samples_array[1] = { samples };
132 printf("\n+++ libFLAC unit test: FLAC__StreamEncoder\n\n");
134 printf("testing FLAC__stream_encoder_new()... ");
135 encoder = FLAC__stream_encoder_new();
137 printf("FAILED, returned NULL\n");
142 printf("testing FLAC__stream_encoder_set_verify()... ");
143 if(!FLAC__stream_encoder_set_verify(encoder, true))
144 return die_s_("returned false", encoder);
147 printf("testing FLAC__stream_encoder_set_streamable_subset()... ");
148 if(!FLAC__stream_encoder_set_streamable_subset(encoder, true))
149 return die_s_("returned false", encoder);
152 printf("testing FLAC__stream_encoder_set_do_mid_side_stereo()... ");
153 if(!FLAC__stream_encoder_set_do_mid_side_stereo(encoder, false))
154 return die_s_("returned false", encoder);
157 printf("testing FLAC__stream_encoder_set_loose_mid_side_stereo()... ");
158 if(!FLAC__stream_encoder_set_loose_mid_side_stereo(encoder, false))
159 return die_s_("returned false", encoder);
162 printf("testing FLAC__stream_encoder_set_channels()... ");
163 if(!FLAC__stream_encoder_set_channels(encoder, streaminfo_.data.stream_info.channels))
164 return die_s_("returned false", encoder);
167 printf("testing FLAC__stream_encoder_set_bits_per_sample()... ");
168 if(!FLAC__stream_encoder_set_bits_per_sample(encoder, streaminfo_.data.stream_info.bits_per_sample))
169 return die_s_("returned false", encoder);
172 printf("testing FLAC__stream_encoder_set_sample_rate()... ");
173 if(!FLAC__stream_encoder_set_sample_rate(encoder, streaminfo_.data.stream_info.sample_rate))
174 return die_s_("returned false", encoder);
177 printf("testing FLAC__stream_encoder_set_blocksize()... ");
178 if(!FLAC__stream_encoder_set_blocksize(encoder, streaminfo_.data.stream_info.min_blocksize))
179 return die_s_("returned false", encoder);
182 printf("testing FLAC__stream_encoder_set_max_lpc_order()... ");
183 if(!FLAC__stream_encoder_set_max_lpc_order(encoder, 0))
184 return die_s_("returned false", encoder);
187 printf("testing FLAC__stream_encoder_set_qlp_coeff_precision()... ");
188 if(!FLAC__stream_encoder_set_qlp_coeff_precision(encoder, 0))
189 return die_s_("returned false", encoder);
192 printf("testing FLAC__stream_encoder_set_do_qlp_coeff_prec_search()... ");
193 if(!FLAC__stream_encoder_set_do_qlp_coeff_prec_search(encoder, false))
194 return die_s_("returned false", encoder);
197 printf("testing FLAC__stream_encoder_set_do_escape_coding()... ");
198 if(!FLAC__stream_encoder_set_do_escape_coding(encoder, false))
199 return die_s_("returned false", encoder);
202 printf("testing FLAC__stream_encoder_set_do_exhaustive_model_search()... ");
203 if(!FLAC__stream_encoder_set_do_exhaustive_model_search(encoder, false))
204 return die_s_("returned false", encoder);
207 printf("testing FLAC__stream_encoder_set_min_residual_partition_order()... ");
208 if(!FLAC__stream_encoder_set_min_residual_partition_order(encoder, 0))
209 return die_s_("returned false", encoder);
212 printf("testing FLAC__stream_encoder_set_max_residual_partition_order()... ");
213 if(!FLAC__stream_encoder_set_max_residual_partition_order(encoder, 0))
214 return die_s_("returned false", encoder);
217 printf("testing FLAC__stream_encoder_set_rice_parameter_search_dist()... ");
218 if(!FLAC__stream_encoder_set_rice_parameter_search_dist(encoder, 0))
219 return die_s_("returned false", encoder);
222 printf("testing FLAC__stream_encoder_set_total_samples_estimate()... ");
223 if(!FLAC__stream_encoder_set_total_samples_estimate(encoder, streaminfo_.data.stream_info.total_samples))
224 return die_s_("returned false", encoder);
227 printf("testing FLAC__stream_encoder_set_metadata()... ");
228 if(!FLAC__stream_encoder_set_metadata(encoder, metadata_sequence_, num_metadata_))
229 return die_s_("returned false", encoder);
232 printf("testing FLAC__stream_encoder_set_write_callback()... ");
233 if(!FLAC__stream_encoder_set_write_callback(encoder, stream_encoder_write_callback_))
234 return die_s_("returned false", encoder);
237 printf("testing FLAC__stream_encoder_set_metadata_callback()... ");
238 if(!FLAC__stream_encoder_set_metadata_callback(encoder, stream_encoder_metadata_callback_))
239 return die_s_("returned false", encoder);
242 printf("testing FLAC__stream_encoder_set_client_data()... ");
243 if(!FLAC__stream_encoder_set_client_data(encoder, 0))
244 return die_s_("returned false", encoder);
247 printf("testing FLAC__stream_encoder_init()... ");
248 if(FLAC__stream_encoder_init(encoder) != FLAC__STREAM_ENCODER_OK)
249 return die_s_(0, encoder);
252 printf("testing FLAC__stream_encoder_get_state()... ");
253 state = FLAC__stream_encoder_get_state(encoder);
254 printf("returned state = %u (%s)... OK\n", (unsigned)state, FLAC__StreamEncoderStateString[state]);
256 printf("testing FLAC__stream_encoder_get_verify_decoder_state()... ");
257 dstate = FLAC__stream_encoder_get_verify_decoder_state(encoder);
258 printf("returned state = %u (%s)... OK\n", (unsigned)dstate, FLAC__StreamDecoderStateString[dstate]);
261 FLAC__uint64 absolute_sample;
262 unsigned frame_number;
265 FLAC__int32 expected;
268 printf("testing FLAC__stream_encoder_get_verify_decoder_error_stats()... ");
269 FLAC__stream_encoder_get_verify_decoder_error_stats(encoder, &absolute_sample, &frame_number, &channel, &sample, &expected, &got);
273 printf("testing FLAC__stream_encoder_get_verify()... ");
274 if(FLAC__stream_encoder_get_verify(encoder) != true) {
275 printf("FAILED, expected true, got false\n");
280 printf("testing FLAC__stream_encoder_get_streamable_subset()... ");
281 if(FLAC__stream_encoder_get_streamable_subset(encoder) != true) {
282 printf("FAILED, expected true, got false\n");
287 printf("testing FLAC__stream_encoder_get_do_mid_side_stereo()... ");
288 if(FLAC__stream_encoder_get_do_mid_side_stereo(encoder) != false) {
289 printf("FAILED, expected false, got true\n");
294 printf("testing FLAC__stream_encoder_get_loose_mid_side_stereo()... ");
295 if(FLAC__stream_encoder_get_loose_mid_side_stereo(encoder) != false) {
296 printf("FAILED, expected false, got true\n");
301 printf("testing FLAC__stream_encoder_get_channels()... ");
302 if(FLAC__stream_encoder_get_channels(encoder) != streaminfo_.data.stream_info.channels) {
303 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.channels, FLAC__stream_encoder_get_channels(encoder));
308 printf("testing FLAC__stream_encoder_get_bits_per_sample()... ");
309 if(FLAC__stream_encoder_get_bits_per_sample(encoder) != streaminfo_.data.stream_info.bits_per_sample) {
310 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.bits_per_sample, FLAC__stream_encoder_get_bits_per_sample(encoder));
315 printf("testing FLAC__stream_encoder_get_sample_rate()... ");
316 if(FLAC__stream_encoder_get_sample_rate(encoder) != streaminfo_.data.stream_info.sample_rate) {
317 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.sample_rate, FLAC__stream_encoder_get_sample_rate(encoder));
322 printf("testing FLAC__stream_encoder_get_blocksize()... ");
323 if(FLAC__stream_encoder_get_blocksize(encoder) != streaminfo_.data.stream_info.min_blocksize) {
324 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.min_blocksize, FLAC__stream_encoder_get_blocksize(encoder));
329 printf("testing FLAC__stream_encoder_get_max_lpc_order()... ");
330 if(FLAC__stream_encoder_get_max_lpc_order(encoder) != 0) {
331 printf("FAILED, expected %u, got %u\n", 0, FLAC__stream_encoder_get_max_lpc_order(encoder));
336 printf("testing FLAC__stream_encoder_get_qlp_coeff_precision()... ");
337 (void)FLAC__stream_encoder_get_qlp_coeff_precision(encoder);
338 /* we asked the encoder to auto select this so we accept anything */
341 printf("testing FLAC__stream_encoder_get_do_qlp_coeff_prec_search()... ");
342 if(FLAC__stream_encoder_get_do_qlp_coeff_prec_search(encoder) != false) {
343 printf("FAILED, expected false, got true\n");
348 printf("testing FLAC__stream_encoder_get_do_escape_coding()... ");
349 if(FLAC__stream_encoder_get_do_escape_coding(encoder) != false) {
350 printf("FAILED, expected false, got true\n");
355 printf("testing FLAC__stream_encoder_get_do_exhaustive_model_search()... ");
356 if(FLAC__stream_encoder_get_do_exhaustive_model_search(encoder) != false) {
357 printf("FAILED, expected false, got true\n");
362 printf("testing FLAC__stream_encoder_get_min_residual_partition_order()... ");
363 if(FLAC__stream_encoder_get_min_residual_partition_order(encoder) != 0) {
364 printf("FAILED, expected %u, got %u\n", 0, FLAC__stream_encoder_get_min_residual_partition_order(encoder));
369 printf("testing FLAC__stream_encoder_get_max_residual_partition_order()... ");
370 if(FLAC__stream_encoder_get_max_residual_partition_order(encoder) != 0) {
371 printf("FAILED, expected %u, got %u\n", 0, FLAC__stream_encoder_get_max_residual_partition_order(encoder));
376 printf("testing FLAC__stream_encoder_get_rice_parameter_search_dist()... ");
377 if(FLAC__stream_encoder_get_rice_parameter_search_dist(encoder) != 0) {
378 printf("FAILED, expected %u, got %u\n", 0, FLAC__stream_encoder_get_rice_parameter_search_dist(encoder));
383 printf("testing FLAC__stream_encoder_get_total_samples_estimate()... ");
384 if(FLAC__stream_encoder_get_total_samples_estimate(encoder) != streaminfo_.data.stream_info.total_samples) {
385 printf("FAILED, expected %llu, got %llu\n", streaminfo_.data.stream_info.total_samples, FLAC__stream_encoder_get_total_samples_estimate(encoder));
390 /* init the dummy sample buffer */
391 for(i = 0; i < sizeof(samples) / sizeof(FLAC__int32); i++)
394 printf("testing FLAC__stream_encoder_process()... ");
395 if(!FLAC__stream_encoder_process(encoder, (const FLAC__int32 * const *)samples_array, sizeof(samples) / sizeof(FLAC__int32)))
396 return die_s_("returned false", encoder);
399 printf("testing FLAC__stream_encoder_process_interleaved()... ");
400 if(!FLAC__stream_encoder_process_interleaved(encoder, samples, sizeof(samples) / sizeof(FLAC__int32)))
401 return die_s_("returned false", encoder);
404 printf("testing FLAC__stream_encoder_finish()... ");
405 FLAC__stream_encoder_finish(encoder);
408 printf("testing FLAC__stream_encoder_delete()... ");
409 FLAC__stream_encoder_delete(encoder);
412 printf("\nPASSED!\n");
417 FLAC__SeekableStreamEncoderSeekStatus seekable_stream_encoder_seek_callback_(const FLAC__SeekableStreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data)
419 (void)encoder, (void)absolute_byte_offset, (void)client_data;
420 return FLAC__SEEKABLE_STREAM_ENCODER_SEEK_STATUS_OK;
423 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)
425 (void)encoder, (void)buffer, (void)bytes, (void)samples, (void)current_frame, (void)client_data;
426 return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
429 static FLAC__bool test_seekable_stream_encoder()
431 FLAC__SeekableStreamEncoder *encoder;
432 FLAC__SeekableStreamEncoderState state;
433 FLAC__StreamEncoderState state_;
434 FLAC__StreamDecoderState dstate;
435 FLAC__int32 samples[1024];
436 FLAC__int32 *samples_array[1] = { samples };
439 printf("\n+++ libFLAC unit test: FLAC__SeekableStreamEncoder\n\n");
441 printf("testing FLAC__seekable_stream_encoder_new()... ");
442 encoder = FLAC__seekable_stream_encoder_new();
444 printf("FAILED, returned NULL\n");
449 printf("testing FLAC__seekable_stream_encoder_set_verify()... ");
450 if(!FLAC__seekable_stream_encoder_set_verify(encoder, true))
451 return die_ss_("returned false", encoder);
454 printf("testing FLAC__seekable_stream_encoder_set_streamable_subset()... ");
455 if(!FLAC__seekable_stream_encoder_set_streamable_subset(encoder, true))
456 return die_ss_("returned false", encoder);
459 printf("testing FLAC__seekable_stream_encoder_set_do_mid_side_stereo()... ");
460 if(!FLAC__seekable_stream_encoder_set_do_mid_side_stereo(encoder, false))
461 return die_ss_("returned false", encoder);
464 printf("testing FLAC__seekable_stream_encoder_set_loose_mid_side_stereo()... ");
465 if(!FLAC__seekable_stream_encoder_set_loose_mid_side_stereo(encoder, false))
466 return die_ss_("returned false", encoder);
469 printf("testing FLAC__seekable_stream_encoder_set_channels()... ");
470 if(!FLAC__seekable_stream_encoder_set_channels(encoder, streaminfo_.data.stream_info.channels))
471 return die_ss_("returned false", encoder);
474 printf("testing FLAC__seekable_stream_encoder_set_bits_per_sample()... ");
475 if(!FLAC__seekable_stream_encoder_set_bits_per_sample(encoder, streaminfo_.data.stream_info.bits_per_sample))
476 return die_ss_("returned false", encoder);
479 printf("testing FLAC__seekable_stream_encoder_set_sample_rate()... ");
480 if(!FLAC__seekable_stream_encoder_set_sample_rate(encoder, streaminfo_.data.stream_info.sample_rate))
481 return die_ss_("returned false", encoder);
484 printf("testing FLAC__seekable_stream_encoder_set_blocksize()... ");
485 if(!FLAC__seekable_stream_encoder_set_blocksize(encoder, streaminfo_.data.stream_info.min_blocksize))
486 return die_ss_("returned false", encoder);
489 printf("testing FLAC__seekable_stream_encoder_set_max_lpc_order()... ");
490 if(!FLAC__seekable_stream_encoder_set_max_lpc_order(encoder, 0))
491 return die_ss_("returned false", encoder);
494 printf("testing FLAC__seekable_stream_encoder_set_qlp_coeff_precision()... ");
495 if(!FLAC__seekable_stream_encoder_set_qlp_coeff_precision(encoder, 0))
496 return die_ss_("returned false", encoder);
499 printf("testing FLAC__seekable_stream_encoder_set_do_qlp_coeff_prec_search()... ");
500 if(!FLAC__seekable_stream_encoder_set_do_qlp_coeff_prec_search(encoder, false))
501 return die_ss_("returned false", encoder);
504 printf("testing FLAC__seekable_stream_encoder_set_do_escape_coding()... ");
505 if(!FLAC__seekable_stream_encoder_set_do_escape_coding(encoder, false))
506 return die_ss_("returned false", encoder);
509 printf("testing FLAC__seekable_stream_encoder_set_do_exhaustive_model_search()... ");
510 if(!FLAC__seekable_stream_encoder_set_do_exhaustive_model_search(encoder, false))
511 return die_ss_("returned false", encoder);
514 printf("testing FLAC__seekable_stream_encoder_set_min_residual_partition_order()... ");
515 if(!FLAC__seekable_stream_encoder_set_min_residual_partition_order(encoder, 0))
516 return die_ss_("returned false", encoder);
519 printf("testing FLAC__seekable_stream_encoder_set_max_residual_partition_order()... ");
520 if(!FLAC__seekable_stream_encoder_set_max_residual_partition_order(encoder, 0))
521 return die_ss_("returned false", encoder);
524 printf("testing FLAC__seekable_stream_encoder_set_rice_parameter_search_dist()... ");
525 if(!FLAC__seekable_stream_encoder_set_rice_parameter_search_dist(encoder, 0))
526 return die_ss_("returned false", encoder);
529 printf("testing FLAC__seekable_stream_encoder_set_total_samples_estimate()... ");
530 if(!FLAC__seekable_stream_encoder_set_total_samples_estimate(encoder, streaminfo_.data.stream_info.total_samples))
531 return die_ss_("returned false", encoder);
534 printf("testing FLAC__seekable_stream_encoder_set_metadata()... ");
535 if(!FLAC__seekable_stream_encoder_set_metadata(encoder, metadata_sequence_, num_metadata_))
536 return die_ss_("returned false", encoder);
539 printf("testing FLAC__seekable_stream_encoder_set_seek_callback()... ");
540 if(!FLAC__seekable_stream_encoder_set_seek_callback(encoder, seekable_stream_encoder_seek_callback_))
541 return die_ss_("returned false", encoder);
544 printf("testing FLAC__seekable_stream_encoder_set_write_callback()... ");
545 if(!FLAC__seekable_stream_encoder_set_write_callback(encoder, seekable_stream_encoder_write_callback_))
546 return die_ss_("returned false", encoder);
549 printf("testing FLAC__seekable_stream_encoder_set_client_data()... ");
550 if(!FLAC__seekable_stream_encoder_set_client_data(encoder, 0))
551 return die_ss_("returned false", encoder);
554 printf("testing FLAC__seekable_stream_encoder_init()... ");
555 if(FLAC__seekable_stream_encoder_init(encoder) != FLAC__SEEKABLE_STREAM_ENCODER_OK)
556 return die_ss_(0, encoder);
559 printf("testing FLAC__seekable_stream_encoder_get_state()... ");
560 state = FLAC__seekable_stream_encoder_get_state(encoder);
561 printf("returned state = %u (%s)... OK\n", (unsigned)state, FLAC__SeekableStreamEncoderStateString[state]);
563 printf("testing FLAC__seekable_stream_encoder_get_stream_encoder_state()... ");
564 state_ = FLAC__seekable_stream_encoder_get_stream_encoder_state(encoder);
565 printf("returned state = %u (%s)... OK\n", (unsigned)state_, FLAC__StreamEncoderStateString[state_]);
567 printf("testing FLAC__seekable_stream_encoder_get_verify_decoder_state()... ");
568 dstate = FLAC__seekable_stream_encoder_get_verify_decoder_state(encoder);
569 printf("returned state = %u (%s)... OK\n", (unsigned)dstate, FLAC__StreamDecoderStateString[dstate]);
572 FLAC__uint64 absolute_sample;
573 unsigned frame_number;
576 FLAC__int32 expected;
579 printf("testing FLAC__seekable_stream_encoder_get_verify_decoder_error_stats()... ");
580 FLAC__seekable_stream_encoder_get_verify_decoder_error_stats(encoder, &absolute_sample, &frame_number, &channel, &sample, &expected, &got);
584 printf("testing FLAC__seekable_stream_encoder_get_verify()... ");
585 if(FLAC__seekable_stream_encoder_get_verify(encoder) != true) {
586 printf("FAILED, expected true, got false\n");
591 printf("testing FLAC__seekable_stream_encoder_get_streamable_subset()... ");
592 if(FLAC__seekable_stream_encoder_get_streamable_subset(encoder) != true) {
593 printf("FAILED, expected true, got false\n");
598 printf("testing FLAC__seekable_stream_encoder_get_do_mid_side_stereo()... ");
599 if(FLAC__seekable_stream_encoder_get_do_mid_side_stereo(encoder) != false) {
600 printf("FAILED, expected false, got true\n");
605 printf("testing FLAC__seekable_stream_encoder_get_loose_mid_side_stereo()... ");
606 if(FLAC__seekable_stream_encoder_get_loose_mid_side_stereo(encoder) != false) {
607 printf("FAILED, expected false, got true\n");
612 printf("testing FLAC__seekable_stream_encoder_get_channels()... ");
613 if(FLAC__seekable_stream_encoder_get_channels(encoder) != streaminfo_.data.stream_info.channels) {
614 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.channels, FLAC__seekable_stream_encoder_get_channels(encoder));
619 printf("testing FLAC__seekable_stream_encoder_get_bits_per_sample()... ");
620 if(FLAC__seekable_stream_encoder_get_bits_per_sample(encoder) != streaminfo_.data.stream_info.bits_per_sample) {
621 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.bits_per_sample, FLAC__seekable_stream_encoder_get_bits_per_sample(encoder));
626 printf("testing FLAC__seekable_stream_encoder_get_sample_rate()... ");
627 if(FLAC__seekable_stream_encoder_get_sample_rate(encoder) != streaminfo_.data.stream_info.sample_rate) {
628 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.sample_rate, FLAC__seekable_stream_encoder_get_sample_rate(encoder));
633 printf("testing FLAC__seekable_stream_encoder_get_blocksize()... ");
634 if(FLAC__seekable_stream_encoder_get_blocksize(encoder) != streaminfo_.data.stream_info.min_blocksize) {
635 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.min_blocksize, FLAC__seekable_stream_encoder_get_blocksize(encoder));
640 printf("testing FLAC__seekable_stream_encoder_get_max_lpc_order()... ");
641 if(FLAC__seekable_stream_encoder_get_max_lpc_order(encoder) != 0) {
642 printf("FAILED, expected %u, got %u\n", 0, FLAC__seekable_stream_encoder_get_max_lpc_order(encoder));
647 printf("testing FLAC__seekable_stream_encoder_get_qlp_coeff_precision()... ");
648 (void)FLAC__seekable_stream_encoder_get_qlp_coeff_precision(encoder);
649 /* we asked the encoder to auto select this so we accept anything */
652 printf("testing FLAC__seekable_stream_encoder_get_do_qlp_coeff_prec_search()... ");
653 if(FLAC__seekable_stream_encoder_get_do_qlp_coeff_prec_search(encoder) != false) {
654 printf("FAILED, expected false, got true\n");
659 printf("testing FLAC__seekable_stream_encoder_get_do_escape_coding()... ");
660 if(FLAC__seekable_stream_encoder_get_do_escape_coding(encoder) != false) {
661 printf("FAILED, expected false, got true\n");
666 printf("testing FLAC__seekable_stream_encoder_get_do_exhaustive_model_search()... ");
667 if(FLAC__seekable_stream_encoder_get_do_exhaustive_model_search(encoder) != false) {
668 printf("FAILED, expected false, got true\n");
673 printf("testing FLAC__seekable_stream_encoder_get_min_residual_partition_order()... ");
674 if(FLAC__seekable_stream_encoder_get_min_residual_partition_order(encoder) != 0) {
675 printf("FAILED, expected %u, got %u\n", 0, FLAC__seekable_stream_encoder_get_min_residual_partition_order(encoder));
680 printf("testing FLAC__seekable_stream_encoder_get_max_residual_partition_order()... ");
681 if(FLAC__seekable_stream_encoder_get_max_residual_partition_order(encoder) != 0) {
682 printf("FAILED, expected %u, got %u\n", 0, FLAC__seekable_stream_encoder_get_max_residual_partition_order(encoder));
687 printf("testing FLAC__seekable_stream_encoder_get_rice_parameter_search_dist()... ");
688 if(FLAC__seekable_stream_encoder_get_rice_parameter_search_dist(encoder) != 0) {
689 printf("FAILED, expected %u, got %u\n", 0, FLAC__seekable_stream_encoder_get_rice_parameter_search_dist(encoder));
694 printf("testing FLAC__seekable_stream_encoder_get_total_samples_estimate()... ");
695 if(FLAC__seekable_stream_encoder_get_total_samples_estimate(encoder) != streaminfo_.data.stream_info.total_samples) {
696 printf("FAILED, expected %llu, got %llu\n", streaminfo_.data.stream_info.total_samples, FLAC__seekable_stream_encoder_get_total_samples_estimate(encoder));
701 /* init the dummy sample buffer */
702 for(i = 0; i < sizeof(samples) / sizeof(FLAC__int32); i++)
705 printf("testing FLAC__seekable_stream_encoder_process()... ");
706 if(!FLAC__seekable_stream_encoder_process(encoder, (const FLAC__int32 * const *)samples_array, sizeof(samples) / sizeof(FLAC__int32)))
707 return die_ss_("returned false", encoder);
710 printf("testing FLAC__seekable_stream_encoder_process_interleaved()... ");
711 if(!FLAC__seekable_stream_encoder_process_interleaved(encoder, samples, sizeof(samples) / sizeof(FLAC__int32)))
712 return die_ss_("returned false", encoder);
715 printf("testing FLAC__seekable_stream_encoder_finish()... ");
716 FLAC__seekable_stream_encoder_finish(encoder);
719 printf("testing FLAC__seekable_stream_encoder_delete()... ");
720 FLAC__seekable_stream_encoder_delete(encoder);
723 printf("\nPASSED!\n");
728 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)
730 (void)encoder, (void)bytes_written, (void)samples_written, (void)frames_written, (void)total_frames_estimate, (void)client_data;
733 static FLAC__bool test_file_encoder()
735 FLAC__FileEncoder *encoder;
736 FLAC__FileEncoderState state;
737 FLAC__SeekableStreamEncoderState state_;
738 FLAC__StreamEncoderState state__;
739 FLAC__StreamDecoderState dstate;
740 FLAC__int32 samples[1024];
741 FLAC__int32 *samples_array[1] = { samples };
744 printf("\n+++ libFLAC unit test: FLAC__FileEncoder\n\n");
746 printf("testing FLAC__file_encoder_new()... ");
747 encoder = FLAC__file_encoder_new();
749 printf("FAILED, returned NULL\n");
754 printf("testing FLAC__file_encoder_set_verify()... ");
755 if(!FLAC__file_encoder_set_verify(encoder, true))
756 return die_f_("returned false", encoder);
759 printf("testing FLAC__file_encoder_set_streamable_subset()... ");
760 if(!FLAC__file_encoder_set_streamable_subset(encoder, true))
761 return die_f_("returned false", encoder);
764 printf("testing FLAC__file_encoder_set_do_mid_side_stereo()... ");
765 if(!FLAC__file_encoder_set_do_mid_side_stereo(encoder, false))
766 return die_f_("returned false", encoder);
769 printf("testing FLAC__file_encoder_set_loose_mid_side_stereo()... ");
770 if(!FLAC__file_encoder_set_loose_mid_side_stereo(encoder, false))
771 return die_f_("returned false", encoder);
774 printf("testing FLAC__file_encoder_set_channels()... ");
775 if(!FLAC__file_encoder_set_channels(encoder, streaminfo_.data.stream_info.channels))
776 return die_f_("returned false", encoder);
779 printf("testing FLAC__file_encoder_set_bits_per_sample()... ");
780 if(!FLAC__file_encoder_set_bits_per_sample(encoder, streaminfo_.data.stream_info.bits_per_sample))
781 return die_f_("returned false", encoder);
784 printf("testing FLAC__file_encoder_set_sample_rate()... ");
785 if(!FLAC__file_encoder_set_sample_rate(encoder, streaminfo_.data.stream_info.sample_rate))
786 return die_f_("returned false", encoder);
789 printf("testing FLAC__file_encoder_set_blocksize()... ");
790 if(!FLAC__file_encoder_set_blocksize(encoder, streaminfo_.data.stream_info.min_blocksize))
791 return die_f_("returned false", encoder);
794 printf("testing FLAC__file_encoder_set_max_lpc_order()... ");
795 if(!FLAC__file_encoder_set_max_lpc_order(encoder, 0))
796 return die_f_("returned false", encoder);
799 printf("testing FLAC__file_encoder_set_qlp_coeff_precision()... ");
800 if(!FLAC__file_encoder_set_qlp_coeff_precision(encoder, 0))
801 return die_f_("returned false", encoder);
804 printf("testing FLAC__file_encoder_set_do_qlp_coeff_prec_search()... ");
805 if(!FLAC__file_encoder_set_do_qlp_coeff_prec_search(encoder, false))
806 return die_f_("returned false", encoder);
809 printf("testing FLAC__file_encoder_set_do_escape_coding()... ");
810 if(!FLAC__file_encoder_set_do_escape_coding(encoder, false))
811 return die_f_("returned false", encoder);
814 printf("testing FLAC__file_encoder_set_do_exhaustive_model_search()... ");
815 if(!FLAC__file_encoder_set_do_exhaustive_model_search(encoder, false))
816 return die_f_("returned false", encoder);
819 printf("testing FLAC__file_encoder_set_min_residual_partition_order()... ");
820 if(!FLAC__file_encoder_set_min_residual_partition_order(encoder, 0))
821 return die_f_("returned false", encoder);
824 printf("testing FLAC__file_encoder_set_max_residual_partition_order()... ");
825 if(!FLAC__file_encoder_set_max_residual_partition_order(encoder, 0))
826 return die_f_("returned false", encoder);
829 printf("testing FLAC__file_encoder_set_rice_parameter_search_dist()... ");
830 if(!FLAC__file_encoder_set_rice_parameter_search_dist(encoder, 0))
831 return die_f_("returned false", encoder);
834 printf("testing FLAC__file_encoder_set_total_samples_estimate()... ");
835 if(!FLAC__file_encoder_set_total_samples_estimate(encoder, streaminfo_.data.stream_info.total_samples))
836 return die_f_("returned false", encoder);
839 printf("testing FLAC__file_encoder_set_metadata()... ");
840 if(!FLAC__file_encoder_set_metadata(encoder, metadata_sequence_, num_metadata_))
841 return die_f_("returned false", encoder);
844 printf("testing FLAC__file_encoder_set_filename()... ");
845 if(!FLAC__file_encoder_set_filename(encoder, flacfilename_))
846 return die_f_("returned false", encoder);
849 printf("testing FLAC__file_encoder_set_progress_callback()... ");
850 if(!FLAC__file_encoder_set_progress_callback(encoder, file_encoder_progress_callback_))
851 return die_f_("returned false", encoder);
854 printf("testing FLAC__file_encoder_set_client_data()... ");
855 if(!FLAC__file_encoder_set_client_data(encoder, 0))
856 return die_f_("returned false", encoder);
859 printf("testing FLAC__file_encoder_init()... ");
860 if(FLAC__file_encoder_init(encoder) != FLAC__FILE_ENCODER_OK)
861 return die_f_(0, encoder);
864 printf("testing FLAC__file_encoder_get_state()... ");
865 state = FLAC__file_encoder_get_state(encoder);
866 printf("returned state = %u (%s)... OK\n", (unsigned)state, FLAC__FileEncoderStateString[state]);
868 printf("testing FLAC__file_encoder_get_seekable_stream_encoder_state()... ");
869 state_ = FLAC__file_encoder_get_seekable_stream_encoder_state(encoder);
870 printf("returned state = %u (%s)... OK\n", (unsigned)state_, FLAC__SeekableStreamEncoderStateString[state_]);
872 printf("testing FLAC__file_encoder_get_stream_encoder_state()... ");
873 state__ = FLAC__file_encoder_get_stream_encoder_state(encoder);
874 printf("returned state = %u (%s)... OK\n", (unsigned)state__, FLAC__StreamEncoderStateString[state__]);
876 printf("testing FLAC__file_encoder_get_verify_decoder_state()... ");
877 dstate = FLAC__file_encoder_get_verify_decoder_state(encoder);
878 printf("returned state = %u (%s)... OK\n", (unsigned)dstate, FLAC__StreamDecoderStateString[dstate]);
881 FLAC__uint64 absolute_sample;
882 unsigned frame_number;
885 FLAC__int32 expected;
888 printf("testing FLAC__file_encoder_get_verify_decoder_error_stats()... ");
889 FLAC__file_encoder_get_verify_decoder_error_stats(encoder, &absolute_sample, &frame_number, &channel, &sample, &expected, &got);
893 printf("testing FLAC__file_encoder_get_verify()... ");
894 if(FLAC__file_encoder_get_verify(encoder) != true) {
895 printf("FAILED, expected true, got false\n");
900 printf("testing FLAC__file_encoder_get_streamable_subset()... ");
901 if(FLAC__file_encoder_get_streamable_subset(encoder) != true) {
902 printf("FAILED, expected true, got false\n");
907 printf("testing FLAC__file_encoder_get_do_mid_side_stereo()... ");
908 if(FLAC__file_encoder_get_do_mid_side_stereo(encoder) != false) {
909 printf("FAILED, expected false, got true\n");
914 printf("testing FLAC__file_encoder_get_loose_mid_side_stereo()... ");
915 if(FLAC__file_encoder_get_loose_mid_side_stereo(encoder) != false) {
916 printf("FAILED, expected false, got true\n");
921 printf("testing FLAC__file_encoder_get_channels()... ");
922 if(FLAC__file_encoder_get_channels(encoder) != streaminfo_.data.stream_info.channels) {
923 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.channels, FLAC__file_encoder_get_channels(encoder));
928 printf("testing FLAC__file_encoder_get_bits_per_sample()... ");
929 if(FLAC__file_encoder_get_bits_per_sample(encoder) != streaminfo_.data.stream_info.bits_per_sample) {
930 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.bits_per_sample, FLAC__file_encoder_get_bits_per_sample(encoder));
935 printf("testing FLAC__file_encoder_get_sample_rate()... ");
936 if(FLAC__file_encoder_get_sample_rate(encoder) != streaminfo_.data.stream_info.sample_rate) {
937 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.sample_rate, FLAC__file_encoder_get_sample_rate(encoder));
942 printf("testing FLAC__file_encoder_get_blocksize()... ");
943 if(FLAC__file_encoder_get_blocksize(encoder) != streaminfo_.data.stream_info.min_blocksize) {
944 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.min_blocksize, FLAC__file_encoder_get_blocksize(encoder));
949 printf("testing FLAC__file_encoder_get_max_lpc_order()... ");
950 if(FLAC__file_encoder_get_max_lpc_order(encoder) != 0) {
951 printf("FAILED, expected %u, got %u\n", 0, FLAC__file_encoder_get_max_lpc_order(encoder));
956 printf("testing FLAC__file_encoder_get_qlp_coeff_precision()... ");
957 (void)FLAC__file_encoder_get_qlp_coeff_precision(encoder);
958 /* we asked the encoder to auto select this so we accept anything */
961 printf("testing FLAC__file_encoder_get_do_qlp_coeff_prec_search()... ");
962 if(FLAC__file_encoder_get_do_qlp_coeff_prec_search(encoder) != false) {
963 printf("FAILED, expected false, got true\n");
968 printf("testing FLAC__file_encoder_get_do_escape_coding()... ");
969 if(FLAC__file_encoder_get_do_escape_coding(encoder) != false) {
970 printf("FAILED, expected false, got true\n");
975 printf("testing FLAC__file_encoder_get_do_exhaustive_model_search()... ");
976 if(FLAC__file_encoder_get_do_exhaustive_model_search(encoder) != false) {
977 printf("FAILED, expected false, got true\n");
982 printf("testing FLAC__file_encoder_get_min_residual_partition_order()... ");
983 if(FLAC__file_encoder_get_min_residual_partition_order(encoder) != 0) {
984 printf("FAILED, expected %u, got %u\n", 0, FLAC__file_encoder_get_min_residual_partition_order(encoder));
989 printf("testing FLAC__file_encoder_get_max_residual_partition_order()... ");
990 if(FLAC__file_encoder_get_max_residual_partition_order(encoder) != 0) {
991 printf("FAILED, expected %u, got %u\n", 0, FLAC__file_encoder_get_max_residual_partition_order(encoder));
996 printf("testing FLAC__file_encoder_get_rice_parameter_search_dist()... ");
997 if(FLAC__file_encoder_get_rice_parameter_search_dist(encoder) != 0) {
998 printf("FAILED, expected %u, got %u\n", 0, FLAC__file_encoder_get_rice_parameter_search_dist(encoder));
1003 printf("testing FLAC__file_encoder_get_total_samples_estimate()... ");
1004 if(FLAC__file_encoder_get_total_samples_estimate(encoder) != streaminfo_.data.stream_info.total_samples) {
1005 printf("FAILED, expected %llu, got %llu\n", streaminfo_.data.stream_info.total_samples, FLAC__file_encoder_get_total_samples_estimate(encoder));
1010 /* init the dummy sample buffer */
1011 for(i = 0; i < sizeof(samples) / sizeof(FLAC__int32); i++)
1014 printf("testing FLAC__file_encoder_process()... ");
1015 if(!FLAC__file_encoder_process(encoder, (const FLAC__int32 * const *)samples_array, sizeof(samples) / sizeof(FLAC__int32)))
1016 return die_f_("returned false", encoder);
1019 printf("testing FLAC__file_encoder_process_interleaved()... ");
1020 if(!FLAC__file_encoder_process_interleaved(encoder, samples, sizeof(samples) / sizeof(FLAC__int32)))
1021 return die_f_("returned false", encoder);
1024 printf("testing FLAC__file_encoder_finish()... ");
1025 FLAC__file_encoder_finish(encoder);
1028 printf("testing FLAC__file_encoder_delete()... ");
1029 FLAC__file_encoder_delete(encoder);
1032 printf("\nPASSED!\n");
1037 FLAC__bool test_encoders()
1039 init_metadata_blocks_();
1041 if(!test_stream_encoder())
1044 if(!test_seekable_stream_encoder())
1047 if(!test_file_encoder())
1050 (void) grabbag__file_remove_file(flacfilename_);
1051 free_metadata_blocks_();