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 /* init the dummy sample buffer */
417 for(i = 0; i < sizeof(samples) / sizeof(FLAC__int32); i++)
420 printf("testing FLAC__stream_encoder_process()... ");
421 if(!FLAC__stream_encoder_process(encoder, (const FLAC__int32 * const *)samples_array, sizeof(samples) / sizeof(FLAC__int32)))
422 return die_s_("returned false", encoder);
425 printf("testing FLAC__stream_encoder_process_interleaved()... ");
426 if(!FLAC__stream_encoder_process_interleaved(encoder, samples, sizeof(samples) / sizeof(FLAC__int32)))
427 return die_s_("returned false", encoder);
430 printf("testing FLAC__stream_encoder_finish()... ");
431 FLAC__stream_encoder_finish(encoder);
434 printf("testing FLAC__stream_encoder_delete()... ");
435 FLAC__stream_encoder_delete(encoder);
438 printf("\nPASSED!\n");
443 FLAC__SeekableStreamEncoderSeekStatus seekable_stream_encoder_seek_callback_(const FLAC__SeekableStreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data)
445 (void)encoder, (void)absolute_byte_offset, (void)client_data;
446 return FLAC__SEEKABLE_STREAM_ENCODER_SEEK_STATUS_OK;
449 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)
451 (void)encoder, (void)buffer, (void)bytes, (void)samples, (void)current_frame, (void)client_data;
452 return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
455 static FLAC__bool test_seekable_stream_encoder()
457 FLAC__SeekableStreamEncoder *encoder;
458 FLAC__SeekableStreamEncoderState state;
459 FLAC__int32 samples[1024];
460 FLAC__int32 *samples_array[1] = { samples };
463 printf("\n+++ libFLAC unit test: FLAC__SeekableStreamEncoder\n\n");
465 printf("testing FLAC__seekable_stream_encoder_new()... ");
466 encoder = FLAC__seekable_stream_encoder_new();
468 printf("FAILED, returned NULL\n");
473 printf("testing FLAC__seekable_stream_encoder_set_streamable_subset()... ");
474 if(!FLAC__seekable_stream_encoder_set_streamable_subset(encoder, true))
475 return die_ss_("returned false", encoder);
478 printf("testing FLAC__seekable_stream_encoder_set_do_mid_side_stereo()... ");
479 if(!FLAC__seekable_stream_encoder_set_do_mid_side_stereo(encoder, false))
480 return die_ss_("returned false", encoder);
483 printf("testing FLAC__seekable_stream_encoder_set_loose_mid_side_stereo()... ");
484 if(!FLAC__seekable_stream_encoder_set_loose_mid_side_stereo(encoder, false))
485 return die_ss_("returned false", encoder);
488 printf("testing FLAC__seekable_stream_encoder_set_channels()... ");
489 if(!FLAC__seekable_stream_encoder_set_channels(encoder, streaminfo_.data.stream_info.channels))
490 return die_ss_("returned false", encoder);
493 printf("testing FLAC__seekable_stream_encoder_set_bits_per_sample()... ");
494 if(!FLAC__seekable_stream_encoder_set_bits_per_sample(encoder, streaminfo_.data.stream_info.bits_per_sample))
495 return die_ss_("returned false", encoder);
498 printf("testing FLAC__seekable_stream_encoder_set_sample_rate()... ");
499 if(!FLAC__seekable_stream_encoder_set_sample_rate(encoder, streaminfo_.data.stream_info.sample_rate))
500 return die_ss_("returned false", encoder);
503 printf("testing FLAC__seekable_stream_encoder_set_blocksize()... ");
504 if(!FLAC__seekable_stream_encoder_set_blocksize(encoder, streaminfo_.data.stream_info.min_blocksize))
505 return die_ss_("returned false", encoder);
508 printf("testing FLAC__seekable_stream_encoder_set_max_lpc_order()... ");
509 if(!FLAC__seekable_stream_encoder_set_max_lpc_order(encoder, 0))
510 return die_ss_("returned false", encoder);
513 printf("testing FLAC__seekable_stream_encoder_set_qlp_coeff_precision()... ");
514 if(!FLAC__seekable_stream_encoder_set_qlp_coeff_precision(encoder, 0))
515 return die_ss_("returned false", encoder);
518 printf("testing FLAC__seekable_stream_encoder_set_do_qlp_coeff_prec_search()... ");
519 if(!FLAC__seekable_stream_encoder_set_do_qlp_coeff_prec_search(encoder, false))
520 return die_ss_("returned false", encoder);
523 printf("testing FLAC__seekable_stream_encoder_set_do_escape_coding()... ");
524 if(!FLAC__seekable_stream_encoder_set_do_escape_coding(encoder, false))
525 return die_ss_("returned false", encoder);
528 printf("testing FLAC__seekable_stream_encoder_set_do_exhaustive_model_search()... ");
529 if(!FLAC__seekable_stream_encoder_set_do_exhaustive_model_search(encoder, false))
530 return die_ss_("returned false", encoder);
533 printf("testing FLAC__seekable_stream_encoder_set_min_residual_partition_order()... ");
534 if(!FLAC__seekable_stream_encoder_set_min_residual_partition_order(encoder, 0))
535 return die_ss_("returned false", encoder);
538 printf("testing FLAC__seekable_stream_encoder_set_max_residual_partition_order()... ");
539 if(!FLAC__seekable_stream_encoder_set_max_residual_partition_order(encoder, 0))
540 return die_ss_("returned false", encoder);
543 printf("testing FLAC__seekable_stream_encoder_set_rice_parameter_search_dist()... ");
544 if(!FLAC__seekable_stream_encoder_set_rice_parameter_search_dist(encoder, 0))
545 return die_ss_("returned false", encoder);
548 printf("testing FLAC__seekable_stream_encoder_set_total_samples_estimate()... ");
549 if(!FLAC__seekable_stream_encoder_set_total_samples_estimate(encoder, streaminfo_.data.stream_info.total_samples))
550 return die_ss_("returned false", encoder);
553 printf("testing FLAC__seekable_stream_encoder_set_metadata()... ");
554 if(!FLAC__seekable_stream_encoder_set_metadata(encoder, metadata_sequence_, num_metadata_))
555 return die_ss_("returned false", encoder);
558 printf("testing FLAC__seekable_stream_encoder_set_seek_callback()... ");
559 if(!FLAC__seekable_stream_encoder_set_seek_callback(encoder, seekable_stream_encoder_seek_callback_))
560 return die_ss_("returned false", encoder);
563 printf("testing FLAC__seekable_stream_encoder_set_write_callback()... ");
564 if(!FLAC__seekable_stream_encoder_set_write_callback(encoder, seekable_stream_encoder_write_callback_))
565 return die_ss_("returned false", encoder);
568 printf("testing FLAC__seekable_stream_encoder_set_client_data()... ");
569 if(!FLAC__seekable_stream_encoder_set_client_data(encoder, 0))
570 return die_ss_("returned false", encoder);
573 printf("testing FLAC__seekable_stream_encoder_init()... ");
574 if(FLAC__seekable_stream_encoder_init(encoder) != FLAC__SEEKABLE_STREAM_ENCODER_OK)
575 return die_ss_(0, encoder);
578 printf("testing FLAC__seekable_stream_encoder_get_state()... ");
579 state = FLAC__seekable_stream_encoder_get_state(encoder);
580 printf("returned state = %u (%s)... OK\n", (unsigned)state, FLAC__SeekableStreamEncoderStateString[state]);
582 printf("testing FLAC__seekable_stream_encoder_get_streamable_subset()... ");
583 if(FLAC__seekable_stream_encoder_get_streamable_subset(encoder) != true) {
584 printf("FAILED, expected true, got false\n");
589 printf("testing FLAC__seekable_stream_encoder_get_do_mid_side_stereo()... ");
590 if(FLAC__seekable_stream_encoder_get_do_mid_side_stereo(encoder) != false) {
591 printf("FAILED, expected false, got true\n");
596 printf("testing FLAC__seekable_stream_encoder_get_loose_mid_side_stereo()... ");
597 if(FLAC__seekable_stream_encoder_get_loose_mid_side_stereo(encoder) != false) {
598 printf("FAILED, expected false, got true\n");
603 printf("testing FLAC__seekable_stream_encoder_get_channels()... ");
604 if(FLAC__seekable_stream_encoder_get_channels(encoder) != streaminfo_.data.stream_info.channels) {
605 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.channels, FLAC__seekable_stream_encoder_get_channels(encoder));
610 printf("testing FLAC__seekable_stream_encoder_get_bits_per_sample()... ");
611 if(FLAC__seekable_stream_encoder_get_bits_per_sample(encoder) != streaminfo_.data.stream_info.bits_per_sample) {
612 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.bits_per_sample, FLAC__seekable_stream_encoder_get_bits_per_sample(encoder));
617 printf("testing FLAC__seekable_stream_encoder_get_sample_rate()... ");
618 if(FLAC__seekable_stream_encoder_get_sample_rate(encoder) != streaminfo_.data.stream_info.sample_rate) {
619 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.sample_rate, FLAC__seekable_stream_encoder_get_sample_rate(encoder));
624 printf("testing FLAC__seekable_stream_encoder_get_blocksize()... ");
625 if(FLAC__seekable_stream_encoder_get_blocksize(encoder) != streaminfo_.data.stream_info.min_blocksize) {
626 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.min_blocksize, FLAC__seekable_stream_encoder_get_blocksize(encoder));
631 printf("testing FLAC__seekable_stream_encoder_get_max_lpc_order()... ");
632 if(FLAC__seekable_stream_encoder_get_max_lpc_order(encoder) != 0) {
633 printf("FAILED, expected %u, got %u\n", 0, FLAC__seekable_stream_encoder_get_max_lpc_order(encoder));
638 printf("testing FLAC__seekable_stream_encoder_get_qlp_coeff_precision()... ");
639 (void)FLAC__seekable_stream_encoder_get_qlp_coeff_precision(encoder);
640 /* we asked the encoder to auto select this so we accept anything */
643 printf("testing FLAC__seekable_stream_encoder_get_do_qlp_coeff_prec_search()... ");
644 if(FLAC__seekable_stream_encoder_get_do_qlp_coeff_prec_search(encoder) != false) {
645 printf("FAILED, expected false, got true\n");
650 printf("testing FLAC__seekable_stream_encoder_get_do_escape_coding()... ");
651 if(FLAC__seekable_stream_encoder_get_do_escape_coding(encoder) != false) {
652 printf("FAILED, expected false, got true\n");
657 printf("testing FLAC__seekable_stream_encoder_get_do_exhaustive_model_search()... ");
658 if(FLAC__seekable_stream_encoder_get_do_exhaustive_model_search(encoder) != false) {
659 printf("FAILED, expected false, got true\n");
664 printf("testing FLAC__seekable_stream_encoder_get_min_residual_partition_order()... ");
665 if(FLAC__seekable_stream_encoder_get_min_residual_partition_order(encoder) != 0) {
666 printf("FAILED, expected %u, got %u\n", 0, FLAC__seekable_stream_encoder_get_min_residual_partition_order(encoder));
671 printf("testing FLAC__seekable_stream_encoder_get_max_residual_partition_order()... ");
672 if(FLAC__seekable_stream_encoder_get_max_residual_partition_order(encoder) != 0) {
673 printf("FAILED, expected %u, got %u\n", 0, FLAC__seekable_stream_encoder_get_max_residual_partition_order(encoder));
678 printf("testing FLAC__seekable_stream_encoder_get_rice_parameter_search_dist()... ");
679 if(FLAC__seekable_stream_encoder_get_rice_parameter_search_dist(encoder) != 0) {
680 printf("FAILED, expected %u, got %u\n", 0, FLAC__seekable_stream_encoder_get_rice_parameter_search_dist(encoder));
685 /* init the dummy sample buffer */
686 for(i = 0; i < sizeof(samples) / sizeof(FLAC__int32); i++)
689 printf("testing FLAC__seekable_stream_encoder_process()... ");
690 if(!FLAC__seekable_stream_encoder_process(encoder, (const FLAC__int32 * const *)samples_array, sizeof(samples) / sizeof(FLAC__int32)))
691 return die_ss_("returned false", encoder);
694 printf("testing FLAC__seekable_stream_encoder_process_interleaved()... ");
695 if(!FLAC__seekable_stream_encoder_process_interleaved(encoder, samples, sizeof(samples) / sizeof(FLAC__int32)))
696 return die_ss_("returned false", encoder);
699 printf("testing FLAC__seekable_stream_encoder_finish()... ");
700 FLAC__seekable_stream_encoder_finish(encoder);
703 printf("testing FLAC__seekable_stream_encoder_delete()... ");
704 FLAC__seekable_stream_encoder_delete(encoder);
707 printf("\nPASSED!\n");
712 static FLAC__bool test_file_encoder()
714 FLAC__FileEncoder *encoder;
715 FLAC__FileEncoderState state;
716 FLAC__int32 samples[1024];
717 FLAC__int32 *samples_array[1] = { samples };
720 printf("\n+++ libFLAC unit test: FLAC__FileEncoder\n\n");
722 printf("testing FLAC__file_encoder_new()... ");
723 encoder = FLAC__file_encoder_new();
725 printf("FAILED, returned NULL\n");
730 printf("testing FLAC__file_encoder_set_streamable_subset()... ");
731 if(!FLAC__file_encoder_set_streamable_subset(encoder, true))
732 return die_f_("returned false", encoder);
735 printf("testing FLAC__file_encoder_set_do_mid_side_stereo()... ");
736 if(!FLAC__file_encoder_set_do_mid_side_stereo(encoder, false))
737 return die_f_("returned false", encoder);
740 printf("testing FLAC__file_encoder_set_loose_mid_side_stereo()... ");
741 if(!FLAC__file_encoder_set_loose_mid_side_stereo(encoder, false))
742 return die_f_("returned false", encoder);
745 printf("testing FLAC__file_encoder_set_channels()... ");
746 if(!FLAC__file_encoder_set_channels(encoder, streaminfo_.data.stream_info.channels))
747 return die_f_("returned false", encoder);
750 printf("testing FLAC__file_encoder_set_bits_per_sample()... ");
751 if(!FLAC__file_encoder_set_bits_per_sample(encoder, streaminfo_.data.stream_info.bits_per_sample))
752 return die_f_("returned false", encoder);
755 printf("testing FLAC__file_encoder_set_sample_rate()... ");
756 if(!FLAC__file_encoder_set_sample_rate(encoder, streaminfo_.data.stream_info.sample_rate))
757 return die_f_("returned false", encoder);
760 printf("testing FLAC__file_encoder_set_blocksize()... ");
761 if(!FLAC__file_encoder_set_blocksize(encoder, streaminfo_.data.stream_info.min_blocksize))
762 return die_f_("returned false", encoder);
765 printf("testing FLAC__file_encoder_set_max_lpc_order()... ");
766 if(!FLAC__file_encoder_set_max_lpc_order(encoder, 0))
767 return die_f_("returned false", encoder);
770 printf("testing FLAC__file_encoder_set_qlp_coeff_precision()... ");
771 if(!FLAC__file_encoder_set_qlp_coeff_precision(encoder, 0))
772 return die_f_("returned false", encoder);
775 printf("testing FLAC__file_encoder_set_do_qlp_coeff_prec_search()... ");
776 if(!FLAC__file_encoder_set_do_qlp_coeff_prec_search(encoder, false))
777 return die_f_("returned false", encoder);
780 printf("testing FLAC__file_encoder_set_do_escape_coding()... ");
781 if(!FLAC__file_encoder_set_do_escape_coding(encoder, false))
782 return die_f_("returned false", encoder);
785 printf("testing FLAC__file_encoder_set_do_exhaustive_model_search()... ");
786 if(!FLAC__file_encoder_set_do_exhaustive_model_search(encoder, false))
787 return die_f_("returned false", encoder);
790 printf("testing FLAC__file_encoder_set_min_residual_partition_order()... ");
791 if(!FLAC__file_encoder_set_min_residual_partition_order(encoder, 0))
792 return die_f_("returned false", encoder);
795 printf("testing FLAC__file_encoder_set_max_residual_partition_order()... ");
796 if(!FLAC__file_encoder_set_max_residual_partition_order(encoder, 0))
797 return die_f_("returned false", encoder);
800 printf("testing FLAC__file_encoder_set_rice_parameter_search_dist()... ");
801 if(!FLAC__file_encoder_set_rice_parameter_search_dist(encoder, 0))
802 return die_f_("returned false", encoder);
805 printf("testing FLAC__file_encoder_set_total_samples_estimate()... ");
806 if(!FLAC__file_encoder_set_total_samples_estimate(encoder, streaminfo_.data.stream_info.total_samples))
807 return die_f_("returned false", encoder);
810 printf("testing FLAC__file_encoder_set_metadata()... ");
811 if(!FLAC__file_encoder_set_metadata(encoder, metadata_sequence_, num_metadata_))
812 return die_f_("returned false", encoder);
815 printf("testing FLAC__file_encoder_set_filename()... ");
816 if(!FLAC__file_encoder_set_filename(encoder, flacfilename_))
817 return die_f_("returned false", encoder);
820 printf("testing FLAC__file_encoder_init()... ");
821 if(FLAC__file_encoder_init(encoder) != FLAC__FILE_ENCODER_OK)
822 return die_f_(0, encoder);
825 printf("testing FLAC__file_encoder_get_state()... ");
826 state = FLAC__file_encoder_get_state(encoder);
827 printf("returned state = %u (%s)... OK\n", (unsigned)state, FLAC__FileEncoderStateString[state]);
829 printf("testing FLAC__file_encoder_get_streamable_subset()... ");
830 if(FLAC__file_encoder_get_streamable_subset(encoder) != true) {
831 printf("FAILED, expected true, got false\n");
836 printf("testing FLAC__file_encoder_get_do_mid_side_stereo()... ");
837 if(FLAC__file_encoder_get_do_mid_side_stereo(encoder) != false) {
838 printf("FAILED, expected false, got true\n");
843 printf("testing FLAC__file_encoder_get_loose_mid_side_stereo()... ");
844 if(FLAC__file_encoder_get_loose_mid_side_stereo(encoder) != false) {
845 printf("FAILED, expected false, got true\n");
850 printf("testing FLAC__file_encoder_get_channels()... ");
851 if(FLAC__file_encoder_get_channels(encoder) != streaminfo_.data.stream_info.channels) {
852 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.channels, FLAC__file_encoder_get_channels(encoder));
857 printf("testing FLAC__file_encoder_get_bits_per_sample()... ");
858 if(FLAC__file_encoder_get_bits_per_sample(encoder) != streaminfo_.data.stream_info.bits_per_sample) {
859 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.bits_per_sample, FLAC__file_encoder_get_bits_per_sample(encoder));
864 printf("testing FLAC__file_encoder_get_sample_rate()... ");
865 if(FLAC__file_encoder_get_sample_rate(encoder) != streaminfo_.data.stream_info.sample_rate) {
866 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.sample_rate, FLAC__file_encoder_get_sample_rate(encoder));
871 printf("testing FLAC__file_encoder_get_blocksize()... ");
872 if(FLAC__file_encoder_get_blocksize(encoder) != streaminfo_.data.stream_info.min_blocksize) {
873 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.min_blocksize, FLAC__file_encoder_get_blocksize(encoder));
878 printf("testing FLAC__file_encoder_get_max_lpc_order()... ");
879 if(FLAC__file_encoder_get_max_lpc_order(encoder) != 0) {
880 printf("FAILED, expected %u, got %u\n", 0, FLAC__file_encoder_get_max_lpc_order(encoder));
885 printf("testing FLAC__file_encoder_get_qlp_coeff_precision()... ");
886 (void)FLAC__file_encoder_get_qlp_coeff_precision(encoder);
887 /* we asked the encoder to auto select this so we accept anything */
890 printf("testing FLAC__file_encoder_get_do_qlp_coeff_prec_search()... ");
891 if(FLAC__file_encoder_get_do_qlp_coeff_prec_search(encoder) != false) {
892 printf("FAILED, expected false, got true\n");
897 printf("testing FLAC__file_encoder_get_do_escape_coding()... ");
898 if(FLAC__file_encoder_get_do_escape_coding(encoder) != false) {
899 printf("FAILED, expected false, got true\n");
904 printf("testing FLAC__file_encoder_get_do_exhaustive_model_search()... ");
905 if(FLAC__file_encoder_get_do_exhaustive_model_search(encoder) != false) {
906 printf("FAILED, expected false, got true\n");
911 printf("testing FLAC__file_encoder_get_min_residual_partition_order()... ");
912 if(FLAC__file_encoder_get_min_residual_partition_order(encoder) != 0) {
913 printf("FAILED, expected %u, got %u\n", 0, FLAC__file_encoder_get_min_residual_partition_order(encoder));
918 printf("testing FLAC__file_encoder_get_max_residual_partition_order()... ");
919 if(FLAC__file_encoder_get_max_residual_partition_order(encoder) != 0) {
920 printf("FAILED, expected %u, got %u\n", 0, FLAC__file_encoder_get_max_residual_partition_order(encoder));
925 printf("testing FLAC__file_encoder_get_rice_parameter_search_dist()... ");
926 if(FLAC__file_encoder_get_rice_parameter_search_dist(encoder) != 0) {
927 printf("FAILED, expected %u, got %u\n", 0, FLAC__file_encoder_get_rice_parameter_search_dist(encoder));
932 /* init the dummy sample buffer */
933 for(i = 0; i < sizeof(samples) / sizeof(FLAC__int32); i++)
936 printf("testing FLAC__file_encoder_process()... ");
937 if(!FLAC__file_encoder_process(encoder, (const FLAC__int32 * const *)samples_array, sizeof(samples) / sizeof(FLAC__int32)))
938 return die_f_("returned false", encoder);
941 printf("testing FLAC__file_encoder_process_interleaved()... ");
942 if(!FLAC__file_encoder_process_interleaved(encoder, samples, sizeof(samples) / sizeof(FLAC__int32)))
943 return die_f_("returned false", encoder);
946 printf("testing FLAC__file_encoder_finish()... ");
947 FLAC__file_encoder_finish(encoder);
950 printf("testing FLAC__file_encoder_delete()... ");
951 FLAC__file_encoder_delete(encoder);
954 printf("\nPASSED!\n");
959 FLAC__bool test_encoders()
961 init_metadata_blocks_();
963 if(!test_stream_encoder())
966 if(!test_seekable_stream_encoder())
969 if(!test_file_encoder())
972 (void) file_utils__remove_file(flacfilename_);
973 free_metadata_blocks_();