1 /* test_libFLAC - Unit tester for libFLAC
2 * Copyright (C) 2002,2003,2004 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)client_data;
428 *absolute_byte_offset = 0;
429 return FLAC__SEEKABLE_STREAM_ENCODER_TELL_STATUS_OK;
432 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)
434 (void)encoder, (void)buffer, (void)bytes, (void)samples, (void)current_frame, (void)client_data;
435 return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
438 static FLAC__bool test_seekable_stream_encoder()
440 FLAC__SeekableStreamEncoder *encoder;
441 FLAC__SeekableStreamEncoderState state;
442 FLAC__StreamEncoderState state_;
443 FLAC__StreamDecoderState dstate;
444 FLAC__int32 samples[1024];
445 FLAC__int32 *samples_array[1];
448 samples_array[0] = samples;
450 printf("\n+++ libFLAC unit test: FLAC__SeekableStreamEncoder\n\n");
452 printf("testing FLAC__seekable_stream_encoder_new()... ");
453 encoder = FLAC__seekable_stream_encoder_new();
455 printf("FAILED, returned NULL\n");
460 printf("testing FLAC__seekable_stream_encoder_set_verify()... ");
461 if(!FLAC__seekable_stream_encoder_set_verify(encoder, true))
462 return die_ss_("returned false", encoder);
465 printf("testing FLAC__seekable_stream_encoder_set_streamable_subset()... ");
466 if(!FLAC__seekable_stream_encoder_set_streamable_subset(encoder, true))
467 return die_ss_("returned false", encoder);
470 printf("testing FLAC__seekable_stream_encoder_set_do_mid_side_stereo()... ");
471 if(!FLAC__seekable_stream_encoder_set_do_mid_side_stereo(encoder, false))
472 return die_ss_("returned false", encoder);
475 printf("testing FLAC__seekable_stream_encoder_set_loose_mid_side_stereo()... ");
476 if(!FLAC__seekable_stream_encoder_set_loose_mid_side_stereo(encoder, false))
477 return die_ss_("returned false", encoder);
480 printf("testing FLAC__seekable_stream_encoder_set_channels()... ");
481 if(!FLAC__seekable_stream_encoder_set_channels(encoder, streaminfo_.data.stream_info.channels))
482 return die_ss_("returned false", encoder);
485 printf("testing FLAC__seekable_stream_encoder_set_bits_per_sample()... ");
486 if(!FLAC__seekable_stream_encoder_set_bits_per_sample(encoder, streaminfo_.data.stream_info.bits_per_sample))
487 return die_ss_("returned false", encoder);
490 printf("testing FLAC__seekable_stream_encoder_set_sample_rate()... ");
491 if(!FLAC__seekable_stream_encoder_set_sample_rate(encoder, streaminfo_.data.stream_info.sample_rate))
492 return die_ss_("returned false", encoder);
495 printf("testing FLAC__seekable_stream_encoder_set_blocksize()... ");
496 if(!FLAC__seekable_stream_encoder_set_blocksize(encoder, streaminfo_.data.stream_info.min_blocksize))
497 return die_ss_("returned false", encoder);
500 printf("testing FLAC__seekable_stream_encoder_set_max_lpc_order()... ");
501 if(!FLAC__seekable_stream_encoder_set_max_lpc_order(encoder, 0))
502 return die_ss_("returned false", encoder);
505 printf("testing FLAC__seekable_stream_encoder_set_qlp_coeff_precision()... ");
506 if(!FLAC__seekable_stream_encoder_set_qlp_coeff_precision(encoder, 0))
507 return die_ss_("returned false", encoder);
510 printf("testing FLAC__seekable_stream_encoder_set_do_qlp_coeff_prec_search()... ");
511 if(!FLAC__seekable_stream_encoder_set_do_qlp_coeff_prec_search(encoder, false))
512 return die_ss_("returned false", encoder);
515 printf("testing FLAC__seekable_stream_encoder_set_do_escape_coding()... ");
516 if(!FLAC__seekable_stream_encoder_set_do_escape_coding(encoder, false))
517 return die_ss_("returned false", encoder);
520 printf("testing FLAC__seekable_stream_encoder_set_do_exhaustive_model_search()... ");
521 if(!FLAC__seekable_stream_encoder_set_do_exhaustive_model_search(encoder, false))
522 return die_ss_("returned false", encoder);
525 printf("testing FLAC__seekable_stream_encoder_set_min_residual_partition_order()... ");
526 if(!FLAC__seekable_stream_encoder_set_min_residual_partition_order(encoder, 0))
527 return die_ss_("returned false", encoder);
530 printf("testing FLAC__seekable_stream_encoder_set_max_residual_partition_order()... ");
531 if(!FLAC__seekable_stream_encoder_set_max_residual_partition_order(encoder, 0))
532 return die_ss_("returned false", encoder);
535 printf("testing FLAC__seekable_stream_encoder_set_rice_parameter_search_dist()... ");
536 if(!FLAC__seekable_stream_encoder_set_rice_parameter_search_dist(encoder, 0))
537 return die_ss_("returned false", encoder);
540 printf("testing FLAC__seekable_stream_encoder_set_total_samples_estimate()... ");
541 if(!FLAC__seekable_stream_encoder_set_total_samples_estimate(encoder, streaminfo_.data.stream_info.total_samples))
542 return die_ss_("returned false", encoder);
545 printf("testing FLAC__seekable_stream_encoder_set_metadata()... ");
546 if(!FLAC__seekable_stream_encoder_set_metadata(encoder, metadata_sequence_, num_metadata_))
547 return die_ss_("returned false", encoder);
550 printf("testing FLAC__seekable_stream_encoder_set_seek_callback()... ");
551 if(!FLAC__seekable_stream_encoder_set_seek_callback(encoder, seekable_stream_encoder_seek_callback_))
552 return die_ss_("returned false", encoder);
555 printf("testing FLAC__seekable_stream_encoder_set_tell_callback()... ");
556 if(!FLAC__seekable_stream_encoder_set_tell_callback(encoder, seekable_stream_encoder_tell_callback_))
557 return die_ss_("returned false", encoder);
560 printf("testing FLAC__seekable_stream_encoder_set_write_callback()... ");
561 if(!FLAC__seekable_stream_encoder_set_write_callback(encoder, seekable_stream_encoder_write_callback_))
562 return die_ss_("returned false", encoder);
565 printf("testing FLAC__seekable_stream_encoder_set_client_data()... ");
566 if(!FLAC__seekable_stream_encoder_set_client_data(encoder, 0))
567 return die_ss_("returned false", encoder);
570 printf("testing FLAC__seekable_stream_encoder_init()... ");
571 if(FLAC__seekable_stream_encoder_init(encoder) != FLAC__SEEKABLE_STREAM_ENCODER_OK)
572 return die_ss_(0, encoder);
575 printf("testing FLAC__seekable_stream_encoder_get_state()... ");
576 state = FLAC__seekable_stream_encoder_get_state(encoder);
577 printf("returned state = %u (%s)... OK\n", (unsigned)state, FLAC__SeekableStreamEncoderStateString[state]);
579 printf("testing FLAC__seekable_stream_encoder_get_stream_encoder_state()... ");
580 state_ = FLAC__seekable_stream_encoder_get_stream_encoder_state(encoder);
581 printf("returned state = %u (%s)... OK\n", (unsigned)state_, FLAC__StreamEncoderStateString[state_]);
583 printf("testing FLAC__seekable_stream_encoder_get_verify_decoder_state()... ");
584 dstate = FLAC__seekable_stream_encoder_get_verify_decoder_state(encoder);
585 printf("returned state = %u (%s)... OK\n", (unsigned)dstate, FLAC__StreamDecoderStateString[dstate]);
588 FLAC__uint64 absolute_sample;
589 unsigned frame_number;
592 FLAC__int32 expected;
595 printf("testing FLAC__seekable_stream_encoder_get_verify_decoder_error_stats()... ");
596 FLAC__seekable_stream_encoder_get_verify_decoder_error_stats(encoder, &absolute_sample, &frame_number, &channel, &sample, &expected, &got);
600 printf("testing FLAC__seekable_stream_encoder_get_verify()... ");
601 if(FLAC__seekable_stream_encoder_get_verify(encoder) != true) {
602 printf("FAILED, expected true, got false\n");
607 printf("testing FLAC__seekable_stream_encoder_get_streamable_subset()... ");
608 if(FLAC__seekable_stream_encoder_get_streamable_subset(encoder) != true) {
609 printf("FAILED, expected true, got false\n");
614 printf("testing FLAC__seekable_stream_encoder_get_do_mid_side_stereo()... ");
615 if(FLAC__seekable_stream_encoder_get_do_mid_side_stereo(encoder) != false) {
616 printf("FAILED, expected false, got true\n");
621 printf("testing FLAC__seekable_stream_encoder_get_loose_mid_side_stereo()... ");
622 if(FLAC__seekable_stream_encoder_get_loose_mid_side_stereo(encoder) != false) {
623 printf("FAILED, expected false, got true\n");
628 printf("testing FLAC__seekable_stream_encoder_get_channels()... ");
629 if(FLAC__seekable_stream_encoder_get_channels(encoder) != streaminfo_.data.stream_info.channels) {
630 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.channels, FLAC__seekable_stream_encoder_get_channels(encoder));
635 printf("testing FLAC__seekable_stream_encoder_get_bits_per_sample()... ");
636 if(FLAC__seekable_stream_encoder_get_bits_per_sample(encoder) != streaminfo_.data.stream_info.bits_per_sample) {
637 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.bits_per_sample, FLAC__seekable_stream_encoder_get_bits_per_sample(encoder));
642 printf("testing FLAC__seekable_stream_encoder_get_sample_rate()... ");
643 if(FLAC__seekable_stream_encoder_get_sample_rate(encoder) != streaminfo_.data.stream_info.sample_rate) {
644 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.sample_rate, FLAC__seekable_stream_encoder_get_sample_rate(encoder));
649 printf("testing FLAC__seekable_stream_encoder_get_blocksize()... ");
650 if(FLAC__seekable_stream_encoder_get_blocksize(encoder) != streaminfo_.data.stream_info.min_blocksize) {
651 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.min_blocksize, FLAC__seekable_stream_encoder_get_blocksize(encoder));
656 printf("testing FLAC__seekable_stream_encoder_get_max_lpc_order()... ");
657 if(FLAC__seekable_stream_encoder_get_max_lpc_order(encoder) != 0) {
658 printf("FAILED, expected %u, got %u\n", 0, FLAC__seekable_stream_encoder_get_max_lpc_order(encoder));
663 printf("testing FLAC__seekable_stream_encoder_get_qlp_coeff_precision()... ");
664 (void)FLAC__seekable_stream_encoder_get_qlp_coeff_precision(encoder);
665 /* we asked the encoder to auto select this so we accept anything */
668 printf("testing FLAC__seekable_stream_encoder_get_do_qlp_coeff_prec_search()... ");
669 if(FLAC__seekable_stream_encoder_get_do_qlp_coeff_prec_search(encoder) != false) {
670 printf("FAILED, expected false, got true\n");
675 printf("testing FLAC__seekable_stream_encoder_get_do_escape_coding()... ");
676 if(FLAC__seekable_stream_encoder_get_do_escape_coding(encoder) != false) {
677 printf("FAILED, expected false, got true\n");
682 printf("testing FLAC__seekable_stream_encoder_get_do_exhaustive_model_search()... ");
683 if(FLAC__seekable_stream_encoder_get_do_exhaustive_model_search(encoder) != false) {
684 printf("FAILED, expected false, got true\n");
689 printf("testing FLAC__seekable_stream_encoder_get_min_residual_partition_order()... ");
690 if(FLAC__seekable_stream_encoder_get_min_residual_partition_order(encoder) != 0) {
691 printf("FAILED, expected %u, got %u\n", 0, FLAC__seekable_stream_encoder_get_min_residual_partition_order(encoder));
696 printf("testing FLAC__seekable_stream_encoder_get_max_residual_partition_order()... ");
697 if(FLAC__seekable_stream_encoder_get_max_residual_partition_order(encoder) != 0) {
698 printf("FAILED, expected %u, got %u\n", 0, FLAC__seekable_stream_encoder_get_max_residual_partition_order(encoder));
703 printf("testing FLAC__seekable_stream_encoder_get_rice_parameter_search_dist()... ");
704 if(FLAC__seekable_stream_encoder_get_rice_parameter_search_dist(encoder) != 0) {
705 printf("FAILED, expected %u, got %u\n", 0, FLAC__seekable_stream_encoder_get_rice_parameter_search_dist(encoder));
710 printf("testing FLAC__seekable_stream_encoder_get_total_samples_estimate()... ");
711 if(FLAC__seekable_stream_encoder_get_total_samples_estimate(encoder) != streaminfo_.data.stream_info.total_samples) {
712 printf("FAILED, expected %llu, got %llu\n", streaminfo_.data.stream_info.total_samples, FLAC__seekable_stream_encoder_get_total_samples_estimate(encoder));
717 /* init the dummy sample buffer */
718 for(i = 0; i < sizeof(samples) / sizeof(FLAC__int32); i++)
721 printf("testing FLAC__seekable_stream_encoder_process()... ");
722 if(!FLAC__seekable_stream_encoder_process(encoder, (const FLAC__int32 * const *)samples_array, sizeof(samples) / sizeof(FLAC__int32)))
723 return die_ss_("returned false", encoder);
726 printf("testing FLAC__seekable_stream_encoder_process_interleaved()... ");
727 if(!FLAC__seekable_stream_encoder_process_interleaved(encoder, samples, sizeof(samples) / sizeof(FLAC__int32)))
728 return die_ss_("returned false", encoder);
731 printf("testing FLAC__seekable_stream_encoder_finish()... ");
732 FLAC__seekable_stream_encoder_finish(encoder);
735 printf("testing FLAC__seekable_stream_encoder_delete()... ");
736 FLAC__seekable_stream_encoder_delete(encoder);
739 printf("\nPASSED!\n");
744 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)
746 (void)encoder, (void)bytes_written, (void)samples_written, (void)frames_written, (void)total_frames_estimate, (void)client_data;
749 static FLAC__bool test_file_encoder()
751 FLAC__FileEncoder *encoder;
752 FLAC__FileEncoderState state;
753 FLAC__SeekableStreamEncoderState state_;
754 FLAC__StreamEncoderState state__;
755 FLAC__StreamDecoderState dstate;
756 FLAC__int32 samples[1024];
757 FLAC__int32 *samples_array[1];
760 samples_array[0] = samples;
762 printf("\n+++ libFLAC unit test: FLAC__FileEncoder\n\n");
764 printf("testing FLAC__file_encoder_new()... ");
765 encoder = FLAC__file_encoder_new();
767 printf("FAILED, returned NULL\n");
772 printf("testing FLAC__file_encoder_set_verify()... ");
773 if(!FLAC__file_encoder_set_verify(encoder, true))
774 return die_f_("returned false", encoder);
777 printf("testing FLAC__file_encoder_set_streamable_subset()... ");
778 if(!FLAC__file_encoder_set_streamable_subset(encoder, true))
779 return die_f_("returned false", encoder);
782 printf("testing FLAC__file_encoder_set_do_mid_side_stereo()... ");
783 if(!FLAC__file_encoder_set_do_mid_side_stereo(encoder, false))
784 return die_f_("returned false", encoder);
787 printf("testing FLAC__file_encoder_set_loose_mid_side_stereo()... ");
788 if(!FLAC__file_encoder_set_loose_mid_side_stereo(encoder, false))
789 return die_f_("returned false", encoder);
792 printf("testing FLAC__file_encoder_set_channels()... ");
793 if(!FLAC__file_encoder_set_channels(encoder, streaminfo_.data.stream_info.channels))
794 return die_f_("returned false", encoder);
797 printf("testing FLAC__file_encoder_set_bits_per_sample()... ");
798 if(!FLAC__file_encoder_set_bits_per_sample(encoder, streaminfo_.data.stream_info.bits_per_sample))
799 return die_f_("returned false", encoder);
802 printf("testing FLAC__file_encoder_set_sample_rate()... ");
803 if(!FLAC__file_encoder_set_sample_rate(encoder, streaminfo_.data.stream_info.sample_rate))
804 return die_f_("returned false", encoder);
807 printf("testing FLAC__file_encoder_set_blocksize()... ");
808 if(!FLAC__file_encoder_set_blocksize(encoder, streaminfo_.data.stream_info.min_blocksize))
809 return die_f_("returned false", encoder);
812 printf("testing FLAC__file_encoder_set_max_lpc_order()... ");
813 if(!FLAC__file_encoder_set_max_lpc_order(encoder, 0))
814 return die_f_("returned false", encoder);
817 printf("testing FLAC__file_encoder_set_qlp_coeff_precision()... ");
818 if(!FLAC__file_encoder_set_qlp_coeff_precision(encoder, 0))
819 return die_f_("returned false", encoder);
822 printf("testing FLAC__file_encoder_set_do_qlp_coeff_prec_search()... ");
823 if(!FLAC__file_encoder_set_do_qlp_coeff_prec_search(encoder, false))
824 return die_f_("returned false", encoder);
827 printf("testing FLAC__file_encoder_set_do_escape_coding()... ");
828 if(!FLAC__file_encoder_set_do_escape_coding(encoder, false))
829 return die_f_("returned false", encoder);
832 printf("testing FLAC__file_encoder_set_do_exhaustive_model_search()... ");
833 if(!FLAC__file_encoder_set_do_exhaustive_model_search(encoder, false))
834 return die_f_("returned false", encoder);
837 printf("testing FLAC__file_encoder_set_min_residual_partition_order()... ");
838 if(!FLAC__file_encoder_set_min_residual_partition_order(encoder, 0))
839 return die_f_("returned false", encoder);
842 printf("testing FLAC__file_encoder_set_max_residual_partition_order()... ");
843 if(!FLAC__file_encoder_set_max_residual_partition_order(encoder, 0))
844 return die_f_("returned false", encoder);
847 printf("testing FLAC__file_encoder_set_rice_parameter_search_dist()... ");
848 if(!FLAC__file_encoder_set_rice_parameter_search_dist(encoder, 0))
849 return die_f_("returned false", encoder);
852 printf("testing FLAC__file_encoder_set_total_samples_estimate()... ");
853 if(!FLAC__file_encoder_set_total_samples_estimate(encoder, streaminfo_.data.stream_info.total_samples))
854 return die_f_("returned false", encoder);
857 printf("testing FLAC__file_encoder_set_metadata()... ");
858 if(!FLAC__file_encoder_set_metadata(encoder, metadata_sequence_, num_metadata_))
859 return die_f_("returned false", encoder);
862 printf("testing FLAC__file_encoder_set_filename()... ");
863 if(!FLAC__file_encoder_set_filename(encoder, flacfilename_))
864 return die_f_("returned false", encoder);
867 printf("testing FLAC__file_encoder_set_progress_callback()... ");
868 if(!FLAC__file_encoder_set_progress_callback(encoder, file_encoder_progress_callback_))
869 return die_f_("returned false", encoder);
872 printf("testing FLAC__file_encoder_set_client_data()... ");
873 if(!FLAC__file_encoder_set_client_data(encoder, 0))
874 return die_f_("returned false", encoder);
877 printf("testing FLAC__file_encoder_init()... ");
878 if(FLAC__file_encoder_init(encoder) != FLAC__FILE_ENCODER_OK)
879 return die_f_(0, encoder);
882 printf("testing FLAC__file_encoder_get_state()... ");
883 state = FLAC__file_encoder_get_state(encoder);
884 printf("returned state = %u (%s)... OK\n", (unsigned)state, FLAC__FileEncoderStateString[state]);
886 printf("testing FLAC__file_encoder_get_seekable_stream_encoder_state()... ");
887 state_ = FLAC__file_encoder_get_seekable_stream_encoder_state(encoder);
888 printf("returned state = %u (%s)... OK\n", (unsigned)state_, FLAC__SeekableStreamEncoderStateString[state_]);
890 printf("testing FLAC__file_encoder_get_stream_encoder_state()... ");
891 state__ = FLAC__file_encoder_get_stream_encoder_state(encoder);
892 printf("returned state = %u (%s)... OK\n", (unsigned)state__, FLAC__StreamEncoderStateString[state__]);
894 printf("testing FLAC__file_encoder_get_verify_decoder_state()... ");
895 dstate = FLAC__file_encoder_get_verify_decoder_state(encoder);
896 printf("returned state = %u (%s)... OK\n", (unsigned)dstate, FLAC__StreamDecoderStateString[dstate]);
899 FLAC__uint64 absolute_sample;
900 unsigned frame_number;
903 FLAC__int32 expected;
906 printf("testing FLAC__file_encoder_get_verify_decoder_error_stats()... ");
907 FLAC__file_encoder_get_verify_decoder_error_stats(encoder, &absolute_sample, &frame_number, &channel, &sample, &expected, &got);
911 printf("testing FLAC__file_encoder_get_verify()... ");
912 if(FLAC__file_encoder_get_verify(encoder) != true) {
913 printf("FAILED, expected true, got false\n");
918 printf("testing FLAC__file_encoder_get_streamable_subset()... ");
919 if(FLAC__file_encoder_get_streamable_subset(encoder) != true) {
920 printf("FAILED, expected true, got false\n");
925 printf("testing FLAC__file_encoder_get_do_mid_side_stereo()... ");
926 if(FLAC__file_encoder_get_do_mid_side_stereo(encoder) != false) {
927 printf("FAILED, expected false, got true\n");
932 printf("testing FLAC__file_encoder_get_loose_mid_side_stereo()... ");
933 if(FLAC__file_encoder_get_loose_mid_side_stereo(encoder) != false) {
934 printf("FAILED, expected false, got true\n");
939 printf("testing FLAC__file_encoder_get_channels()... ");
940 if(FLAC__file_encoder_get_channels(encoder) != streaminfo_.data.stream_info.channels) {
941 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.channels, FLAC__file_encoder_get_channels(encoder));
946 printf("testing FLAC__file_encoder_get_bits_per_sample()... ");
947 if(FLAC__file_encoder_get_bits_per_sample(encoder) != streaminfo_.data.stream_info.bits_per_sample) {
948 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.bits_per_sample, FLAC__file_encoder_get_bits_per_sample(encoder));
953 printf("testing FLAC__file_encoder_get_sample_rate()... ");
954 if(FLAC__file_encoder_get_sample_rate(encoder) != streaminfo_.data.stream_info.sample_rate) {
955 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.sample_rate, FLAC__file_encoder_get_sample_rate(encoder));
960 printf("testing FLAC__file_encoder_get_blocksize()... ");
961 if(FLAC__file_encoder_get_blocksize(encoder) != streaminfo_.data.stream_info.min_blocksize) {
962 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.min_blocksize, FLAC__file_encoder_get_blocksize(encoder));
967 printf("testing FLAC__file_encoder_get_max_lpc_order()... ");
968 if(FLAC__file_encoder_get_max_lpc_order(encoder) != 0) {
969 printf("FAILED, expected %u, got %u\n", 0, FLAC__file_encoder_get_max_lpc_order(encoder));
974 printf("testing FLAC__file_encoder_get_qlp_coeff_precision()... ");
975 (void)FLAC__file_encoder_get_qlp_coeff_precision(encoder);
976 /* we asked the encoder to auto select this so we accept anything */
979 printf("testing FLAC__file_encoder_get_do_qlp_coeff_prec_search()... ");
980 if(FLAC__file_encoder_get_do_qlp_coeff_prec_search(encoder) != false) {
981 printf("FAILED, expected false, got true\n");
986 printf("testing FLAC__file_encoder_get_do_escape_coding()... ");
987 if(FLAC__file_encoder_get_do_escape_coding(encoder) != false) {
988 printf("FAILED, expected false, got true\n");
993 printf("testing FLAC__file_encoder_get_do_exhaustive_model_search()... ");
994 if(FLAC__file_encoder_get_do_exhaustive_model_search(encoder) != false) {
995 printf("FAILED, expected false, got true\n");
1000 printf("testing FLAC__file_encoder_get_min_residual_partition_order()... ");
1001 if(FLAC__file_encoder_get_min_residual_partition_order(encoder) != 0) {
1002 printf("FAILED, expected %u, got %u\n", 0, FLAC__file_encoder_get_min_residual_partition_order(encoder));
1007 printf("testing FLAC__file_encoder_get_max_residual_partition_order()... ");
1008 if(FLAC__file_encoder_get_max_residual_partition_order(encoder) != 0) {
1009 printf("FAILED, expected %u, got %u\n", 0, FLAC__file_encoder_get_max_residual_partition_order(encoder));
1014 printf("testing FLAC__file_encoder_get_rice_parameter_search_dist()... ");
1015 if(FLAC__file_encoder_get_rice_parameter_search_dist(encoder) != 0) {
1016 printf("FAILED, expected %u, got %u\n", 0, FLAC__file_encoder_get_rice_parameter_search_dist(encoder));
1021 printf("testing FLAC__file_encoder_get_total_samples_estimate()... ");
1022 if(FLAC__file_encoder_get_total_samples_estimate(encoder) != streaminfo_.data.stream_info.total_samples) {
1023 printf("FAILED, expected %llu, got %llu\n", streaminfo_.data.stream_info.total_samples, FLAC__file_encoder_get_total_samples_estimate(encoder));
1028 /* init the dummy sample buffer */
1029 for(i = 0; i < sizeof(samples) / sizeof(FLAC__int32); i++)
1032 printf("testing FLAC__file_encoder_process()... ");
1033 if(!FLAC__file_encoder_process(encoder, (const FLAC__int32 * const *)samples_array, sizeof(samples) / sizeof(FLAC__int32)))
1034 return die_f_("returned false", encoder);
1037 printf("testing FLAC__file_encoder_process_interleaved()... ");
1038 if(!FLAC__file_encoder_process_interleaved(encoder, samples, sizeof(samples) / sizeof(FLAC__int32)))
1039 return die_f_("returned false", encoder);
1042 printf("testing FLAC__file_encoder_finish()... ");
1043 FLAC__file_encoder_finish(encoder);
1046 printf("testing FLAC__file_encoder_delete()... ");
1047 FLAC__file_encoder_delete(encoder);
1050 printf("\nPASSED!\n");
1055 FLAC__bool test_encoders()
1057 init_metadata_blocks_();
1059 if(!test_stream_encoder())
1062 if(!test_seekable_stream_encoder())
1065 if(!test_file_encoder())
1068 (void) grabbag__file_remove_file(flacfilename_);
1069 free_metadata_blocks_();