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