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