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