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