1 /* test_libFLAC - Unit tester for libFLAC
2 * Copyright (C) 2002-2009 Josh Coalson
3 * Copyright (C) 2011-2023 Xiph.Org Foundation
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #ifdef HAVE_CONFIG_H
21 # include <config.h>
22 #endif
23
24 #include <errno.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include "encoders.h"
29 #include "FLAC/assert.h"
30 #include "FLAC/stream_encoder.h"
31 #include "share/grabbag.h"
32 #include "share/compat.h"
33 #include "test_libs_common/file_utils_flac.h"
34 #include "test_libs_common/metadata_utils.h"
35
36 typedef enum {
37 LAYER_STREAM = 0, /* FLAC__stream_encoder_init_[ogg_]stream() without seeking */
38 LAYER_SEEKABLE_STREAM, /* FLAC__stream_encoder_init_[ogg_]stream() with seeking */
39 LAYER_FILE, /* FLAC__stream_encoder_init_[ogg_]FILE() */
40 LAYER_FILENAME /* FLAC__stream_encoder_init_[ogg_]file() */
41 } Layer;
42
43 static const char * const LayerString[] = {
44 "Stream",
45 "Seekable Stream",
46 "FILE*",
47 "Filename"
48 };
49
50 static FLAC__StreamMetadata streaminfo_, padding_, seektable_, application1_, application2_, vorbiscomment_, cuesheet_, picture_, unknown_;
51 static FLAC__StreamMetadata *metadata_sequence_[] = { &vorbiscomment_, &padding_, &seektable_, &application1_, &application2_, &cuesheet_, &picture_, &unknown_ };
52 static const uint32_t num_metadata_ = sizeof(metadata_sequence_) / sizeof(metadata_sequence_[0]);
53
flacfilename(FLAC__bool is_ogg)54 static const char *flacfilename(FLAC__bool is_ogg)
55 {
56 return is_ogg? "metadata.oga" : "metadata.flac";
57 }
58
die_(const char * msg)59 static FLAC__bool die_(const char *msg)
60 {
61 printf("ERROR: %s\n", msg);
62 return false;
63 }
64
die_s_(const char * msg,const FLAC__StreamEncoder * encoder)65 static FLAC__bool die_s_(const char *msg, const FLAC__StreamEncoder *encoder)
66 {
67 FLAC__StreamEncoderState state = FLAC__stream_encoder_get_state(encoder);
68
69 if(msg)
70 printf("FAILED, %s", msg);
71 else
72 printf("FAILED");
73
74 printf(", state = %u (%s)\n", (uint32_t)state, FLAC__StreamEncoderStateString[state]);
75 if(state == FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR) {
76 FLAC__StreamDecoderState dstate = FLAC__stream_encoder_get_verify_decoder_state(encoder);
77 printf(" verify decoder state = %u (%s)\n", (uint32_t)dstate, FLAC__StreamDecoderStateString[dstate]);
78 }
79
80 return false;
81 }
82
init_metadata_blocks_(void)83 static void init_metadata_blocks_(void)
84 {
85 mutils__init_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &picture_, &unknown_);
86 }
87
free_metadata_blocks_(void)88 static void free_metadata_blocks_(void)
89 {
90 mutils__free_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &picture_, &unknown_);
91 }
92
stream_encoder_read_callback_(const FLAC__StreamEncoder * encoder,FLAC__byte buffer[],size_t * bytes,void * client_data)93 static FLAC__StreamEncoderReadStatus stream_encoder_read_callback_(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
94 {
95 FILE *f = (FILE*)client_data;
96 (void)encoder;
97 if(*bytes > 0) {
98 *bytes = fread(buffer, sizeof(FLAC__byte), *bytes, f);
99 if(ferror(f))
100 return FLAC__STREAM_ENCODER_READ_STATUS_ABORT;
101 else if(*bytes == 0)
102 return FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM;
103 else
104 return FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE;
105 }
106 else
107 return FLAC__STREAM_ENCODER_READ_STATUS_ABORT;
108 }
109
stream_encoder_write_callback_(const FLAC__StreamEncoder * encoder,const FLAC__byte buffer[],size_t bytes,uint32_t samples,uint32_t current_frame,void * client_data)110 static FLAC__StreamEncoderWriteStatus stream_encoder_write_callback_(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, uint32_t samples, uint32_t current_frame, void *client_data)
111 {
112 FILE *f = (FILE*)client_data;
113 (void)encoder, (void)samples, (void)current_frame;
114 if(fwrite(buffer, 1, bytes, f) != bytes)
115 return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
116 else
117 return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
118 }
119
stream_encoder_seek_callback_(const FLAC__StreamEncoder * encoder,FLAC__uint64 absolute_byte_offset,void * client_data)120 static FLAC__StreamEncoderSeekStatus stream_encoder_seek_callback_(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data)
121 {
122 FILE *f = (FILE*)client_data;
123 (void)encoder;
124 if(fseeko(f, (long)absolute_byte_offset, SEEK_SET) < 0)
125 return FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR;
126 else
127 return FLAC__STREAM_ENCODER_SEEK_STATUS_OK;
128 }
129
stream_encoder_tell_callback_(const FLAC__StreamEncoder * encoder,FLAC__uint64 * absolute_byte_offset,void * client_data)130 static FLAC__StreamEncoderTellStatus stream_encoder_tell_callback_(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
131 {
132 FILE *f = (FILE*)client_data;
133 FLAC__off_t pos;
134 (void)encoder;
135 if((pos = ftello(f)) < 0)
136 return FLAC__STREAM_ENCODER_TELL_STATUS_ERROR;
137 else {
138 *absolute_byte_offset = (FLAC__uint64)pos;
139 return FLAC__STREAM_ENCODER_TELL_STATUS_OK;
140 }
141 }
142
stream_encoder_metadata_callback_(const FLAC__StreamEncoder * encoder,const FLAC__StreamMetadata * metadata,void * client_data)143 static void stream_encoder_metadata_callback_(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetadata *metadata, void *client_data)
144 {
145 (void)encoder, (void)metadata, (void)client_data;
146 }
147
stream_encoder_progress_callback_(const FLAC__StreamEncoder * encoder,FLAC__uint64 bytes_written,FLAC__uint64 samples_written,uint32_t frames_written,uint32_t total_frames_estimate,void * client_data)148 static void stream_encoder_progress_callback_(const FLAC__StreamEncoder *encoder, FLAC__uint64 bytes_written, FLAC__uint64 samples_written, uint32_t frames_written, uint32_t total_frames_estimate, void *client_data)
149 {
150 (void)encoder, (void)bytes_written, (void)samples_written, (void)frames_written, (void)total_frames_estimate, (void)client_data;
151 }
152
test_stream_encoder(Layer layer,FLAC__bool is_ogg)153 static FLAC__bool test_stream_encoder(Layer layer, FLAC__bool is_ogg)
154 {
155 FLAC__StreamEncoder *encoder;
156 FLAC__StreamEncoderInitStatus init_status;
157 FLAC__StreamEncoderState state;
158 FLAC__StreamDecoderState dstate;
159 FILE *file = 0;
160 FLAC__int32 samples[1024];
161 FLAC__int32 *samples_array[1];
162 uint32_t i;
163
164 samples_array[0] = samples;
165
166 printf("\n+++ libFLAC unit test: FLAC__StreamEncoder (layer: %s, format: %s)\n\n", LayerString[layer], is_ogg? "Ogg FLAC":"FLAC");
167
168 printf("testing FLAC__stream_encoder_new()... ");
169 encoder = FLAC__stream_encoder_new();
170 if(0 == encoder) {
171 printf("FAILED, returned NULL\n");
172 return false;
173 }
174 printf("OK\n");
175
176 if(is_ogg) {
177 printf("testing FLAC__stream_encoder_set_ogg_serial_number()... ");
178 if(!FLAC__stream_encoder_set_ogg_serial_number(encoder, file_utils__ogg_serial_number))
179 return die_s_("returned false", encoder);
180 printf("OK\n");
181 }
182
183 printf("testing FLAC__stream_encoder_set_verify()... ");
184 if(!FLAC__stream_encoder_set_verify(encoder, true))
185 return die_s_("returned false", encoder);
186 printf("OK\n");
187
188 printf("testing FLAC__stream_encoder_set_streamable_subset()... ");
189 if(!FLAC__stream_encoder_set_streamable_subset(encoder, true))
190 return die_s_("returned false", encoder);
191 printf("OK\n");
192
193 printf("testing FLAC__stream_encoder_set_channels()... ");
194 if(!FLAC__stream_encoder_set_channels(encoder, streaminfo_.data.stream_info.channels))
195 return die_s_("returned false", encoder);
196 printf("OK\n");
197
198 printf("testing FLAC__stream_encoder_set_bits_per_sample()... ");
199 if(!FLAC__stream_encoder_set_bits_per_sample(encoder, streaminfo_.data.stream_info.bits_per_sample))
200 return die_s_("returned false", encoder);
201 printf("OK\n");
202
203 printf("testing FLAC__stream_encoder_set_sample_rate()... ");
204 if(!FLAC__stream_encoder_set_sample_rate(encoder, streaminfo_.data.stream_info.sample_rate))
205 return die_s_("returned false", encoder);
206 printf("OK\n");
207
208 printf("testing FLAC__stream_encoder_set_compression_level()... ");
209 if(!FLAC__stream_encoder_set_compression_level(encoder, (uint32_t)(-1)))
210 return die_s_("returned false", encoder);
211 printf("OK\n");
212
213 printf("testing FLAC__stream_encoder_set_blocksize()... ");
214 if(!FLAC__stream_encoder_set_blocksize(encoder, streaminfo_.data.stream_info.min_blocksize))
215 return die_s_("returned false", encoder);
216 printf("OK\n");
217
218 printf("testing FLAC__stream_encoder_set_do_mid_side_stereo()... ");
219 if(!FLAC__stream_encoder_set_do_mid_side_stereo(encoder, false))
220 return die_s_("returned false", encoder);
221 printf("OK\n");
222
223 printf("testing FLAC__stream_encoder_set_loose_mid_side_stereo()... ");
224 if(!FLAC__stream_encoder_set_loose_mid_side_stereo(encoder, false))
225 return die_s_("returned false", encoder);
226 printf("OK\n");
227
228 printf("testing FLAC__stream_encoder_set_max_lpc_order()... ");
229 if(!FLAC__stream_encoder_set_max_lpc_order(encoder, 0))
230 return die_s_("returned false", encoder);
231 printf("OK\n");
232
233 printf("testing FLAC__stream_encoder_set_qlp_coeff_precision()... ");
234 if(!FLAC__stream_encoder_set_qlp_coeff_precision(encoder, 0))
235 return die_s_("returned false", encoder);
236 printf("OK\n");
237
238 printf("testing FLAC__stream_encoder_set_do_qlp_coeff_prec_search()... ");
239 if(!FLAC__stream_encoder_set_do_qlp_coeff_prec_search(encoder, false))
240 return die_s_("returned false", encoder);
241 printf("OK\n");
242
243 printf("testing FLAC__stream_encoder_set_do_escape_coding()... ");
244 if(!FLAC__stream_encoder_set_do_escape_coding(encoder, false))
245 return die_s_("returned false", encoder);
246 printf("OK\n");
247
248 printf("testing FLAC__stream_encoder_set_do_exhaustive_model_search()... ");
249 if(!FLAC__stream_encoder_set_do_exhaustive_model_search(encoder, false))
250 return die_s_("returned false", encoder);
251 printf("OK\n");
252
253 printf("testing FLAC__stream_encoder_set_min_residual_partition_order()... ");
254 if(!FLAC__stream_encoder_set_min_residual_partition_order(encoder, 0))
255 return die_s_("returned false", encoder);
256 printf("OK\n");
257
258 printf("testing FLAC__stream_encoder_set_max_residual_partition_order()... ");
259 if(!FLAC__stream_encoder_set_max_residual_partition_order(encoder, 0))
260 return die_s_("returned false", encoder);
261 printf("OK\n");
262
263 printf("testing FLAC__stream_encoder_set_rice_parameter_search_dist()... ");
264 if(!FLAC__stream_encoder_set_rice_parameter_search_dist(encoder, 0))
265 return die_s_("returned false", encoder);
266 printf("OK\n");
267
268 printf("testing FLAC__stream_encoder_set_total_samples_estimate()... ");
269 if(!FLAC__stream_encoder_set_total_samples_estimate(encoder, streaminfo_.data.stream_info.total_samples))
270 return die_s_("returned false", encoder);
271 printf("OK\n");
272
273 printf("testing FLAC__stream_encoder_set_metadata()... ");
274 if(!FLAC__stream_encoder_set_metadata(encoder, metadata_sequence_, num_metadata_))
275 return die_s_("returned false", encoder);
276 printf("OK\n");
277
278 printf("testing FLAC__stream_encoder_set_limit_min_bitrate()... ");
279 if(!FLAC__stream_encoder_set_limit_min_bitrate(encoder, true))
280 return die_s_("returned false", encoder);
281 printf("OK\n");
282
283 if(layer < LAYER_FILENAME) {
284 printf("opening file for FLAC output... ");
285 file = flac_fopen(flacfilename(is_ogg), "w+b");
286 if(0 == file) {
287 printf("ERROR (%s)\n", strerror(errno));
288 return false;
289 }
290 printf("OK\n");
291 }
292
293 switch(layer) {
294 case LAYER_STREAM:
295 printf("testing FLAC__stream_encoder_init_%sstream()... ", is_ogg? "ogg_":"");
296 init_status = is_ogg?
297 FLAC__stream_encoder_init_ogg_stream(encoder, /*read_callback=*/0, stream_encoder_write_callback_, /*seek_callback=*/0, /*tell_callback=*/0, stream_encoder_metadata_callback_, /*client_data=*/file) :
298 FLAC__stream_encoder_init_stream(encoder, stream_encoder_write_callback_, /*seek_callback=*/0, /*tell_callback=*/0, stream_encoder_metadata_callback_, /*client_data=*/file);
299 break;
300 case LAYER_SEEKABLE_STREAM:
301 printf("testing FLAC__stream_encoder_init_%sstream()... ", is_ogg? "ogg_":"");
302 init_status = is_ogg?
303 FLAC__stream_encoder_init_ogg_stream(encoder, stream_encoder_read_callback_, stream_encoder_write_callback_, stream_encoder_seek_callback_, stream_encoder_tell_callback_, /*metadata_callback=*/0, /*client_data=*/file) :
304 FLAC__stream_encoder_init_stream(encoder, stream_encoder_write_callback_, stream_encoder_seek_callback_, stream_encoder_tell_callback_, /*metadata_callback=*/0, /*client_data=*/file);
305 break;
306 case LAYER_FILE:
307 printf("testing FLAC__stream_encoder_init_%sFILE()... ", is_ogg? "ogg_":"");
308 init_status = is_ogg?
309 FLAC__stream_encoder_init_ogg_FILE(encoder, file, stream_encoder_progress_callback_, /*client_data=*/0) :
310 FLAC__stream_encoder_init_FILE(encoder, file, stream_encoder_progress_callback_, /*client_data=*/0);
311 break;
312 case LAYER_FILENAME:
313 printf("testing FLAC__stream_encoder_init_%sfile()... ", is_ogg? "ogg_":"");
314 init_status = is_ogg?
315 FLAC__stream_encoder_init_ogg_file(encoder, flacfilename(is_ogg), stream_encoder_progress_callback_, /*client_data=*/0) :
316 FLAC__stream_encoder_init_file(encoder, flacfilename(is_ogg), stream_encoder_progress_callback_, /*client_data=*/0);
317 break;
318 default:
319 die_("internal error 001");
320 return false;
321 }
322 if(init_status != FLAC__STREAM_ENCODER_INIT_STATUS_OK)
323 return die_s_(0, encoder);
324 printf("OK\n");
325
326 printf("testing FLAC__stream_encoder_get_state()... ");
327 state = FLAC__stream_encoder_get_state(encoder);
328 printf("returned state = %u (%s)... OK\n", (uint32_t)state, FLAC__StreamEncoderStateString[state]);
329
330 printf("testing FLAC__stream_encoder_get_verify_decoder_state()... ");
331 dstate = FLAC__stream_encoder_get_verify_decoder_state(encoder);
332 printf("returned state = %u (%s)... OK\n", (uint32_t)dstate, FLAC__StreamDecoderStateString[dstate]);
333
334 {
335 FLAC__uint64 absolute_sample;
336 uint32_t frame_number;
337 uint32_t channel;
338 uint32_t sample;
339 FLAC__int32 expected;
340 FLAC__int32 got;
341
342 printf("testing FLAC__stream_encoder_get_verify_decoder_error_stats()... ");
343 FLAC__stream_encoder_get_verify_decoder_error_stats(encoder, &absolute_sample, &frame_number, &channel, &sample, &expected, &got);
344 printf("OK\n");
345 }
346
347 printf("testing FLAC__stream_encoder_get_verify()... ");
348 if(FLAC__stream_encoder_get_verify(encoder) != true) {
349 printf("FAILED, expected true, got false\n");
350 return false;
351 }
352 printf("OK\n");
353
354 printf("testing FLAC__stream_encoder_get_streamable_subset()... ");
355 if(FLAC__stream_encoder_get_streamable_subset(encoder) != true) {
356 printf("FAILED, expected true, got false\n");
357 return false;
358 }
359 printf("OK\n");
360
361 printf("testing FLAC__stream_encoder_get_do_mid_side_stereo()... ");
362 if(FLAC__stream_encoder_get_do_mid_side_stereo(encoder) != false) {
363 printf("FAILED, expected false, got true\n");
364 return false;
365 }
366 printf("OK\n");
367
368 printf("testing FLAC__stream_encoder_get_loose_mid_side_stereo()... ");
369 if(FLAC__stream_encoder_get_loose_mid_side_stereo(encoder) != false) {
370 printf("FAILED, expected false, got true\n");
371 return false;
372 }
373 printf("OK\n");
374
375 printf("testing FLAC__stream_encoder_get_channels()... ");
376 if(FLAC__stream_encoder_get_channels(encoder) != streaminfo_.data.stream_info.channels) {
377 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.channels, FLAC__stream_encoder_get_channels(encoder));
378 return false;
379 }
380 printf("OK\n");
381
382 printf("testing FLAC__stream_encoder_get_bits_per_sample()... ");
383 if(FLAC__stream_encoder_get_bits_per_sample(encoder) != streaminfo_.data.stream_info.bits_per_sample) {
384 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.bits_per_sample, FLAC__stream_encoder_get_bits_per_sample(encoder));
385 return false;
386 }
387 printf("OK\n");
388
389 printf("testing FLAC__stream_encoder_get_sample_rate()... ");
390 if(FLAC__stream_encoder_get_sample_rate(encoder) != streaminfo_.data.stream_info.sample_rate) {
391 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.sample_rate, FLAC__stream_encoder_get_sample_rate(encoder));
392 return false;
393 }
394 printf("OK\n");
395
396 printf("testing FLAC__stream_encoder_get_blocksize()... ");
397 if(FLAC__stream_encoder_get_blocksize(encoder) != streaminfo_.data.stream_info.min_blocksize) {
398 printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.min_blocksize, FLAC__stream_encoder_get_blocksize(encoder));
399 return false;
400 }
401 printf("OK\n");
402
403 printf("testing FLAC__stream_encoder_get_max_lpc_order()... ");
404 if(FLAC__stream_encoder_get_max_lpc_order(encoder) != 0) {
405 printf("FAILED, expected %d, got %u\n", 0, FLAC__stream_encoder_get_max_lpc_order(encoder));
406 return false;
407 }
408 printf("OK\n");
409
410 printf("testing FLAC__stream_encoder_get_qlp_coeff_precision()... ");
411 (void)FLAC__stream_encoder_get_qlp_coeff_precision(encoder);
412 /* we asked the encoder to auto select this so we accept anything */
413 printf("OK\n");
414
415 printf("testing FLAC__stream_encoder_get_do_qlp_coeff_prec_search()... ");
416 if(FLAC__stream_encoder_get_do_qlp_coeff_prec_search(encoder) != false) {
417 printf("FAILED, expected false, got true\n");
418 return false;
419 }
420 printf("OK\n");
421
422 printf("testing FLAC__stream_encoder_get_do_escape_coding()... ");
423 if(FLAC__stream_encoder_get_do_escape_coding(encoder) != false) {
424 printf("FAILED, expected false, got true\n");
425 return false;
426 }
427 printf("OK\n");
428
429 printf("testing FLAC__stream_encoder_get_do_exhaustive_model_search()... ");
430 if(FLAC__stream_encoder_get_do_exhaustive_model_search(encoder) != false) {
431 printf("FAILED, expected false, got true\n");
432 return false;
433 }
434 printf("OK\n");
435
436 printf("testing FLAC__stream_encoder_get_min_residual_partition_order()... ");
437 if(FLAC__stream_encoder_get_min_residual_partition_order(encoder) != 0) {
438 printf("FAILED, expected %d, got %u\n", 0, FLAC__stream_encoder_get_min_residual_partition_order(encoder));
439 return false;
440 }
441 printf("OK\n");
442
443 printf("testing FLAC__stream_encoder_get_max_residual_partition_order()... ");
444 if(FLAC__stream_encoder_get_max_residual_partition_order(encoder) != 0) {
445 printf("FAILED, expected %d, got %u\n", 0, FLAC__stream_encoder_get_max_residual_partition_order(encoder));
446 return false;
447 }
448 printf("OK\n");
449
450 printf("testing FLAC__stream_encoder_get_rice_parameter_search_dist()... ");
451 if(FLAC__stream_encoder_get_rice_parameter_search_dist(encoder) != 0) {
452 printf("FAILED, expected %d, got %u\n", 0, FLAC__stream_encoder_get_rice_parameter_search_dist(encoder));
453 return false;
454 }
455 printf("OK\n");
456
457 printf("testing FLAC__stream_encoder_get_total_samples_estimate()... ");
458 if(FLAC__stream_encoder_get_total_samples_estimate(encoder) != streaminfo_.data.stream_info.total_samples) {
459 printf("FAILED, expected %" PRIu64 ", got %" PRIu64 "\n", streaminfo_.data.stream_info.total_samples, FLAC__stream_encoder_get_total_samples_estimate(encoder));
460 return false;
461 }
462 printf("OK\n");
463
464 printf("testing FLAC__stream_encoder_get_limit_min_bitrate()... ");
465 if(FLAC__stream_encoder_get_limit_min_bitrate(encoder) != true) {
466 printf("FAILED, expected true, got false\n");
467 return false;
468 }
469
470 /* init the dummy sample buffer */
471 for(i = 0; i < sizeof(samples) / sizeof(FLAC__int32); i++)
472 samples[i] = i & 7;
473
474 printf("testing FLAC__stream_encoder_process()... ");
475 if(!FLAC__stream_encoder_process(encoder, (const FLAC__int32 * const *)samples_array, sizeof(samples) / sizeof(FLAC__int32)))
476 return die_s_("returned false", encoder);
477 printf("OK\n");
478
479 printf("testing FLAC__stream_encoder_process_interleaved()... ");
480 if(!FLAC__stream_encoder_process_interleaved(encoder, samples, sizeof(samples) / sizeof(FLAC__int32)))
481 return die_s_("returned false", encoder);
482 printf("OK\n");
483
484 printf("testing FLAC__stream_encoder_finish()... ");
485 if(!FLAC__stream_encoder_finish(encoder))
486 return die_s_("returned false", encoder);
487 printf("OK\n");
488
489 if(layer < LAYER_FILE)
490 fclose(file);
491
492 printf("testing FLAC__stream_encoder_delete()... ");
493 FLAC__stream_encoder_delete(encoder);
494 printf("OK\n");
495
496 printf("\nPASSED!\n");
497
498 return true;
499 }
500
test_encoders(void)501 FLAC__bool test_encoders(void)
502 {
503 FLAC__bool is_ogg = false;
504
505 while(1) {
506 init_metadata_blocks_();
507
508 if(!test_stream_encoder(LAYER_STREAM, is_ogg))
509 return false;
510
511 if(!test_stream_encoder(LAYER_SEEKABLE_STREAM, is_ogg))
512 return false;
513
514 if(!test_stream_encoder(LAYER_FILE, is_ogg))
515 return false;
516
517 if(!test_stream_encoder(LAYER_FILENAME, is_ogg))
518 return false;
519
520 (void) grabbag__file_remove_file(flacfilename(is_ogg));
521
522 free_metadata_blocks_();
523
524 if(!FLAC_API_SUPPORTS_OGG_FLAC || is_ogg)
525 break;
526 is_ogg = true;
527 }
528
529 return true;
530 }
531