update to match new default vorbis comment size (now with vendor string)
[flac.git] / src / test_libFLAC / encoders.c
1 /* test_libFLAC - Unit tester for libFLAC
2  * Copyright (C) 2002  Josh Coalson
3  *
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.
8  *
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.
13  *
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.
17  */
18
19 #include "encoders.h"
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"
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28
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";
33
34 static FLAC__bool die_s_(const char *msg, const FLAC__StreamEncoder *encoder)
35 {
36         FLAC__StreamEncoderState state = FLAC__stream_encoder_get_state(encoder);
37
38         if(msg)
39                 printf("FAILED, %s", msg);
40         else
41                 printf("FAILED");
42
43         printf(", state = %u (%s)\n", (unsigned)state, FLAC__StreamEncoderStateString[state]);
44         if(state == FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR) {
45                 FLAC__StreamDecoderState dstate = FLAC__stream_encoder_get_verify_decoder_state(encoder);
46                 printf("      verify decoder state = %u (%s)\n", (unsigned)dstate, FLAC__StreamDecoderStateString[dstate]);
47         }
48
49         return false;
50 }
51
52 static FLAC__bool die_ss_(const char *msg, const FLAC__SeekableStreamEncoder *encoder)
53 {
54         FLAC__SeekableStreamEncoderState state = FLAC__seekable_stream_encoder_get_state(encoder);
55
56         if(msg)
57                 printf("FAILED, %s", msg);
58         else
59                 printf("FAILED");
60
61         printf(", state = %u (%s)\n", (unsigned)state, FLAC__SeekableStreamEncoderStateString[state]);
62         if(state == FLAC__SEEKABLE_STREAM_ENCODER_STREAM_ENCODER_ERROR) {
63                 FLAC__StreamEncoderState state_ = FLAC__seekable_stream_encoder_get_stream_encoder_state(encoder);
64                 printf("      stream encoder state = %u (%s)\n", (unsigned)state_, FLAC__StreamEncoderStateString[state_]);
65                 if(state_ == FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR) {
66                         FLAC__StreamDecoderState dstate = FLAC__seekable_stream_encoder_get_verify_decoder_state(encoder);
67                         printf("      verify decoder state = %u (%s)\n", (unsigned)dstate, FLAC__StreamDecoderStateString[dstate]);
68                 }
69         }
70
71         return false;
72 }
73
74 static FLAC__bool die_f_(const char *msg, const FLAC__FileEncoder *encoder)
75 {
76         FLAC__FileEncoderState state = FLAC__file_encoder_get_state(encoder);
77
78         if(msg)
79                 printf("FAILED, %s", msg);
80         else
81                 printf("FAILED");
82
83         printf(", state = %u (%s)\n", (unsigned)state, FLAC__FileEncoderStateString[state]);
84         if(state == FLAC__FILE_ENCODER_SEEKABLE_STREAM_ENCODER_ERROR) {
85                 FLAC__SeekableStreamEncoderState state_ = FLAC__file_encoder_get_seekable_stream_encoder_state(encoder);
86                 printf("      seekable stream encoder state = %u (%s)\n", (unsigned)state_, FLAC__SeekableStreamEncoderStateString[state_]);
87                 if(state_ == FLAC__SEEKABLE_STREAM_ENCODER_STREAM_ENCODER_ERROR) {
88                         FLAC__StreamEncoderState state__ = FLAC__file_encoder_get_stream_encoder_state(encoder);
89                         printf("      stream encoder state = %u (%s)\n", (unsigned)state__, FLAC__StreamEncoderStateString[state__]);
90                         if(state__ == FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR) {
91                                 FLAC__StreamDecoderState dstate = FLAC__file_encoder_get_verify_decoder_state(encoder);
92                                 printf("      verify decoder state = %u (%s)\n", (unsigned)dstate, FLAC__StreamDecoderStateString[dstate]);
93                         }
94                 }
95         }
96
97         return false;
98 }
99
100 static void *malloc_or_die_(size_t size)
101 {
102         void *x = malloc(size);
103         if(0 == x) {
104                 fprintf(stderr, "ERROR: out of memory allocating %u bytes\n", (unsigned)size);
105                 exit(1);
106         }
107         return x;
108 }
109
110 static void init_metadata_blocks_()
111 {
112         /*
113                 most of the actual numbers and data in the blocks don't matter,
114                 we just want to make sure the encoder encodes them correctly
115
116                 remember, the metadata interface gets tested after the encoders,
117                 so we do all the metadata manipulation here without it.
118         */
119
120         /* min/max_framesize and md5sum don't get written at first, so we have to leave them 0 */
121         streaminfo_.is_last = false;
122         streaminfo_.type = FLAC__METADATA_TYPE_STREAMINFO;
123         streaminfo_.length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH;
124         streaminfo_.data.stream_info.min_blocksize = 576;
125         streaminfo_.data.stream_info.max_blocksize = 576;
126         streaminfo_.data.stream_info.min_framesize = 0;
127         streaminfo_.data.stream_info.max_framesize = 0;
128         streaminfo_.data.stream_info.sample_rate = 44100;
129         streaminfo_.data.stream_info.channels = 1;
130         streaminfo_.data.stream_info.bits_per_sample = 8;
131         streaminfo_.data.stream_info.total_samples = 0;
132         memset(streaminfo_.data.stream_info.md5sum, 0, 16);
133
134         padding_.is_last = false;
135         padding_.type = FLAC__METADATA_TYPE_PADDING;
136         padding_.length = 1234;
137
138         seektable_.is_last = false;
139         seektable_.type = FLAC__METADATA_TYPE_SEEKTABLE;
140         seektable_.data.seek_table.num_points = 2;
141         seektable_.length = seektable_.data.seek_table.num_points * FLAC__STREAM_METADATA_SEEKPOINT_LENGTH;
142         seektable_.data.seek_table.points = malloc_or_die_(seektable_.data.seek_table.num_points * sizeof(FLAC__StreamMetadata_SeekPoint));
143         seektable_.data.seek_table.points[0].sample_number = 0;
144         seektable_.data.seek_table.points[0].stream_offset = 0;
145         seektable_.data.seek_table.points[0].frame_samples = streaminfo_.data.stream_info.min_blocksize;
146         seektable_.data.seek_table.points[1].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
147         seektable_.data.seek_table.points[1].stream_offset = 1000;
148         seektable_.data.seek_table.points[1].frame_samples = streaminfo_.data.stream_info.min_blocksize;
149
150         application1_.is_last = false;
151         application1_.type = FLAC__METADATA_TYPE_APPLICATION;
152         application1_.length = 8;
153         memcpy(application1_.data.application.id, "\xfe\xdc\xba\x98", 4);
154         application1_.data.application.data = malloc_or_die_(4);
155         memcpy(application1_.data.application.data, "\xf0\xe1\xd2\xc3", 4);
156
157         application2_.is_last = false;
158         application2_.type = FLAC__METADATA_TYPE_APPLICATION;
159         application2_.length = 4;
160         memcpy(application2_.data.application.id, "\x76\x54\x32\x10", 4);
161         application2_.data.application.data = 0;
162
163         vorbiscomment_.is_last = true;
164         vorbiscomment_.type = FLAC__METADATA_TYPE_VORBIS_COMMENT;
165         vorbiscomment_.length = (4 + 8) + 4 + (4 + 5) + (4 + 0);
166         vorbiscomment_.data.vorbis_comment.vendor_string.length = 8;
167         vorbiscomment_.data.vorbis_comment.vendor_string.entry = malloc_or_die_(8);
168         memcpy(vorbiscomment_.data.vorbis_comment.vendor_string.entry, "flac 1.x", 8);
169         vorbiscomment_.data.vorbis_comment.num_comments = 2;
170         vorbiscomment_.data.vorbis_comment.comments = malloc_or_die_(vorbiscomment_.data.vorbis_comment.num_comments * sizeof(FLAC__StreamMetadata_VorbisComment_Entry));
171         vorbiscomment_.data.vorbis_comment.comments[0].length = 5;
172         vorbiscomment_.data.vorbis_comment.comments[0].entry = malloc_or_die_(5);
173         memcpy(vorbiscomment_.data.vorbis_comment.comments[0].entry, "ab=cd", 5);
174         vorbiscomment_.data.vorbis_comment.comments[1].length = 0;
175         vorbiscomment_.data.vorbis_comment.comments[1].entry = 0;
176 }
177
178 static void free_metadata_blocks_()
179 {
180         free(seektable_.data.seek_table.points);
181         free(application1_.data.application.data);
182         free(vorbiscomment_.data.vorbis_comment.vendor_string.entry);
183         free(vorbiscomment_.data.vorbis_comment.comments[0].entry);
184         free(vorbiscomment_.data.vorbis_comment.comments);
185 }
186
187 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)
188 {
189         (void)encoder, (void)buffer, (void)bytes, (void)samples, (void)current_frame, (void)client_data;
190         return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
191 }
192
193 static void stream_encoder_metadata_callback_(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetadata *metadata, void *client_data)
194 {
195         (void)encoder, (void)metadata, (void)client_data;
196 }
197
198 static FLAC__bool test_stream_encoder()
199 {
200         FLAC__StreamEncoder *encoder;
201         FLAC__StreamEncoderState state;
202         FLAC__StreamDecoderState dstate;
203         FLAC__int32 samples[1024];
204         FLAC__int32 *samples_array[1] = { samples };
205         unsigned i;
206
207         printf("\n+++ libFLAC unit test: FLAC__StreamEncoder\n\n");
208
209         printf("testing FLAC__stream_encoder_new()... ");
210         encoder = FLAC__stream_encoder_new();
211         if(0 == encoder) {
212                 printf("FAILED, returned NULL\n");
213                 return false;
214         }
215         printf("OK\n");
216
217         printf("testing FLAC__stream_encoder_set_verify()... ");
218         if(!FLAC__stream_encoder_set_verify(encoder, true))
219                 return die_s_("returned false", encoder);
220         printf("OK\n");
221
222         printf("testing FLAC__stream_encoder_set_streamable_subset()... ");
223         if(!FLAC__stream_encoder_set_streamable_subset(encoder, true))
224                 return die_s_("returned false", encoder);
225         printf("OK\n");
226
227         printf("testing FLAC__stream_encoder_set_do_mid_side_stereo()... ");
228         if(!FLAC__stream_encoder_set_do_mid_side_stereo(encoder, false))
229                 return die_s_("returned false", encoder);
230         printf("OK\n");
231
232         printf("testing FLAC__stream_encoder_set_loose_mid_side_stereo()... ");
233         if(!FLAC__stream_encoder_set_loose_mid_side_stereo(encoder, false))
234                 return die_s_("returned false", encoder);
235         printf("OK\n");
236
237         printf("testing FLAC__stream_encoder_set_channels()... ");
238         if(!FLAC__stream_encoder_set_channels(encoder, streaminfo_.data.stream_info.channels))
239                 return die_s_("returned false", encoder);
240         printf("OK\n");
241
242         printf("testing FLAC__stream_encoder_set_bits_per_sample()... ");
243         if(!FLAC__stream_encoder_set_bits_per_sample(encoder, streaminfo_.data.stream_info.bits_per_sample))
244                 return die_s_("returned false", encoder);
245         printf("OK\n");
246
247         printf("testing FLAC__stream_encoder_set_sample_rate()... ");
248         if(!FLAC__stream_encoder_set_sample_rate(encoder, streaminfo_.data.stream_info.sample_rate))
249                 return die_s_("returned false", encoder);
250         printf("OK\n");
251
252         printf("testing FLAC__stream_encoder_set_blocksize()... ");
253         if(!FLAC__stream_encoder_set_blocksize(encoder, streaminfo_.data.stream_info.min_blocksize))
254                 return die_s_("returned false", encoder);
255         printf("OK\n");
256
257         printf("testing FLAC__stream_encoder_set_max_lpc_order()... ");
258         if(!FLAC__stream_encoder_set_max_lpc_order(encoder, 0))
259                 return die_s_("returned false", encoder);
260         printf("OK\n");
261
262         printf("testing FLAC__stream_encoder_set_qlp_coeff_precision()... ");
263         if(!FLAC__stream_encoder_set_qlp_coeff_precision(encoder, 0))
264                 return die_s_("returned false", encoder);
265         printf("OK\n");
266
267         printf("testing FLAC__stream_encoder_set_do_qlp_coeff_prec_search()... ");
268         if(!FLAC__stream_encoder_set_do_qlp_coeff_prec_search(encoder, false))
269                 return die_s_("returned false", encoder);
270         printf("OK\n");
271
272         printf("testing FLAC__stream_encoder_set_do_escape_coding()... ");
273         if(!FLAC__stream_encoder_set_do_escape_coding(encoder, false))
274                 return die_s_("returned false", encoder);
275         printf("OK\n");
276
277         printf("testing FLAC__stream_encoder_set_do_exhaustive_model_search()... ");
278         if(!FLAC__stream_encoder_set_do_exhaustive_model_search(encoder, false))
279                 return die_s_("returned false", encoder);
280         printf("OK\n");
281
282         printf("testing FLAC__stream_encoder_set_min_residual_partition_order()... ");
283         if(!FLAC__stream_encoder_set_min_residual_partition_order(encoder, 0))
284                 return die_s_("returned false", encoder);
285         printf("OK\n");
286
287         printf("testing FLAC__stream_encoder_set_max_residual_partition_order()... ");
288         if(!FLAC__stream_encoder_set_max_residual_partition_order(encoder, 0))
289                 return die_s_("returned false", encoder);
290         printf("OK\n");
291
292         printf("testing FLAC__stream_encoder_set_rice_parameter_search_dist()... ");
293         if(!FLAC__stream_encoder_set_rice_parameter_search_dist(encoder, 0))
294                 return die_s_("returned false", encoder);
295         printf("OK\n");
296
297         printf("testing FLAC__stream_encoder_set_total_samples_estimate()... ");
298         if(!FLAC__stream_encoder_set_total_samples_estimate(encoder, streaminfo_.data.stream_info.total_samples))
299                 return die_s_("returned false", encoder);
300         printf("OK\n");
301
302         printf("testing FLAC__stream_encoder_set_metadata()... ");
303         if(!FLAC__stream_encoder_set_metadata(encoder, metadata_sequence_, num_metadata_))
304                 return die_s_("returned false", encoder);
305         printf("OK\n");
306
307         printf("testing FLAC__stream_encoder_set_write_callback()... ");
308         if(!FLAC__stream_encoder_set_write_callback(encoder, stream_encoder_write_callback_))
309                 return die_s_("returned false", encoder);
310         printf("OK\n");
311
312         printf("testing FLAC__stream_encoder_set_metadata_callback()... ");
313         if(!FLAC__stream_encoder_set_metadata_callback(encoder, stream_encoder_metadata_callback_))
314                 return die_s_("returned false", encoder);
315         printf("OK\n");
316
317         printf("testing FLAC__stream_encoder_set_client_data()... ");
318         if(!FLAC__stream_encoder_set_client_data(encoder, 0))
319                 return die_s_("returned false", encoder);
320         printf("OK\n");
321
322         printf("testing FLAC__stream_encoder_init()... ");
323         if(FLAC__stream_encoder_init(encoder) != FLAC__STREAM_ENCODER_OK)
324                 return die_s_(0, encoder);
325         printf("OK\n");
326
327         printf("testing FLAC__stream_encoder_get_state()... ");
328         state = FLAC__stream_encoder_get_state(encoder);
329         printf("returned state = %u (%s)... OK\n", (unsigned)state, FLAC__StreamEncoderStateString[state]);
330
331         printf("testing FLAC__stream_encoder_get_verify_decoder_state()... ");
332         dstate = FLAC__stream_encoder_get_verify_decoder_state(encoder);
333         printf("returned state = %u (%s)... OK\n", (unsigned)dstate, FLAC__StreamDecoderStateString[dstate]);
334
335         {
336                 FLAC__uint64 absolute_sample;
337                 unsigned frame_number;
338                 unsigned channel;
339                 unsigned sample;
340                 FLAC__int32 expected;
341                 FLAC__int32 got;
342
343                 printf("testing FLAC__stream_encoder_get_verify_decoder_error_stats()... ");
344                 FLAC__stream_encoder_get_verify_decoder_error_stats(encoder, &absolute_sample, &frame_number, &channel, &sample, &expected, &got);
345                 printf("OK\n");
346         }
347
348         printf("testing FLAC__stream_encoder_get_verify()... ");
349         if(FLAC__stream_encoder_get_verify(encoder) != true) {
350                 printf("FAILED, expected true, got false\n");
351                 return false;
352         }
353         printf("OK\n");
354
355         printf("testing FLAC__stream_encoder_get_streamable_subset()... ");
356         if(FLAC__stream_encoder_get_streamable_subset(encoder) != true) {
357                 printf("FAILED, expected true, got false\n");
358                 return false;
359         }
360         printf("OK\n");
361
362         printf("testing FLAC__stream_encoder_get_do_mid_side_stereo()... ");
363         if(FLAC__stream_encoder_get_do_mid_side_stereo(encoder) != false) {
364                 printf("FAILED, expected false, got true\n");
365                 return false;
366         }
367         printf("OK\n");
368
369         printf("testing FLAC__stream_encoder_get_loose_mid_side_stereo()... ");
370         if(FLAC__stream_encoder_get_loose_mid_side_stereo(encoder) != false) {
371                 printf("FAILED, expected false, got true\n");
372                 return false;
373         }
374         printf("OK\n");
375
376         printf("testing FLAC__stream_encoder_get_channels()... ");
377         if(FLAC__stream_encoder_get_channels(encoder) != streaminfo_.data.stream_info.channels) {
378                 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.channels, FLAC__stream_encoder_get_channels(encoder));
379                 return false;
380         }
381         printf("OK\n");
382
383         printf("testing FLAC__stream_encoder_get_bits_per_sample()... ");
384         if(FLAC__stream_encoder_get_bits_per_sample(encoder) != streaminfo_.data.stream_info.bits_per_sample) {
385                 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.bits_per_sample, FLAC__stream_encoder_get_bits_per_sample(encoder));
386                 return false;
387         }
388         printf("OK\n");
389
390         printf("testing FLAC__stream_encoder_get_sample_rate()... ");
391         if(FLAC__stream_encoder_get_sample_rate(encoder) != streaminfo_.data.stream_info.sample_rate) {
392                 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.sample_rate, FLAC__stream_encoder_get_sample_rate(encoder));
393                 return false;
394         }
395         printf("OK\n");
396
397         printf("testing FLAC__stream_encoder_get_blocksize()... ");
398         if(FLAC__stream_encoder_get_blocksize(encoder) != streaminfo_.data.stream_info.min_blocksize) {
399                 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.min_blocksize, FLAC__stream_encoder_get_blocksize(encoder));
400                 return false;
401         }
402         printf("OK\n");
403
404         printf("testing FLAC__stream_encoder_get_max_lpc_order()... ");
405         if(FLAC__stream_encoder_get_max_lpc_order(encoder) != 0) {
406                 printf("FAILED, expected %u, got %u\n", 0, FLAC__stream_encoder_get_max_lpc_order(encoder));
407                 return false;
408         }
409         printf("OK\n");
410
411         printf("testing FLAC__stream_encoder_get_qlp_coeff_precision()... ");
412         (void)FLAC__stream_encoder_get_qlp_coeff_precision(encoder);
413         /* we asked the encoder to auto select this so we accept anything */
414         printf("OK\n");
415
416         printf("testing FLAC__stream_encoder_get_do_qlp_coeff_prec_search()... ");
417         if(FLAC__stream_encoder_get_do_qlp_coeff_prec_search(encoder) != false) {
418                 printf("FAILED, expected false, got true\n");
419                 return false;
420         }
421         printf("OK\n");
422
423         printf("testing FLAC__stream_encoder_get_do_escape_coding()... ");
424         if(FLAC__stream_encoder_get_do_escape_coding(encoder) != false) {
425                 printf("FAILED, expected false, got true\n");
426                 return false;
427         }
428         printf("OK\n");
429
430         printf("testing FLAC__stream_encoder_get_do_exhaustive_model_search()... ");
431         if(FLAC__stream_encoder_get_do_exhaustive_model_search(encoder) != false) {
432                 printf("FAILED, expected false, got true\n");
433                 return false;
434         }
435         printf("OK\n");
436
437         printf("testing FLAC__stream_encoder_get_min_residual_partition_order()... ");
438         if(FLAC__stream_encoder_get_min_residual_partition_order(encoder) != 0) {
439                 printf("FAILED, expected %u, got %u\n", 0, FLAC__stream_encoder_get_min_residual_partition_order(encoder));
440                 return false;
441         }
442         printf("OK\n");
443
444         printf("testing FLAC__stream_encoder_get_max_residual_partition_order()... ");
445         if(FLAC__stream_encoder_get_max_residual_partition_order(encoder) != 0) {
446                 printf("FAILED, expected %u, got %u\n", 0, FLAC__stream_encoder_get_max_residual_partition_order(encoder));
447                 return false;
448         }
449         printf("OK\n");
450
451         printf("testing FLAC__stream_encoder_get_rice_parameter_search_dist()... ");
452         if(FLAC__stream_encoder_get_rice_parameter_search_dist(encoder) != 0) {
453                 printf("FAILED, expected %u, got %u\n", 0, FLAC__stream_encoder_get_rice_parameter_search_dist(encoder));
454                 return false;
455         }
456         printf("OK\n");
457
458         printf("testing FLAC__stream_encoder_get_total_samples_estimate()... ");
459         if(FLAC__stream_encoder_get_total_samples_estimate(encoder) != streaminfo_.data.stream_info.total_samples) {
460                 printf("FAILED, expected %llu, got %llu\n", streaminfo_.data.stream_info.total_samples, FLAC__stream_encoder_get_total_samples_estimate(encoder));
461                 return false;
462         }
463         printf("OK\n");
464
465         /* init the dummy sample buffer */
466         for(i = 0; i < sizeof(samples) / sizeof(FLAC__int32); i++)
467                 samples[i] = i & 7;
468
469         printf("testing FLAC__stream_encoder_process()... ");
470         if(!FLAC__stream_encoder_process(encoder, (const FLAC__int32 * const *)samples_array, sizeof(samples) / sizeof(FLAC__int32)))
471                 return die_s_("returned false", encoder);
472         printf("OK\n");
473
474         printf("testing FLAC__stream_encoder_process_interleaved()... ");
475         if(!FLAC__stream_encoder_process_interleaved(encoder, samples, sizeof(samples) / sizeof(FLAC__int32)))
476                 return die_s_("returned false", encoder);
477         printf("OK\n");
478
479         printf("testing FLAC__stream_encoder_finish()... ");
480         FLAC__stream_encoder_finish(encoder);
481         printf("OK\n");
482
483         printf("testing FLAC__stream_encoder_delete()... ");
484         FLAC__stream_encoder_delete(encoder);
485         printf("OK\n");
486
487         printf("\nPASSED!\n");
488
489         return true;
490 }
491
492 FLAC__SeekableStreamEncoderSeekStatus seekable_stream_encoder_seek_callback_(const FLAC__SeekableStreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data)
493 {
494         (void)encoder, (void)absolute_byte_offset, (void)client_data;
495         return FLAC__SEEKABLE_STREAM_ENCODER_SEEK_STATUS_OK;
496 }
497
498 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)
499 {
500         (void)encoder, (void)buffer, (void)bytes, (void)samples, (void)current_frame, (void)client_data;
501         return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
502 }
503
504 static FLAC__bool test_seekable_stream_encoder()
505 {
506         FLAC__SeekableStreamEncoder *encoder;
507         FLAC__SeekableStreamEncoderState state;
508         FLAC__StreamEncoderState state_;
509         FLAC__StreamDecoderState dstate;
510         FLAC__int32 samples[1024];
511         FLAC__int32 *samples_array[1] = { samples };
512         unsigned i;
513
514         printf("\n+++ libFLAC unit test: FLAC__SeekableStreamEncoder\n\n");
515
516         printf("testing FLAC__seekable_stream_encoder_new()... ");
517         encoder = FLAC__seekable_stream_encoder_new();
518         if(0 == encoder) {
519                 printf("FAILED, returned NULL\n");
520                 return false;
521         }
522         printf("OK\n");
523
524         printf("testing FLAC__seekable_stream_encoder_set_verify()... ");
525         if(!FLAC__seekable_stream_encoder_set_verify(encoder, true))
526                 return die_ss_("returned false", encoder);
527         printf("OK\n");
528
529         printf("testing FLAC__seekable_stream_encoder_set_streamable_subset()... ");
530         if(!FLAC__seekable_stream_encoder_set_streamable_subset(encoder, true))
531                 return die_ss_("returned false", encoder);
532         printf("OK\n");
533
534         printf("testing FLAC__seekable_stream_encoder_set_do_mid_side_stereo()... ");
535         if(!FLAC__seekable_stream_encoder_set_do_mid_side_stereo(encoder, false))
536                 return die_ss_("returned false", encoder);
537         printf("OK\n");
538
539         printf("testing FLAC__seekable_stream_encoder_set_loose_mid_side_stereo()... ");
540         if(!FLAC__seekable_stream_encoder_set_loose_mid_side_stereo(encoder, false))
541                 return die_ss_("returned false", encoder);
542         printf("OK\n");
543
544         printf("testing FLAC__seekable_stream_encoder_set_channels()... ");
545         if(!FLAC__seekable_stream_encoder_set_channels(encoder, streaminfo_.data.stream_info.channels))
546                 return die_ss_("returned false", encoder);
547         printf("OK\n");
548
549         printf("testing FLAC__seekable_stream_encoder_set_bits_per_sample()... ");
550         if(!FLAC__seekable_stream_encoder_set_bits_per_sample(encoder, streaminfo_.data.stream_info.bits_per_sample))
551                 return die_ss_("returned false", encoder);
552         printf("OK\n");
553
554         printf("testing FLAC__seekable_stream_encoder_set_sample_rate()... ");
555         if(!FLAC__seekable_stream_encoder_set_sample_rate(encoder, streaminfo_.data.stream_info.sample_rate))
556                 return die_ss_("returned false", encoder);
557         printf("OK\n");
558
559         printf("testing FLAC__seekable_stream_encoder_set_blocksize()... ");
560         if(!FLAC__seekable_stream_encoder_set_blocksize(encoder, streaminfo_.data.stream_info.min_blocksize))
561                 return die_ss_("returned false", encoder);
562         printf("OK\n");
563
564         printf("testing FLAC__seekable_stream_encoder_set_max_lpc_order()... ");
565         if(!FLAC__seekable_stream_encoder_set_max_lpc_order(encoder, 0))
566                 return die_ss_("returned false", encoder);
567         printf("OK\n");
568
569         printf("testing FLAC__seekable_stream_encoder_set_qlp_coeff_precision()... ");
570         if(!FLAC__seekable_stream_encoder_set_qlp_coeff_precision(encoder, 0))
571                 return die_ss_("returned false", encoder);
572         printf("OK\n");
573
574         printf("testing FLAC__seekable_stream_encoder_set_do_qlp_coeff_prec_search()... ");
575         if(!FLAC__seekable_stream_encoder_set_do_qlp_coeff_prec_search(encoder, false))
576                 return die_ss_("returned false", encoder);
577         printf("OK\n");
578
579         printf("testing FLAC__seekable_stream_encoder_set_do_escape_coding()... ");
580         if(!FLAC__seekable_stream_encoder_set_do_escape_coding(encoder, false))
581                 return die_ss_("returned false", encoder);
582         printf("OK\n");
583
584         printf("testing FLAC__seekable_stream_encoder_set_do_exhaustive_model_search()... ");
585         if(!FLAC__seekable_stream_encoder_set_do_exhaustive_model_search(encoder, false))
586                 return die_ss_("returned false", encoder);
587         printf("OK\n");
588
589         printf("testing FLAC__seekable_stream_encoder_set_min_residual_partition_order()... ");
590         if(!FLAC__seekable_stream_encoder_set_min_residual_partition_order(encoder, 0))
591                 return die_ss_("returned false", encoder);
592         printf("OK\n");
593
594         printf("testing FLAC__seekable_stream_encoder_set_max_residual_partition_order()... ");
595         if(!FLAC__seekable_stream_encoder_set_max_residual_partition_order(encoder, 0))
596                 return die_ss_("returned false", encoder);
597         printf("OK\n");
598
599         printf("testing FLAC__seekable_stream_encoder_set_rice_parameter_search_dist()... ");
600         if(!FLAC__seekable_stream_encoder_set_rice_parameter_search_dist(encoder, 0))
601                 return die_ss_("returned false", encoder);
602         printf("OK\n");
603
604         printf("testing FLAC__seekable_stream_encoder_set_total_samples_estimate()... ");
605         if(!FLAC__seekable_stream_encoder_set_total_samples_estimate(encoder, streaminfo_.data.stream_info.total_samples))
606                 return die_ss_("returned false", encoder);
607         printf("OK\n");
608
609         printf("testing FLAC__seekable_stream_encoder_set_metadata()... ");
610         if(!FLAC__seekable_stream_encoder_set_metadata(encoder, metadata_sequence_, num_metadata_))
611                 return die_ss_("returned false", encoder);
612         printf("OK\n");
613
614         printf("testing FLAC__seekable_stream_encoder_set_seek_callback()... ");
615         if(!FLAC__seekable_stream_encoder_set_seek_callback(encoder, seekable_stream_encoder_seek_callback_))
616                 return die_ss_("returned false", encoder);
617         printf("OK\n");
618
619         printf("testing FLAC__seekable_stream_encoder_set_write_callback()... ");
620         if(!FLAC__seekable_stream_encoder_set_write_callback(encoder, seekable_stream_encoder_write_callback_))
621                 return die_ss_("returned false", encoder);
622         printf("OK\n");
623
624         printf("testing FLAC__seekable_stream_encoder_set_client_data()... ");
625         if(!FLAC__seekable_stream_encoder_set_client_data(encoder, 0))
626                 return die_ss_("returned false", encoder);
627         printf("OK\n");
628
629         printf("testing FLAC__seekable_stream_encoder_init()... ");
630         if(FLAC__seekable_stream_encoder_init(encoder) != FLAC__SEEKABLE_STREAM_ENCODER_OK)
631                 return die_ss_(0, encoder);
632         printf("OK\n");
633
634         printf("testing FLAC__seekable_stream_encoder_get_state()... ");
635         state = FLAC__seekable_stream_encoder_get_state(encoder);
636         printf("returned state = %u (%s)... OK\n", (unsigned)state, FLAC__SeekableStreamEncoderStateString[state]);
637
638         printf("testing FLAC__seekable_stream_encoder_get_stream_encoder_state()... ");
639         state_ = FLAC__seekable_stream_encoder_get_stream_encoder_state(encoder);
640         printf("returned state = %u (%s)... OK\n", (unsigned)state_, FLAC__StreamEncoderStateString[state_]);
641
642         printf("testing FLAC__seekable_stream_encoder_get_verify_decoder_state()... ");
643         dstate = FLAC__seekable_stream_encoder_get_verify_decoder_state(encoder);
644         printf("returned state = %u (%s)... OK\n", (unsigned)dstate, FLAC__StreamDecoderStateString[dstate]);
645
646         {
647                 FLAC__uint64 absolute_sample;
648                 unsigned frame_number;
649                 unsigned channel;
650                 unsigned sample;
651                 FLAC__int32 expected;
652                 FLAC__int32 got;
653
654                 printf("testing FLAC__seekable_stream_encoder_get_verify_decoder_error_stats()... ");
655                 FLAC__seekable_stream_encoder_get_verify_decoder_error_stats(encoder, &absolute_sample, &frame_number, &channel, &sample, &expected, &got);
656                 printf("OK\n");
657         }
658
659         printf("testing FLAC__seekable_stream_encoder_get_verify()... ");
660         if(FLAC__seekable_stream_encoder_get_verify(encoder) != true) {
661                 printf("FAILED, expected true, got false\n");
662                 return false;
663         }
664         printf("OK\n");
665
666         printf("testing FLAC__seekable_stream_encoder_get_streamable_subset()... ");
667         if(FLAC__seekable_stream_encoder_get_streamable_subset(encoder) != true) {
668                 printf("FAILED, expected true, got false\n");
669                 return false;
670         }
671         printf("OK\n");
672
673         printf("testing FLAC__seekable_stream_encoder_get_do_mid_side_stereo()... ");
674         if(FLAC__seekable_stream_encoder_get_do_mid_side_stereo(encoder) != false) {
675                 printf("FAILED, expected false, got true\n");
676                 return false;
677         }
678         printf("OK\n");
679
680         printf("testing FLAC__seekable_stream_encoder_get_loose_mid_side_stereo()... ");
681         if(FLAC__seekable_stream_encoder_get_loose_mid_side_stereo(encoder) != false) {
682                 printf("FAILED, expected false, got true\n");
683                 return false;
684         }
685         printf("OK\n");
686
687         printf("testing FLAC__seekable_stream_encoder_get_channels()... ");
688         if(FLAC__seekable_stream_encoder_get_channels(encoder) != streaminfo_.data.stream_info.channels) {
689                 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.channels, FLAC__seekable_stream_encoder_get_channels(encoder));
690                 return false;
691         }
692         printf("OK\n");
693
694         printf("testing FLAC__seekable_stream_encoder_get_bits_per_sample()... ");
695         if(FLAC__seekable_stream_encoder_get_bits_per_sample(encoder) != streaminfo_.data.stream_info.bits_per_sample) {
696                 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.bits_per_sample, FLAC__seekable_stream_encoder_get_bits_per_sample(encoder));
697                 return false;
698         }
699         printf("OK\n");
700
701         printf("testing FLAC__seekable_stream_encoder_get_sample_rate()... ");
702         if(FLAC__seekable_stream_encoder_get_sample_rate(encoder) != streaminfo_.data.stream_info.sample_rate) {
703                 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.sample_rate, FLAC__seekable_stream_encoder_get_sample_rate(encoder));
704                 return false;
705         }
706         printf("OK\n");
707
708         printf("testing FLAC__seekable_stream_encoder_get_blocksize()... ");
709         if(FLAC__seekable_stream_encoder_get_blocksize(encoder) != streaminfo_.data.stream_info.min_blocksize) {
710                 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.min_blocksize, FLAC__seekable_stream_encoder_get_blocksize(encoder));
711                 return false;
712         }
713         printf("OK\n");
714
715         printf("testing FLAC__seekable_stream_encoder_get_max_lpc_order()... ");
716         if(FLAC__seekable_stream_encoder_get_max_lpc_order(encoder) != 0) {
717                 printf("FAILED, expected %u, got %u\n", 0, FLAC__seekable_stream_encoder_get_max_lpc_order(encoder));
718                 return false;
719         }
720         printf("OK\n");
721
722         printf("testing FLAC__seekable_stream_encoder_get_qlp_coeff_precision()... ");
723         (void)FLAC__seekable_stream_encoder_get_qlp_coeff_precision(encoder);
724         /* we asked the encoder to auto select this so we accept anything */
725         printf("OK\n");
726
727         printf("testing FLAC__seekable_stream_encoder_get_do_qlp_coeff_prec_search()... ");
728         if(FLAC__seekable_stream_encoder_get_do_qlp_coeff_prec_search(encoder) != false) {
729                 printf("FAILED, expected false, got true\n");
730                 return false;
731         }
732         printf("OK\n");
733
734         printf("testing FLAC__seekable_stream_encoder_get_do_escape_coding()... ");
735         if(FLAC__seekable_stream_encoder_get_do_escape_coding(encoder) != false) {
736                 printf("FAILED, expected false, got true\n");
737                 return false;
738         }
739         printf("OK\n");
740
741         printf("testing FLAC__seekable_stream_encoder_get_do_exhaustive_model_search()... ");
742         if(FLAC__seekable_stream_encoder_get_do_exhaustive_model_search(encoder) != false) {
743                 printf("FAILED, expected false, got true\n");
744                 return false;
745         }
746         printf("OK\n");
747
748         printf("testing FLAC__seekable_stream_encoder_get_min_residual_partition_order()... ");
749         if(FLAC__seekable_stream_encoder_get_min_residual_partition_order(encoder) != 0) {
750                 printf("FAILED, expected %u, got %u\n", 0, FLAC__seekable_stream_encoder_get_min_residual_partition_order(encoder));
751                 return false;
752         }
753         printf("OK\n");
754
755         printf("testing FLAC__seekable_stream_encoder_get_max_residual_partition_order()... ");
756         if(FLAC__seekable_stream_encoder_get_max_residual_partition_order(encoder) != 0) {
757                 printf("FAILED, expected %u, got %u\n", 0, FLAC__seekable_stream_encoder_get_max_residual_partition_order(encoder));
758                 return false;
759         }
760         printf("OK\n");
761
762         printf("testing FLAC__seekable_stream_encoder_get_rice_parameter_search_dist()... ");
763         if(FLAC__seekable_stream_encoder_get_rice_parameter_search_dist(encoder) != 0) {
764                 printf("FAILED, expected %u, got %u\n", 0, FLAC__seekable_stream_encoder_get_rice_parameter_search_dist(encoder));
765                 return false;
766         }
767         printf("OK\n");
768
769         printf("testing FLAC__seekable_stream_encoder_get_total_samples_estimate()... ");
770         if(FLAC__seekable_stream_encoder_get_total_samples_estimate(encoder) != streaminfo_.data.stream_info.total_samples) {
771                 printf("FAILED, expected %llu, got %llu\n", streaminfo_.data.stream_info.total_samples, FLAC__seekable_stream_encoder_get_total_samples_estimate(encoder));
772                 return false;
773         }
774         printf("OK\n");
775
776         /* init the dummy sample buffer */
777         for(i = 0; i < sizeof(samples) / sizeof(FLAC__int32); i++)
778                 samples[i] = i & 7;
779
780         printf("testing FLAC__seekable_stream_encoder_process()... ");
781         if(!FLAC__seekable_stream_encoder_process(encoder, (const FLAC__int32 * const *)samples_array, sizeof(samples) / sizeof(FLAC__int32)))
782                 return die_ss_("returned false", encoder);
783         printf("OK\n");
784
785         printf("testing FLAC__seekable_stream_encoder_process_interleaved()... ");
786         if(!FLAC__seekable_stream_encoder_process_interleaved(encoder, samples, sizeof(samples) / sizeof(FLAC__int32)))
787                 return die_ss_("returned false", encoder);
788         printf("OK\n");
789
790         printf("testing FLAC__seekable_stream_encoder_finish()... ");
791         FLAC__seekable_stream_encoder_finish(encoder);
792         printf("OK\n");
793
794         printf("testing FLAC__seekable_stream_encoder_delete()... ");
795         FLAC__seekable_stream_encoder_delete(encoder);
796         printf("OK\n");
797
798         printf("\nPASSED!\n");
799
800         return true;
801 }
802
803 static void file_encoder_progress_callback_(const FLAC__FileEncoder *encoder, FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate, void *client_data)
804 {
805         (void)encoder, (void)bytes_written, (void)samples_written, (void)frames_written, (void)total_frames_estimate, (void)client_data;
806 }
807
808 static FLAC__bool test_file_encoder()
809 {
810         FLAC__FileEncoder *encoder;
811         FLAC__FileEncoderState state;
812         FLAC__SeekableStreamEncoderState state_;
813         FLAC__StreamEncoderState state__;
814         FLAC__StreamDecoderState dstate;
815         FLAC__int32 samples[1024];
816         FLAC__int32 *samples_array[1] = { samples };
817         unsigned i;
818
819         printf("\n+++ libFLAC unit test: FLAC__FileEncoder\n\n");
820
821         printf("testing FLAC__file_encoder_new()... ");
822         encoder = FLAC__file_encoder_new();
823         if(0 == encoder) {
824                 printf("FAILED, returned NULL\n");
825                 return false;
826         }
827         printf("OK\n");
828
829         printf("testing FLAC__file_encoder_set_verify()... ");
830         if(!FLAC__file_encoder_set_verify(encoder, true))
831                 return die_f_("returned false", encoder);
832         printf("OK\n");
833
834         printf("testing FLAC__file_encoder_set_streamable_subset()... ");
835         if(!FLAC__file_encoder_set_streamable_subset(encoder, true))
836                 return die_f_("returned false", encoder);
837         printf("OK\n");
838
839         printf("testing FLAC__file_encoder_set_do_mid_side_stereo()... ");
840         if(!FLAC__file_encoder_set_do_mid_side_stereo(encoder, false))
841                 return die_f_("returned false", encoder);
842         printf("OK\n");
843
844         printf("testing FLAC__file_encoder_set_loose_mid_side_stereo()... ");
845         if(!FLAC__file_encoder_set_loose_mid_side_stereo(encoder, false))
846                 return die_f_("returned false", encoder);
847         printf("OK\n");
848
849         printf("testing FLAC__file_encoder_set_channels()... ");
850         if(!FLAC__file_encoder_set_channels(encoder, streaminfo_.data.stream_info.channels))
851                 return die_f_("returned false", encoder);
852         printf("OK\n");
853
854         printf("testing FLAC__file_encoder_set_bits_per_sample()... ");
855         if(!FLAC__file_encoder_set_bits_per_sample(encoder, streaminfo_.data.stream_info.bits_per_sample))
856                 return die_f_("returned false", encoder);
857         printf("OK\n");
858
859         printf("testing FLAC__file_encoder_set_sample_rate()... ");
860         if(!FLAC__file_encoder_set_sample_rate(encoder, streaminfo_.data.stream_info.sample_rate))
861                 return die_f_("returned false", encoder);
862         printf("OK\n");
863
864         printf("testing FLAC__file_encoder_set_blocksize()... ");
865         if(!FLAC__file_encoder_set_blocksize(encoder, streaminfo_.data.stream_info.min_blocksize))
866                 return die_f_("returned false", encoder);
867         printf("OK\n");
868
869         printf("testing FLAC__file_encoder_set_max_lpc_order()... ");
870         if(!FLAC__file_encoder_set_max_lpc_order(encoder, 0))
871                 return die_f_("returned false", encoder);
872         printf("OK\n");
873
874         printf("testing FLAC__file_encoder_set_qlp_coeff_precision()... ");
875         if(!FLAC__file_encoder_set_qlp_coeff_precision(encoder, 0))
876                 return die_f_("returned false", encoder);
877         printf("OK\n");
878
879         printf("testing FLAC__file_encoder_set_do_qlp_coeff_prec_search()... ");
880         if(!FLAC__file_encoder_set_do_qlp_coeff_prec_search(encoder, false))
881                 return die_f_("returned false", encoder);
882         printf("OK\n");
883
884         printf("testing FLAC__file_encoder_set_do_escape_coding()... ");
885         if(!FLAC__file_encoder_set_do_escape_coding(encoder, false))
886                 return die_f_("returned false", encoder);
887         printf("OK\n");
888
889         printf("testing FLAC__file_encoder_set_do_exhaustive_model_search()... ");
890         if(!FLAC__file_encoder_set_do_exhaustive_model_search(encoder, false))
891                 return die_f_("returned false", encoder);
892         printf("OK\n");
893
894         printf("testing FLAC__file_encoder_set_min_residual_partition_order()... ");
895         if(!FLAC__file_encoder_set_min_residual_partition_order(encoder, 0))
896                 return die_f_("returned false", encoder);
897         printf("OK\n");
898
899         printf("testing FLAC__file_encoder_set_max_residual_partition_order()... ");
900         if(!FLAC__file_encoder_set_max_residual_partition_order(encoder, 0))
901                 return die_f_("returned false", encoder);
902         printf("OK\n");
903
904         printf("testing FLAC__file_encoder_set_rice_parameter_search_dist()... ");
905         if(!FLAC__file_encoder_set_rice_parameter_search_dist(encoder, 0))
906                 return die_f_("returned false", encoder);
907         printf("OK\n");
908
909         printf("testing FLAC__file_encoder_set_total_samples_estimate()... ");
910         if(!FLAC__file_encoder_set_total_samples_estimate(encoder, streaminfo_.data.stream_info.total_samples))
911                 return die_f_("returned false", encoder);
912         printf("OK\n");
913
914         printf("testing FLAC__file_encoder_set_metadata()... ");
915         if(!FLAC__file_encoder_set_metadata(encoder, metadata_sequence_, num_metadata_))
916                 return die_f_("returned false", encoder);
917         printf("OK\n");
918
919         printf("testing FLAC__file_encoder_set_filename()... ");
920         if(!FLAC__file_encoder_set_filename(encoder, flacfilename_))
921                 return die_f_("returned false", encoder);
922         printf("OK\n");
923
924         printf("testing FLAC__file_encoder_set_progress_callback()... ");
925         if(!FLAC__file_encoder_set_progress_callback(encoder, file_encoder_progress_callback_))
926                 return die_f_("returned false", encoder);
927         printf("OK\n");
928
929         printf("testing FLAC__file_encoder_set_client_data()... ");
930         if(!FLAC__file_encoder_set_client_data(encoder, 0))
931                 return die_f_("returned false", encoder);
932         printf("OK\n");
933
934         printf("testing FLAC__file_encoder_init()... ");
935         if(FLAC__file_encoder_init(encoder) != FLAC__FILE_ENCODER_OK)
936                 return die_f_(0, encoder);
937         printf("OK\n");
938
939         printf("testing FLAC__file_encoder_get_state()... ");
940         state = FLAC__file_encoder_get_state(encoder);
941         printf("returned state = %u (%s)... OK\n", (unsigned)state, FLAC__FileEncoderStateString[state]);
942
943         printf("testing FLAC__file_encoder_get_seekable_stream_encoder_state()... ");
944         state_ = FLAC__file_encoder_get_seekable_stream_encoder_state(encoder);
945         printf("returned state = %u (%s)... OK\n", (unsigned)state_, FLAC__SeekableStreamEncoderStateString[state_]);
946
947         printf("testing FLAC__file_encoder_get_stream_encoder_state()... ");
948         state__ = FLAC__file_encoder_get_stream_encoder_state(encoder);
949         printf("returned state = %u (%s)... OK\n", (unsigned)state__, FLAC__StreamEncoderStateString[state__]);
950
951         printf("testing FLAC__file_encoder_get_verify_decoder_state()... ");
952         dstate = FLAC__file_encoder_get_verify_decoder_state(encoder);
953         printf("returned state = %u (%s)... OK\n", (unsigned)dstate, FLAC__StreamDecoderStateString[dstate]);
954
955         {
956                 FLAC__uint64 absolute_sample;
957                 unsigned frame_number;
958                 unsigned channel;
959                 unsigned sample;
960                 FLAC__int32 expected;
961                 FLAC__int32 got;
962
963                 printf("testing FLAC__file_encoder_get_verify_decoder_error_stats()... ");
964                 FLAC__file_encoder_get_verify_decoder_error_stats(encoder, &absolute_sample, &frame_number, &channel, &sample, &expected, &got);
965                 printf("OK\n");
966         }
967
968         printf("testing FLAC__file_encoder_get_verify()... ");
969         if(FLAC__file_encoder_get_verify(encoder) != true) {
970                 printf("FAILED, expected true, got false\n");
971                 return false;
972         }
973         printf("OK\n");
974
975         printf("testing FLAC__file_encoder_get_streamable_subset()... ");
976         if(FLAC__file_encoder_get_streamable_subset(encoder) != true) {
977                 printf("FAILED, expected true, got false\n");
978                 return false;
979         }
980         printf("OK\n");
981
982         printf("testing FLAC__file_encoder_get_do_mid_side_stereo()... ");
983         if(FLAC__file_encoder_get_do_mid_side_stereo(encoder) != false) {
984                 printf("FAILED, expected false, got true\n");
985                 return false;
986         }
987         printf("OK\n");
988
989         printf("testing FLAC__file_encoder_get_loose_mid_side_stereo()... ");
990         if(FLAC__file_encoder_get_loose_mid_side_stereo(encoder) != false) {
991                 printf("FAILED, expected false, got true\n");
992                 return false;
993         }
994         printf("OK\n");
995
996         printf("testing FLAC__file_encoder_get_channels()... ");
997         if(FLAC__file_encoder_get_channels(encoder) != streaminfo_.data.stream_info.channels) {
998                 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.channels, FLAC__file_encoder_get_channels(encoder));
999                 return false;
1000         }
1001         printf("OK\n");
1002
1003         printf("testing FLAC__file_encoder_get_bits_per_sample()... ");
1004         if(FLAC__file_encoder_get_bits_per_sample(encoder) != streaminfo_.data.stream_info.bits_per_sample) {
1005                 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.bits_per_sample, FLAC__file_encoder_get_bits_per_sample(encoder));
1006                 return false;
1007         }
1008         printf("OK\n");
1009
1010         printf("testing FLAC__file_encoder_get_sample_rate()... ");
1011         if(FLAC__file_encoder_get_sample_rate(encoder) != streaminfo_.data.stream_info.sample_rate) {
1012                 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.sample_rate, FLAC__file_encoder_get_sample_rate(encoder));
1013                 return false;
1014         }
1015         printf("OK\n");
1016
1017         printf("testing FLAC__file_encoder_get_blocksize()... ");
1018         if(FLAC__file_encoder_get_blocksize(encoder) != streaminfo_.data.stream_info.min_blocksize) {
1019                 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.min_blocksize, FLAC__file_encoder_get_blocksize(encoder));
1020                 return false;
1021         }
1022         printf("OK\n");
1023
1024         printf("testing FLAC__file_encoder_get_max_lpc_order()... ");
1025         if(FLAC__file_encoder_get_max_lpc_order(encoder) != 0) {
1026                 printf("FAILED, expected %u, got %u\n", 0, FLAC__file_encoder_get_max_lpc_order(encoder));
1027                 return false;
1028         }
1029         printf("OK\n");
1030
1031         printf("testing FLAC__file_encoder_get_qlp_coeff_precision()... ");
1032         (void)FLAC__file_encoder_get_qlp_coeff_precision(encoder);
1033         /* we asked the encoder to auto select this so we accept anything */
1034         printf("OK\n");
1035
1036         printf("testing FLAC__file_encoder_get_do_qlp_coeff_prec_search()... ");
1037         if(FLAC__file_encoder_get_do_qlp_coeff_prec_search(encoder) != false) {
1038                 printf("FAILED, expected false, got true\n");
1039                 return false;
1040         }
1041         printf("OK\n");
1042
1043         printf("testing FLAC__file_encoder_get_do_escape_coding()... ");
1044         if(FLAC__file_encoder_get_do_escape_coding(encoder) != false) {
1045                 printf("FAILED, expected false, got true\n");
1046                 return false;
1047         }
1048         printf("OK\n");
1049
1050         printf("testing FLAC__file_encoder_get_do_exhaustive_model_search()... ");
1051         if(FLAC__file_encoder_get_do_exhaustive_model_search(encoder) != false) {
1052                 printf("FAILED, expected false, got true\n");
1053                 return false;
1054         }
1055         printf("OK\n");
1056
1057         printf("testing FLAC__file_encoder_get_min_residual_partition_order()... ");
1058         if(FLAC__file_encoder_get_min_residual_partition_order(encoder) != 0) {
1059                 printf("FAILED, expected %u, got %u\n", 0, FLAC__file_encoder_get_min_residual_partition_order(encoder));
1060                 return false;
1061         }
1062         printf("OK\n");
1063
1064         printf("testing FLAC__file_encoder_get_max_residual_partition_order()... ");
1065         if(FLAC__file_encoder_get_max_residual_partition_order(encoder) != 0) {
1066                 printf("FAILED, expected %u, got %u\n", 0, FLAC__file_encoder_get_max_residual_partition_order(encoder));
1067                 return false;
1068         }
1069         printf("OK\n");
1070
1071         printf("testing FLAC__file_encoder_get_rice_parameter_search_dist()... ");
1072         if(FLAC__file_encoder_get_rice_parameter_search_dist(encoder) != 0) {
1073                 printf("FAILED, expected %u, got %u\n", 0, FLAC__file_encoder_get_rice_parameter_search_dist(encoder));
1074                 return false;
1075         }
1076         printf("OK\n");
1077
1078         printf("testing FLAC__file_encoder_get_total_samples_estimate()... ");
1079         if(FLAC__file_encoder_get_total_samples_estimate(encoder) != streaminfo_.data.stream_info.total_samples) {
1080                 printf("FAILED, expected %llu, got %llu\n", streaminfo_.data.stream_info.total_samples, FLAC__file_encoder_get_total_samples_estimate(encoder));
1081                 return false;
1082         }
1083         printf("OK\n");
1084
1085         /* init the dummy sample buffer */
1086         for(i = 0; i < sizeof(samples) / sizeof(FLAC__int32); i++)
1087                 samples[i] = i & 7;
1088
1089         printf("testing FLAC__file_encoder_process()... ");
1090         if(!FLAC__file_encoder_process(encoder, (const FLAC__int32 * const *)samples_array, sizeof(samples) / sizeof(FLAC__int32)))
1091                 return die_f_("returned false", encoder);
1092         printf("OK\n");
1093
1094         printf("testing FLAC__file_encoder_process_interleaved()... ");
1095         if(!FLAC__file_encoder_process_interleaved(encoder, samples, sizeof(samples) / sizeof(FLAC__int32)))
1096                 return die_f_("returned false", encoder);
1097         printf("OK\n");
1098
1099         printf("testing FLAC__file_encoder_finish()... ");
1100         FLAC__file_encoder_finish(encoder);
1101         printf("OK\n");
1102
1103         printf("testing FLAC__file_encoder_delete()... ");
1104         FLAC__file_encoder_delete(encoder);
1105         printf("OK\n");
1106
1107         printf("\nPASSED!\n");
1108
1109         return true;
1110 }
1111
1112 FLAC__bool test_encoders()
1113 {
1114         init_metadata_blocks_();
1115
1116         if(!test_stream_encoder())
1117                 return false;
1118
1119         if(!test_seekable_stream_encoder())
1120                 return false;
1121
1122         if(!test_file_encoder())
1123                 return false;
1124
1125         (void) file_utils__remove_file(flacfilename_);
1126         free_metadata_blocks_();
1127
1128         return true;
1129 }