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