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];
132 samples_array[0] = samples;
134 printf("\n+++ libFLAC unit test: FLAC__StreamEncoder\n\n");
136 printf("testing FLAC__stream_encoder_new()... ");
137 encoder = FLAC__stream_encoder_new();
139 printf("FAILED, returned NULL\n");
144 printf("testing FLAC__stream_encoder_set_verify()... ");
145 if(!FLAC__stream_encoder_set_verify(encoder, true))
146 return die_s_("returned false", encoder);
149 printf("testing FLAC__stream_encoder_set_streamable_subset()... ");
150 if(!FLAC__stream_encoder_set_streamable_subset(encoder, true))
151 return die_s_("returned false", encoder);
154 printf("testing FLAC__stream_encoder_set_do_mid_side_stereo()... ");
155 if(!FLAC__stream_encoder_set_do_mid_side_stereo(encoder, false))
156 return die_s_("returned false", encoder);
159 printf("testing FLAC__stream_encoder_set_loose_mid_side_stereo()... ");
160 if(!FLAC__stream_encoder_set_loose_mid_side_stereo(encoder, false))
161 return die_s_("returned false", encoder);
164 printf("testing FLAC__stream_encoder_set_channels()... ");
165 if(!FLAC__stream_encoder_set_channels(encoder, streaminfo_.data.stream_info.channels))
166 return die_s_("returned false", encoder);
169 printf("testing FLAC__stream_encoder_set_bits_per_sample()... ");
170 if(!FLAC__stream_encoder_set_bits_per_sample(encoder, streaminfo_.data.stream_info.bits_per_sample))
171 return die_s_("returned false", encoder);
174 printf("testing FLAC__stream_encoder_set_sample_rate()... ");
175 if(!FLAC__stream_encoder_set_sample_rate(encoder, streaminfo_.data.stream_info.sample_rate))
176 return die_s_("returned false", encoder);
179 printf("testing FLAC__stream_encoder_set_blocksize()... ");
180 if(!FLAC__stream_encoder_set_blocksize(encoder, streaminfo_.data.stream_info.min_blocksize))
181 return die_s_("returned false", encoder);
184 printf("testing FLAC__stream_encoder_set_max_lpc_order()... ");
185 if(!FLAC__stream_encoder_set_max_lpc_order(encoder, 0))
186 return die_s_("returned false", encoder);
189 printf("testing FLAC__stream_encoder_set_qlp_coeff_precision()... ");
190 if(!FLAC__stream_encoder_set_qlp_coeff_precision(encoder, 0))
191 return die_s_("returned false", encoder);
194 printf("testing FLAC__stream_encoder_set_do_qlp_coeff_prec_search()... ");
195 if(!FLAC__stream_encoder_set_do_qlp_coeff_prec_search(encoder, false))
196 return die_s_("returned false", encoder);
199 printf("testing FLAC__stream_encoder_set_do_escape_coding()... ");
200 if(!FLAC__stream_encoder_set_do_escape_coding(encoder, false))
201 return die_s_("returned false", encoder);
204 printf("testing FLAC__stream_encoder_set_do_exhaustive_model_search()... ");
205 if(!FLAC__stream_encoder_set_do_exhaustive_model_search(encoder, false))
206 return die_s_("returned false", encoder);
209 printf("testing FLAC__stream_encoder_set_min_residual_partition_order()... ");
210 if(!FLAC__stream_encoder_set_min_residual_partition_order(encoder, 0))
211 return die_s_("returned false", encoder);
214 printf("testing FLAC__stream_encoder_set_max_residual_partition_order()... ");
215 if(!FLAC__stream_encoder_set_max_residual_partition_order(encoder, 0))
216 return die_s_("returned false", encoder);
219 printf("testing FLAC__stream_encoder_set_rice_parameter_search_dist()... ");
220 if(!FLAC__stream_encoder_set_rice_parameter_search_dist(encoder, 0))
221 return die_s_("returned false", encoder);
224 printf("testing FLAC__stream_encoder_set_total_samples_estimate()... ");
225 if(!FLAC__stream_encoder_set_total_samples_estimate(encoder, streaminfo_.data.stream_info.total_samples))
226 return die_s_("returned false", encoder);
229 printf("testing FLAC__stream_encoder_set_metadata()... ");
230 if(!FLAC__stream_encoder_set_metadata(encoder, metadata_sequence_, num_metadata_))
231 return die_s_("returned false", encoder);
234 printf("testing FLAC__stream_encoder_set_write_callback()... ");
235 if(!FLAC__stream_encoder_set_write_callback(encoder, stream_encoder_write_callback_))
236 return die_s_("returned false", encoder);
239 printf("testing FLAC__stream_encoder_set_metadata_callback()... ");
240 if(!FLAC__stream_encoder_set_metadata_callback(encoder, stream_encoder_metadata_callback_))
241 return die_s_("returned false", encoder);
244 printf("testing FLAC__stream_encoder_set_client_data()... ");
245 if(!FLAC__stream_encoder_set_client_data(encoder, 0))
246 return die_s_("returned false", encoder);
249 printf("testing FLAC__stream_encoder_init()... ");
250 if(FLAC__stream_encoder_init(encoder) != FLAC__STREAM_ENCODER_OK)
251 return die_s_(0, encoder);
254 printf("testing FLAC__stream_encoder_get_state()... ");
255 state = FLAC__stream_encoder_get_state(encoder);
256 printf("returned state = %u (%s)... OK\n", (unsigned)state, FLAC__StreamEncoderStateString[state]);
258 printf("testing FLAC__stream_encoder_get_verify_decoder_state()... ");
259 dstate = FLAC__stream_encoder_get_verify_decoder_state(encoder);
260 printf("returned state = %u (%s)... OK\n", (unsigned)dstate, FLAC__StreamDecoderStateString[dstate]);
263 FLAC__uint64 absolute_sample;
264 unsigned frame_number;
267 FLAC__int32 expected;
270 printf("testing FLAC__stream_encoder_get_verify_decoder_error_stats()... ");
271 FLAC__stream_encoder_get_verify_decoder_error_stats(encoder, &absolute_sample, &frame_number, &channel, &sample, &expected, &got);
275 printf("testing FLAC__stream_encoder_get_verify()... ");
276 if(FLAC__stream_encoder_get_verify(encoder) != true) {
277 printf("FAILED, expected true, got false\n");
282 printf("testing FLAC__stream_encoder_get_streamable_subset()... ");
283 if(FLAC__stream_encoder_get_streamable_subset(encoder) != true) {
284 printf("FAILED, expected true, got false\n");
289 printf("testing FLAC__stream_encoder_get_do_mid_side_stereo()... ");
290 if(FLAC__stream_encoder_get_do_mid_side_stereo(encoder) != false) {
291 printf("FAILED, expected false, got true\n");
296 printf("testing FLAC__stream_encoder_get_loose_mid_side_stereo()... ");
297 if(FLAC__stream_encoder_get_loose_mid_side_stereo(encoder) != false) {
298 printf("FAILED, expected false, got true\n");
303 printf("testing FLAC__stream_encoder_get_channels()... ");
304 if(FLAC__stream_encoder_get_channels(encoder) != streaminfo_.data.stream_info.channels) {
305 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.channels, FLAC__stream_encoder_get_channels(encoder));
310 printf("testing FLAC__stream_encoder_get_bits_per_sample()... ");
311 if(FLAC__stream_encoder_get_bits_per_sample(encoder) != streaminfo_.data.stream_info.bits_per_sample) {
312 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.bits_per_sample, FLAC__stream_encoder_get_bits_per_sample(encoder));
317 printf("testing FLAC__stream_encoder_get_sample_rate()... ");
318 if(FLAC__stream_encoder_get_sample_rate(encoder) != streaminfo_.data.stream_info.sample_rate) {
319 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.sample_rate, FLAC__stream_encoder_get_sample_rate(encoder));
324 printf("testing FLAC__stream_encoder_get_blocksize()... ");
325 if(FLAC__stream_encoder_get_blocksize(encoder) != streaminfo_.data.stream_info.min_blocksize) {
326 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.min_blocksize, FLAC__stream_encoder_get_blocksize(encoder));
331 printf("testing FLAC__stream_encoder_get_max_lpc_order()... ");
332 if(FLAC__stream_encoder_get_max_lpc_order(encoder) != 0) {
333 printf("FAILED, expected %u, got %u\n", 0, FLAC__stream_encoder_get_max_lpc_order(encoder));
338 printf("testing FLAC__stream_encoder_get_qlp_coeff_precision()... ");
339 (void)FLAC__stream_encoder_get_qlp_coeff_precision(encoder);
340 /* we asked the encoder to auto select this so we accept anything */
343 printf("testing FLAC__stream_encoder_get_do_qlp_coeff_prec_search()... ");
344 if(FLAC__stream_encoder_get_do_qlp_coeff_prec_search(encoder) != false) {
345 printf("FAILED, expected false, got true\n");
350 printf("testing FLAC__stream_encoder_get_do_escape_coding()... ");
351 if(FLAC__stream_encoder_get_do_escape_coding(encoder) != false) {
352 printf("FAILED, expected false, got true\n");
357 printf("testing FLAC__stream_encoder_get_do_exhaustive_model_search()... ");
358 if(FLAC__stream_encoder_get_do_exhaustive_model_search(encoder) != false) {
359 printf("FAILED, expected false, got true\n");
364 printf("testing FLAC__stream_encoder_get_min_residual_partition_order()... ");
365 if(FLAC__stream_encoder_get_min_residual_partition_order(encoder) != 0) {
366 printf("FAILED, expected %u, got %u\n", 0, FLAC__stream_encoder_get_min_residual_partition_order(encoder));
371 printf("testing FLAC__stream_encoder_get_max_residual_partition_order()... ");
372 if(FLAC__stream_encoder_get_max_residual_partition_order(encoder) != 0) {
373 printf("FAILED, expected %u, got %u\n", 0, FLAC__stream_encoder_get_max_residual_partition_order(encoder));
378 printf("testing FLAC__stream_encoder_get_rice_parameter_search_dist()... ");
379 if(FLAC__stream_encoder_get_rice_parameter_search_dist(encoder) != 0) {
380 printf("FAILED, expected %u, got %u\n", 0, FLAC__stream_encoder_get_rice_parameter_search_dist(encoder));
385 printf("testing FLAC__stream_encoder_get_total_samples_estimate()... ");
386 if(FLAC__stream_encoder_get_total_samples_estimate(encoder) != streaminfo_.data.stream_info.total_samples) {
387 printf("FAILED, expected %llu, got %llu\n", streaminfo_.data.stream_info.total_samples, FLAC__stream_encoder_get_total_samples_estimate(encoder));
392 /* init the dummy sample buffer */
393 for(i = 0; i < sizeof(samples) / sizeof(FLAC__int32); i++)
396 printf("testing FLAC__stream_encoder_process()... ");
397 if(!FLAC__stream_encoder_process(encoder, (const FLAC__int32 * const *)samples_array, sizeof(samples) / sizeof(FLAC__int32)))
398 return die_s_("returned false", encoder);
401 printf("testing FLAC__stream_encoder_process_interleaved()... ");
402 if(!FLAC__stream_encoder_process_interleaved(encoder, samples, sizeof(samples) / sizeof(FLAC__int32)))
403 return die_s_("returned false", encoder);
406 printf("testing FLAC__stream_encoder_finish()... ");
407 FLAC__stream_encoder_finish(encoder);
410 printf("testing FLAC__stream_encoder_delete()... ");
411 FLAC__stream_encoder_delete(encoder);
414 printf("\nPASSED!\n");
419 FLAC__SeekableStreamEncoderSeekStatus seekable_stream_encoder_seek_callback_(const FLAC__SeekableStreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data)
421 (void)encoder, (void)absolute_byte_offset, (void)client_data;
422 return FLAC__SEEKABLE_STREAM_ENCODER_SEEK_STATUS_OK;
425 FLAC__SeekableStreamEncoderTellStatus seekable_stream_encoder_tell_callback_(const FLAC__SeekableStreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
427 (void)encoder, (void)absolute_byte_offset, (void)client_data;
428 return FLAC__SEEKABLE_STREAM_ENCODER_TELL_STATUS_OK;
431 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)
433 (void)encoder, (void)buffer, (void)bytes, (void)samples, (void)current_frame, (void)client_data;
434 return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
437 static FLAC__bool test_seekable_stream_encoder()
439 FLAC__SeekableStreamEncoder *encoder;
440 FLAC__SeekableStreamEncoderState state;
441 FLAC__StreamEncoderState state_;
442 FLAC__StreamDecoderState dstate;
443 FLAC__int32 samples[1024];
444 FLAC__int32 *samples_array[1];
447 samples_array[0] = samples;
449 printf("\n+++ libFLAC unit test: FLAC__SeekableStreamEncoder\n\n");
451 printf("testing FLAC__seekable_stream_encoder_new()... ");
452 encoder = FLAC__seekable_stream_encoder_new();
454 printf("FAILED, returned NULL\n");
459 printf("testing FLAC__seekable_stream_encoder_set_verify()... ");
460 if(!FLAC__seekable_stream_encoder_set_verify(encoder, true))
461 return die_ss_("returned false", encoder);
464 printf("testing FLAC__seekable_stream_encoder_set_streamable_subset()... ");
465 if(!FLAC__seekable_stream_encoder_set_streamable_subset(encoder, true))
466 return die_ss_("returned false", encoder);
469 printf("testing FLAC__seekable_stream_encoder_set_do_mid_side_stereo()... ");
470 if(!FLAC__seekable_stream_encoder_set_do_mid_side_stereo(encoder, false))
471 return die_ss_("returned false", encoder);
474 printf("testing FLAC__seekable_stream_encoder_set_loose_mid_side_stereo()... ");
475 if(!FLAC__seekable_stream_encoder_set_loose_mid_side_stereo(encoder, false))
476 return die_ss_("returned false", encoder);
479 printf("testing FLAC__seekable_stream_encoder_set_channels()... ");
480 if(!FLAC__seekable_stream_encoder_set_channels(encoder, streaminfo_.data.stream_info.channels))
481 return die_ss_("returned false", encoder);
484 printf("testing FLAC__seekable_stream_encoder_set_bits_per_sample()... ");
485 if(!FLAC__seekable_stream_encoder_set_bits_per_sample(encoder, streaminfo_.data.stream_info.bits_per_sample))
486 return die_ss_("returned false", encoder);
489 printf("testing FLAC__seekable_stream_encoder_set_sample_rate()... ");
490 if(!FLAC__seekable_stream_encoder_set_sample_rate(encoder, streaminfo_.data.stream_info.sample_rate))
491 return die_ss_("returned false", encoder);
494 printf("testing FLAC__seekable_stream_encoder_set_blocksize()... ");
495 if(!FLAC__seekable_stream_encoder_set_blocksize(encoder, streaminfo_.data.stream_info.min_blocksize))
496 return die_ss_("returned false", encoder);
499 printf("testing FLAC__seekable_stream_encoder_set_max_lpc_order()... ");
500 if(!FLAC__seekable_stream_encoder_set_max_lpc_order(encoder, 0))
501 return die_ss_("returned false", encoder);
504 printf("testing FLAC__seekable_stream_encoder_set_qlp_coeff_precision()... ");
505 if(!FLAC__seekable_stream_encoder_set_qlp_coeff_precision(encoder, 0))
506 return die_ss_("returned false", encoder);
509 printf("testing FLAC__seekable_stream_encoder_set_do_qlp_coeff_prec_search()... ");
510 if(!FLAC__seekable_stream_encoder_set_do_qlp_coeff_prec_search(encoder, false))
511 return die_ss_("returned false", encoder);
514 printf("testing FLAC__seekable_stream_encoder_set_do_escape_coding()... ");
515 if(!FLAC__seekable_stream_encoder_set_do_escape_coding(encoder, false))
516 return die_ss_("returned false", encoder);
519 printf("testing FLAC__seekable_stream_encoder_set_do_exhaustive_model_search()... ");
520 if(!FLAC__seekable_stream_encoder_set_do_exhaustive_model_search(encoder, false))
521 return die_ss_("returned false", encoder);
524 printf("testing FLAC__seekable_stream_encoder_set_min_residual_partition_order()... ");
525 if(!FLAC__seekable_stream_encoder_set_min_residual_partition_order(encoder, 0))
526 return die_ss_("returned false", encoder);
529 printf("testing FLAC__seekable_stream_encoder_set_max_residual_partition_order()... ");
530 if(!FLAC__seekable_stream_encoder_set_max_residual_partition_order(encoder, 0))
531 return die_ss_("returned false", encoder);
534 printf("testing FLAC__seekable_stream_encoder_set_rice_parameter_search_dist()... ");
535 if(!FLAC__seekable_stream_encoder_set_rice_parameter_search_dist(encoder, 0))
536 return die_ss_("returned false", encoder);
539 printf("testing FLAC__seekable_stream_encoder_set_total_samples_estimate()... ");
540 if(!FLAC__seekable_stream_encoder_set_total_samples_estimate(encoder, streaminfo_.data.stream_info.total_samples))
541 return die_ss_("returned false", encoder);
544 printf("testing FLAC__seekable_stream_encoder_set_metadata()... ");
545 if(!FLAC__seekable_stream_encoder_set_metadata(encoder, metadata_sequence_, num_metadata_))
546 return die_ss_("returned false", encoder);
549 printf("testing FLAC__seekable_stream_encoder_set_seek_callback()... ");
550 if(!FLAC__seekable_stream_encoder_set_seek_callback(encoder, seekable_stream_encoder_seek_callback_))
551 return die_ss_("returned false", encoder);
554 printf("testing FLAC__seekable_stream_encoder_set_tell_callback()... ");
555 if(!FLAC__seekable_stream_encoder_set_tell_callback(encoder, seekable_stream_encoder_tell_callback_))
556 return die_ss_("returned false", encoder);
559 printf("testing FLAC__seekable_stream_encoder_set_write_callback()... ");
560 if(!FLAC__seekable_stream_encoder_set_write_callback(encoder, seekable_stream_encoder_write_callback_))
561 return die_ss_("returned false", encoder);
564 printf("testing FLAC__seekable_stream_encoder_set_client_data()... ");
565 if(!FLAC__seekable_stream_encoder_set_client_data(encoder, 0))
566 return die_ss_("returned false", encoder);
569 printf("testing FLAC__seekable_stream_encoder_init()... ");
570 if(FLAC__seekable_stream_encoder_init(encoder) != FLAC__SEEKABLE_STREAM_ENCODER_OK)
571 return die_ss_(0, encoder);
574 printf("testing FLAC__seekable_stream_encoder_get_state()... ");
575 state = FLAC__seekable_stream_encoder_get_state(encoder);
576 printf("returned state = %u (%s)... OK\n", (unsigned)state, FLAC__SeekableStreamEncoderStateString[state]);
578 printf("testing FLAC__seekable_stream_encoder_get_stream_encoder_state()... ");
579 state_ = FLAC__seekable_stream_encoder_get_stream_encoder_state(encoder);
580 printf("returned state = %u (%s)... OK\n", (unsigned)state_, FLAC__StreamEncoderStateString[state_]);
582 printf("testing FLAC__seekable_stream_encoder_get_verify_decoder_state()... ");
583 dstate = FLAC__seekable_stream_encoder_get_verify_decoder_state(encoder);
584 printf("returned state = %u (%s)... OK\n", (unsigned)dstate, FLAC__StreamDecoderStateString[dstate]);
587 FLAC__uint64 absolute_sample;
588 unsigned frame_number;
591 FLAC__int32 expected;
594 printf("testing FLAC__seekable_stream_encoder_get_verify_decoder_error_stats()... ");
595 FLAC__seekable_stream_encoder_get_verify_decoder_error_stats(encoder, &absolute_sample, &frame_number, &channel, &sample, &expected, &got);
599 printf("testing FLAC__seekable_stream_encoder_get_verify()... ");
600 if(FLAC__seekable_stream_encoder_get_verify(encoder) != true) {
601 printf("FAILED, expected true, got false\n");
606 printf("testing FLAC__seekable_stream_encoder_get_streamable_subset()... ");
607 if(FLAC__seekable_stream_encoder_get_streamable_subset(encoder) != true) {
608 printf("FAILED, expected true, got false\n");
613 printf("testing FLAC__seekable_stream_encoder_get_do_mid_side_stereo()... ");
614 if(FLAC__seekable_stream_encoder_get_do_mid_side_stereo(encoder) != false) {
615 printf("FAILED, expected false, got true\n");
620 printf("testing FLAC__seekable_stream_encoder_get_loose_mid_side_stereo()... ");
621 if(FLAC__seekable_stream_encoder_get_loose_mid_side_stereo(encoder) != false) {
622 printf("FAILED, expected false, got true\n");
627 printf("testing FLAC__seekable_stream_encoder_get_channels()... ");
628 if(FLAC__seekable_stream_encoder_get_channels(encoder) != streaminfo_.data.stream_info.channels) {
629 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.channels, FLAC__seekable_stream_encoder_get_channels(encoder));
634 printf("testing FLAC__seekable_stream_encoder_get_bits_per_sample()... ");
635 if(FLAC__seekable_stream_encoder_get_bits_per_sample(encoder) != streaminfo_.data.stream_info.bits_per_sample) {
636 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.bits_per_sample, FLAC__seekable_stream_encoder_get_bits_per_sample(encoder));
641 printf("testing FLAC__seekable_stream_encoder_get_sample_rate()... ");
642 if(FLAC__seekable_stream_encoder_get_sample_rate(encoder) != streaminfo_.data.stream_info.sample_rate) {
643 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.sample_rate, FLAC__seekable_stream_encoder_get_sample_rate(encoder));
648 printf("testing FLAC__seekable_stream_encoder_get_blocksize()... ");
649 if(FLAC__seekable_stream_encoder_get_blocksize(encoder) != streaminfo_.data.stream_info.min_blocksize) {
650 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.min_blocksize, FLAC__seekable_stream_encoder_get_blocksize(encoder));
655 printf("testing FLAC__seekable_stream_encoder_get_max_lpc_order()... ");
656 if(FLAC__seekable_stream_encoder_get_max_lpc_order(encoder) != 0) {
657 printf("FAILED, expected %u, got %u\n", 0, FLAC__seekable_stream_encoder_get_max_lpc_order(encoder));
662 printf("testing FLAC__seekable_stream_encoder_get_qlp_coeff_precision()... ");
663 (void)FLAC__seekable_stream_encoder_get_qlp_coeff_precision(encoder);
664 /* we asked the encoder to auto select this so we accept anything */
667 printf("testing FLAC__seekable_stream_encoder_get_do_qlp_coeff_prec_search()... ");
668 if(FLAC__seekable_stream_encoder_get_do_qlp_coeff_prec_search(encoder) != false) {
669 printf("FAILED, expected false, got true\n");
674 printf("testing FLAC__seekable_stream_encoder_get_do_escape_coding()... ");
675 if(FLAC__seekable_stream_encoder_get_do_escape_coding(encoder) != false) {
676 printf("FAILED, expected false, got true\n");
681 printf("testing FLAC__seekable_stream_encoder_get_do_exhaustive_model_search()... ");
682 if(FLAC__seekable_stream_encoder_get_do_exhaustive_model_search(encoder) != false) {
683 printf("FAILED, expected false, got true\n");
688 printf("testing FLAC__seekable_stream_encoder_get_min_residual_partition_order()... ");
689 if(FLAC__seekable_stream_encoder_get_min_residual_partition_order(encoder) != 0) {
690 printf("FAILED, expected %u, got %u\n", 0, FLAC__seekable_stream_encoder_get_min_residual_partition_order(encoder));
695 printf("testing FLAC__seekable_stream_encoder_get_max_residual_partition_order()... ");
696 if(FLAC__seekable_stream_encoder_get_max_residual_partition_order(encoder) != 0) {
697 printf("FAILED, expected %u, got %u\n", 0, FLAC__seekable_stream_encoder_get_max_residual_partition_order(encoder));
702 printf("testing FLAC__seekable_stream_encoder_get_rice_parameter_search_dist()... ");
703 if(FLAC__seekable_stream_encoder_get_rice_parameter_search_dist(encoder) != 0) {
704 printf("FAILED, expected %u, got %u\n", 0, FLAC__seekable_stream_encoder_get_rice_parameter_search_dist(encoder));
709 printf("testing FLAC__seekable_stream_encoder_get_total_samples_estimate()... ");
710 if(FLAC__seekable_stream_encoder_get_total_samples_estimate(encoder) != streaminfo_.data.stream_info.total_samples) {
711 printf("FAILED, expected %llu, got %llu\n", streaminfo_.data.stream_info.total_samples, FLAC__seekable_stream_encoder_get_total_samples_estimate(encoder));
716 /* init the dummy sample buffer */
717 for(i = 0; i < sizeof(samples) / sizeof(FLAC__int32); i++)
720 printf("testing FLAC__seekable_stream_encoder_process()... ");
721 if(!FLAC__seekable_stream_encoder_process(encoder, (const FLAC__int32 * const *)samples_array, sizeof(samples) / sizeof(FLAC__int32)))
722 return die_ss_("returned false", encoder);
725 printf("testing FLAC__seekable_stream_encoder_process_interleaved()... ");
726 if(!FLAC__seekable_stream_encoder_process_interleaved(encoder, samples, sizeof(samples) / sizeof(FLAC__int32)))
727 return die_ss_("returned false", encoder);
730 printf("testing FLAC__seekable_stream_encoder_finish()... ");
731 FLAC__seekable_stream_encoder_finish(encoder);
734 printf("testing FLAC__seekable_stream_encoder_delete()... ");
735 FLAC__seekable_stream_encoder_delete(encoder);
738 printf("\nPASSED!\n");
743 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)
745 (void)encoder, (void)bytes_written, (void)samples_written, (void)frames_written, (void)total_frames_estimate, (void)client_data;
748 static FLAC__bool test_file_encoder()
750 FLAC__FileEncoder *encoder;
751 FLAC__FileEncoderState state;
752 FLAC__SeekableStreamEncoderState state_;
753 FLAC__StreamEncoderState state__;
754 FLAC__StreamDecoderState dstate;
755 FLAC__int32 samples[1024];
756 FLAC__int32 *samples_array[1];
759 samples_array[0] = samples;
761 printf("\n+++ libFLAC unit test: FLAC__FileEncoder\n\n");
763 printf("testing FLAC__file_encoder_new()... ");
764 encoder = FLAC__file_encoder_new();
766 printf("FAILED, returned NULL\n");
771 printf("testing FLAC__file_encoder_set_verify()... ");
772 if(!FLAC__file_encoder_set_verify(encoder, true))
773 return die_f_("returned false", encoder);
776 printf("testing FLAC__file_encoder_set_streamable_subset()... ");
777 if(!FLAC__file_encoder_set_streamable_subset(encoder, true))
778 return die_f_("returned false", encoder);
781 printf("testing FLAC__file_encoder_set_do_mid_side_stereo()... ");
782 if(!FLAC__file_encoder_set_do_mid_side_stereo(encoder, false))
783 return die_f_("returned false", encoder);
786 printf("testing FLAC__file_encoder_set_loose_mid_side_stereo()... ");
787 if(!FLAC__file_encoder_set_loose_mid_side_stereo(encoder, false))
788 return die_f_("returned false", encoder);
791 printf("testing FLAC__file_encoder_set_channels()... ");
792 if(!FLAC__file_encoder_set_channels(encoder, streaminfo_.data.stream_info.channels))
793 return die_f_("returned false", encoder);
796 printf("testing FLAC__file_encoder_set_bits_per_sample()... ");
797 if(!FLAC__file_encoder_set_bits_per_sample(encoder, streaminfo_.data.stream_info.bits_per_sample))
798 return die_f_("returned false", encoder);
801 printf("testing FLAC__file_encoder_set_sample_rate()... ");
802 if(!FLAC__file_encoder_set_sample_rate(encoder, streaminfo_.data.stream_info.sample_rate))
803 return die_f_("returned false", encoder);
806 printf("testing FLAC__file_encoder_set_blocksize()... ");
807 if(!FLAC__file_encoder_set_blocksize(encoder, streaminfo_.data.stream_info.min_blocksize))
808 return die_f_("returned false", encoder);
811 printf("testing FLAC__file_encoder_set_max_lpc_order()... ");
812 if(!FLAC__file_encoder_set_max_lpc_order(encoder, 0))
813 return die_f_("returned false", encoder);
816 printf("testing FLAC__file_encoder_set_qlp_coeff_precision()... ");
817 if(!FLAC__file_encoder_set_qlp_coeff_precision(encoder, 0))
818 return die_f_("returned false", encoder);
821 printf("testing FLAC__file_encoder_set_do_qlp_coeff_prec_search()... ");
822 if(!FLAC__file_encoder_set_do_qlp_coeff_prec_search(encoder, false))
823 return die_f_("returned false", encoder);
826 printf("testing FLAC__file_encoder_set_do_escape_coding()... ");
827 if(!FLAC__file_encoder_set_do_escape_coding(encoder, false))
828 return die_f_("returned false", encoder);
831 printf("testing FLAC__file_encoder_set_do_exhaustive_model_search()... ");
832 if(!FLAC__file_encoder_set_do_exhaustive_model_search(encoder, false))
833 return die_f_("returned false", encoder);
836 printf("testing FLAC__file_encoder_set_min_residual_partition_order()... ");
837 if(!FLAC__file_encoder_set_min_residual_partition_order(encoder, 0))
838 return die_f_("returned false", encoder);
841 printf("testing FLAC__file_encoder_set_max_residual_partition_order()... ");
842 if(!FLAC__file_encoder_set_max_residual_partition_order(encoder, 0))
843 return die_f_("returned false", encoder);
846 printf("testing FLAC__file_encoder_set_rice_parameter_search_dist()... ");
847 if(!FLAC__file_encoder_set_rice_parameter_search_dist(encoder, 0))
848 return die_f_("returned false", encoder);
851 printf("testing FLAC__file_encoder_set_total_samples_estimate()... ");
852 if(!FLAC__file_encoder_set_total_samples_estimate(encoder, streaminfo_.data.stream_info.total_samples))
853 return die_f_("returned false", encoder);
856 printf("testing FLAC__file_encoder_set_metadata()... ");
857 if(!FLAC__file_encoder_set_metadata(encoder, metadata_sequence_, num_metadata_))
858 return die_f_("returned false", encoder);
861 printf("testing FLAC__file_encoder_set_filename()... ");
862 if(!FLAC__file_encoder_set_filename(encoder, flacfilename_))
863 return die_f_("returned false", encoder);
866 printf("testing FLAC__file_encoder_set_progress_callback()... ");
867 if(!FLAC__file_encoder_set_progress_callback(encoder, file_encoder_progress_callback_))
868 return die_f_("returned false", encoder);
871 printf("testing FLAC__file_encoder_set_client_data()... ");
872 if(!FLAC__file_encoder_set_client_data(encoder, 0))
873 return die_f_("returned false", encoder);
876 printf("testing FLAC__file_encoder_init()... ");
877 if(FLAC__file_encoder_init(encoder) != FLAC__FILE_ENCODER_OK)
878 return die_f_(0, encoder);
881 printf("testing FLAC__file_encoder_get_state()... ");
882 state = FLAC__file_encoder_get_state(encoder);
883 printf("returned state = %u (%s)... OK\n", (unsigned)state, FLAC__FileEncoderStateString[state]);
885 printf("testing FLAC__file_encoder_get_seekable_stream_encoder_state()... ");
886 state_ = FLAC__file_encoder_get_seekable_stream_encoder_state(encoder);
887 printf("returned state = %u (%s)... OK\n", (unsigned)state_, FLAC__SeekableStreamEncoderStateString[state_]);
889 printf("testing FLAC__file_encoder_get_stream_encoder_state()... ");
890 state__ = FLAC__file_encoder_get_stream_encoder_state(encoder);
891 printf("returned state = %u (%s)... OK\n", (unsigned)state__, FLAC__StreamEncoderStateString[state__]);
893 printf("testing FLAC__file_encoder_get_verify_decoder_state()... ");
894 dstate = FLAC__file_encoder_get_verify_decoder_state(encoder);
895 printf("returned state = %u (%s)... OK\n", (unsigned)dstate, FLAC__StreamDecoderStateString[dstate]);
898 FLAC__uint64 absolute_sample;
899 unsigned frame_number;
902 FLAC__int32 expected;
905 printf("testing FLAC__file_encoder_get_verify_decoder_error_stats()... ");
906 FLAC__file_encoder_get_verify_decoder_error_stats(encoder, &absolute_sample, &frame_number, &channel, &sample, &expected, &got);
910 printf("testing FLAC__file_encoder_get_verify()... ");
911 if(FLAC__file_encoder_get_verify(encoder) != true) {
912 printf("FAILED, expected true, got false\n");
917 printf("testing FLAC__file_encoder_get_streamable_subset()... ");
918 if(FLAC__file_encoder_get_streamable_subset(encoder) != true) {
919 printf("FAILED, expected true, got false\n");
924 printf("testing FLAC__file_encoder_get_do_mid_side_stereo()... ");
925 if(FLAC__file_encoder_get_do_mid_side_stereo(encoder) != false) {
926 printf("FAILED, expected false, got true\n");
931 printf("testing FLAC__file_encoder_get_loose_mid_side_stereo()... ");
932 if(FLAC__file_encoder_get_loose_mid_side_stereo(encoder) != false) {
933 printf("FAILED, expected false, got true\n");
938 printf("testing FLAC__file_encoder_get_channels()... ");
939 if(FLAC__file_encoder_get_channels(encoder) != streaminfo_.data.stream_info.channels) {
940 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.channels, FLAC__file_encoder_get_channels(encoder));
945 printf("testing FLAC__file_encoder_get_bits_per_sample()... ");
946 if(FLAC__file_encoder_get_bits_per_sample(encoder) != streaminfo_.data.stream_info.bits_per_sample) {
947 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.bits_per_sample, FLAC__file_encoder_get_bits_per_sample(encoder));
952 printf("testing FLAC__file_encoder_get_sample_rate()... ");
953 if(FLAC__file_encoder_get_sample_rate(encoder) != streaminfo_.data.stream_info.sample_rate) {
954 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.sample_rate, FLAC__file_encoder_get_sample_rate(encoder));
959 printf("testing FLAC__file_encoder_get_blocksize()... ");
960 if(FLAC__file_encoder_get_blocksize(encoder) != streaminfo_.data.stream_info.min_blocksize) {
961 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.min_blocksize, FLAC__file_encoder_get_blocksize(encoder));
966 printf("testing FLAC__file_encoder_get_max_lpc_order()... ");
967 if(FLAC__file_encoder_get_max_lpc_order(encoder) != 0) {
968 printf("FAILED, expected %u, got %u\n", 0, FLAC__file_encoder_get_max_lpc_order(encoder));
973 printf("testing FLAC__file_encoder_get_qlp_coeff_precision()... ");
974 (void)FLAC__file_encoder_get_qlp_coeff_precision(encoder);
975 /* we asked the encoder to auto select this so we accept anything */
978 printf("testing FLAC__file_encoder_get_do_qlp_coeff_prec_search()... ");
979 if(FLAC__file_encoder_get_do_qlp_coeff_prec_search(encoder) != false) {
980 printf("FAILED, expected false, got true\n");
985 printf("testing FLAC__file_encoder_get_do_escape_coding()... ");
986 if(FLAC__file_encoder_get_do_escape_coding(encoder) != false) {
987 printf("FAILED, expected false, got true\n");
992 printf("testing FLAC__file_encoder_get_do_exhaustive_model_search()... ");
993 if(FLAC__file_encoder_get_do_exhaustive_model_search(encoder) != false) {
994 printf("FAILED, expected false, got true\n");
999 printf("testing FLAC__file_encoder_get_min_residual_partition_order()... ");
1000 if(FLAC__file_encoder_get_min_residual_partition_order(encoder) != 0) {
1001 printf("FAILED, expected %u, got %u\n", 0, FLAC__file_encoder_get_min_residual_partition_order(encoder));
1006 printf("testing FLAC__file_encoder_get_max_residual_partition_order()... ");
1007 if(FLAC__file_encoder_get_max_residual_partition_order(encoder) != 0) {
1008 printf("FAILED, expected %u, got %u\n", 0, FLAC__file_encoder_get_max_residual_partition_order(encoder));
1013 printf("testing FLAC__file_encoder_get_rice_parameter_search_dist()... ");
1014 if(FLAC__file_encoder_get_rice_parameter_search_dist(encoder) != 0) {
1015 printf("FAILED, expected %u, got %u\n", 0, FLAC__file_encoder_get_rice_parameter_search_dist(encoder));
1020 printf("testing FLAC__file_encoder_get_total_samples_estimate()... ");
1021 if(FLAC__file_encoder_get_total_samples_estimate(encoder) != streaminfo_.data.stream_info.total_samples) {
1022 printf("FAILED, expected %llu, got %llu\n", streaminfo_.data.stream_info.total_samples, FLAC__file_encoder_get_total_samples_estimate(encoder));
1027 /* init the dummy sample buffer */
1028 for(i = 0; i < sizeof(samples) / sizeof(FLAC__int32); i++)
1031 printf("testing FLAC__file_encoder_process()... ");
1032 if(!FLAC__file_encoder_process(encoder, (const FLAC__int32 * const *)samples_array, sizeof(samples) / sizeof(FLAC__int32)))
1033 return die_f_("returned false", encoder);
1036 printf("testing FLAC__file_encoder_process_interleaved()... ");
1037 if(!FLAC__file_encoder_process_interleaved(encoder, samples, sizeof(samples) / sizeof(FLAC__int32)))
1038 return die_f_("returned false", encoder);
1041 printf("testing FLAC__file_encoder_finish()... ");
1042 FLAC__file_encoder_finish(encoder);
1045 printf("testing FLAC__file_encoder_delete()... ");
1046 FLAC__file_encoder_delete(encoder);
1049 printf("\nPASSED!\n");
1054 FLAC__bool test_encoders()
1056 init_metadata_blocks_();
1058 if(!test_stream_encoder())
1061 if(!test_seekable_stream_encoder())
1064 if(!test_file_encoder())
1067 (void) grabbag__file_remove_file(flacfilename_);
1068 free_metadata_blocks_();