1 /* test_libFLAC - Unit tester for libFLAC
2 * Copyright (C) 2002 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 "FLAC/assert.h"
22 #include "FLAC/file_encoder.h"
23 #include "FLAC/seekable_stream_encoder.h"
24 #include "FLAC/stream_encoder.h"
29 static FLAC__StreamMetadata streaminfo_, padding_, seektable_, application1_, application2_, vorbiscomment_;
30 static FLAC__StreamMetadata *metadata_sequence_[] = { &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_ };
31 static const unsigned num_metadata_ = 5;
32 static const char *flacfilename_ = "metadata.flac";
34 static FLAC__bool die_s_(const char *msg, const FLAC__StreamEncoder *encoder)
36 FLAC__StreamEncoderState state = FLAC__stream_encoder_get_state(encoder);
39 printf("FAILED, %s", msg);
43 printf(", state = %u (%s)\n", (unsigned)state, FLAC__StreamEncoderStateString[state]);
48 static FLAC__bool die_ss_(const char *msg, const FLAC__SeekableStreamEncoder *encoder)
50 FLAC__SeekableStreamEncoderState state = FLAC__seekable_stream_encoder_get_state(encoder);
53 printf("FAILED, %s", msg);
57 printf(", state = %u (%s)\n", (unsigned)state, FLAC__SeekableStreamEncoderStateString[state]);
58 if(state == FLAC__SEEKABLE_STREAM_ENCODER_STREAM_ENCODER_ERROR) {
59 FLAC__StreamEncoderState state_ = FLAC__seekable_stream_encoder_get_stream_encoder_state(encoder);
60 printf(" stream encoder state = %u (%s)\n", (unsigned)state, FLAC__StreamEncoderStateString[state_]);
66 static FLAC__bool die_f_(const char *msg, const FLAC__FileEncoder *encoder)
68 FLAC__FileEncoderState state = FLAC__file_encoder_get_state(encoder);
71 printf("FAILED, %s", msg);
75 printf(", state = %u (%s)\n", (unsigned)state, FLAC__FileEncoderStateString[state]);
76 if(state == FLAC__FILE_ENCODER_SEEKABLE_STREAM_ENCODER_ERROR) {
77 FLAC__SeekableStreamEncoderState state_ = FLAC__file_encoder_get_seekable_stream_encoder_state(encoder);
78 printf(" seekable stream encoder state = %u (%s)\n", (unsigned)state, FLAC__SeekableStreamEncoderStateString[state_]);
79 if(state_ == FLAC__SEEKABLE_STREAM_ENCODER_STREAM_ENCODER_ERROR) {
80 FLAC__StreamEncoderState state__ = FLAC__file_encoder_get_stream_encoder_state(encoder);
81 printf(" stream encoder state = %u (%s)\n", (unsigned)state, FLAC__StreamEncoderStateString[state__]);
88 static void *malloc_or_die_(size_t size)
90 void *x = malloc(size);
92 fprintf(stderr, "ERROR: out of memory allocating %u bytes\n", (unsigned)size);
98 static void init_metadata_blocks_()
101 most of the actual numbers and data in the blocks don't matter,
102 we just want to make sure the encoder encodes them correctly
104 remember, the metadata interface gets tested after the encoders,
105 so we do all the metadata manipulation here without it.
108 /* min/max_framesize and md5sum don't get written at first, so we have to leave them 0 */
109 streaminfo_.is_last = false;
110 streaminfo_.type = FLAC__METADATA_TYPE_STREAMINFO;
111 streaminfo_.length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH;
112 streaminfo_.data.stream_info.min_blocksize = 576;
113 streaminfo_.data.stream_info.max_blocksize = 576;
114 streaminfo_.data.stream_info.min_framesize = 0;
115 streaminfo_.data.stream_info.max_framesize = 0;
116 streaminfo_.data.stream_info.sample_rate = 44100;
117 streaminfo_.data.stream_info.channels = 1;
118 streaminfo_.data.stream_info.bits_per_sample = 8;
119 streaminfo_.data.stream_info.total_samples = 0;
120 memset(streaminfo_.data.stream_info.md5sum, 0, 16);
122 padding_.is_last = false;
123 padding_.type = FLAC__METADATA_TYPE_PADDING;
124 padding_.length = 1234;
126 seektable_.is_last = false;
127 seektable_.type = FLAC__METADATA_TYPE_SEEKTABLE;
128 seektable_.data.seek_table.num_points = 2;
129 seektable_.length = seektable_.data.seek_table.num_points * FLAC__STREAM_METADATA_SEEKPOINT_LENGTH;
130 seektable_.data.seek_table.points = malloc_or_die_(seektable_.data.seek_table.num_points * sizeof(FLAC__StreamMetadata_SeekPoint));
131 seektable_.data.seek_table.points[0].sample_number = 0;
132 seektable_.data.seek_table.points[0].stream_offset = 0;
133 seektable_.data.seek_table.points[0].frame_samples = streaminfo_.data.stream_info.min_blocksize;
134 seektable_.data.seek_table.points[1].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
135 seektable_.data.seek_table.points[1].stream_offset = 1000;
136 seektable_.data.seek_table.points[1].frame_samples = streaminfo_.data.stream_info.min_blocksize;
138 application1_.is_last = false;
139 application1_.type = FLAC__METADATA_TYPE_APPLICATION;
140 application1_.length = 8;
141 memcpy(application1_.data.application.id, "\xfe\xdc\xba\x98", 4);
142 application1_.data.application.data = malloc_or_die_(4);
143 memcpy(application1_.data.application.data, "\xf0\xe1\xd2\xc3", 4);
145 application2_.is_last = false;
146 application2_.type = FLAC__METADATA_TYPE_APPLICATION;
147 application2_.length = 4;
148 memcpy(application2_.data.application.id, "\x76\x54\x32\x10", 4);
149 application2_.data.application.data = 0;
151 vorbiscomment_.is_last = true;
152 vorbiscomment_.type = FLAC__METADATA_TYPE_VORBIS_COMMENT;
153 vorbiscomment_.length = (4 + 8) + 4 + (4 + 5) + (4 + 0);
154 vorbiscomment_.data.vorbis_comment.vendor_string.length = 8;
155 vorbiscomment_.data.vorbis_comment.vendor_string.entry = malloc_or_die_(8);
156 memcpy(vorbiscomment_.data.vorbis_comment.vendor_string.entry, "flac 1.x", 8);
157 vorbiscomment_.data.vorbis_comment.num_comments = 2;
158 vorbiscomment_.data.vorbis_comment.comments = malloc_or_die_(vorbiscomment_.data.vorbis_comment.num_comments * sizeof(FLAC__StreamMetadata_VorbisComment_Entry));
159 vorbiscomment_.data.vorbis_comment.comments[0].length = 5;
160 vorbiscomment_.data.vorbis_comment.comments[0].entry = malloc_or_die_(5);
161 memcpy(vorbiscomment_.data.vorbis_comment.comments[0].entry, "ab=cd", 5);
162 vorbiscomment_.data.vorbis_comment.comments[1].length = 0;
163 vorbiscomment_.data.vorbis_comment.comments[1].entry = 0;
166 static void free_metadata_blocks_()
168 free(seektable_.data.seek_table.points);
169 free(application1_.data.application.data);
170 free(vorbiscomment_.data.vorbis_comment.vendor_string.entry);
171 free(vorbiscomment_.data.vorbis_comment.comments[0].entry);
172 free(vorbiscomment_.data.vorbis_comment.comments);
175 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)
177 (void)encoder, (void)buffer, (void)bytes, (void)samples, (void)current_frame, (void)client_data;
178 return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
181 static void stream_encoder_metadata_callback_(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetadata *metadata, void *client_data)
183 (void)encoder, (void)metadata, (void)client_data;
186 static FLAC__bool test_stream_encoder()
188 FLAC__StreamEncoder *encoder;
189 FLAC__StreamEncoderState state;
190 FLAC__int32 samples[1024];
191 FLAC__int32 *samples_array[1] = { samples };
194 printf("\n+++ libFLAC unit test: FLAC__StreamEncoder\n\n");
196 printf("testing FLAC__stream_encoder_new()... ");
197 encoder = FLAC__stream_encoder_new();
199 printf("FAILED, returned NULL\n");
204 printf("testing FLAC__stream_encoder_set_streamable_subset()... ");
205 if(!FLAC__stream_encoder_set_streamable_subset(encoder, true))
206 return die_s_("returned false", encoder);
209 printf("testing FLAC__stream_encoder_set_do_mid_side_stereo()... ");
210 if(!FLAC__stream_encoder_set_do_mid_side_stereo(encoder, false))
211 return die_s_("returned false", encoder);
214 printf("testing FLAC__stream_encoder_set_loose_mid_side_stereo()... ");
215 if(!FLAC__stream_encoder_set_loose_mid_side_stereo(encoder, false))
216 return die_s_("returned false", encoder);
219 printf("testing FLAC__stream_encoder_set_channels()... ");
220 if(!FLAC__stream_encoder_set_channels(encoder, streaminfo_.data.stream_info.channels))
221 return die_s_("returned false", encoder);
224 printf("testing FLAC__stream_encoder_set_bits_per_sample()... ");
225 if(!FLAC__stream_encoder_set_bits_per_sample(encoder, streaminfo_.data.stream_info.bits_per_sample))
226 return die_s_("returned false", encoder);
229 printf("testing FLAC__stream_encoder_set_sample_rate()... ");
230 if(!FLAC__stream_encoder_set_sample_rate(encoder, streaminfo_.data.stream_info.sample_rate))
231 return die_s_("returned false", encoder);
234 printf("testing FLAC__stream_encoder_set_blocksize()... ");
235 if(!FLAC__stream_encoder_set_blocksize(encoder, streaminfo_.data.stream_info.min_blocksize))
236 return die_s_("returned false", encoder);
239 printf("testing FLAC__stream_encoder_set_max_lpc_order()... ");
240 if(!FLAC__stream_encoder_set_max_lpc_order(encoder, 0))
241 return die_s_("returned false", encoder);
244 printf("testing FLAC__stream_encoder_set_qlp_coeff_precision()... ");
245 if(!FLAC__stream_encoder_set_qlp_coeff_precision(encoder, 0))
246 return die_s_("returned false", encoder);
249 printf("testing FLAC__stream_encoder_set_do_qlp_coeff_prec_search()... ");
250 if(!FLAC__stream_encoder_set_do_qlp_coeff_prec_search(encoder, false))
251 return die_s_("returned false", encoder);
254 printf("testing FLAC__stream_encoder_set_do_escape_coding()... ");
255 if(!FLAC__stream_encoder_set_do_escape_coding(encoder, false))
256 return die_s_("returned false", encoder);
259 printf("testing FLAC__stream_encoder_set_do_exhaustive_model_search()... ");
260 if(!FLAC__stream_encoder_set_do_exhaustive_model_search(encoder, false))
261 return die_s_("returned false", encoder);
264 printf("testing FLAC__stream_encoder_set_min_residual_partition_order()... ");
265 if(!FLAC__stream_encoder_set_min_residual_partition_order(encoder, 0))
266 return die_s_("returned false", encoder);
269 printf("testing FLAC__stream_encoder_set_max_residual_partition_order()... ");
270 if(!FLAC__stream_encoder_set_max_residual_partition_order(encoder, 0))
271 return die_s_("returned false", encoder);
274 printf("testing FLAC__stream_encoder_set_rice_parameter_search_dist()... ");
275 if(!FLAC__stream_encoder_set_rice_parameter_search_dist(encoder, 0))
276 return die_s_("returned false", encoder);
279 printf("testing FLAC__stream_encoder_set_total_samples_estimate()... ");
280 if(!FLAC__stream_encoder_set_total_samples_estimate(encoder, streaminfo_.data.stream_info.total_samples))
281 return die_s_("returned false", encoder);
284 printf("testing FLAC__stream_encoder_set_metadata()... ");
285 if(!FLAC__stream_encoder_set_metadata(encoder, metadata_sequence_, num_metadata_))
286 return die_s_("returned false", encoder);
289 printf("testing FLAC__stream_encoder_set_write_callback()... ");
290 if(!FLAC__stream_encoder_set_write_callback(encoder, stream_encoder_write_callback_))
291 return die_s_("returned false", encoder);
294 printf("testing FLAC__stream_encoder_set_metadata_callback()... ");
295 if(!FLAC__stream_encoder_set_metadata_callback(encoder, stream_encoder_metadata_callback_))
296 return die_s_("returned false", encoder);
299 printf("testing FLAC__stream_encoder_set_client_data()... ");
300 if(!FLAC__stream_encoder_set_client_data(encoder, 0))
301 return die_s_("returned false", encoder);
304 printf("testing FLAC__stream_encoder_init()... ");
305 if(FLAC__stream_encoder_init(encoder) != FLAC__STREAM_ENCODER_OK)
306 return die_s_(0, encoder);
309 printf("testing FLAC__stream_encoder_get_state()... ");
310 state = FLAC__stream_encoder_get_state(encoder);
311 printf("returned state = %u (%s)... OK\n", (unsigned)state, FLAC__StreamEncoderStateString[state]);
313 printf("testing FLAC__stream_encoder_get_streamable_subset()... ");
314 if(FLAC__stream_encoder_get_streamable_subset(encoder) != true) {
315 printf("FAILED, expected true, got false\n");
320 printf("testing FLAC__stream_encoder_get_do_mid_side_stereo()... ");
321 if(FLAC__stream_encoder_get_do_mid_side_stereo(encoder) != false) {
322 printf("FAILED, expected false, got true\n");
327 printf("testing FLAC__stream_encoder_get_loose_mid_side_stereo()... ");
328 if(FLAC__stream_encoder_get_loose_mid_side_stereo(encoder) != false) {
329 printf("FAILED, expected false, got true\n");
334 printf("testing FLAC__stream_encoder_get_channels()... ");
335 if(FLAC__stream_encoder_get_channels(encoder) != streaminfo_.data.stream_info.channels) {
336 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.channels, FLAC__stream_encoder_get_channels(encoder));
341 printf("testing FLAC__stream_encoder_get_bits_per_sample()... ");
342 if(FLAC__stream_encoder_get_bits_per_sample(encoder) != streaminfo_.data.stream_info.bits_per_sample) {
343 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.bits_per_sample, FLAC__stream_encoder_get_bits_per_sample(encoder));
348 printf("testing FLAC__stream_encoder_get_sample_rate()... ");
349 if(FLAC__stream_encoder_get_sample_rate(encoder) != streaminfo_.data.stream_info.sample_rate) {
350 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.sample_rate, FLAC__stream_encoder_get_sample_rate(encoder));
355 printf("testing FLAC__stream_encoder_get_blocksize()... ");
356 if(FLAC__stream_encoder_get_blocksize(encoder) != streaminfo_.data.stream_info.min_blocksize) {
357 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.min_blocksize, FLAC__stream_encoder_get_blocksize(encoder));
362 printf("testing FLAC__stream_encoder_get_max_lpc_order()... ");
363 if(FLAC__stream_encoder_get_max_lpc_order(encoder) != 0) {
364 printf("FAILED, expected %u, got %u\n", 0, FLAC__stream_encoder_get_max_lpc_order(encoder));
369 printf("testing FLAC__stream_encoder_get_qlp_coeff_precision()... ");
370 (void)FLAC__stream_encoder_get_qlp_coeff_precision(encoder);
371 /* we asked the encoder to auto select this so we accept anything */
374 printf("testing FLAC__stream_encoder_get_do_qlp_coeff_prec_search()... ");
375 if(FLAC__stream_encoder_get_do_qlp_coeff_prec_search(encoder) != false) {
376 printf("FAILED, expected false, got true\n");
381 printf("testing FLAC__stream_encoder_get_do_escape_coding()... ");
382 if(FLAC__stream_encoder_get_do_escape_coding(encoder) != false) {
383 printf("FAILED, expected false, got true\n");
388 printf("testing FLAC__stream_encoder_get_do_exhaustive_model_search()... ");
389 if(FLAC__stream_encoder_get_do_exhaustive_model_search(encoder) != false) {
390 printf("FAILED, expected false, got true\n");
395 printf("testing FLAC__stream_encoder_get_min_residual_partition_order()... ");
396 if(FLAC__stream_encoder_get_min_residual_partition_order(encoder) != 0) {
397 printf("FAILED, expected %u, got %u\n", 0, FLAC__stream_encoder_get_min_residual_partition_order(encoder));
402 printf("testing FLAC__stream_encoder_get_max_residual_partition_order()... ");
403 if(FLAC__stream_encoder_get_max_residual_partition_order(encoder) != 0) {
404 printf("FAILED, expected %u, got %u\n", 0, FLAC__stream_encoder_get_max_residual_partition_order(encoder));
409 printf("testing FLAC__stream_encoder_get_rice_parameter_search_dist()... ");
410 if(FLAC__stream_encoder_get_rice_parameter_search_dist(encoder) != 0) {
411 printf("FAILED, expected %u, got %u\n", 0, FLAC__stream_encoder_get_rice_parameter_search_dist(encoder));
416 printf("testing FLAC__stream_encoder_get_total_samples_estimate()... ");
417 if(FLAC__stream_encoder_get_total_samples_estimate(encoder) != streaminfo_.data.stream_info.total_samples) {
418 printf("FAILED, expected %llu, got %llu\n", streaminfo_.data.stream_info.total_samples, FLAC__stream_encoder_get_total_samples_estimate(encoder));
423 /* init the dummy sample buffer */
424 for(i = 0; i < sizeof(samples) / sizeof(FLAC__int32); i++)
427 printf("testing FLAC__stream_encoder_process()... ");
428 if(!FLAC__stream_encoder_process(encoder, (const FLAC__int32 * const *)samples_array, sizeof(samples) / sizeof(FLAC__int32)))
429 return die_s_("returned false", encoder);
432 printf("testing FLAC__stream_encoder_process_interleaved()... ");
433 if(!FLAC__stream_encoder_process_interleaved(encoder, samples, sizeof(samples) / sizeof(FLAC__int32)))
434 return die_s_("returned false", encoder);
437 printf("testing FLAC__stream_encoder_finish()... ");
438 FLAC__stream_encoder_finish(encoder);
441 printf("testing FLAC__stream_encoder_delete()... ");
442 FLAC__stream_encoder_delete(encoder);
445 printf("\nPASSED!\n");
450 FLAC__SeekableStreamEncoderSeekStatus seekable_stream_encoder_seek_callback_(const FLAC__SeekableStreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data)
452 (void)encoder, (void)absolute_byte_offset, (void)client_data;
453 return FLAC__SEEKABLE_STREAM_ENCODER_SEEK_STATUS_OK;
456 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)
458 (void)encoder, (void)buffer, (void)bytes, (void)samples, (void)current_frame, (void)client_data;
459 return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
462 static FLAC__bool test_seekable_stream_encoder()
464 FLAC__SeekableStreamEncoder *encoder;
465 FLAC__SeekableStreamEncoderState state;
466 FLAC__int32 samples[1024];
467 FLAC__int32 *samples_array[1] = { samples };
470 printf("\n+++ libFLAC unit test: FLAC__SeekableStreamEncoder\n\n");
472 printf("testing FLAC__seekable_stream_encoder_new()... ");
473 encoder = FLAC__seekable_stream_encoder_new();
475 printf("FAILED, returned NULL\n");
480 printf("testing FLAC__seekable_stream_encoder_set_streamable_subset()... ");
481 if(!FLAC__seekable_stream_encoder_set_streamable_subset(encoder, true))
482 return die_ss_("returned false", encoder);
485 printf("testing FLAC__seekable_stream_encoder_set_do_mid_side_stereo()... ");
486 if(!FLAC__seekable_stream_encoder_set_do_mid_side_stereo(encoder, false))
487 return die_ss_("returned false", encoder);
490 printf("testing FLAC__seekable_stream_encoder_set_loose_mid_side_stereo()... ");
491 if(!FLAC__seekable_stream_encoder_set_loose_mid_side_stereo(encoder, false))
492 return die_ss_("returned false", encoder);
495 printf("testing FLAC__seekable_stream_encoder_set_channels()... ");
496 if(!FLAC__seekable_stream_encoder_set_channels(encoder, streaminfo_.data.stream_info.channels))
497 return die_ss_("returned false", encoder);
500 printf("testing FLAC__seekable_stream_encoder_set_bits_per_sample()... ");
501 if(!FLAC__seekable_stream_encoder_set_bits_per_sample(encoder, streaminfo_.data.stream_info.bits_per_sample))
502 return die_ss_("returned false", encoder);
505 printf("testing FLAC__seekable_stream_encoder_set_sample_rate()... ");
506 if(!FLAC__seekable_stream_encoder_set_sample_rate(encoder, streaminfo_.data.stream_info.sample_rate))
507 return die_ss_("returned false", encoder);
510 printf("testing FLAC__seekable_stream_encoder_set_blocksize()... ");
511 if(!FLAC__seekable_stream_encoder_set_blocksize(encoder, streaminfo_.data.stream_info.min_blocksize))
512 return die_ss_("returned false", encoder);
515 printf("testing FLAC__seekable_stream_encoder_set_max_lpc_order()... ");
516 if(!FLAC__seekable_stream_encoder_set_max_lpc_order(encoder, 0))
517 return die_ss_("returned false", encoder);
520 printf("testing FLAC__seekable_stream_encoder_set_qlp_coeff_precision()... ");
521 if(!FLAC__seekable_stream_encoder_set_qlp_coeff_precision(encoder, 0))
522 return die_ss_("returned false", encoder);
525 printf("testing FLAC__seekable_stream_encoder_set_do_qlp_coeff_prec_search()... ");
526 if(!FLAC__seekable_stream_encoder_set_do_qlp_coeff_prec_search(encoder, false))
527 return die_ss_("returned false", encoder);
530 printf("testing FLAC__seekable_stream_encoder_set_do_escape_coding()... ");
531 if(!FLAC__seekable_stream_encoder_set_do_escape_coding(encoder, false))
532 return die_ss_("returned false", encoder);
535 printf("testing FLAC__seekable_stream_encoder_set_do_exhaustive_model_search()... ");
536 if(!FLAC__seekable_stream_encoder_set_do_exhaustive_model_search(encoder, false))
537 return die_ss_("returned false", encoder);
540 printf("testing FLAC__seekable_stream_encoder_set_min_residual_partition_order()... ");
541 if(!FLAC__seekable_stream_encoder_set_min_residual_partition_order(encoder, 0))
542 return die_ss_("returned false", encoder);
545 printf("testing FLAC__seekable_stream_encoder_set_max_residual_partition_order()... ");
546 if(!FLAC__seekable_stream_encoder_set_max_residual_partition_order(encoder, 0))
547 return die_ss_("returned false", encoder);
550 printf("testing FLAC__seekable_stream_encoder_set_rice_parameter_search_dist()... ");
551 if(!FLAC__seekable_stream_encoder_set_rice_parameter_search_dist(encoder, 0))
552 return die_ss_("returned false", encoder);
555 printf("testing FLAC__seekable_stream_encoder_set_total_samples_estimate()... ");
556 if(!FLAC__seekable_stream_encoder_set_total_samples_estimate(encoder, streaminfo_.data.stream_info.total_samples))
557 return die_ss_("returned false", encoder);
560 printf("testing FLAC__seekable_stream_encoder_set_metadata()... ");
561 if(!FLAC__seekable_stream_encoder_set_metadata(encoder, metadata_sequence_, num_metadata_))
562 return die_ss_("returned false", encoder);
565 printf("testing FLAC__seekable_stream_encoder_set_seek_callback()... ");
566 if(!FLAC__seekable_stream_encoder_set_seek_callback(encoder, seekable_stream_encoder_seek_callback_))
567 return die_ss_("returned false", encoder);
570 printf("testing FLAC__seekable_stream_encoder_set_write_callback()... ");
571 if(!FLAC__seekable_stream_encoder_set_write_callback(encoder, seekable_stream_encoder_write_callback_))
572 return die_ss_("returned false", encoder);
575 printf("testing FLAC__seekable_stream_encoder_set_client_data()... ");
576 if(!FLAC__seekable_stream_encoder_set_client_data(encoder, 0))
577 return die_ss_("returned false", encoder);
580 printf("testing FLAC__seekable_stream_encoder_init()... ");
581 if(FLAC__seekable_stream_encoder_init(encoder) != FLAC__SEEKABLE_STREAM_ENCODER_OK)
582 return die_ss_(0, encoder);
585 printf("testing FLAC__seekable_stream_encoder_get_state()... ");
586 state = FLAC__seekable_stream_encoder_get_state(encoder);
587 printf("returned state = %u (%s)... OK\n", (unsigned)state, FLAC__SeekableStreamEncoderStateString[state]);
589 printf("testing FLAC__seekable_stream_encoder_get_streamable_subset()... ");
590 if(FLAC__seekable_stream_encoder_get_streamable_subset(encoder) != true) {
591 printf("FAILED, expected true, got false\n");
596 printf("testing FLAC__seekable_stream_encoder_get_do_mid_side_stereo()... ");
597 if(FLAC__seekable_stream_encoder_get_do_mid_side_stereo(encoder) != false) {
598 printf("FAILED, expected false, got true\n");
603 printf("testing FLAC__seekable_stream_encoder_get_loose_mid_side_stereo()... ");
604 if(FLAC__seekable_stream_encoder_get_loose_mid_side_stereo(encoder) != false) {
605 printf("FAILED, expected false, got true\n");
610 printf("testing FLAC__seekable_stream_encoder_get_channels()... ");
611 if(FLAC__seekable_stream_encoder_get_channels(encoder) != streaminfo_.data.stream_info.channels) {
612 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.channels, FLAC__seekable_stream_encoder_get_channels(encoder));
617 printf("testing FLAC__seekable_stream_encoder_get_bits_per_sample()... ");
618 if(FLAC__seekable_stream_encoder_get_bits_per_sample(encoder) != streaminfo_.data.stream_info.bits_per_sample) {
619 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.bits_per_sample, FLAC__seekable_stream_encoder_get_bits_per_sample(encoder));
624 printf("testing FLAC__seekable_stream_encoder_get_sample_rate()... ");
625 if(FLAC__seekable_stream_encoder_get_sample_rate(encoder) != streaminfo_.data.stream_info.sample_rate) {
626 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.sample_rate, FLAC__seekable_stream_encoder_get_sample_rate(encoder));
631 printf("testing FLAC__seekable_stream_encoder_get_blocksize()... ");
632 if(FLAC__seekable_stream_encoder_get_blocksize(encoder) != streaminfo_.data.stream_info.min_blocksize) {
633 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.min_blocksize, FLAC__seekable_stream_encoder_get_blocksize(encoder));
638 printf("testing FLAC__seekable_stream_encoder_get_max_lpc_order()... ");
639 if(FLAC__seekable_stream_encoder_get_max_lpc_order(encoder) != 0) {
640 printf("FAILED, expected %u, got %u\n", 0, FLAC__seekable_stream_encoder_get_max_lpc_order(encoder));
645 printf("testing FLAC__seekable_stream_encoder_get_qlp_coeff_precision()... ");
646 (void)FLAC__seekable_stream_encoder_get_qlp_coeff_precision(encoder);
647 /* we asked the encoder to auto select this so we accept anything */
650 printf("testing FLAC__seekable_stream_encoder_get_do_qlp_coeff_prec_search()... ");
651 if(FLAC__seekable_stream_encoder_get_do_qlp_coeff_prec_search(encoder) != false) {
652 printf("FAILED, expected false, got true\n");
657 printf("testing FLAC__seekable_stream_encoder_get_do_escape_coding()... ");
658 if(FLAC__seekable_stream_encoder_get_do_escape_coding(encoder) != false) {
659 printf("FAILED, expected false, got true\n");
664 printf("testing FLAC__seekable_stream_encoder_get_do_exhaustive_model_search()... ");
665 if(FLAC__seekable_stream_encoder_get_do_exhaustive_model_search(encoder) != false) {
666 printf("FAILED, expected false, got true\n");
671 printf("testing FLAC__seekable_stream_encoder_get_min_residual_partition_order()... ");
672 if(FLAC__seekable_stream_encoder_get_min_residual_partition_order(encoder) != 0) {
673 printf("FAILED, expected %u, got %u\n", 0, FLAC__seekable_stream_encoder_get_min_residual_partition_order(encoder));
678 printf("testing FLAC__seekable_stream_encoder_get_max_residual_partition_order()... ");
679 if(FLAC__seekable_stream_encoder_get_max_residual_partition_order(encoder) != 0) {
680 printf("FAILED, expected %u, got %u\n", 0, FLAC__seekable_stream_encoder_get_max_residual_partition_order(encoder));
685 printf("testing FLAC__seekable_stream_encoder_get_rice_parameter_search_dist()... ");
686 if(FLAC__seekable_stream_encoder_get_rice_parameter_search_dist(encoder) != 0) {
687 printf("FAILED, expected %u, got %u\n", 0, FLAC__seekable_stream_encoder_get_rice_parameter_search_dist(encoder));
692 printf("testing FLAC__seekable_stream_encoder_get_total_samples_estimate()... ");
693 if(FLAC__seekable_stream_encoder_get_total_samples_estimate(encoder) != streaminfo_.data.stream_info.total_samples) {
694 printf("FAILED, expected %llu, got %llu\n", streaminfo_.data.stream_info.total_samples, FLAC__seekable_stream_encoder_get_total_samples_estimate(encoder));
699 /* init the dummy sample buffer */
700 for(i = 0; i < sizeof(samples) / sizeof(FLAC__int32); i++)
703 printf("testing FLAC__seekable_stream_encoder_process()... ");
704 if(!FLAC__seekable_stream_encoder_process(encoder, (const FLAC__int32 * const *)samples_array, sizeof(samples) / sizeof(FLAC__int32)))
705 return die_ss_("returned false", encoder);
708 printf("testing FLAC__seekable_stream_encoder_process_interleaved()... ");
709 if(!FLAC__seekable_stream_encoder_process_interleaved(encoder, samples, sizeof(samples) / sizeof(FLAC__int32)))
710 return die_ss_("returned false", encoder);
713 printf("testing FLAC__seekable_stream_encoder_finish()... ");
714 FLAC__seekable_stream_encoder_finish(encoder);
717 printf("testing FLAC__seekable_stream_encoder_delete()... ");
718 FLAC__seekable_stream_encoder_delete(encoder);
721 printf("\nPASSED!\n");
726 static void file_encoder_progress_callback_(const FLAC__FileEncoder *encoder, unsigned current_frame, unsigned total_frames_estimate, void *client_data)
728 (void)encoder, (void)current_frame, (void)total_frames_estimate, (void)client_data;
731 static FLAC__bool test_file_encoder()
733 FLAC__FileEncoder *encoder;
734 FLAC__FileEncoderState state;
735 FLAC__int32 samples[1024];
736 FLAC__int32 *samples_array[1] = { samples };
739 printf("\n+++ libFLAC unit test: FLAC__FileEncoder\n\n");
741 printf("testing FLAC__file_encoder_new()... ");
742 encoder = FLAC__file_encoder_new();
744 printf("FAILED, returned NULL\n");
749 printf("testing FLAC__file_encoder_set_streamable_subset()... ");
750 if(!FLAC__file_encoder_set_streamable_subset(encoder, true))
751 return die_f_("returned false", encoder);
754 printf("testing FLAC__file_encoder_set_do_mid_side_stereo()... ");
755 if(!FLAC__file_encoder_set_do_mid_side_stereo(encoder, false))
756 return die_f_("returned false", encoder);
759 printf("testing FLAC__file_encoder_set_loose_mid_side_stereo()... ");
760 if(!FLAC__file_encoder_set_loose_mid_side_stereo(encoder, false))
761 return die_f_("returned false", encoder);
764 printf("testing FLAC__file_encoder_set_channels()... ");
765 if(!FLAC__file_encoder_set_channels(encoder, streaminfo_.data.stream_info.channels))
766 return die_f_("returned false", encoder);
769 printf("testing FLAC__file_encoder_set_bits_per_sample()... ");
770 if(!FLAC__file_encoder_set_bits_per_sample(encoder, streaminfo_.data.stream_info.bits_per_sample))
771 return die_f_("returned false", encoder);
774 printf("testing FLAC__file_encoder_set_sample_rate()... ");
775 if(!FLAC__file_encoder_set_sample_rate(encoder, streaminfo_.data.stream_info.sample_rate))
776 return die_f_("returned false", encoder);
779 printf("testing FLAC__file_encoder_set_blocksize()... ");
780 if(!FLAC__file_encoder_set_blocksize(encoder, streaminfo_.data.stream_info.min_blocksize))
781 return die_f_("returned false", encoder);
784 printf("testing FLAC__file_encoder_set_max_lpc_order()... ");
785 if(!FLAC__file_encoder_set_max_lpc_order(encoder, 0))
786 return die_f_("returned false", encoder);
789 printf("testing FLAC__file_encoder_set_qlp_coeff_precision()... ");
790 if(!FLAC__file_encoder_set_qlp_coeff_precision(encoder, 0))
791 return die_f_("returned false", encoder);
794 printf("testing FLAC__file_encoder_set_do_qlp_coeff_prec_search()... ");
795 if(!FLAC__file_encoder_set_do_qlp_coeff_prec_search(encoder, false))
796 return die_f_("returned false", encoder);
799 printf("testing FLAC__file_encoder_set_do_escape_coding()... ");
800 if(!FLAC__file_encoder_set_do_escape_coding(encoder, false))
801 return die_f_("returned false", encoder);
804 printf("testing FLAC__file_encoder_set_do_exhaustive_model_search()... ");
805 if(!FLAC__file_encoder_set_do_exhaustive_model_search(encoder, false))
806 return die_f_("returned false", encoder);
809 printf("testing FLAC__file_encoder_set_min_residual_partition_order()... ");
810 if(!FLAC__file_encoder_set_min_residual_partition_order(encoder, 0))
811 return die_f_("returned false", encoder);
814 printf("testing FLAC__file_encoder_set_max_residual_partition_order()... ");
815 if(!FLAC__file_encoder_set_max_residual_partition_order(encoder, 0))
816 return die_f_("returned false", encoder);
819 printf("testing FLAC__file_encoder_set_rice_parameter_search_dist()... ");
820 if(!FLAC__file_encoder_set_rice_parameter_search_dist(encoder, 0))
821 return die_f_("returned false", encoder);
824 printf("testing FLAC__file_encoder_set_total_samples_estimate()... ");
825 if(!FLAC__file_encoder_set_total_samples_estimate(encoder, streaminfo_.data.stream_info.total_samples))
826 return die_f_("returned false", encoder);
829 printf("testing FLAC__file_encoder_set_metadata()... ");
830 if(!FLAC__file_encoder_set_metadata(encoder, metadata_sequence_, num_metadata_))
831 return die_f_("returned false", encoder);
834 printf("testing FLAC__file_encoder_set_filename()... ");
835 if(!FLAC__file_encoder_set_filename(encoder, flacfilename_))
836 return die_f_("returned false", encoder);
839 printf("testing FLAC__file_encoder_set_progress_callback()... ");
840 if(!FLAC__file_encoder_set_progress_callback(encoder, file_encoder_progress_callback_))
841 return die_f_("returned false", encoder);
844 printf("testing FLAC__file_encoder_set_client_data()... ");
845 if(!FLAC__file_encoder_set_client_data(encoder, 0))
846 return die_f_("returned false", encoder);
849 printf("testing FLAC__file_encoder_init()... ");
850 if(FLAC__file_encoder_init(encoder) != FLAC__FILE_ENCODER_OK)
851 return die_f_(0, encoder);
854 printf("testing FLAC__file_encoder_get_state()... ");
855 state = FLAC__file_encoder_get_state(encoder);
856 printf("returned state = %u (%s)... OK\n", (unsigned)state, FLAC__FileEncoderStateString[state]);
858 printf("testing FLAC__file_encoder_get_streamable_subset()... ");
859 if(FLAC__file_encoder_get_streamable_subset(encoder) != true) {
860 printf("FAILED, expected true, got false\n");
865 printf("testing FLAC__file_encoder_get_do_mid_side_stereo()... ");
866 if(FLAC__file_encoder_get_do_mid_side_stereo(encoder) != false) {
867 printf("FAILED, expected false, got true\n");
872 printf("testing FLAC__file_encoder_get_loose_mid_side_stereo()... ");
873 if(FLAC__file_encoder_get_loose_mid_side_stereo(encoder) != false) {
874 printf("FAILED, expected false, got true\n");
879 printf("testing FLAC__file_encoder_get_channels()... ");
880 if(FLAC__file_encoder_get_channels(encoder) != streaminfo_.data.stream_info.channels) {
881 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.channels, FLAC__file_encoder_get_channels(encoder));
886 printf("testing FLAC__file_encoder_get_bits_per_sample()... ");
887 if(FLAC__file_encoder_get_bits_per_sample(encoder) != streaminfo_.data.stream_info.bits_per_sample) {
888 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.bits_per_sample, FLAC__file_encoder_get_bits_per_sample(encoder));
893 printf("testing FLAC__file_encoder_get_sample_rate()... ");
894 if(FLAC__file_encoder_get_sample_rate(encoder) != streaminfo_.data.stream_info.sample_rate) {
895 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.sample_rate, FLAC__file_encoder_get_sample_rate(encoder));
900 printf("testing FLAC__file_encoder_get_blocksize()... ");
901 if(FLAC__file_encoder_get_blocksize(encoder) != streaminfo_.data.stream_info.min_blocksize) {
902 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.min_blocksize, FLAC__file_encoder_get_blocksize(encoder));
907 printf("testing FLAC__file_encoder_get_max_lpc_order()... ");
908 if(FLAC__file_encoder_get_max_lpc_order(encoder) != 0) {
909 printf("FAILED, expected %u, got %u\n", 0, FLAC__file_encoder_get_max_lpc_order(encoder));
914 printf("testing FLAC__file_encoder_get_qlp_coeff_precision()... ");
915 (void)FLAC__file_encoder_get_qlp_coeff_precision(encoder);
916 /* we asked the encoder to auto select this so we accept anything */
919 printf("testing FLAC__file_encoder_get_do_qlp_coeff_prec_search()... ");
920 if(FLAC__file_encoder_get_do_qlp_coeff_prec_search(encoder) != false) {
921 printf("FAILED, expected false, got true\n");
926 printf("testing FLAC__file_encoder_get_do_escape_coding()... ");
927 if(FLAC__file_encoder_get_do_escape_coding(encoder) != false) {
928 printf("FAILED, expected false, got true\n");
933 printf("testing FLAC__file_encoder_get_do_exhaustive_model_search()... ");
934 if(FLAC__file_encoder_get_do_exhaustive_model_search(encoder) != false) {
935 printf("FAILED, expected false, got true\n");
940 printf("testing FLAC__file_encoder_get_min_residual_partition_order()... ");
941 if(FLAC__file_encoder_get_min_residual_partition_order(encoder) != 0) {
942 printf("FAILED, expected %u, got %u\n", 0, FLAC__file_encoder_get_min_residual_partition_order(encoder));
947 printf("testing FLAC__file_encoder_get_max_residual_partition_order()... ");
948 if(FLAC__file_encoder_get_max_residual_partition_order(encoder) != 0) {
949 printf("FAILED, expected %u, got %u\n", 0, FLAC__file_encoder_get_max_residual_partition_order(encoder));
954 printf("testing FLAC__file_encoder_get_rice_parameter_search_dist()... ");
955 if(FLAC__file_encoder_get_rice_parameter_search_dist(encoder) != 0) {
956 printf("FAILED, expected %u, got %u\n", 0, FLAC__file_encoder_get_rice_parameter_search_dist(encoder));
961 printf("testing FLAC__file_encoder_get_total_samples_estimate()... ");
962 if(FLAC__file_encoder_get_total_samples_estimate(encoder) != streaminfo_.data.stream_info.total_samples) {
963 printf("FAILED, expected %llu, got %llu\n", streaminfo_.data.stream_info.total_samples, FLAC__file_encoder_get_total_samples_estimate(encoder));
968 /* init the dummy sample buffer */
969 for(i = 0; i < sizeof(samples) / sizeof(FLAC__int32); i++)
972 printf("testing FLAC__file_encoder_process()... ");
973 if(!FLAC__file_encoder_process(encoder, (const FLAC__int32 * const *)samples_array, sizeof(samples) / sizeof(FLAC__int32)))
974 return die_f_("returned false", encoder);
977 printf("testing FLAC__file_encoder_process_interleaved()... ");
978 if(!FLAC__file_encoder_process_interleaved(encoder, samples, sizeof(samples) / sizeof(FLAC__int32)))
979 return die_f_("returned false", encoder);
982 printf("testing FLAC__file_encoder_finish()... ");
983 FLAC__file_encoder_finish(encoder);
986 printf("testing FLAC__file_encoder_delete()... ");
987 FLAC__file_encoder_delete(encoder);
990 printf("\nPASSED!\n");
995 FLAC__bool test_encoders()
997 init_metadata_blocks_();
999 if(!test_stream_encoder())
1002 if(!test_seekable_stream_encoder())
1005 if(!test_file_encoder())
1008 (void) file_utils__remove_file(flacfilename_);
1009 free_metadata_blocks_();