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_]);
61 if(state_ == FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR) {
62 FLAC__StreamDecoderState dstate = FLAC__seekable_stream_encoder_get_verify_decoder_state(encoder);
63 printf(" verify decoder state = %u (%s)\n", (unsigned)dstate, FLAC__StreamDecoderStateString[dstate]);
70 static FLAC__bool die_f_(const char *msg, const FLAC__FileEncoder *encoder)
72 FLAC__FileEncoderState state = FLAC__file_encoder_get_state(encoder);
75 printf("FAILED, %s", msg);
79 printf(", state = %u (%s)\n", (unsigned)state, FLAC__FileEncoderStateString[state]);
80 if(state == FLAC__FILE_ENCODER_SEEKABLE_STREAM_ENCODER_ERROR) {
81 FLAC__SeekableStreamEncoderState state_ = FLAC__file_encoder_get_seekable_stream_encoder_state(encoder);
82 printf(" seekable stream encoder state = %u (%s)\n", (unsigned)state_, FLAC__SeekableStreamEncoderStateString[state_]);
83 if(state_ == FLAC__SEEKABLE_STREAM_ENCODER_STREAM_ENCODER_ERROR) {
84 FLAC__StreamEncoderState state__ = FLAC__file_encoder_get_stream_encoder_state(encoder);
85 printf(" stream encoder state = %u (%s)\n", (unsigned)state__, FLAC__StreamEncoderStateString[state__]);
86 if(state__ == FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR) {
87 FLAC__StreamDecoderState dstate = FLAC__file_encoder_get_verify_decoder_state(encoder);
88 printf(" verify decoder state = %u (%s)\n", (unsigned)dstate, FLAC__StreamDecoderStateString[dstate]);
96 static void *malloc_or_die_(size_t size)
98 void *x = malloc(size);
100 fprintf(stderr, "ERROR: out of memory allocating %u bytes\n", (unsigned)size);
106 static void init_metadata_blocks_()
109 most of the actual numbers and data in the blocks don't matter,
110 we just want to make sure the encoder encodes them correctly
112 remember, the metadata interface gets tested after the encoders,
113 so we do all the metadata manipulation here without it.
116 /* min/max_framesize and md5sum don't get written at first, so we have to leave them 0 */
117 streaminfo_.is_last = false;
118 streaminfo_.type = FLAC__METADATA_TYPE_STREAMINFO;
119 streaminfo_.length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH;
120 streaminfo_.data.stream_info.min_blocksize = 576;
121 streaminfo_.data.stream_info.max_blocksize = 576;
122 streaminfo_.data.stream_info.min_framesize = 0;
123 streaminfo_.data.stream_info.max_framesize = 0;
124 streaminfo_.data.stream_info.sample_rate = 44100;
125 streaminfo_.data.stream_info.channels = 1;
126 streaminfo_.data.stream_info.bits_per_sample = 8;
127 streaminfo_.data.stream_info.total_samples = 0;
128 memset(streaminfo_.data.stream_info.md5sum, 0, 16);
130 padding_.is_last = false;
131 padding_.type = FLAC__METADATA_TYPE_PADDING;
132 padding_.length = 1234;
134 seektable_.is_last = false;
135 seektable_.type = FLAC__METADATA_TYPE_SEEKTABLE;
136 seektable_.data.seek_table.num_points = 2;
137 seektable_.length = seektable_.data.seek_table.num_points * FLAC__STREAM_METADATA_SEEKPOINT_LENGTH;
138 seektable_.data.seek_table.points = malloc_or_die_(seektable_.data.seek_table.num_points * sizeof(FLAC__StreamMetadata_SeekPoint));
139 seektable_.data.seek_table.points[0].sample_number = 0;
140 seektable_.data.seek_table.points[0].stream_offset = 0;
141 seektable_.data.seek_table.points[0].frame_samples = streaminfo_.data.stream_info.min_blocksize;
142 seektable_.data.seek_table.points[1].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
143 seektable_.data.seek_table.points[1].stream_offset = 1000;
144 seektable_.data.seek_table.points[1].frame_samples = streaminfo_.data.stream_info.min_blocksize;
146 application1_.is_last = false;
147 application1_.type = FLAC__METADATA_TYPE_APPLICATION;
148 application1_.length = 8;
149 memcpy(application1_.data.application.id, "\xfe\xdc\xba\x98", 4);
150 application1_.data.application.data = malloc_or_die_(4);
151 memcpy(application1_.data.application.data, "\xf0\xe1\xd2\xc3", 4);
153 application2_.is_last = false;
154 application2_.type = FLAC__METADATA_TYPE_APPLICATION;
155 application2_.length = 4;
156 memcpy(application2_.data.application.id, "\x76\x54\x32\x10", 4);
157 application2_.data.application.data = 0;
159 vorbiscomment_.is_last = true;
160 vorbiscomment_.type = FLAC__METADATA_TYPE_VORBIS_COMMENT;
161 vorbiscomment_.length = (4 + 8) + 4 + (4 + 5) + (4 + 0);
162 vorbiscomment_.data.vorbis_comment.vendor_string.length = 8;
163 vorbiscomment_.data.vorbis_comment.vendor_string.entry = malloc_or_die_(8);
164 memcpy(vorbiscomment_.data.vorbis_comment.vendor_string.entry, "flac 1.x", 8);
165 vorbiscomment_.data.vorbis_comment.num_comments = 2;
166 vorbiscomment_.data.vorbis_comment.comments = malloc_or_die_(vorbiscomment_.data.vorbis_comment.num_comments * sizeof(FLAC__StreamMetadata_VorbisComment_Entry));
167 vorbiscomment_.data.vorbis_comment.comments[0].length = 5;
168 vorbiscomment_.data.vorbis_comment.comments[0].entry = malloc_or_die_(5);
169 memcpy(vorbiscomment_.data.vorbis_comment.comments[0].entry, "ab=cd", 5);
170 vorbiscomment_.data.vorbis_comment.comments[1].length = 0;
171 vorbiscomment_.data.vorbis_comment.comments[1].entry = 0;
174 static void free_metadata_blocks_()
176 free(seektable_.data.seek_table.points);
177 free(application1_.data.application.data);
178 free(vorbiscomment_.data.vorbis_comment.vendor_string.entry);
179 free(vorbiscomment_.data.vorbis_comment.comments[0].entry);
180 free(vorbiscomment_.data.vorbis_comment.comments);
183 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)
185 (void)encoder, (void)buffer, (void)bytes, (void)samples, (void)current_frame, (void)client_data;
186 return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
189 static void stream_encoder_metadata_callback_(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetadata *metadata, void *client_data)
191 (void)encoder, (void)metadata, (void)client_data;
194 static FLAC__bool test_stream_encoder()
196 FLAC__StreamEncoder *encoder;
197 FLAC__StreamEncoderState state;
198 FLAC__StreamDecoderState dstate;
199 FLAC__int32 samples[1024];
200 FLAC__int32 *samples_array[1] = { samples };
203 printf("\n+++ libFLAC unit test: FLAC__StreamEncoder\n\n");
205 printf("testing FLAC__stream_encoder_new()... ");
206 encoder = FLAC__stream_encoder_new();
208 printf("FAILED, returned NULL\n");
213 printf("testing FLAC__stream_encoder_set_verify()... ");
214 if(!FLAC__stream_encoder_set_verify(encoder, true))
215 return die_s_("returned false", encoder);
218 printf("testing FLAC__stream_encoder_set_streamable_subset()... ");
219 if(!FLAC__stream_encoder_set_streamable_subset(encoder, true))
220 return die_s_("returned false", encoder);
223 printf("testing FLAC__stream_encoder_set_do_mid_side_stereo()... ");
224 if(!FLAC__stream_encoder_set_do_mid_side_stereo(encoder, false))
225 return die_s_("returned false", encoder);
228 printf("testing FLAC__stream_encoder_set_loose_mid_side_stereo()... ");
229 if(!FLAC__stream_encoder_set_loose_mid_side_stereo(encoder, false))
230 return die_s_("returned false", encoder);
233 printf("testing FLAC__stream_encoder_set_channels()... ");
234 if(!FLAC__stream_encoder_set_channels(encoder, streaminfo_.data.stream_info.channels))
235 return die_s_("returned false", encoder);
238 printf("testing FLAC__stream_encoder_set_bits_per_sample()... ");
239 if(!FLAC__stream_encoder_set_bits_per_sample(encoder, streaminfo_.data.stream_info.bits_per_sample))
240 return die_s_("returned false", encoder);
243 printf("testing FLAC__stream_encoder_set_sample_rate()... ");
244 if(!FLAC__stream_encoder_set_sample_rate(encoder, streaminfo_.data.stream_info.sample_rate))
245 return die_s_("returned false", encoder);
248 printf("testing FLAC__stream_encoder_set_blocksize()... ");
249 if(!FLAC__stream_encoder_set_blocksize(encoder, streaminfo_.data.stream_info.min_blocksize))
250 return die_s_("returned false", encoder);
253 printf("testing FLAC__stream_encoder_set_max_lpc_order()... ");
254 if(!FLAC__stream_encoder_set_max_lpc_order(encoder, 0))
255 return die_s_("returned false", encoder);
258 printf("testing FLAC__stream_encoder_set_qlp_coeff_precision()... ");
259 if(!FLAC__stream_encoder_set_qlp_coeff_precision(encoder, 0))
260 return die_s_("returned false", encoder);
263 printf("testing FLAC__stream_encoder_set_do_qlp_coeff_prec_search()... ");
264 if(!FLAC__stream_encoder_set_do_qlp_coeff_prec_search(encoder, false))
265 return die_s_("returned false", encoder);
268 printf("testing FLAC__stream_encoder_set_do_escape_coding()... ");
269 if(!FLAC__stream_encoder_set_do_escape_coding(encoder, false))
270 return die_s_("returned false", encoder);
273 printf("testing FLAC__stream_encoder_set_do_exhaustive_model_search()... ");
274 if(!FLAC__stream_encoder_set_do_exhaustive_model_search(encoder, false))
275 return die_s_("returned false", encoder);
278 printf("testing FLAC__stream_encoder_set_min_residual_partition_order()... ");
279 if(!FLAC__stream_encoder_set_min_residual_partition_order(encoder, 0))
280 return die_s_("returned false", encoder);
283 printf("testing FLAC__stream_encoder_set_max_residual_partition_order()... ");
284 if(!FLAC__stream_encoder_set_max_residual_partition_order(encoder, 0))
285 return die_s_("returned false", encoder);
288 printf("testing FLAC__stream_encoder_set_rice_parameter_search_dist()... ");
289 if(!FLAC__stream_encoder_set_rice_parameter_search_dist(encoder, 0))
290 return die_s_("returned false", encoder);
293 printf("testing FLAC__stream_encoder_set_total_samples_estimate()... ");
294 if(!FLAC__stream_encoder_set_total_samples_estimate(encoder, streaminfo_.data.stream_info.total_samples))
295 return die_s_("returned false", encoder);
298 printf("testing FLAC__stream_encoder_set_metadata()... ");
299 if(!FLAC__stream_encoder_set_metadata(encoder, metadata_sequence_, num_metadata_))
300 return die_s_("returned false", encoder);
303 printf("testing FLAC__stream_encoder_set_write_callback()... ");
304 if(!FLAC__stream_encoder_set_write_callback(encoder, stream_encoder_write_callback_))
305 return die_s_("returned false", encoder);
308 printf("testing FLAC__stream_encoder_set_metadata_callback()... ");
309 if(!FLAC__stream_encoder_set_metadata_callback(encoder, stream_encoder_metadata_callback_))
310 return die_s_("returned false", encoder);
313 printf("testing FLAC__stream_encoder_set_client_data()... ");
314 if(!FLAC__stream_encoder_set_client_data(encoder, 0))
315 return die_s_("returned false", encoder);
318 printf("testing FLAC__stream_encoder_init()... ");
319 if(FLAC__stream_encoder_init(encoder) != FLAC__STREAM_ENCODER_OK)
320 return die_s_(0, encoder);
323 printf("testing FLAC__stream_encoder_get_state()... ");
324 state = FLAC__stream_encoder_get_state(encoder);
325 printf("returned state = %u (%s)... OK\n", (unsigned)state, FLAC__StreamEncoderStateString[state]);
327 printf("testing FLAC__stream_encoder_get_verify_decoder_state()... ");
328 dstate = FLAC__stream_encoder_get_verify_decoder_state(encoder);
329 printf("returned state = %u (%s)... OK\n", (unsigned)dstate, FLAC__StreamDecoderStateString[dstate]);
331 printf("testing FLAC__stream_encoder_get_verify()... ");
332 if(FLAC__stream_encoder_get_verify(encoder) != true) {
333 printf("FAILED, expected true, got false\n");
338 printf("testing FLAC__stream_encoder_get_streamable_subset()... ");
339 if(FLAC__stream_encoder_get_streamable_subset(encoder) != true) {
340 printf("FAILED, expected true, got false\n");
345 printf("testing FLAC__stream_encoder_get_do_mid_side_stereo()... ");
346 if(FLAC__stream_encoder_get_do_mid_side_stereo(encoder) != false) {
347 printf("FAILED, expected false, got true\n");
352 printf("testing FLAC__stream_encoder_get_loose_mid_side_stereo()... ");
353 if(FLAC__stream_encoder_get_loose_mid_side_stereo(encoder) != false) {
354 printf("FAILED, expected false, got true\n");
359 printf("testing FLAC__stream_encoder_get_channels()... ");
360 if(FLAC__stream_encoder_get_channels(encoder) != streaminfo_.data.stream_info.channels) {
361 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.channels, FLAC__stream_encoder_get_channels(encoder));
366 printf("testing FLAC__stream_encoder_get_bits_per_sample()... ");
367 if(FLAC__stream_encoder_get_bits_per_sample(encoder) != streaminfo_.data.stream_info.bits_per_sample) {
368 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.bits_per_sample, FLAC__stream_encoder_get_bits_per_sample(encoder));
373 printf("testing FLAC__stream_encoder_get_sample_rate()... ");
374 if(FLAC__stream_encoder_get_sample_rate(encoder) != streaminfo_.data.stream_info.sample_rate) {
375 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.sample_rate, FLAC__stream_encoder_get_sample_rate(encoder));
380 printf("testing FLAC__stream_encoder_get_blocksize()... ");
381 if(FLAC__stream_encoder_get_blocksize(encoder) != streaminfo_.data.stream_info.min_blocksize) {
382 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.min_blocksize, FLAC__stream_encoder_get_blocksize(encoder));
387 printf("testing FLAC__stream_encoder_get_max_lpc_order()... ");
388 if(FLAC__stream_encoder_get_max_lpc_order(encoder) != 0) {
389 printf("FAILED, expected %u, got %u\n", 0, FLAC__stream_encoder_get_max_lpc_order(encoder));
394 printf("testing FLAC__stream_encoder_get_qlp_coeff_precision()... ");
395 (void)FLAC__stream_encoder_get_qlp_coeff_precision(encoder);
396 /* we asked the encoder to auto select this so we accept anything */
399 printf("testing FLAC__stream_encoder_get_do_qlp_coeff_prec_search()... ");
400 if(FLAC__stream_encoder_get_do_qlp_coeff_prec_search(encoder) != false) {
401 printf("FAILED, expected false, got true\n");
406 printf("testing FLAC__stream_encoder_get_do_escape_coding()... ");
407 if(FLAC__stream_encoder_get_do_escape_coding(encoder) != false) {
408 printf("FAILED, expected false, got true\n");
413 printf("testing FLAC__stream_encoder_get_do_exhaustive_model_search()... ");
414 if(FLAC__stream_encoder_get_do_exhaustive_model_search(encoder) != false) {
415 printf("FAILED, expected false, got true\n");
420 printf("testing FLAC__stream_encoder_get_min_residual_partition_order()... ");
421 if(FLAC__stream_encoder_get_min_residual_partition_order(encoder) != 0) {
422 printf("FAILED, expected %u, got %u\n", 0, FLAC__stream_encoder_get_min_residual_partition_order(encoder));
427 printf("testing FLAC__stream_encoder_get_max_residual_partition_order()... ");
428 if(FLAC__stream_encoder_get_max_residual_partition_order(encoder) != 0) {
429 printf("FAILED, expected %u, got %u\n", 0, FLAC__stream_encoder_get_max_residual_partition_order(encoder));
434 printf("testing FLAC__stream_encoder_get_rice_parameter_search_dist()... ");
435 if(FLAC__stream_encoder_get_rice_parameter_search_dist(encoder) != 0) {
436 printf("FAILED, expected %u, got %u\n", 0, FLAC__stream_encoder_get_rice_parameter_search_dist(encoder));
441 printf("testing FLAC__stream_encoder_get_total_samples_estimate()... ");
442 if(FLAC__stream_encoder_get_total_samples_estimate(encoder) != streaminfo_.data.stream_info.total_samples) {
443 printf("FAILED, expected %llu, got %llu\n", streaminfo_.data.stream_info.total_samples, FLAC__stream_encoder_get_total_samples_estimate(encoder));
448 /* init the dummy sample buffer */
449 for(i = 0; i < sizeof(samples) / sizeof(FLAC__int32); i++)
452 printf("testing FLAC__stream_encoder_process()... ");
453 if(!FLAC__stream_encoder_process(encoder, (const FLAC__int32 * const *)samples_array, sizeof(samples) / sizeof(FLAC__int32)))
454 return die_s_("returned false", encoder);
457 printf("testing FLAC__stream_encoder_process_interleaved()... ");
458 if(!FLAC__stream_encoder_process_interleaved(encoder, samples, sizeof(samples) / sizeof(FLAC__int32)))
459 return die_s_("returned false", encoder);
462 printf("testing FLAC__stream_encoder_finish()... ");
463 FLAC__stream_encoder_finish(encoder);
466 printf("testing FLAC__stream_encoder_delete()... ");
467 FLAC__stream_encoder_delete(encoder);
470 printf("\nPASSED!\n");
475 FLAC__SeekableStreamEncoderSeekStatus seekable_stream_encoder_seek_callback_(const FLAC__SeekableStreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data)
477 (void)encoder, (void)absolute_byte_offset, (void)client_data;
478 return FLAC__SEEKABLE_STREAM_ENCODER_SEEK_STATUS_OK;
481 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)
483 (void)encoder, (void)buffer, (void)bytes, (void)samples, (void)current_frame, (void)client_data;
484 return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
487 static FLAC__bool test_seekable_stream_encoder()
489 FLAC__SeekableStreamEncoder *encoder;
490 FLAC__SeekableStreamEncoderState state;
491 FLAC__StreamEncoderState state_;
492 FLAC__StreamDecoderState dstate;
493 FLAC__int32 samples[1024];
494 FLAC__int32 *samples_array[1] = { samples };
497 printf("\n+++ libFLAC unit test: FLAC__SeekableStreamEncoder\n\n");
499 printf("testing FLAC__seekable_stream_encoder_new()... ");
500 encoder = FLAC__seekable_stream_encoder_new();
502 printf("FAILED, returned NULL\n");
507 printf("testing FLAC__seekable_stream_encoder_set_verify()... ");
508 if(!FLAC__seekable_stream_encoder_set_verify(encoder, true))
509 return die_ss_("returned false", encoder);
512 printf("testing FLAC__seekable_stream_encoder_set_streamable_subset()... ");
513 if(!FLAC__seekable_stream_encoder_set_streamable_subset(encoder, true))
514 return die_ss_("returned false", encoder);
517 printf("testing FLAC__seekable_stream_encoder_set_do_mid_side_stereo()... ");
518 if(!FLAC__seekable_stream_encoder_set_do_mid_side_stereo(encoder, false))
519 return die_ss_("returned false", encoder);
522 printf("testing FLAC__seekable_stream_encoder_set_loose_mid_side_stereo()... ");
523 if(!FLAC__seekable_stream_encoder_set_loose_mid_side_stereo(encoder, false))
524 return die_ss_("returned false", encoder);
527 printf("testing FLAC__seekable_stream_encoder_set_channels()... ");
528 if(!FLAC__seekable_stream_encoder_set_channels(encoder, streaminfo_.data.stream_info.channels))
529 return die_ss_("returned false", encoder);
532 printf("testing FLAC__seekable_stream_encoder_set_bits_per_sample()... ");
533 if(!FLAC__seekable_stream_encoder_set_bits_per_sample(encoder, streaminfo_.data.stream_info.bits_per_sample))
534 return die_ss_("returned false", encoder);
537 printf("testing FLAC__seekable_stream_encoder_set_sample_rate()... ");
538 if(!FLAC__seekable_stream_encoder_set_sample_rate(encoder, streaminfo_.data.stream_info.sample_rate))
539 return die_ss_("returned false", encoder);
542 printf("testing FLAC__seekable_stream_encoder_set_blocksize()... ");
543 if(!FLAC__seekable_stream_encoder_set_blocksize(encoder, streaminfo_.data.stream_info.min_blocksize))
544 return die_ss_("returned false", encoder);
547 printf("testing FLAC__seekable_stream_encoder_set_max_lpc_order()... ");
548 if(!FLAC__seekable_stream_encoder_set_max_lpc_order(encoder, 0))
549 return die_ss_("returned false", encoder);
552 printf("testing FLAC__seekable_stream_encoder_set_qlp_coeff_precision()... ");
553 if(!FLAC__seekable_stream_encoder_set_qlp_coeff_precision(encoder, 0))
554 return die_ss_("returned false", encoder);
557 printf("testing FLAC__seekable_stream_encoder_set_do_qlp_coeff_prec_search()... ");
558 if(!FLAC__seekable_stream_encoder_set_do_qlp_coeff_prec_search(encoder, false))
559 return die_ss_("returned false", encoder);
562 printf("testing FLAC__seekable_stream_encoder_set_do_escape_coding()... ");
563 if(!FLAC__seekable_stream_encoder_set_do_escape_coding(encoder, false))
564 return die_ss_("returned false", encoder);
567 printf("testing FLAC__seekable_stream_encoder_set_do_exhaustive_model_search()... ");
568 if(!FLAC__seekable_stream_encoder_set_do_exhaustive_model_search(encoder, false))
569 return die_ss_("returned false", encoder);
572 printf("testing FLAC__seekable_stream_encoder_set_min_residual_partition_order()... ");
573 if(!FLAC__seekable_stream_encoder_set_min_residual_partition_order(encoder, 0))
574 return die_ss_("returned false", encoder);
577 printf("testing FLAC__seekable_stream_encoder_set_max_residual_partition_order()... ");
578 if(!FLAC__seekable_stream_encoder_set_max_residual_partition_order(encoder, 0))
579 return die_ss_("returned false", encoder);
582 printf("testing FLAC__seekable_stream_encoder_set_rice_parameter_search_dist()... ");
583 if(!FLAC__seekable_stream_encoder_set_rice_parameter_search_dist(encoder, 0))
584 return die_ss_("returned false", encoder);
587 printf("testing FLAC__seekable_stream_encoder_set_total_samples_estimate()... ");
588 if(!FLAC__seekable_stream_encoder_set_total_samples_estimate(encoder, streaminfo_.data.stream_info.total_samples))
589 return die_ss_("returned false", encoder);
592 printf("testing FLAC__seekable_stream_encoder_set_metadata()... ");
593 if(!FLAC__seekable_stream_encoder_set_metadata(encoder, metadata_sequence_, num_metadata_))
594 return die_ss_("returned false", encoder);
597 printf("testing FLAC__seekable_stream_encoder_set_seek_callback()... ");
598 if(!FLAC__seekable_stream_encoder_set_seek_callback(encoder, seekable_stream_encoder_seek_callback_))
599 return die_ss_("returned false", encoder);
602 printf("testing FLAC__seekable_stream_encoder_set_write_callback()... ");
603 if(!FLAC__seekable_stream_encoder_set_write_callback(encoder, seekable_stream_encoder_write_callback_))
604 return die_ss_("returned false", encoder);
607 printf("testing FLAC__seekable_stream_encoder_set_client_data()... ");
608 if(!FLAC__seekable_stream_encoder_set_client_data(encoder, 0))
609 return die_ss_("returned false", encoder);
612 printf("testing FLAC__seekable_stream_encoder_init()... ");
613 if(FLAC__seekable_stream_encoder_init(encoder) != FLAC__SEEKABLE_STREAM_ENCODER_OK)
614 return die_ss_(0, encoder);
617 printf("testing FLAC__seekable_stream_encoder_get_state()... ");
618 state = FLAC__seekable_stream_encoder_get_state(encoder);
619 printf("returned state = %u (%s)... OK\n", (unsigned)state, FLAC__SeekableStreamEncoderStateString[state]);
621 printf("testing FLAC__seekable_stream_encoder_get_stream_encoder_state()... ");
622 state_ = FLAC__seekable_stream_encoder_get_stream_encoder_state(encoder);
623 printf("returned state = %u (%s)... OK\n", (unsigned)state_, FLAC__StreamEncoderStateString[state_]);
625 printf("testing FLAC__seekable_stream_encoder_get_verify_decoder_state()... ");
626 dstate = FLAC__seekable_stream_encoder_get_verify_decoder_state(encoder);
627 printf("returned state = %u (%s)... OK\n", (unsigned)dstate, FLAC__StreamDecoderStateString[dstate]);
629 printf("testing FLAC__seekable_stream_encoder_get_verify()... ");
630 if(FLAC__seekable_stream_encoder_get_verify(encoder) != true) {
631 printf("FAILED, expected true, got false\n");
636 printf("testing FLAC__seekable_stream_encoder_get_streamable_subset()... ");
637 if(FLAC__seekable_stream_encoder_get_streamable_subset(encoder) != true) {
638 printf("FAILED, expected true, got false\n");
643 printf("testing FLAC__seekable_stream_encoder_get_do_mid_side_stereo()... ");
644 if(FLAC__seekable_stream_encoder_get_do_mid_side_stereo(encoder) != false) {
645 printf("FAILED, expected false, got true\n");
650 printf("testing FLAC__seekable_stream_encoder_get_loose_mid_side_stereo()... ");
651 if(FLAC__seekable_stream_encoder_get_loose_mid_side_stereo(encoder) != false) {
652 printf("FAILED, expected false, got true\n");
657 printf("testing FLAC__seekable_stream_encoder_get_channels()... ");
658 if(FLAC__seekable_stream_encoder_get_channels(encoder) != streaminfo_.data.stream_info.channels) {
659 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.channels, FLAC__seekable_stream_encoder_get_channels(encoder));
664 printf("testing FLAC__seekable_stream_encoder_get_bits_per_sample()... ");
665 if(FLAC__seekable_stream_encoder_get_bits_per_sample(encoder) != streaminfo_.data.stream_info.bits_per_sample) {
666 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.bits_per_sample, FLAC__seekable_stream_encoder_get_bits_per_sample(encoder));
671 printf("testing FLAC__seekable_stream_encoder_get_sample_rate()... ");
672 if(FLAC__seekable_stream_encoder_get_sample_rate(encoder) != streaminfo_.data.stream_info.sample_rate) {
673 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.sample_rate, FLAC__seekable_stream_encoder_get_sample_rate(encoder));
678 printf("testing FLAC__seekable_stream_encoder_get_blocksize()... ");
679 if(FLAC__seekable_stream_encoder_get_blocksize(encoder) != streaminfo_.data.stream_info.min_blocksize) {
680 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.min_blocksize, FLAC__seekable_stream_encoder_get_blocksize(encoder));
685 printf("testing FLAC__seekable_stream_encoder_get_max_lpc_order()... ");
686 if(FLAC__seekable_stream_encoder_get_max_lpc_order(encoder) != 0) {
687 printf("FAILED, expected %u, got %u\n", 0, FLAC__seekable_stream_encoder_get_max_lpc_order(encoder));
692 printf("testing FLAC__seekable_stream_encoder_get_qlp_coeff_precision()... ");
693 (void)FLAC__seekable_stream_encoder_get_qlp_coeff_precision(encoder);
694 /* we asked the encoder to auto select this so we accept anything */
697 printf("testing FLAC__seekable_stream_encoder_get_do_qlp_coeff_prec_search()... ");
698 if(FLAC__seekable_stream_encoder_get_do_qlp_coeff_prec_search(encoder) != false) {
699 printf("FAILED, expected false, got true\n");
704 printf("testing FLAC__seekable_stream_encoder_get_do_escape_coding()... ");
705 if(FLAC__seekable_stream_encoder_get_do_escape_coding(encoder) != false) {
706 printf("FAILED, expected false, got true\n");
711 printf("testing FLAC__seekable_stream_encoder_get_do_exhaustive_model_search()... ");
712 if(FLAC__seekable_stream_encoder_get_do_exhaustive_model_search(encoder) != false) {
713 printf("FAILED, expected false, got true\n");
718 printf("testing FLAC__seekable_stream_encoder_get_min_residual_partition_order()... ");
719 if(FLAC__seekable_stream_encoder_get_min_residual_partition_order(encoder) != 0) {
720 printf("FAILED, expected %u, got %u\n", 0, FLAC__seekable_stream_encoder_get_min_residual_partition_order(encoder));
725 printf("testing FLAC__seekable_stream_encoder_get_max_residual_partition_order()... ");
726 if(FLAC__seekable_stream_encoder_get_max_residual_partition_order(encoder) != 0) {
727 printf("FAILED, expected %u, got %u\n", 0, FLAC__seekable_stream_encoder_get_max_residual_partition_order(encoder));
732 printf("testing FLAC__seekable_stream_encoder_get_rice_parameter_search_dist()... ");
733 if(FLAC__seekable_stream_encoder_get_rice_parameter_search_dist(encoder) != 0) {
734 printf("FAILED, expected %u, got %u\n", 0, FLAC__seekable_stream_encoder_get_rice_parameter_search_dist(encoder));
739 printf("testing FLAC__seekable_stream_encoder_get_total_samples_estimate()... ");
740 if(FLAC__seekable_stream_encoder_get_total_samples_estimate(encoder) != streaminfo_.data.stream_info.total_samples) {
741 printf("FAILED, expected %llu, got %llu\n", streaminfo_.data.stream_info.total_samples, FLAC__seekable_stream_encoder_get_total_samples_estimate(encoder));
746 /* init the dummy sample buffer */
747 for(i = 0; i < sizeof(samples) / sizeof(FLAC__int32); i++)
750 printf("testing FLAC__seekable_stream_encoder_process()... ");
751 if(!FLAC__seekable_stream_encoder_process(encoder, (const FLAC__int32 * const *)samples_array, sizeof(samples) / sizeof(FLAC__int32)))
752 return die_ss_("returned false", encoder);
755 printf("testing FLAC__seekable_stream_encoder_process_interleaved()... ");
756 if(!FLAC__seekable_stream_encoder_process_interleaved(encoder, samples, sizeof(samples) / sizeof(FLAC__int32)))
757 return die_ss_("returned false", encoder);
760 printf("testing FLAC__seekable_stream_encoder_finish()... ");
761 FLAC__seekable_stream_encoder_finish(encoder);
764 printf("testing FLAC__seekable_stream_encoder_delete()... ");
765 FLAC__seekable_stream_encoder_delete(encoder);
768 printf("\nPASSED!\n");
773 static void file_encoder_progress_callback_(const FLAC__FileEncoder *encoder, unsigned current_frame, unsigned total_frames_estimate, void *client_data)
775 (void)encoder, (void)current_frame, (void)total_frames_estimate, (void)client_data;
778 static FLAC__bool test_file_encoder()
780 FLAC__FileEncoder *encoder;
781 FLAC__FileEncoderState state;
782 FLAC__SeekableStreamEncoderState state_;
783 FLAC__StreamEncoderState state__;
784 FLAC__StreamDecoderState dstate;
785 FLAC__int32 samples[1024];
786 FLAC__int32 *samples_array[1] = { samples };
789 printf("\n+++ libFLAC unit test: FLAC__FileEncoder\n\n");
791 printf("testing FLAC__file_encoder_new()... ");
792 encoder = FLAC__file_encoder_new();
794 printf("FAILED, returned NULL\n");
799 printf("testing FLAC__file_encoder_set_verify()... ");
800 if(!FLAC__file_encoder_set_verify(encoder, true))
801 return die_f_("returned false", encoder);
804 printf("testing FLAC__file_encoder_set_streamable_subset()... ");
805 if(!FLAC__file_encoder_set_streamable_subset(encoder, true))
806 return die_f_("returned false", encoder);
809 printf("testing FLAC__file_encoder_set_do_mid_side_stereo()... ");
810 if(!FLAC__file_encoder_set_do_mid_side_stereo(encoder, false))
811 return die_f_("returned false", encoder);
814 printf("testing FLAC__file_encoder_set_loose_mid_side_stereo()... ");
815 if(!FLAC__file_encoder_set_loose_mid_side_stereo(encoder, false))
816 return die_f_("returned false", encoder);
819 printf("testing FLAC__file_encoder_set_channels()... ");
820 if(!FLAC__file_encoder_set_channels(encoder, streaminfo_.data.stream_info.channels))
821 return die_f_("returned false", encoder);
824 printf("testing FLAC__file_encoder_set_bits_per_sample()... ");
825 if(!FLAC__file_encoder_set_bits_per_sample(encoder, streaminfo_.data.stream_info.bits_per_sample))
826 return die_f_("returned false", encoder);
829 printf("testing FLAC__file_encoder_set_sample_rate()... ");
830 if(!FLAC__file_encoder_set_sample_rate(encoder, streaminfo_.data.stream_info.sample_rate))
831 return die_f_("returned false", encoder);
834 printf("testing FLAC__file_encoder_set_blocksize()... ");
835 if(!FLAC__file_encoder_set_blocksize(encoder, streaminfo_.data.stream_info.min_blocksize))
836 return die_f_("returned false", encoder);
839 printf("testing FLAC__file_encoder_set_max_lpc_order()... ");
840 if(!FLAC__file_encoder_set_max_lpc_order(encoder, 0))
841 return die_f_("returned false", encoder);
844 printf("testing FLAC__file_encoder_set_qlp_coeff_precision()... ");
845 if(!FLAC__file_encoder_set_qlp_coeff_precision(encoder, 0))
846 return die_f_("returned false", encoder);
849 printf("testing FLAC__file_encoder_set_do_qlp_coeff_prec_search()... ");
850 if(!FLAC__file_encoder_set_do_qlp_coeff_prec_search(encoder, false))
851 return die_f_("returned false", encoder);
854 printf("testing FLAC__file_encoder_set_do_escape_coding()... ");
855 if(!FLAC__file_encoder_set_do_escape_coding(encoder, false))
856 return die_f_("returned false", encoder);
859 printf("testing FLAC__file_encoder_set_do_exhaustive_model_search()... ");
860 if(!FLAC__file_encoder_set_do_exhaustive_model_search(encoder, false))
861 return die_f_("returned false", encoder);
864 printf("testing FLAC__file_encoder_set_min_residual_partition_order()... ");
865 if(!FLAC__file_encoder_set_min_residual_partition_order(encoder, 0))
866 return die_f_("returned false", encoder);
869 printf("testing FLAC__file_encoder_set_max_residual_partition_order()... ");
870 if(!FLAC__file_encoder_set_max_residual_partition_order(encoder, 0))
871 return die_f_("returned false", encoder);
874 printf("testing FLAC__file_encoder_set_rice_parameter_search_dist()... ");
875 if(!FLAC__file_encoder_set_rice_parameter_search_dist(encoder, 0))
876 return die_f_("returned false", encoder);
879 printf("testing FLAC__file_encoder_set_total_samples_estimate()... ");
880 if(!FLAC__file_encoder_set_total_samples_estimate(encoder, streaminfo_.data.stream_info.total_samples))
881 return die_f_("returned false", encoder);
884 printf("testing FLAC__file_encoder_set_metadata()... ");
885 if(!FLAC__file_encoder_set_metadata(encoder, metadata_sequence_, num_metadata_))
886 return die_f_("returned false", encoder);
889 printf("testing FLAC__file_encoder_set_filename()... ");
890 if(!FLAC__file_encoder_set_filename(encoder, flacfilename_))
891 return die_f_("returned false", encoder);
894 printf("testing FLAC__file_encoder_set_progress_callback()... ");
895 if(!FLAC__file_encoder_set_progress_callback(encoder, file_encoder_progress_callback_))
896 return die_f_("returned false", encoder);
899 printf("testing FLAC__file_encoder_set_client_data()... ");
900 if(!FLAC__file_encoder_set_client_data(encoder, 0))
901 return die_f_("returned false", encoder);
904 printf("testing FLAC__file_encoder_init()... ");
905 if(FLAC__file_encoder_init(encoder) != FLAC__FILE_ENCODER_OK)
906 return die_f_(0, encoder);
909 printf("testing FLAC__file_encoder_get_state()... ");
910 state = FLAC__file_encoder_get_state(encoder);
911 printf("returned state = %u (%s)... OK\n", (unsigned)state, FLAC__FileEncoderStateString[state]);
913 printf("testing FLAC__file_encoder_get_seekable_stream_encoder_state()... ");
914 state_ = FLAC__file_encoder_get_seekable_stream_encoder_state(encoder);
915 printf("returned state = %u (%s)... OK\n", (unsigned)state_, FLAC__SeekableStreamEncoderStateString[state_]);
917 printf("testing FLAC__file_encoder_get_stream_encoder_state()... ");
918 state__ = FLAC__file_encoder_get_stream_encoder_state(encoder);
919 printf("returned state = %u (%s)... OK\n", (unsigned)state__, FLAC__StreamEncoderStateString[state__]);
921 printf("testing FLAC__file_encoder_get_verify_decoder_state()... ");
922 dstate = FLAC__file_encoder_get_verify_decoder_state(encoder);
923 printf("returned state = %u (%s)... OK\n", (unsigned)dstate, FLAC__StreamDecoderStateString[dstate]);
925 printf("testing FLAC__file_encoder_get_verify()... ");
926 if(FLAC__file_encoder_get_verify(encoder) != true) {
927 printf("FAILED, expected true, got false\n");
932 printf("testing FLAC__file_encoder_get_streamable_subset()... ");
933 if(FLAC__file_encoder_get_streamable_subset(encoder) != true) {
934 printf("FAILED, expected true, got false\n");
939 printf("testing FLAC__file_encoder_get_do_mid_side_stereo()... ");
940 if(FLAC__file_encoder_get_do_mid_side_stereo(encoder) != false) {
941 printf("FAILED, expected false, got true\n");
946 printf("testing FLAC__file_encoder_get_loose_mid_side_stereo()... ");
947 if(FLAC__file_encoder_get_loose_mid_side_stereo(encoder) != false) {
948 printf("FAILED, expected false, got true\n");
953 printf("testing FLAC__file_encoder_get_channels()... ");
954 if(FLAC__file_encoder_get_channels(encoder) != streaminfo_.data.stream_info.channels) {
955 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.channels, FLAC__file_encoder_get_channels(encoder));
960 printf("testing FLAC__file_encoder_get_bits_per_sample()... ");
961 if(FLAC__file_encoder_get_bits_per_sample(encoder) != streaminfo_.data.stream_info.bits_per_sample) {
962 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.bits_per_sample, FLAC__file_encoder_get_bits_per_sample(encoder));
967 printf("testing FLAC__file_encoder_get_sample_rate()... ");
968 if(FLAC__file_encoder_get_sample_rate(encoder) != streaminfo_.data.stream_info.sample_rate) {
969 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.sample_rate, FLAC__file_encoder_get_sample_rate(encoder));
974 printf("testing FLAC__file_encoder_get_blocksize()... ");
975 if(FLAC__file_encoder_get_blocksize(encoder) != streaminfo_.data.stream_info.min_blocksize) {
976 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.min_blocksize, FLAC__file_encoder_get_blocksize(encoder));
981 printf("testing FLAC__file_encoder_get_max_lpc_order()... ");
982 if(FLAC__file_encoder_get_max_lpc_order(encoder) != 0) {
983 printf("FAILED, expected %u, got %u\n", 0, FLAC__file_encoder_get_max_lpc_order(encoder));
988 printf("testing FLAC__file_encoder_get_qlp_coeff_precision()... ");
989 (void)FLAC__file_encoder_get_qlp_coeff_precision(encoder);
990 /* we asked the encoder to auto select this so we accept anything */
993 printf("testing FLAC__file_encoder_get_do_qlp_coeff_prec_search()... ");
994 if(FLAC__file_encoder_get_do_qlp_coeff_prec_search(encoder) != false) {
995 printf("FAILED, expected false, got true\n");
1000 printf("testing FLAC__file_encoder_get_do_escape_coding()... ");
1001 if(FLAC__file_encoder_get_do_escape_coding(encoder) != false) {
1002 printf("FAILED, expected false, got true\n");
1007 printf("testing FLAC__file_encoder_get_do_exhaustive_model_search()... ");
1008 if(FLAC__file_encoder_get_do_exhaustive_model_search(encoder) != false) {
1009 printf("FAILED, expected false, got true\n");
1014 printf("testing FLAC__file_encoder_get_min_residual_partition_order()... ");
1015 if(FLAC__file_encoder_get_min_residual_partition_order(encoder) != 0) {
1016 printf("FAILED, expected %u, got %u\n", 0, FLAC__file_encoder_get_min_residual_partition_order(encoder));
1021 printf("testing FLAC__file_encoder_get_max_residual_partition_order()... ");
1022 if(FLAC__file_encoder_get_max_residual_partition_order(encoder) != 0) {
1023 printf("FAILED, expected %u, got %u\n", 0, FLAC__file_encoder_get_max_residual_partition_order(encoder));
1028 printf("testing FLAC__file_encoder_get_rice_parameter_search_dist()... ");
1029 if(FLAC__file_encoder_get_rice_parameter_search_dist(encoder) != 0) {
1030 printf("FAILED, expected %u, got %u\n", 0, FLAC__file_encoder_get_rice_parameter_search_dist(encoder));
1035 printf("testing FLAC__file_encoder_get_total_samples_estimate()... ");
1036 if(FLAC__file_encoder_get_total_samples_estimate(encoder) != streaminfo_.data.stream_info.total_samples) {
1037 printf("FAILED, expected %llu, got %llu\n", streaminfo_.data.stream_info.total_samples, FLAC__file_encoder_get_total_samples_estimate(encoder));
1042 /* init the dummy sample buffer */
1043 for(i = 0; i < sizeof(samples) / sizeof(FLAC__int32); i++)
1046 printf("testing FLAC__file_encoder_process()... ");
1047 if(!FLAC__file_encoder_process(encoder, (const FLAC__int32 * const *)samples_array, sizeof(samples) / sizeof(FLAC__int32)))
1048 return die_f_("returned false", encoder);
1051 printf("testing FLAC__file_encoder_process_interleaved()... ");
1052 if(!FLAC__file_encoder_process_interleaved(encoder, samples, sizeof(samples) / sizeof(FLAC__int32)))
1053 return die_f_("returned false", encoder);
1056 printf("testing FLAC__file_encoder_finish()... ");
1057 FLAC__file_encoder_finish(encoder);
1060 printf("testing FLAC__file_encoder_delete()... ");
1061 FLAC__file_encoder_delete(encoder);
1064 printf("\nPASSED!\n");
1069 FLAC__bool test_encoders()
1071 init_metadata_blocks_();
1073 if(!test_stream_encoder())
1076 if(!test_seekable_stream_encoder())
1079 if(!test_file_encoder())
1082 (void) file_utils__remove_file(flacfilename_);
1083 free_metadata_blocks_();