1 /* test_libFLAC++ - Unit tester for libFLAC++
2 * Copyright (C) 2002,2003,2004,2005 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.
21 #include "file_utils.h"
22 #include "metadata_utils.h"
24 #include "FLAC/assert.h"
25 #include "FLAC++/encoder.h"
30 static ::FLAC__StreamMetadata streaminfo_, padding_, seektable_, application1_, application2_, vorbiscomment_, cuesheet_, unknown_;
31 static ::FLAC__StreamMetadata *metadata_sequence_[] = { &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &unknown_ };
32 static const unsigned num_metadata_ = sizeof(metadata_sequence_) / sizeof(metadata_sequence_[0]);
33 static const char *flacfilename_ = "metadata.flac";
35 static void init_metadata_blocks_()
37 mutils__init_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &unknown_);
40 static void free_metadata_blocks_()
42 mutils__free_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &unknown_);
45 class StreamEncoder : public FLAC::Encoder::Stream {
47 StreamEncoder(): FLAC::Encoder::Stream() { }
50 // from FLAC::Encoder::Stream
51 ::FLAC__StreamEncoderWriteStatus write_callback(const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame);
52 void metadata_callback(const ::FLAC__StreamMetadata *metadata);
54 bool die(const char *msg = 0) const;
57 ::FLAC__StreamEncoderWriteStatus StreamEncoder::write_callback(const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame)
59 (void)buffer, (void)bytes, (void)samples, (void)current_frame;
61 return ::FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
64 void StreamEncoder::metadata_callback(const ::FLAC__StreamMetadata *metadata)
69 bool StreamEncoder::die(const char *msg) const
71 State state = get_state();
74 printf("FAILED, %s", msg);
78 printf(", state = %u (%s)\n", (unsigned)((::FLAC__StreamEncoderState)state), state.as_cstring());
79 if(state == ::FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR) {
80 FLAC::Decoder::Stream::State dstate = get_verify_decoder_state();
81 printf(" verify decoder state = %u (%s)\n", (unsigned)((::FLAC__StreamDecoderState)dstate), dstate.as_cstring());
87 static bool test_stream_encoder()
89 StreamEncoder *encoder;
90 FLAC__int32 samples[1024];
91 FLAC__int32 *samples_array[1] = { samples };
94 printf("\n+++ libFLAC++ unit test: FLAC::Encoder::Stream\n\n");
96 printf("allocating encoder instance... ");
97 encoder = new StreamEncoder();
99 printf("FAILED, new returned NULL\n");
104 printf("testing is_valid()... ");
105 if(!encoder->is_valid()) {
106 printf("FAILED, returned false\n");
111 printf("testing set_verify()... ");
112 if(!encoder->set_verify(true))
113 return encoder->die("returned false");
116 printf("testing set_streamable_subset()... ");
117 if(!encoder->set_streamable_subset(true))
118 return encoder->die("returned false");
121 printf("testing set_do_mid_side_stereo()... ");
122 if(!encoder->set_do_mid_side_stereo(false))
123 return encoder->die("returned false");
126 printf("testing set_loose_mid_side_stereo()... ");
127 if(!encoder->set_loose_mid_side_stereo(false))
128 return encoder->die("returned false");
131 printf("testing set_channels()... ");
132 if(!encoder->set_channels(streaminfo_.data.stream_info.channels))
133 return encoder->die("returned false");
136 printf("testing set_bits_per_sample()... ");
137 if(!encoder->set_bits_per_sample(streaminfo_.data.stream_info.bits_per_sample))
138 return encoder->die("returned false");
141 printf("testing set_sample_rate()... ");
142 if(!encoder->set_sample_rate(streaminfo_.data.stream_info.sample_rate))
143 return encoder->die("returned false");
146 printf("testing set_blocksize()... ");
147 if(!encoder->set_blocksize(streaminfo_.data.stream_info.min_blocksize))
148 return encoder->die("returned false");
151 printf("testing set_max_lpc_order()... ");
152 if(!encoder->set_max_lpc_order(0))
153 return encoder->die("returned false");
156 printf("testing set_qlp_coeff_precision()... ");
157 if(!encoder->set_qlp_coeff_precision(0))
158 return encoder->die("returned false");
161 printf("testing set_do_qlp_coeff_prec_search()... ");
162 if(!encoder->set_do_qlp_coeff_prec_search(false))
163 return encoder->die("returned false");
166 printf("testing set_do_escape_coding()... ");
167 if(!encoder->set_do_escape_coding(false))
168 return encoder->die("returned false");
171 printf("testing set_do_exhaustive_model_search()... ");
172 if(!encoder->set_do_exhaustive_model_search(false))
173 return encoder->die("returned false");
176 printf("testing set_min_residual_partition_order()... ");
177 if(!encoder->set_min_residual_partition_order(0))
178 return encoder->die("returned false");
181 printf("testing set_max_residual_partition_order()... ");
182 if(!encoder->set_max_residual_partition_order(0))
183 return encoder->die("returned false");
186 printf("testing set_rice_parameter_search_dist()... ");
187 if(!encoder->set_rice_parameter_search_dist(0))
188 return encoder->die("returned false");
191 printf("testing set_total_samples_estimate()... ");
192 if(!encoder->set_total_samples_estimate(streaminfo_.data.stream_info.total_samples))
193 return encoder->die("returned false");
196 printf("testing set_metadata()... ");
197 if(!encoder->set_metadata(metadata_sequence_, num_metadata_))
198 return encoder->die("returned false");
201 printf("testing init()... ");
202 if(encoder->init() != ::FLAC__STREAM_ENCODER_OK)
203 return encoder->die();
206 printf("testing get_state()... ");
207 FLAC::Encoder::Stream::State state = encoder->get_state();
208 printf("returned state = %u (%s)... OK\n", (unsigned)((::FLAC__StreamEncoderState)state), state.as_cstring());
210 printf("testing get_verify_decoder_state()... ");
211 FLAC::Decoder::Stream::State dstate = encoder->get_verify_decoder_state();
212 printf("returned state = %u (%s)... OK\n", (unsigned)((::FLAC__StreamDecoderState)dstate), dstate.as_cstring());
215 FLAC__uint64 absolute_sample;
216 unsigned frame_number;
219 FLAC__int32 expected;
222 printf("testing get_verify_decoder_error_stats()... ");
223 encoder->get_verify_decoder_error_stats(&absolute_sample, &frame_number, &channel, &sample, &expected, &got);
227 printf("testing get_verify()... ");
228 if(encoder->get_verify() != true) {
229 printf("FAILED, expected true, got false\n");
234 printf("testing get_streamable_subset()... ");
235 if(encoder->get_streamable_subset() != true) {
236 printf("FAILED, expected true, got false\n");
241 printf("testing get_do_mid_side_stereo()... ");
242 if(encoder->get_do_mid_side_stereo() != false) {
243 printf("FAILED, expected false, got true\n");
248 printf("testing get_loose_mid_side_stereo()... ");
249 if(encoder->get_loose_mid_side_stereo() != false) {
250 printf("FAILED, expected false, got true\n");
255 printf("testing get_channels()... ");
256 if(encoder->get_channels() != streaminfo_.data.stream_info.channels) {
257 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.channels, encoder->get_channels());
262 printf("testing get_bits_per_sample()... ");
263 if(encoder->get_bits_per_sample() != streaminfo_.data.stream_info.bits_per_sample) {
264 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.bits_per_sample, encoder->get_bits_per_sample());
269 printf("testing get_sample_rate()... ");
270 if(encoder->get_sample_rate() != streaminfo_.data.stream_info.sample_rate) {
271 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.sample_rate, encoder->get_sample_rate());
276 printf("testing get_blocksize()... ");
277 if(encoder->get_blocksize() != streaminfo_.data.stream_info.min_blocksize) {
278 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.min_blocksize, encoder->get_blocksize());
283 printf("testing get_max_lpc_order()... ");
284 if(encoder->get_max_lpc_order() != 0) {
285 printf("FAILED, expected %u, got %u\n", 0, encoder->get_max_lpc_order());
290 printf("testing get_qlp_coeff_precision()... ");
291 (void)encoder->get_qlp_coeff_precision();
292 /* we asked the encoder to auto select this so we accept anything */
295 printf("testing get_do_qlp_coeff_prec_search()... ");
296 if(encoder->get_do_qlp_coeff_prec_search() != false) {
297 printf("FAILED, expected false, got true\n");
302 printf("testing get_do_escape_coding()... ");
303 if(encoder->get_do_escape_coding() != false) {
304 printf("FAILED, expected false, got true\n");
309 printf("testing get_do_exhaustive_model_search()... ");
310 if(encoder->get_do_exhaustive_model_search() != false) {
311 printf("FAILED, expected false, got true\n");
316 printf("testing get_min_residual_partition_order()... ");
317 if(encoder->get_min_residual_partition_order() != 0) {
318 printf("FAILED, expected %u, got %u\n", 0, encoder->get_min_residual_partition_order());
323 printf("testing get_max_residual_partition_order()... ");
324 if(encoder->get_max_residual_partition_order() != 0) {
325 printf("FAILED, expected %u, got %u\n", 0, encoder->get_max_residual_partition_order());
330 printf("testing get_rice_parameter_search_dist()... ");
331 if(encoder->get_rice_parameter_search_dist() != 0) {
332 printf("FAILED, expected %u, got %u\n", 0, encoder->get_rice_parameter_search_dist());
337 printf("testing get_total_samples_estimate()... ");
338 if(encoder->get_total_samples_estimate() != streaminfo_.data.stream_info.total_samples) {
339 printf("FAILED, expected %llu, got %llu\n", streaminfo_.data.stream_info.total_samples, encoder->get_total_samples_estimate());
344 /* init the dummy sample buffer */
345 for(i = 0; i < sizeof(samples) / sizeof(FLAC__int32); i++)
348 printf("testing process()... ");
349 if(!encoder->process(samples_array, sizeof(samples) / sizeof(FLAC__int32)))
350 return encoder->die("returned false");
353 printf("testing process_interleaved()... ");
354 if(!encoder->process_interleaved(samples, sizeof(samples) / sizeof(FLAC__int32)))
355 return encoder->die("returned false");
358 printf("testing finish()... ");
362 printf("freeing encoder instance... ");
366 printf("\nPASSED!\n");
371 class SeekableStreamEncoder : public FLAC::Encoder::SeekableStream {
373 SeekableStreamEncoder(): FLAC::Encoder::SeekableStream() { }
374 ~SeekableStreamEncoder() { }
376 // from FLAC::Encoder::SeekableStream
377 ::FLAC__SeekableStreamEncoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset);
378 ::FLAC__SeekableStreamEncoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset);
379 ::FLAC__StreamEncoderWriteStatus write_callback(const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame);
381 bool die(const char *msg = 0) const;
384 ::FLAC__SeekableStreamEncoderSeekStatus SeekableStreamEncoder::seek_callback(FLAC__uint64 absolute_byte_offset)
386 (void)absolute_byte_offset;
388 return ::FLAC__SEEKABLE_STREAM_ENCODER_SEEK_STATUS_OK;
391 ::FLAC__SeekableStreamEncoderTellStatus SeekableStreamEncoder::tell_callback(FLAC__uint64 *absolute_byte_offset)
393 *absolute_byte_offset = 0;
395 return ::FLAC__SEEKABLE_STREAM_ENCODER_TELL_STATUS_OK;
398 ::FLAC__StreamEncoderWriteStatus SeekableStreamEncoder::write_callback(const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame)
400 (void)buffer, (void)bytes, (void)samples, (void)current_frame;
402 return ::FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
405 bool SeekableStreamEncoder::die(const char *msg) const
407 State state = get_state();
410 printf("FAILED, %s", msg);
414 printf(", state = %u (%s)\n", (unsigned)((::FLAC__SeekableStreamEncoderState)state), state.as_cstring());
415 if(state == ::FLAC__SEEKABLE_STREAM_ENCODER_STREAM_ENCODER_ERROR) {
416 FLAC::Encoder::Stream::State state_ = get_stream_encoder_state();
417 printf(" stream encoder state = %u (%s)\n", (unsigned)((::FLAC__StreamEncoderState)state_), state_.as_cstring());
418 if(state_ == ::FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR) {
419 FLAC::Decoder::Stream::State dstate = get_verify_decoder_state();
420 printf(" verify decoder state = %u (%s)\n", (unsigned)((::FLAC__StreamDecoderState)dstate), dstate.as_cstring());
427 static bool test_seekable_stream_encoder()
429 SeekableStreamEncoder *encoder;
430 FLAC__int32 samples[1024];
431 FLAC__int32 *samples_array[1] = { samples };
434 printf("\n+++ libFLAC++ unit test: FLAC::Encoder::SeekableStream\n\n");
436 printf("allocating encoder instance... ");
437 encoder = new SeekableStreamEncoder();
439 printf("FAILED, new returned NULL\n");
444 printf("testing is_valid()... ");
445 if(!encoder->is_valid()) {
446 printf("FAILED, returned false\n");
451 printf("testing set_verify()... ");
452 if(!encoder->set_verify(true))
453 return encoder->die("returned false");
456 printf("testing set_streamable_subset()... ");
457 if(!encoder->set_streamable_subset(true))
458 return encoder->die("returned false");
461 printf("testing set_do_mid_side_stereo()... ");
462 if(!encoder->set_do_mid_side_stereo(false))
463 return encoder->die("returned false");
466 printf("testing set_loose_mid_side_stereo()... ");
467 if(!encoder->set_loose_mid_side_stereo(false))
468 return encoder->die("returned false");
471 printf("testing set_channels()... ");
472 if(!encoder->set_channels(streaminfo_.data.stream_info.channels))
473 return encoder->die("returned false");
476 printf("testing set_bits_per_sample()... ");
477 if(!encoder->set_bits_per_sample(streaminfo_.data.stream_info.bits_per_sample))
478 return encoder->die("returned false");
481 printf("testing set_sample_rate()... ");
482 if(!encoder->set_sample_rate(streaminfo_.data.stream_info.sample_rate))
483 return encoder->die("returned false");
486 printf("testing set_blocksize()... ");
487 if(!encoder->set_blocksize(streaminfo_.data.stream_info.min_blocksize))
488 return encoder->die("returned false");
491 printf("testing set_max_lpc_order()... ");
492 if(!encoder->set_max_lpc_order(0))
493 return encoder->die("returned false");
496 printf("testing set_qlp_coeff_precision()... ");
497 if(!encoder->set_qlp_coeff_precision(0))
498 return encoder->die("returned false");
501 printf("testing set_do_qlp_coeff_prec_search()... ");
502 if(!encoder->set_do_qlp_coeff_prec_search(false))
503 return encoder->die("returned false");
506 printf("testing set_do_escape_coding()... ");
507 if(!encoder->set_do_escape_coding(false))
508 return encoder->die("returned false");
511 printf("testing set_do_exhaustive_model_search()... ");
512 if(!encoder->set_do_exhaustive_model_search(false))
513 return encoder->die("returned false");
516 printf("testing set_min_residual_partition_order()... ");
517 if(!encoder->set_min_residual_partition_order(0))
518 return encoder->die("returned false");
521 printf("testing set_max_residual_partition_order()... ");
522 if(!encoder->set_max_residual_partition_order(0))
523 return encoder->die("returned false");
526 printf("testing set_rice_parameter_search_dist()... ");
527 if(!encoder->set_rice_parameter_search_dist(0))
528 return encoder->die("returned false");
531 printf("testing set_total_samples_estimate()... ");
532 if(!encoder->set_total_samples_estimate(streaminfo_.data.stream_info.total_samples))
533 return encoder->die("returned false");
536 printf("testing set_metadata()... ");
537 if(!encoder->set_metadata(metadata_sequence_, num_metadata_))
538 return encoder->die("returned false");
541 printf("testing init()... ");
542 if(encoder->init() != ::FLAC__SEEKABLE_STREAM_ENCODER_OK)
543 return encoder->die();
546 printf("testing get_state()... ");
547 FLAC::Encoder::SeekableStream::State state = encoder->get_state();
548 printf("returned state = %u (%s)... OK\n", (unsigned)((::FLAC__SeekableStreamEncoderState)state), state.as_cstring());
550 printf("testing get_stream_encoder_state()... ");
551 FLAC::Encoder::Stream::State state_ = encoder->get_stream_encoder_state();
552 printf("returned state = %u (%s)... OK\n", (unsigned)((::FLAC__StreamEncoderState)state_), state_.as_cstring());
554 printf("testing get_verify_decoder_state()... ");
555 FLAC::Decoder::Stream::State dstate = encoder->get_verify_decoder_state();
556 printf("returned state = %u (%s)... OK\n", (unsigned)((::FLAC__StreamDecoderState)dstate), dstate.as_cstring());
559 FLAC__uint64 absolute_sample;
560 unsigned frame_number;
563 FLAC__int32 expected;
566 printf("testing get_verify_decoder_error_stats()... ");
567 encoder->get_verify_decoder_error_stats(&absolute_sample, &frame_number, &channel, &sample, &expected, &got);
571 printf("testing get_verify()... ");
572 if(encoder->get_verify() != true) {
573 printf("FAILED, expected true, got false\n");
578 printf("testing get_streamable_subset()... ");
579 if(encoder->get_streamable_subset() != true) {
580 printf("FAILED, expected true, got false\n");
585 printf("testing get_do_mid_side_stereo()... ");
586 if(encoder->get_do_mid_side_stereo() != false) {
587 printf("FAILED, expected false, got true\n");
592 printf("testing get_loose_mid_side_stereo()... ");
593 if(encoder->get_loose_mid_side_stereo() != false) {
594 printf("FAILED, expected false, got true\n");
599 printf("testing get_channels()... ");
600 if(encoder->get_channels() != streaminfo_.data.stream_info.channels) {
601 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.channels, encoder->get_channels());
606 printf("testing get_bits_per_sample()... ");
607 if(encoder->get_bits_per_sample() != streaminfo_.data.stream_info.bits_per_sample) {
608 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.bits_per_sample, encoder->get_bits_per_sample());
613 printf("testing get_sample_rate()... ");
614 if(encoder->get_sample_rate() != streaminfo_.data.stream_info.sample_rate) {
615 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.sample_rate, encoder->get_sample_rate());
620 printf("testing get_blocksize()... ");
621 if(encoder->get_blocksize() != streaminfo_.data.stream_info.min_blocksize) {
622 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.min_blocksize, encoder->get_blocksize());
627 printf("testing get_max_lpc_order()... ");
628 if(encoder->get_max_lpc_order() != 0) {
629 printf("FAILED, expected %u, got %u\n", 0, encoder->get_max_lpc_order());
634 printf("testing get_qlp_coeff_precision()... ");
635 (void)encoder->get_qlp_coeff_precision();
636 /* we asked the encoder to auto select this so we accept anything */
639 printf("testing get_do_qlp_coeff_prec_search()... ");
640 if(encoder->get_do_qlp_coeff_prec_search() != false) {
641 printf("FAILED, expected false, got true\n");
646 printf("testing get_do_escape_coding()... ");
647 if(encoder->get_do_escape_coding() != false) {
648 printf("FAILED, expected false, got true\n");
653 printf("testing get_do_exhaustive_model_search()... ");
654 if(encoder->get_do_exhaustive_model_search() != false) {
655 printf("FAILED, expected false, got true\n");
660 printf("testing get_min_residual_partition_order()... ");
661 if(encoder->get_min_residual_partition_order() != 0) {
662 printf("FAILED, expected %u, got %u\n", 0, encoder->get_min_residual_partition_order());
667 printf("testing get_max_residual_partition_order()... ");
668 if(encoder->get_max_residual_partition_order() != 0) {
669 printf("FAILED, expected %u, got %u\n", 0, encoder->get_max_residual_partition_order());
674 printf("testing get_rice_parameter_search_dist()... ");
675 if(encoder->get_rice_parameter_search_dist() != 0) {
676 printf("FAILED, expected %u, got %u\n", 0, encoder->get_rice_parameter_search_dist());
681 printf("testing get_total_samples_estimate()... ");
682 if(encoder->get_total_samples_estimate() != streaminfo_.data.stream_info.total_samples) {
683 printf("FAILED, expected %llu, got %llu\n", streaminfo_.data.stream_info.total_samples, encoder->get_total_samples_estimate());
688 /* init the dummy sample buffer */
689 for(i = 0; i < sizeof(samples) / sizeof(FLAC__int32); i++)
692 printf("testing process()... ");
693 if(!encoder->process(samples_array, sizeof(samples) / sizeof(FLAC__int32)))
694 return encoder->die("returned false");
697 printf("testing process_interleaved()... ");
698 if(!encoder->process_interleaved(samples, sizeof(samples) / sizeof(FLAC__int32)))
699 return encoder->die("returned false");
702 printf("testing finish()... ");
706 printf("freeing encoder instance... ");
710 printf("\nPASSED!\n");
715 class FileEncoder : public FLAC::Encoder::File {
717 FileEncoder(): FLAC::Encoder::File() { }
720 // from FLAC::Encoder::File
721 void progress_callback(FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate);
723 bool die(const char *msg = 0) const;
726 void FileEncoder::progress_callback(FLAC__uint64, FLAC__uint64, unsigned, unsigned)
730 bool FileEncoder::die(const char *msg) const
732 State state = get_state();
735 printf("FAILED, %s", msg);
739 printf(", state = %u (%s)\n", (unsigned)((::FLAC__FileEncoderState)state), state.as_cstring());
740 if(state == ::FLAC__FILE_ENCODER_SEEKABLE_STREAM_ENCODER_ERROR) {
741 FLAC::Encoder::SeekableStream::State state_ = get_seekable_stream_encoder_state();
742 printf(" seekable stream encoder state = %u (%s)\n", (unsigned)((::FLAC__SeekableStreamEncoderState)state_), state_.as_cstring());
743 if(state_ == ::FLAC__SEEKABLE_STREAM_ENCODER_STREAM_ENCODER_ERROR) {
744 FLAC::Encoder::Stream::State state__ = get_stream_encoder_state();
745 printf(" stream encoder state = %u (%s)\n", (unsigned)((::FLAC__StreamEncoderState)state__), state__.as_cstring());
746 if(state__ == ::FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR) {
747 FLAC::Decoder::Stream::State dstate = get_verify_decoder_state();
748 printf(" verify decoder state = %u (%s)\n", (unsigned)((::FLAC__StreamDecoderState)dstate), dstate.as_cstring());
756 static bool test_file_encoder()
758 FileEncoder *encoder;
759 FLAC__int32 samples[1024];
760 FLAC__int32 *samples_array[1] = { samples };
763 printf("\n+++ libFLAC++ unit test: FLAC::Encoder::File\n\n");
765 printf("allocating encoder instance... ");
766 encoder = new FileEncoder();
768 printf("FAILED, new returned NULL\n");
773 printf("testing is_valid()... ");
774 if(!encoder->is_valid()) {
775 printf("FAILED, returned false\n");
780 printf("testing set_verify()... ");
781 if(!encoder->set_verify(true))
782 return encoder->die("returned false");
785 printf("testing set_streamable_subset()... ");
786 if(!encoder->set_streamable_subset(true))
787 return encoder->die("returned false");
790 printf("testing set_do_mid_side_stereo()... ");
791 if(!encoder->set_do_mid_side_stereo(false))
792 return encoder->die("returned false");
795 printf("testing set_loose_mid_side_stereo()... ");
796 if(!encoder->set_loose_mid_side_stereo(false))
797 return encoder->die("returned false");
800 printf("testing set_channels()... ");
801 if(!encoder->set_channels(streaminfo_.data.stream_info.channels))
802 return encoder->die("returned false");
805 printf("testing set_bits_per_sample()... ");
806 if(!encoder->set_bits_per_sample(streaminfo_.data.stream_info.bits_per_sample))
807 return encoder->die("returned false");
810 printf("testing set_sample_rate()... ");
811 if(!encoder->set_sample_rate(streaminfo_.data.stream_info.sample_rate))
812 return encoder->die("returned false");
815 printf("testing set_blocksize()... ");
816 if(!encoder->set_blocksize(streaminfo_.data.stream_info.min_blocksize))
817 return encoder->die("returned false");
820 printf("testing set_max_lpc_order()... ");
821 if(!encoder->set_max_lpc_order(0))
822 return encoder->die("returned false");
825 printf("testing set_qlp_coeff_precision()... ");
826 if(!encoder->set_qlp_coeff_precision(0))
827 return encoder->die("returned false");
830 printf("testing set_do_qlp_coeff_prec_search()... ");
831 if(!encoder->set_do_qlp_coeff_prec_search(false))
832 return encoder->die("returned false");
835 printf("testing set_do_escape_coding()... ");
836 if(!encoder->set_do_escape_coding(false))
837 return encoder->die("returned false");
840 printf("testing set_do_exhaustive_model_search()... ");
841 if(!encoder->set_do_exhaustive_model_search(false))
842 return encoder->die("returned false");
845 printf("testing set_min_residual_partition_order()... ");
846 if(!encoder->set_min_residual_partition_order(0))
847 return encoder->die("returned false");
850 printf("testing set_max_residual_partition_order()... ");
851 if(!encoder->set_max_residual_partition_order(0))
852 return encoder->die("returned false");
855 printf("testing set_rice_parameter_search_dist()... ");
856 if(!encoder->set_rice_parameter_search_dist(0))
857 return encoder->die("returned false");
860 printf("testing set_total_samples_estimate()... ");
861 if(!encoder->set_total_samples_estimate(streaminfo_.data.stream_info.total_samples))
862 return encoder->die("returned false");
865 printf("testing set_metadata()... ");
866 if(!encoder->set_metadata(metadata_sequence_, num_metadata_))
867 return encoder->die("returned false");
870 printf("testing set_filename()... ");
871 if(!encoder->set_filename(flacfilename_))
872 return encoder->die("returned false");
875 printf("testing init()... ");
876 if(encoder->init() != ::FLAC__FILE_ENCODER_OK)
877 return encoder->die();
880 printf("testing get_state()... ");
881 FLAC::Encoder::File::State state = encoder->get_state();
882 printf("returned state = %u (%s)... OK\n", (unsigned)((::FLAC__FileEncoderState)state), state.as_cstring());
884 printf("testing get_seekable_stream_encoder_state()... ");
885 FLAC::Encoder::SeekableStream::State state_ = encoder->get_seekable_stream_encoder_state();
886 printf("returned state = %u (%s)... OK\n", (unsigned)((::FLAC__SeekableStreamEncoderState)state_), state_.as_cstring());
888 printf("testing get_stream_encoder_state()... ");
889 FLAC::Encoder::Stream::State state__ = encoder->get_stream_encoder_state();
890 printf("returned state = %u (%s)... OK\n", (unsigned)((::FLAC__StreamEncoderState)state__), state__.as_cstring());
892 printf("testing get_verify_decoder_state()... ");
893 FLAC::Decoder::Stream::State dstate = encoder->get_verify_decoder_state();
894 printf("returned state = %u (%s)... OK\n", (unsigned)((::FLAC__StreamDecoderState)dstate), dstate.as_cstring());
897 FLAC__uint64 absolute_sample;
898 unsigned frame_number;
901 FLAC__int32 expected;
904 printf("testing get_verify_decoder_error_stats()... ");
905 encoder->get_verify_decoder_error_stats(&absolute_sample, &frame_number, &channel, &sample, &expected, &got);
909 printf("testing get_verify()... ");
910 if(encoder->get_verify() != true) {
911 printf("FAILED, expected true, got false\n");
916 printf("testing get_streamable_subset()... ");
917 if(encoder->get_streamable_subset() != true) {
918 printf("FAILED, expected true, got false\n");
923 printf("testing get_do_mid_side_stereo()... ");
924 if(encoder->get_do_mid_side_stereo() != false) {
925 printf("FAILED, expected false, got true\n");
930 printf("testing get_loose_mid_side_stereo()... ");
931 if(encoder->get_loose_mid_side_stereo() != false) {
932 printf("FAILED, expected false, got true\n");
937 printf("testing get_channels()... ");
938 if(encoder->get_channels() != streaminfo_.data.stream_info.channels) {
939 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.channels, encoder->get_channels());
944 printf("testing get_bits_per_sample()... ");
945 if(encoder->get_bits_per_sample() != streaminfo_.data.stream_info.bits_per_sample) {
946 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.bits_per_sample, encoder->get_bits_per_sample());
951 printf("testing get_sample_rate()... ");
952 if(encoder->get_sample_rate() != streaminfo_.data.stream_info.sample_rate) {
953 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.sample_rate, encoder->get_sample_rate());
958 printf("testing get_blocksize()... ");
959 if(encoder->get_blocksize() != streaminfo_.data.stream_info.min_blocksize) {
960 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.min_blocksize, encoder->get_blocksize());
965 printf("testing get_max_lpc_order()... ");
966 if(encoder->get_max_lpc_order() != 0) {
967 printf("FAILED, expected %u, got %u\n", 0, encoder->get_max_lpc_order());
972 printf("testing get_qlp_coeff_precision()... ");
973 (void)encoder->get_qlp_coeff_precision();
974 /* we asked the encoder to auto select this so we accept anything */
977 printf("testing get_do_qlp_coeff_prec_search()... ");
978 if(encoder->get_do_qlp_coeff_prec_search() != false) {
979 printf("FAILED, expected false, got true\n");
984 printf("testing get_do_escape_coding()... ");
985 if(encoder->get_do_escape_coding() != false) {
986 printf("FAILED, expected false, got true\n");
991 printf("testing get_do_exhaustive_model_search()... ");
992 if(encoder->get_do_exhaustive_model_search() != false) {
993 printf("FAILED, expected false, got true\n");
998 printf("testing get_min_residual_partition_order()... ");
999 if(encoder->get_min_residual_partition_order() != 0) {
1000 printf("FAILED, expected %u, got %u\n", 0, encoder->get_min_residual_partition_order());
1005 printf("testing get_max_residual_partition_order()... ");
1006 if(encoder->get_max_residual_partition_order() != 0) {
1007 printf("FAILED, expected %u, got %u\n", 0, encoder->get_max_residual_partition_order());
1012 printf("testing get_rice_parameter_search_dist()... ");
1013 if(encoder->get_rice_parameter_search_dist() != 0) {
1014 printf("FAILED, expected %u, got %u\n", 0, encoder->get_rice_parameter_search_dist());
1019 printf("testing get_total_samples_estimate()... ");
1020 if(encoder->get_total_samples_estimate() != streaminfo_.data.stream_info.total_samples) {
1021 printf("FAILED, expected %llu, got %llu\n", streaminfo_.data.stream_info.total_samples, encoder->get_total_samples_estimate());
1026 /* init the dummy sample buffer */
1027 for(i = 0; i < sizeof(samples) / sizeof(FLAC__int32); i++)
1030 printf("testing process()... ");
1031 if(!encoder->process(samples_array, sizeof(samples) / sizeof(FLAC__int32)))
1032 return encoder->die("returned false");
1035 printf("testing process_interleaved()... ");
1036 if(!encoder->process_interleaved(samples, sizeof(samples) / sizeof(FLAC__int32)))
1037 return encoder->die("returned false");
1040 printf("testing finish()... ");
1044 printf("freeing encoder instance... ");
1048 printf("\nPASSED!\n");
1053 bool test_encoders()
1055 init_metadata_blocks_();
1057 if(!test_stream_encoder())
1060 if(!test_seekable_stream_encoder())
1063 if(!test_file_encoder())
1066 free_metadata_blocks_();