1 /* test_libFLAC - Unit tester for libFLAC
2 * Copyright (C) 2002,2003,2004,2005,2006 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.
24 #include "file_utils.h"
25 #include "metadata_utils.h"
26 #include "FLAC/assert.h"
27 #include "FLAC/file_encoder.h"
28 #include "FLAC/seekable_stream_encoder.h"
29 #include "FLAC/stream_encoder.h"
30 #include "share/grabbag.h"
35 static FLAC__StreamMetadata streaminfo_, padding_, seektable_, application1_, application2_, vorbiscomment_, cuesheet_, unknown_;
36 static FLAC__StreamMetadata *metadata_sequence_[] = { &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &unknown_ };
37 static const unsigned num_metadata_ = sizeof(metadata_sequence_) / sizeof(metadata_sequence_[0]);
38 static const char *flacfilename_ = "metadata.flac";
40 static FLAC__bool die_s_(const char *msg, const FLAC__StreamEncoder *encoder)
42 FLAC__StreamEncoderState state = FLAC__stream_encoder_get_state(encoder);
45 printf("FAILED, %s", msg);
49 printf(", state = %u (%s)\n", (unsigned)state, FLAC__StreamEncoderStateString[state]);
50 if(state == FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR) {
51 FLAC__StreamDecoderState dstate = FLAC__stream_encoder_get_verify_decoder_state(encoder);
52 printf(" verify decoder state = %u (%s)\n", (unsigned)dstate, FLAC__StreamDecoderStateString[dstate]);
58 static FLAC__bool die_ss_(const char *msg, const FLAC__SeekableStreamEncoder *encoder)
60 FLAC__SeekableStreamEncoderState state = FLAC__seekable_stream_encoder_get_state(encoder);
63 printf("FAILED, %s", msg);
67 printf(", state = %u (%s)\n", (unsigned)state, FLAC__SeekableStreamEncoderStateString[state]);
68 if(state == FLAC__SEEKABLE_STREAM_ENCODER_STREAM_ENCODER_ERROR) {
69 FLAC__StreamEncoderState state_ = FLAC__seekable_stream_encoder_get_stream_encoder_state(encoder);
70 printf(" stream encoder state = %u (%s)\n", (unsigned)state_, FLAC__StreamEncoderStateString[state_]);
71 if(state_ == FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR) {
72 FLAC__StreamDecoderState dstate = FLAC__seekable_stream_encoder_get_verify_decoder_state(encoder);
73 printf(" verify decoder state = %u (%s)\n", (unsigned)dstate, FLAC__StreamDecoderStateString[dstate]);
80 static FLAC__bool die_f_(const char *msg, const FLAC__FileEncoder *encoder)
82 FLAC__FileEncoderState state = FLAC__file_encoder_get_state(encoder);
85 printf("FAILED, %s", msg);
89 printf(", state = %u (%s)\n", (unsigned)state, FLAC__FileEncoderStateString[state]);
90 if(state == FLAC__FILE_ENCODER_SEEKABLE_STREAM_ENCODER_ERROR) {
91 FLAC__SeekableStreamEncoderState state_ = FLAC__file_encoder_get_seekable_stream_encoder_state(encoder);
92 printf(" seekable stream encoder state = %u (%s)\n", (unsigned)state_, FLAC__SeekableStreamEncoderStateString[state_]);
93 if(state_ == FLAC__SEEKABLE_STREAM_ENCODER_STREAM_ENCODER_ERROR) {
94 FLAC__StreamEncoderState state__ = FLAC__file_encoder_get_stream_encoder_state(encoder);
95 printf(" stream encoder state = %u (%s)\n", (unsigned)state__, FLAC__StreamEncoderStateString[state__]);
96 if(state__ == FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR) {
97 FLAC__StreamDecoderState dstate = FLAC__file_encoder_get_verify_decoder_state(encoder);
98 printf(" verify decoder state = %u (%s)\n", (unsigned)dstate, FLAC__StreamDecoderStateString[dstate]);
106 static void init_metadata_blocks_()
108 mutils__init_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &unknown_);
111 static void free_metadata_blocks_()
113 mutils__free_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &unknown_);
116 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)
118 (void)encoder, (void)buffer, (void)bytes, (void)samples, (void)current_frame, (void)client_data;
119 return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
122 static void stream_encoder_metadata_callback_(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetadata *metadata, void *client_data)
124 (void)encoder, (void)metadata, (void)client_data;
127 static FLAC__bool test_stream_encoder()
129 FLAC__StreamEncoder *encoder;
130 FLAC__StreamEncoderState state;
131 FLAC__StreamDecoderState dstate;
132 FLAC__int32 samples[1024];
133 FLAC__int32 *samples_array[1];
136 samples_array[0] = samples;
138 printf("\n+++ libFLAC unit test: FLAC__StreamEncoder\n\n");
140 printf("testing FLAC__stream_encoder_new()... ");
141 encoder = FLAC__stream_encoder_new();
143 printf("FAILED, returned NULL\n");
148 printf("testing FLAC__stream_encoder_set_verify()... ");
149 if(!FLAC__stream_encoder_set_verify(encoder, true))
150 return die_s_("returned false", encoder);
153 printf("testing FLAC__stream_encoder_set_streamable_subset()... ");
154 if(!FLAC__stream_encoder_set_streamable_subset(encoder, true))
155 return die_s_("returned false", encoder);
158 printf("testing FLAC__stream_encoder_set_do_mid_side_stereo()... ");
159 if(!FLAC__stream_encoder_set_do_mid_side_stereo(encoder, false))
160 return die_s_("returned false", encoder);
163 printf("testing FLAC__stream_encoder_set_loose_mid_side_stereo()... ");
164 if(!FLAC__stream_encoder_set_loose_mid_side_stereo(encoder, false))
165 return die_s_("returned false", encoder);
168 printf("testing FLAC__stream_encoder_set_channels()... ");
169 if(!FLAC__stream_encoder_set_channels(encoder, streaminfo_.data.stream_info.channels))
170 return die_s_("returned false", encoder);
173 printf("testing FLAC__stream_encoder_set_bits_per_sample()... ");
174 if(!FLAC__stream_encoder_set_bits_per_sample(encoder, streaminfo_.data.stream_info.bits_per_sample))
175 return die_s_("returned false", encoder);
178 printf("testing FLAC__stream_encoder_set_sample_rate()... ");
179 if(!FLAC__stream_encoder_set_sample_rate(encoder, streaminfo_.data.stream_info.sample_rate))
180 return die_s_("returned false", encoder);
183 printf("testing FLAC__stream_encoder_set_blocksize()... ");
184 if(!FLAC__stream_encoder_set_blocksize(encoder, streaminfo_.data.stream_info.min_blocksize))
185 return die_s_("returned false", encoder);
188 printf("testing FLAC__stream_encoder_set_max_lpc_order()... ");
189 if(!FLAC__stream_encoder_set_max_lpc_order(encoder, 0))
190 return die_s_("returned false", encoder);
193 printf("testing FLAC__stream_encoder_set_qlp_coeff_precision()... ");
194 if(!FLAC__stream_encoder_set_qlp_coeff_precision(encoder, 0))
195 return die_s_("returned false", encoder);
198 printf("testing FLAC__stream_encoder_set_do_qlp_coeff_prec_search()... ");
199 if(!FLAC__stream_encoder_set_do_qlp_coeff_prec_search(encoder, false))
200 return die_s_("returned false", encoder);
203 printf("testing FLAC__stream_encoder_set_do_escape_coding()... ");
204 if(!FLAC__stream_encoder_set_do_escape_coding(encoder, false))
205 return die_s_("returned false", encoder);
208 printf("testing FLAC__stream_encoder_set_do_exhaustive_model_search()... ");
209 if(!FLAC__stream_encoder_set_do_exhaustive_model_search(encoder, false))
210 return die_s_("returned false", encoder);
213 printf("testing FLAC__stream_encoder_set_min_residual_partition_order()... ");
214 if(!FLAC__stream_encoder_set_min_residual_partition_order(encoder, 0))
215 return die_s_("returned false", encoder);
218 printf("testing FLAC__stream_encoder_set_max_residual_partition_order()... ");
219 if(!FLAC__stream_encoder_set_max_residual_partition_order(encoder, 0))
220 return die_s_("returned false", encoder);
223 printf("testing FLAC__stream_encoder_set_rice_parameter_search_dist()... ");
224 if(!FLAC__stream_encoder_set_rice_parameter_search_dist(encoder, 0))
225 return die_s_("returned false", encoder);
228 printf("testing FLAC__stream_encoder_set_total_samples_estimate()... ");
229 if(!FLAC__stream_encoder_set_total_samples_estimate(encoder, streaminfo_.data.stream_info.total_samples))
230 return die_s_("returned false", encoder);
233 printf("testing FLAC__stream_encoder_set_metadata()... ");
234 if(!FLAC__stream_encoder_set_metadata(encoder, metadata_sequence_, num_metadata_))
235 return die_s_("returned false", encoder);
238 printf("testing FLAC__stream_encoder_set_write_callback()... ");
239 if(!FLAC__stream_encoder_set_write_callback(encoder, stream_encoder_write_callback_))
240 return die_s_("returned false", encoder);
243 printf("testing FLAC__stream_encoder_set_metadata_callback()... ");
244 if(!FLAC__stream_encoder_set_metadata_callback(encoder, stream_encoder_metadata_callback_))
245 return die_s_("returned false", encoder);
248 printf("testing FLAC__stream_encoder_set_client_data()... ");
249 if(!FLAC__stream_encoder_set_client_data(encoder, 0))
250 return die_s_("returned false", encoder);
253 printf("testing FLAC__stream_encoder_init()... ");
254 if(FLAC__stream_encoder_init(encoder) != FLAC__STREAM_ENCODER_OK)
255 return die_s_(0, encoder);
258 printf("testing FLAC__stream_encoder_get_state()... ");
259 state = FLAC__stream_encoder_get_state(encoder);
260 printf("returned state = %u (%s)... OK\n", (unsigned)state, FLAC__StreamEncoderStateString[state]);
262 printf("testing FLAC__stream_encoder_get_verify_decoder_state()... ");
263 dstate = FLAC__stream_encoder_get_verify_decoder_state(encoder);
264 printf("returned state = %u (%s)... OK\n", (unsigned)dstate, FLAC__StreamDecoderStateString[dstate]);
267 FLAC__uint64 absolute_sample;
268 unsigned frame_number;
271 FLAC__int32 expected;
274 printf("testing FLAC__stream_encoder_get_verify_decoder_error_stats()... ");
275 FLAC__stream_encoder_get_verify_decoder_error_stats(encoder, &absolute_sample, &frame_number, &channel, &sample, &expected, &got);
279 printf("testing FLAC__stream_encoder_get_verify()... ");
280 if(FLAC__stream_encoder_get_verify(encoder) != true) {
281 printf("FAILED, expected true, got false\n");
286 printf("testing FLAC__stream_encoder_get_streamable_subset()... ");
287 if(FLAC__stream_encoder_get_streamable_subset(encoder) != true) {
288 printf("FAILED, expected true, got false\n");
293 printf("testing FLAC__stream_encoder_get_do_mid_side_stereo()... ");
294 if(FLAC__stream_encoder_get_do_mid_side_stereo(encoder) != false) {
295 printf("FAILED, expected false, got true\n");
300 printf("testing FLAC__stream_encoder_get_loose_mid_side_stereo()... ");
301 if(FLAC__stream_encoder_get_loose_mid_side_stereo(encoder) != false) {
302 printf("FAILED, expected false, got true\n");
307 printf("testing FLAC__stream_encoder_get_channels()... ");
308 if(FLAC__stream_encoder_get_channels(encoder) != streaminfo_.data.stream_info.channels) {
309 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.channels, FLAC__stream_encoder_get_channels(encoder));
314 printf("testing FLAC__stream_encoder_get_bits_per_sample()... ");
315 if(FLAC__stream_encoder_get_bits_per_sample(encoder) != streaminfo_.data.stream_info.bits_per_sample) {
316 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.bits_per_sample, FLAC__stream_encoder_get_bits_per_sample(encoder));
321 printf("testing FLAC__stream_encoder_get_sample_rate()... ");
322 if(FLAC__stream_encoder_get_sample_rate(encoder) != streaminfo_.data.stream_info.sample_rate) {
323 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.sample_rate, FLAC__stream_encoder_get_sample_rate(encoder));
328 printf("testing FLAC__stream_encoder_get_blocksize()... ");
329 if(FLAC__stream_encoder_get_blocksize(encoder) != streaminfo_.data.stream_info.min_blocksize) {
330 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.min_blocksize, FLAC__stream_encoder_get_blocksize(encoder));
335 printf("testing FLAC__stream_encoder_get_max_lpc_order()... ");
336 if(FLAC__stream_encoder_get_max_lpc_order(encoder) != 0) {
337 printf("FAILED, expected %u, got %u\n", 0, FLAC__stream_encoder_get_max_lpc_order(encoder));
342 printf("testing FLAC__stream_encoder_get_qlp_coeff_precision()... ");
343 (void)FLAC__stream_encoder_get_qlp_coeff_precision(encoder);
344 /* we asked the encoder to auto select this so we accept anything */
347 printf("testing FLAC__stream_encoder_get_do_qlp_coeff_prec_search()... ");
348 if(FLAC__stream_encoder_get_do_qlp_coeff_prec_search(encoder) != false) {
349 printf("FAILED, expected false, got true\n");
354 printf("testing FLAC__stream_encoder_get_do_escape_coding()... ");
355 if(FLAC__stream_encoder_get_do_escape_coding(encoder) != false) {
356 printf("FAILED, expected false, got true\n");
361 printf("testing FLAC__stream_encoder_get_do_exhaustive_model_search()... ");
362 if(FLAC__stream_encoder_get_do_exhaustive_model_search(encoder) != false) {
363 printf("FAILED, expected false, got true\n");
368 printf("testing FLAC__stream_encoder_get_min_residual_partition_order()... ");
369 if(FLAC__stream_encoder_get_min_residual_partition_order(encoder) != 0) {
370 printf("FAILED, expected %u, got %u\n", 0, FLAC__stream_encoder_get_min_residual_partition_order(encoder));
375 printf("testing FLAC__stream_encoder_get_max_residual_partition_order()... ");
376 if(FLAC__stream_encoder_get_max_residual_partition_order(encoder) != 0) {
377 printf("FAILED, expected %u, got %u\n", 0, FLAC__stream_encoder_get_max_residual_partition_order(encoder));
382 printf("testing FLAC__stream_encoder_get_rice_parameter_search_dist()... ");
383 if(FLAC__stream_encoder_get_rice_parameter_search_dist(encoder) != 0) {
384 printf("FAILED, expected %u, got %u\n", 0, FLAC__stream_encoder_get_rice_parameter_search_dist(encoder));
389 printf("testing FLAC__stream_encoder_get_total_samples_estimate()... ");
390 if(FLAC__stream_encoder_get_total_samples_estimate(encoder) != streaminfo_.data.stream_info.total_samples) {
391 printf("FAILED, expected %llu, got %llu\n", streaminfo_.data.stream_info.total_samples, FLAC__stream_encoder_get_total_samples_estimate(encoder));
396 /* init the dummy sample buffer */
397 for(i = 0; i < sizeof(samples) / sizeof(FLAC__int32); i++)
400 printf("testing FLAC__stream_encoder_process()... ");
401 if(!FLAC__stream_encoder_process(encoder, (const FLAC__int32 * const *)samples_array, sizeof(samples) / sizeof(FLAC__int32)))
402 return die_s_("returned false", encoder);
405 printf("testing FLAC__stream_encoder_process_interleaved()... ");
406 if(!FLAC__stream_encoder_process_interleaved(encoder, samples, sizeof(samples) / sizeof(FLAC__int32)))
407 return die_s_("returned false", encoder);
410 printf("testing FLAC__stream_encoder_finish()... ");
411 FLAC__stream_encoder_finish(encoder);
414 printf("testing FLAC__stream_encoder_delete()... ");
415 FLAC__stream_encoder_delete(encoder);
418 printf("\nPASSED!\n");
423 FLAC__SeekableStreamEncoderSeekStatus seekable_stream_encoder_seek_callback_(const FLAC__SeekableStreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data)
425 (void)encoder, (void)absolute_byte_offset, (void)client_data;
426 return FLAC__SEEKABLE_STREAM_ENCODER_SEEK_STATUS_OK;
429 FLAC__SeekableStreamEncoderTellStatus seekable_stream_encoder_tell_callback_(const FLAC__SeekableStreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
431 (void)encoder, (void)client_data;
432 *absolute_byte_offset = 0;
433 return FLAC__SEEKABLE_STREAM_ENCODER_TELL_STATUS_OK;
436 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)
438 (void)encoder, (void)buffer, (void)bytes, (void)samples, (void)current_frame, (void)client_data;
439 return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
442 static FLAC__bool test_seekable_stream_encoder()
444 FLAC__SeekableStreamEncoder *encoder;
445 FLAC__SeekableStreamEncoderState state;
446 FLAC__StreamEncoderState state_;
447 FLAC__StreamDecoderState dstate;
448 FLAC__int32 samples[1024];
449 FLAC__int32 *samples_array[1];
452 samples_array[0] = samples;
454 printf("\n+++ libFLAC unit test: FLAC__SeekableStreamEncoder\n\n");
456 printf("testing FLAC__seekable_stream_encoder_new()... ");
457 encoder = FLAC__seekable_stream_encoder_new();
459 printf("FAILED, returned NULL\n");
464 printf("testing FLAC__seekable_stream_encoder_set_verify()... ");
465 if(!FLAC__seekable_stream_encoder_set_verify(encoder, true))
466 return die_ss_("returned false", encoder);
469 printf("testing FLAC__seekable_stream_encoder_set_streamable_subset()... ");
470 if(!FLAC__seekable_stream_encoder_set_streamable_subset(encoder, true))
471 return die_ss_("returned false", encoder);
474 printf("testing FLAC__seekable_stream_encoder_set_do_mid_side_stereo()... ");
475 if(!FLAC__seekable_stream_encoder_set_do_mid_side_stereo(encoder, false))
476 return die_ss_("returned false", encoder);
479 printf("testing FLAC__seekable_stream_encoder_set_loose_mid_side_stereo()... ");
480 if(!FLAC__seekable_stream_encoder_set_loose_mid_side_stereo(encoder, false))
481 return die_ss_("returned false", encoder);
484 printf("testing FLAC__seekable_stream_encoder_set_channels()... ");
485 if(!FLAC__seekable_stream_encoder_set_channels(encoder, streaminfo_.data.stream_info.channels))
486 return die_ss_("returned false", encoder);
489 printf("testing FLAC__seekable_stream_encoder_set_bits_per_sample()... ");
490 if(!FLAC__seekable_stream_encoder_set_bits_per_sample(encoder, streaminfo_.data.stream_info.bits_per_sample))
491 return die_ss_("returned false", encoder);
494 printf("testing FLAC__seekable_stream_encoder_set_sample_rate()... ");
495 if(!FLAC__seekable_stream_encoder_set_sample_rate(encoder, streaminfo_.data.stream_info.sample_rate))
496 return die_ss_("returned false", encoder);
499 printf("testing FLAC__seekable_stream_encoder_set_blocksize()... ");
500 if(!FLAC__seekable_stream_encoder_set_blocksize(encoder, streaminfo_.data.stream_info.min_blocksize))
501 return die_ss_("returned false", encoder);
504 printf("testing FLAC__seekable_stream_encoder_set_max_lpc_order()... ");
505 if(!FLAC__seekable_stream_encoder_set_max_lpc_order(encoder, 0))
506 return die_ss_("returned false", encoder);
509 printf("testing FLAC__seekable_stream_encoder_set_qlp_coeff_precision()... ");
510 if(!FLAC__seekable_stream_encoder_set_qlp_coeff_precision(encoder, 0))
511 return die_ss_("returned false", encoder);
514 printf("testing FLAC__seekable_stream_encoder_set_do_qlp_coeff_prec_search()... ");
515 if(!FLAC__seekable_stream_encoder_set_do_qlp_coeff_prec_search(encoder, false))
516 return die_ss_("returned false", encoder);
519 printf("testing FLAC__seekable_stream_encoder_set_do_escape_coding()... ");
520 if(!FLAC__seekable_stream_encoder_set_do_escape_coding(encoder, false))
521 return die_ss_("returned false", encoder);
524 printf("testing FLAC__seekable_stream_encoder_set_do_exhaustive_model_search()... ");
525 if(!FLAC__seekable_stream_encoder_set_do_exhaustive_model_search(encoder, false))
526 return die_ss_("returned false", encoder);
529 printf("testing FLAC__seekable_stream_encoder_set_min_residual_partition_order()... ");
530 if(!FLAC__seekable_stream_encoder_set_min_residual_partition_order(encoder, 0))
531 return die_ss_("returned false", encoder);
534 printf("testing FLAC__seekable_stream_encoder_set_max_residual_partition_order()... ");
535 if(!FLAC__seekable_stream_encoder_set_max_residual_partition_order(encoder, 0))
536 return die_ss_("returned false", encoder);
539 printf("testing FLAC__seekable_stream_encoder_set_rice_parameter_search_dist()... ");
540 if(!FLAC__seekable_stream_encoder_set_rice_parameter_search_dist(encoder, 0))
541 return die_ss_("returned false", encoder);
544 printf("testing FLAC__seekable_stream_encoder_set_total_samples_estimate()... ");
545 if(!FLAC__seekable_stream_encoder_set_total_samples_estimate(encoder, streaminfo_.data.stream_info.total_samples))
546 return die_ss_("returned false", encoder);
549 printf("testing FLAC__seekable_stream_encoder_set_metadata()... ");
550 if(!FLAC__seekable_stream_encoder_set_metadata(encoder, metadata_sequence_, num_metadata_))
551 return die_ss_("returned false", encoder);
554 printf("testing FLAC__seekable_stream_encoder_set_seek_callback()... ");
555 if(!FLAC__seekable_stream_encoder_set_seek_callback(encoder, seekable_stream_encoder_seek_callback_))
556 return die_ss_("returned false", encoder);
559 printf("testing FLAC__seekable_stream_encoder_set_tell_callback()... ");
560 if(!FLAC__seekable_stream_encoder_set_tell_callback(encoder, seekable_stream_encoder_tell_callback_))
561 return die_ss_("returned false", encoder);
564 printf("testing FLAC__seekable_stream_encoder_set_write_callback()... ");
565 if(!FLAC__seekable_stream_encoder_set_write_callback(encoder, seekable_stream_encoder_write_callback_))
566 return die_ss_("returned false", encoder);
569 printf("testing FLAC__seekable_stream_encoder_set_client_data()... ");
570 if(!FLAC__seekable_stream_encoder_set_client_data(encoder, 0))
571 return die_ss_("returned false", encoder);
574 printf("testing FLAC__seekable_stream_encoder_init()... ");
575 if(FLAC__seekable_stream_encoder_init(encoder) != FLAC__SEEKABLE_STREAM_ENCODER_OK)
576 return die_ss_(0, encoder);
579 printf("testing FLAC__seekable_stream_encoder_get_state()... ");
580 state = FLAC__seekable_stream_encoder_get_state(encoder);
581 printf("returned state = %u (%s)... OK\n", (unsigned)state, FLAC__SeekableStreamEncoderStateString[state]);
583 printf("testing FLAC__seekable_stream_encoder_get_stream_encoder_state()... ");
584 state_ = FLAC__seekable_stream_encoder_get_stream_encoder_state(encoder);
585 printf("returned state = %u (%s)... OK\n", (unsigned)state_, FLAC__StreamEncoderStateString[state_]);
587 printf("testing FLAC__seekable_stream_encoder_get_verify_decoder_state()... ");
588 dstate = FLAC__seekable_stream_encoder_get_verify_decoder_state(encoder);
589 printf("returned state = %u (%s)... OK\n", (unsigned)dstate, FLAC__StreamDecoderStateString[dstate]);
592 FLAC__uint64 absolute_sample;
593 unsigned frame_number;
596 FLAC__int32 expected;
599 printf("testing FLAC__seekable_stream_encoder_get_verify_decoder_error_stats()... ");
600 FLAC__seekable_stream_encoder_get_verify_decoder_error_stats(encoder, &absolute_sample, &frame_number, &channel, &sample, &expected, &got);
604 printf("testing FLAC__seekable_stream_encoder_get_verify()... ");
605 if(FLAC__seekable_stream_encoder_get_verify(encoder) != true) {
606 printf("FAILED, expected true, got false\n");
611 printf("testing FLAC__seekable_stream_encoder_get_streamable_subset()... ");
612 if(FLAC__seekable_stream_encoder_get_streamable_subset(encoder) != true) {
613 printf("FAILED, expected true, got false\n");
618 printf("testing FLAC__seekable_stream_encoder_get_do_mid_side_stereo()... ");
619 if(FLAC__seekable_stream_encoder_get_do_mid_side_stereo(encoder) != false) {
620 printf("FAILED, expected false, got true\n");
625 printf("testing FLAC__seekable_stream_encoder_get_loose_mid_side_stereo()... ");
626 if(FLAC__seekable_stream_encoder_get_loose_mid_side_stereo(encoder) != false) {
627 printf("FAILED, expected false, got true\n");
632 printf("testing FLAC__seekable_stream_encoder_get_channels()... ");
633 if(FLAC__seekable_stream_encoder_get_channels(encoder) != streaminfo_.data.stream_info.channels) {
634 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.channels, FLAC__seekable_stream_encoder_get_channels(encoder));
639 printf("testing FLAC__seekable_stream_encoder_get_bits_per_sample()... ");
640 if(FLAC__seekable_stream_encoder_get_bits_per_sample(encoder) != streaminfo_.data.stream_info.bits_per_sample) {
641 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.bits_per_sample, FLAC__seekable_stream_encoder_get_bits_per_sample(encoder));
646 printf("testing FLAC__seekable_stream_encoder_get_sample_rate()... ");
647 if(FLAC__seekable_stream_encoder_get_sample_rate(encoder) != streaminfo_.data.stream_info.sample_rate) {
648 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.sample_rate, FLAC__seekable_stream_encoder_get_sample_rate(encoder));
653 printf("testing FLAC__seekable_stream_encoder_get_blocksize()... ");
654 if(FLAC__seekable_stream_encoder_get_blocksize(encoder) != streaminfo_.data.stream_info.min_blocksize) {
655 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.min_blocksize, FLAC__seekable_stream_encoder_get_blocksize(encoder));
660 printf("testing FLAC__seekable_stream_encoder_get_max_lpc_order()... ");
661 if(FLAC__seekable_stream_encoder_get_max_lpc_order(encoder) != 0) {
662 printf("FAILED, expected %u, got %u\n", 0, FLAC__seekable_stream_encoder_get_max_lpc_order(encoder));
667 printf("testing FLAC__seekable_stream_encoder_get_qlp_coeff_precision()... ");
668 (void)FLAC__seekable_stream_encoder_get_qlp_coeff_precision(encoder);
669 /* we asked the encoder to auto select this so we accept anything */
672 printf("testing FLAC__seekable_stream_encoder_get_do_qlp_coeff_prec_search()... ");
673 if(FLAC__seekable_stream_encoder_get_do_qlp_coeff_prec_search(encoder) != false) {
674 printf("FAILED, expected false, got true\n");
679 printf("testing FLAC__seekable_stream_encoder_get_do_escape_coding()... ");
680 if(FLAC__seekable_stream_encoder_get_do_escape_coding(encoder) != false) {
681 printf("FAILED, expected false, got true\n");
686 printf("testing FLAC__seekable_stream_encoder_get_do_exhaustive_model_search()... ");
687 if(FLAC__seekable_stream_encoder_get_do_exhaustive_model_search(encoder) != false) {
688 printf("FAILED, expected false, got true\n");
693 printf("testing FLAC__seekable_stream_encoder_get_min_residual_partition_order()... ");
694 if(FLAC__seekable_stream_encoder_get_min_residual_partition_order(encoder) != 0) {
695 printf("FAILED, expected %u, got %u\n", 0, FLAC__seekable_stream_encoder_get_min_residual_partition_order(encoder));
700 printf("testing FLAC__seekable_stream_encoder_get_max_residual_partition_order()... ");
701 if(FLAC__seekable_stream_encoder_get_max_residual_partition_order(encoder) != 0) {
702 printf("FAILED, expected %u, got %u\n", 0, FLAC__seekable_stream_encoder_get_max_residual_partition_order(encoder));
707 printf("testing FLAC__seekable_stream_encoder_get_rice_parameter_search_dist()... ");
708 if(FLAC__seekable_stream_encoder_get_rice_parameter_search_dist(encoder) != 0) {
709 printf("FAILED, expected %u, got %u\n", 0, FLAC__seekable_stream_encoder_get_rice_parameter_search_dist(encoder));
714 printf("testing FLAC__seekable_stream_encoder_get_total_samples_estimate()... ");
715 if(FLAC__seekable_stream_encoder_get_total_samples_estimate(encoder) != streaminfo_.data.stream_info.total_samples) {
716 printf("FAILED, expected %llu, got %llu\n", streaminfo_.data.stream_info.total_samples, FLAC__seekable_stream_encoder_get_total_samples_estimate(encoder));
721 /* init the dummy sample buffer */
722 for(i = 0; i < sizeof(samples) / sizeof(FLAC__int32); i++)
725 printf("testing FLAC__seekable_stream_encoder_process()... ");
726 if(!FLAC__seekable_stream_encoder_process(encoder, (const FLAC__int32 * const *)samples_array, sizeof(samples) / sizeof(FLAC__int32)))
727 return die_ss_("returned false", encoder);
730 printf("testing FLAC__seekable_stream_encoder_process_interleaved()... ");
731 if(!FLAC__seekable_stream_encoder_process_interleaved(encoder, samples, sizeof(samples) / sizeof(FLAC__int32)))
732 return die_ss_("returned false", encoder);
735 printf("testing FLAC__seekable_stream_encoder_finish()... ");
736 FLAC__seekable_stream_encoder_finish(encoder);
739 printf("testing FLAC__seekable_stream_encoder_delete()... ");
740 FLAC__seekable_stream_encoder_delete(encoder);
743 printf("\nPASSED!\n");
748 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)
750 (void)encoder, (void)bytes_written, (void)samples_written, (void)frames_written, (void)total_frames_estimate, (void)client_data;
753 static FLAC__bool test_file_encoder()
755 FLAC__FileEncoder *encoder;
756 FLAC__FileEncoderState state;
757 FLAC__SeekableStreamEncoderState state_;
758 FLAC__StreamEncoderState state__;
759 FLAC__StreamDecoderState dstate;
760 FLAC__int32 samples[1024];
761 FLAC__int32 *samples_array[1];
764 samples_array[0] = samples;
766 printf("\n+++ libFLAC unit test: FLAC__FileEncoder\n\n");
768 printf("testing FLAC__file_encoder_new()... ");
769 encoder = FLAC__file_encoder_new();
771 printf("FAILED, returned NULL\n");
776 printf("testing FLAC__file_encoder_set_verify()... ");
777 if(!FLAC__file_encoder_set_verify(encoder, true))
778 return die_f_("returned false", encoder);
781 printf("testing FLAC__file_encoder_set_streamable_subset()... ");
782 if(!FLAC__file_encoder_set_streamable_subset(encoder, true))
783 return die_f_("returned false", encoder);
786 printf("testing FLAC__file_encoder_set_do_mid_side_stereo()... ");
787 if(!FLAC__file_encoder_set_do_mid_side_stereo(encoder, false))
788 return die_f_("returned false", encoder);
791 printf("testing FLAC__file_encoder_set_loose_mid_side_stereo()... ");
792 if(!FLAC__file_encoder_set_loose_mid_side_stereo(encoder, false))
793 return die_f_("returned false", encoder);
796 printf("testing FLAC__file_encoder_set_channels()... ");
797 if(!FLAC__file_encoder_set_channels(encoder, streaminfo_.data.stream_info.channels))
798 return die_f_("returned false", encoder);
801 printf("testing FLAC__file_encoder_set_bits_per_sample()... ");
802 if(!FLAC__file_encoder_set_bits_per_sample(encoder, streaminfo_.data.stream_info.bits_per_sample))
803 return die_f_("returned false", encoder);
806 printf("testing FLAC__file_encoder_set_sample_rate()... ");
807 if(!FLAC__file_encoder_set_sample_rate(encoder, streaminfo_.data.stream_info.sample_rate))
808 return die_f_("returned false", encoder);
811 printf("testing FLAC__file_encoder_set_blocksize()... ");
812 if(!FLAC__file_encoder_set_blocksize(encoder, streaminfo_.data.stream_info.min_blocksize))
813 return die_f_("returned false", encoder);
816 printf("testing FLAC__file_encoder_set_max_lpc_order()... ");
817 if(!FLAC__file_encoder_set_max_lpc_order(encoder, 0))
818 return die_f_("returned false", encoder);
821 printf("testing FLAC__file_encoder_set_qlp_coeff_precision()... ");
822 if(!FLAC__file_encoder_set_qlp_coeff_precision(encoder, 0))
823 return die_f_("returned false", encoder);
826 printf("testing FLAC__file_encoder_set_do_qlp_coeff_prec_search()... ");
827 if(!FLAC__file_encoder_set_do_qlp_coeff_prec_search(encoder, false))
828 return die_f_("returned false", encoder);
831 printf("testing FLAC__file_encoder_set_do_escape_coding()... ");
832 if(!FLAC__file_encoder_set_do_escape_coding(encoder, false))
833 return die_f_("returned false", encoder);
836 printf("testing FLAC__file_encoder_set_do_exhaustive_model_search()... ");
837 if(!FLAC__file_encoder_set_do_exhaustive_model_search(encoder, false))
838 return die_f_("returned false", encoder);
841 printf("testing FLAC__file_encoder_set_min_residual_partition_order()... ");
842 if(!FLAC__file_encoder_set_min_residual_partition_order(encoder, 0))
843 return die_f_("returned false", encoder);
846 printf("testing FLAC__file_encoder_set_max_residual_partition_order()... ");
847 if(!FLAC__file_encoder_set_max_residual_partition_order(encoder, 0))
848 return die_f_("returned false", encoder);
851 printf("testing FLAC__file_encoder_set_rice_parameter_search_dist()... ");
852 if(!FLAC__file_encoder_set_rice_parameter_search_dist(encoder, 0))
853 return die_f_("returned false", encoder);
856 printf("testing FLAC__file_encoder_set_total_samples_estimate()... ");
857 if(!FLAC__file_encoder_set_total_samples_estimate(encoder, streaminfo_.data.stream_info.total_samples))
858 return die_f_("returned false", encoder);
861 printf("testing FLAC__file_encoder_set_metadata()... ");
862 if(!FLAC__file_encoder_set_metadata(encoder, metadata_sequence_, num_metadata_))
863 return die_f_("returned false", encoder);
866 printf("testing FLAC__file_encoder_set_filename()... ");
867 if(!FLAC__file_encoder_set_filename(encoder, flacfilename_))
868 return die_f_("returned false", encoder);
871 printf("testing FLAC__file_encoder_set_progress_callback()... ");
872 if(!FLAC__file_encoder_set_progress_callback(encoder, file_encoder_progress_callback_))
873 return die_f_("returned false", encoder);
876 printf("testing FLAC__file_encoder_set_client_data()... ");
877 if(!FLAC__file_encoder_set_client_data(encoder, 0))
878 return die_f_("returned false", encoder);
881 printf("testing FLAC__file_encoder_init()... ");
882 if(FLAC__file_encoder_init(encoder) != FLAC__FILE_ENCODER_OK)
883 return die_f_(0, encoder);
886 printf("testing FLAC__file_encoder_get_state()... ");
887 state = FLAC__file_encoder_get_state(encoder);
888 printf("returned state = %u (%s)... OK\n", (unsigned)state, FLAC__FileEncoderStateString[state]);
890 printf("testing FLAC__file_encoder_get_seekable_stream_encoder_state()... ");
891 state_ = FLAC__file_encoder_get_seekable_stream_encoder_state(encoder);
892 printf("returned state = %u (%s)... OK\n", (unsigned)state_, FLAC__SeekableStreamEncoderStateString[state_]);
894 printf("testing FLAC__file_encoder_get_stream_encoder_state()... ");
895 state__ = FLAC__file_encoder_get_stream_encoder_state(encoder);
896 printf("returned state = %u (%s)... OK\n", (unsigned)state__, FLAC__StreamEncoderStateString[state__]);
898 printf("testing FLAC__file_encoder_get_verify_decoder_state()... ");
899 dstate = FLAC__file_encoder_get_verify_decoder_state(encoder);
900 printf("returned state = %u (%s)... OK\n", (unsigned)dstate, FLAC__StreamDecoderStateString[dstate]);
903 FLAC__uint64 absolute_sample;
904 unsigned frame_number;
907 FLAC__int32 expected;
910 printf("testing FLAC__file_encoder_get_verify_decoder_error_stats()... ");
911 FLAC__file_encoder_get_verify_decoder_error_stats(encoder, &absolute_sample, &frame_number, &channel, &sample, &expected, &got);
915 printf("testing FLAC__file_encoder_get_verify()... ");
916 if(FLAC__file_encoder_get_verify(encoder) != true) {
917 printf("FAILED, expected true, got false\n");
922 printf("testing FLAC__file_encoder_get_streamable_subset()... ");
923 if(FLAC__file_encoder_get_streamable_subset(encoder) != true) {
924 printf("FAILED, expected true, got false\n");
929 printf("testing FLAC__file_encoder_get_do_mid_side_stereo()... ");
930 if(FLAC__file_encoder_get_do_mid_side_stereo(encoder) != false) {
931 printf("FAILED, expected false, got true\n");
936 printf("testing FLAC__file_encoder_get_loose_mid_side_stereo()... ");
937 if(FLAC__file_encoder_get_loose_mid_side_stereo(encoder) != false) {
938 printf("FAILED, expected false, got true\n");
943 printf("testing FLAC__file_encoder_get_channels()... ");
944 if(FLAC__file_encoder_get_channels(encoder) != streaminfo_.data.stream_info.channels) {
945 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.channels, FLAC__file_encoder_get_channels(encoder));
950 printf("testing FLAC__file_encoder_get_bits_per_sample()... ");
951 if(FLAC__file_encoder_get_bits_per_sample(encoder) != streaminfo_.data.stream_info.bits_per_sample) {
952 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.bits_per_sample, FLAC__file_encoder_get_bits_per_sample(encoder));
957 printf("testing FLAC__file_encoder_get_sample_rate()... ");
958 if(FLAC__file_encoder_get_sample_rate(encoder) != streaminfo_.data.stream_info.sample_rate) {
959 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.sample_rate, FLAC__file_encoder_get_sample_rate(encoder));
964 printf("testing FLAC__file_encoder_get_blocksize()... ");
965 if(FLAC__file_encoder_get_blocksize(encoder) != streaminfo_.data.stream_info.min_blocksize) {
966 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.min_blocksize, FLAC__file_encoder_get_blocksize(encoder));
971 printf("testing FLAC__file_encoder_get_max_lpc_order()... ");
972 if(FLAC__file_encoder_get_max_lpc_order(encoder) != 0) {
973 printf("FAILED, expected %u, got %u\n", 0, FLAC__file_encoder_get_max_lpc_order(encoder));
978 printf("testing FLAC__file_encoder_get_qlp_coeff_precision()... ");
979 (void)FLAC__file_encoder_get_qlp_coeff_precision(encoder);
980 /* we asked the encoder to auto select this so we accept anything */
983 printf("testing FLAC__file_encoder_get_do_qlp_coeff_prec_search()... ");
984 if(FLAC__file_encoder_get_do_qlp_coeff_prec_search(encoder) != false) {
985 printf("FAILED, expected false, got true\n");
990 printf("testing FLAC__file_encoder_get_do_escape_coding()... ");
991 if(FLAC__file_encoder_get_do_escape_coding(encoder) != false) {
992 printf("FAILED, expected false, got true\n");
997 printf("testing FLAC__file_encoder_get_do_exhaustive_model_search()... ");
998 if(FLAC__file_encoder_get_do_exhaustive_model_search(encoder) != false) {
999 printf("FAILED, expected false, got true\n");
1004 printf("testing FLAC__file_encoder_get_min_residual_partition_order()... ");
1005 if(FLAC__file_encoder_get_min_residual_partition_order(encoder) != 0) {
1006 printf("FAILED, expected %u, got %u\n", 0, FLAC__file_encoder_get_min_residual_partition_order(encoder));
1011 printf("testing FLAC__file_encoder_get_max_residual_partition_order()... ");
1012 if(FLAC__file_encoder_get_max_residual_partition_order(encoder) != 0) {
1013 printf("FAILED, expected %u, got %u\n", 0, FLAC__file_encoder_get_max_residual_partition_order(encoder));
1018 printf("testing FLAC__file_encoder_get_rice_parameter_search_dist()... ");
1019 if(FLAC__file_encoder_get_rice_parameter_search_dist(encoder) != 0) {
1020 printf("FAILED, expected %u, got %u\n", 0, FLAC__file_encoder_get_rice_parameter_search_dist(encoder));
1025 printf("testing FLAC__file_encoder_get_total_samples_estimate()... ");
1026 if(FLAC__file_encoder_get_total_samples_estimate(encoder) != streaminfo_.data.stream_info.total_samples) {
1027 printf("FAILED, expected %llu, got %llu\n", streaminfo_.data.stream_info.total_samples, FLAC__file_encoder_get_total_samples_estimate(encoder));
1032 /* init the dummy sample buffer */
1033 for(i = 0; i < sizeof(samples) / sizeof(FLAC__int32); i++)
1036 printf("testing FLAC__file_encoder_process()... ");
1037 if(!FLAC__file_encoder_process(encoder, (const FLAC__int32 * const *)samples_array, sizeof(samples) / sizeof(FLAC__int32)))
1038 return die_f_("returned false", encoder);
1041 printf("testing FLAC__file_encoder_process_interleaved()... ");
1042 if(!FLAC__file_encoder_process_interleaved(encoder, samples, sizeof(samples) / sizeof(FLAC__int32)))
1043 return die_f_("returned false", encoder);
1046 printf("testing FLAC__file_encoder_finish()... ");
1047 FLAC__file_encoder_finish(encoder);
1050 printf("testing FLAC__file_encoder_delete()... ");
1051 FLAC__file_encoder_delete(encoder);
1054 printf("\nPASSED!\n");
1059 FLAC__bool test_encoders()
1061 init_metadata_blocks_();
1063 if(!test_stream_encoder())
1066 if(!test_seekable_stream_encoder())
1069 if(!test_file_encoder())
1072 (void) grabbag__file_remove_file(flacfilename_);
1073 free_metadata_blocks_();