blob: a56fc254a8ce3f2585471336390bbab6132216f1 [file] [log] [blame]
Josh Coalsona86f8702002-08-20 04:03:24 +00001/* test_libOggFLAC++ - Unit tester for libOggFLAC++
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 "decoders.h"
20extern "C" {
21#include "file_utils.h"
22}
23#include "FLAC/assert.h"
24#include "FLAC/metadata.h" // for ::FLAC__metadata_object_is_equal()
25#include "OggFLAC++/decoder.h"
26#include <errno.h>
27#include <stdio.h>
28#include <stdlib.h>
29#include <string.h>
30
31static ::FLAC__StreamMetadata streaminfo_, padding_, seektable_, application1_, application2_, vorbiscomment_;
32static ::FLAC__StreamMetadata *expected_metadata_sequence_[6];
33static unsigned num_expected_;
34static const char *oggflacfilename_ = "metadata.ogg";
35static unsigned oggflacfilesize_;
36
37static bool die_(const char *msg)
38{
39 printf("ERROR: %s\n", msg);
40 return false;
41}
42
43static void *malloc_or_die_(size_t size)
44{
45 void *x = malloc(size);
46 if(0 == x) {
47 fprintf(stderr, "ERROR: out of memory allocating %u bytes\n", (unsigned)size);
48 exit(1);
49 }
50 return x;
51}
52
53static void init_metadata_blocks_()
54{
55 /*
56 most of the actual numbers and data in the blocks don't matter,
57 we just want to make sure the decoder parses them correctly
58
59 remember, the metadata interface gets tested after the decoders,
60 so we do all the metadata manipulation here without it.
61 */
62
63 /* min/max_framesize and md5sum don't get written at first, so we have to leave them 0 */
Josh Coalson765ff502002-08-27 05:46:11 +000064 streaminfo_.is_last = false;
65 streaminfo_.type = ::FLAC__METADATA_TYPE_STREAMINFO;
66 streaminfo_.length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH;
67 streaminfo_.data.stream_info.min_blocksize = 576;
68 streaminfo_.data.stream_info.max_blocksize = 576;
69 streaminfo_.data.stream_info.min_framesize = 0;
70 streaminfo_.data.stream_info.max_framesize = 0;
71 streaminfo_.data.stream_info.sample_rate = 44100;
72 streaminfo_.data.stream_info.channels = 1;
73 streaminfo_.data.stream_info.bits_per_sample = 8;
74 streaminfo_.data.stream_info.total_samples = 0;
Josh Coalsona86f8702002-08-20 04:03:24 +000075 memset(streaminfo_.data.stream_info.md5sum, 0, 16);
76
Josh Coalson765ff502002-08-27 05:46:11 +000077 padding_.is_last = false;
78 padding_.type = ::FLAC__METADATA_TYPE_PADDING;
79 padding_.length = 1234;
Josh Coalsona86f8702002-08-20 04:03:24 +000080
Josh Coalson765ff502002-08-27 05:46:11 +000081 seektable_.is_last = false;
82 seektable_.type = ::FLAC__METADATA_TYPE_SEEKTABLE;
Josh Coalsona86f8702002-08-20 04:03:24 +000083 seektable_.data.seek_table.num_points = 2;
Josh Coalson765ff502002-08-27 05:46:11 +000084 seektable_.length = seektable_.data.seek_table.num_points * FLAC__STREAM_METADATA_SEEKPOINT_LENGTH;
Josh Coalsona86f8702002-08-20 04:03:24 +000085 seektable_.data.seek_table.points = (::FLAC__StreamMetadata_SeekPoint*)malloc_or_die_(seektable_.data.seek_table.num_points * sizeof(::FLAC__StreamMetadata_SeekPoint));
86 seektable_.data.seek_table.points[0].sample_number = 0;
87 seektable_.data.seek_table.points[0].stream_offset = 0;
88 seektable_.data.seek_table.points[0].frame_samples = streaminfo_.data.stream_info.min_blocksize;
89 seektable_.data.seek_table.points[1].sample_number = ::FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
90 seektable_.data.seek_table.points[1].stream_offset = 1000;
91 seektable_.data.seek_table.points[1].frame_samples = streaminfo_.data.stream_info.min_blocksize;
92
Josh Coalson765ff502002-08-27 05:46:11 +000093 application1_.is_last = false;
94 application1_.type = ::FLAC__METADATA_TYPE_APPLICATION;
95 application1_.length = 8;
Josh Coalsona86f8702002-08-20 04:03:24 +000096 memcpy(application1_.data.application.id, "\xfe\xdc\xba\x98", 4);
97 application1_.data.application.data = (FLAC__byte*)malloc_or_die_(4);
98 memcpy(application1_.data.application.data, "\xf0\xe1\xd2\xc3", 4);
99
Josh Coalson765ff502002-08-27 05:46:11 +0000100 application2_.is_last = false;
101 application2_.type = ::FLAC__METADATA_TYPE_APPLICATION;
102 application2_.length = 4;
Josh Coalsona86f8702002-08-20 04:03:24 +0000103 memcpy(application2_.data.application.id, "\x76\x54\x32\x10", 4);
104 application2_.data.application.data = 0;
105
Josh Coalsonfedb0ae2002-08-25 05:10:37 +0000106 {
107 const unsigned vendor_string_length = (unsigned)strlen((const char *)FLAC__VENDOR_STRING);
108 vorbiscomment_.is_last = true;
109 vorbiscomment_.type = FLAC__METADATA_TYPE_VORBIS_COMMENT;
110 vorbiscomment_.length = (4 + vendor_string_length) + 4 + (4 + 5) + (4 + 0);
111 vorbiscomment_.data.vorbis_comment.vendor_string.length = vendor_string_length;
112 vorbiscomment_.data.vorbis_comment.vendor_string.entry = (FLAC__byte*)malloc_or_die_(vendor_string_length);
113 memcpy(vorbiscomment_.data.vorbis_comment.vendor_string.entry, FLAC__VENDOR_STRING, vendor_string_length);
114 vorbiscomment_.data.vorbis_comment.num_comments = 2;
115 vorbiscomment_.data.vorbis_comment.comments = (FLAC__StreamMetadata_VorbisComment_Entry*)malloc_or_die_(vorbiscomment_.data.vorbis_comment.num_comments * sizeof(FLAC__StreamMetadata_VorbisComment_Entry));
116 vorbiscomment_.data.vorbis_comment.comments[0].length = 5;
117 vorbiscomment_.data.vorbis_comment.comments[0].entry = (FLAC__byte*)malloc_or_die_(5);
118 memcpy(vorbiscomment_.data.vorbis_comment.comments[0].entry, "ab=cd", 5);
119 vorbiscomment_.data.vorbis_comment.comments[1].length = 0;
120 vorbiscomment_.data.vorbis_comment.comments[1].entry = 0;
121 }
Josh Coalsona86f8702002-08-20 04:03:24 +0000122}
123
124static void free_metadata_blocks_()
125{
126 free(seektable_.data.seek_table.points);
127 free(application1_.data.application.data);
128 free(vorbiscomment_.data.vorbis_comment.vendor_string.entry);
129 free(vorbiscomment_.data.vorbis_comment.comments[0].entry);
130 free(vorbiscomment_.data.vorbis_comment.comments);
131}
132
133static bool generate_file_()
134{
135 printf("\n\ngenerating Ogg FLAC file for decoder tests...\n");
136
137 expected_metadata_sequence_[0] = &padding_;
138 expected_metadata_sequence_[1] = &seektable_;
139 expected_metadata_sequence_[2] = &application1_;
140 expected_metadata_sequence_[3] = &application2_;
141 expected_metadata_sequence_[4] = &vorbiscomment_;
142 num_expected_ = 5;
143
144 if(!file_utils__generate_oggflacfile(oggflacfilename_, &oggflacfilesize_, 512 * 1024, &streaminfo_, expected_metadata_sequence_, num_expected_))
Josh Coalson765ff502002-08-27 05:46:11 +0000145 return die_("creating the encoded file");
Josh Coalsona86f8702002-08-20 04:03:24 +0000146
147 return true;
148}
149
150
151class DecoderCommon {
152public:
153 FILE *file_;
154 unsigned current_metadata_number_;
155 bool ignore_errors_;
156 bool error_occurred_;
157
158 DecoderCommon(): file_(0), current_metadata_number_(0), ignore_errors_(false), error_occurred_(false) { }
159 ::FLAC__StreamDecoderReadStatus common_read_callback_(FLAC__byte buffer[], unsigned *bytes);
160 ::FLAC__StreamDecoderWriteStatus common_write_callback_(const ::FLAC__Frame *frame);
161 void common_metadata_callback_(const ::FLAC__StreamMetadata *metadata);
162 void common_error_callback_(::FLAC__StreamDecoderErrorStatus status);
163};
164
165::FLAC__StreamDecoderReadStatus DecoderCommon::common_read_callback_(FLAC__byte buffer[], unsigned *bytes)
166{
167 if(error_occurred_)
168 return ::FLAC__STREAM_DECODER_READ_STATUS_ABORT;
169
170 if(feof(file_))
171 return ::FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
Josh Coalson765ff502002-08-27 05:46:11 +0000172 else if(*bytes > 0) {
173 unsigned bytes_read = ::fread(buffer, 1, *bytes, file_);
174 if(bytes_read == 0) {
175 if(feof(file_))
176 return ::FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
177 else
178 return ::FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
179 }
180 else {
181 *bytes = bytes_read;
182 return ::FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
183 }
184 }
185 else
186 return ::FLAC__STREAM_DECODER_READ_STATUS_ABORT; /* abort to avoid a deadlock */
Josh Coalsona86f8702002-08-20 04:03:24 +0000187}
188
189::FLAC__StreamDecoderWriteStatus DecoderCommon::common_write_callback_(const ::FLAC__Frame *frame)
190{
191 if(error_occurred_)
192 return ::FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
193
Josh Coalson765ff502002-08-27 05:46:11 +0000194 if(
195 (frame->header.number_type == ::FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER && frame->header.number.frame_number == 0) ||
196 (frame->header.number_type == ::FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER && frame->header.number.sample_number == 0)
197 ) {
198 printf("content... ");
199 fflush(stdout);
200 }
Josh Coalsona86f8702002-08-20 04:03:24 +0000201
202 return ::FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
203}
204
205void DecoderCommon::common_metadata_callback_(const ::FLAC__StreamMetadata *metadata)
206{
207 if(error_occurred_)
208 return;
209
210 printf("%d... ", current_metadata_number_);
211 fflush(stdout);
212
213 if(current_metadata_number_ >= num_expected_) {
214 (void)die_("got more metadata blocks than expected");
215 error_occurred_ = true;
216 }
217 else {
218 if(!::FLAC__metadata_object_is_equal(expected_metadata_sequence_[current_metadata_number_], metadata)) {
219 (void)die_("metadata block mismatch");
220 error_occurred_ = true;
221 }
222 }
223 current_metadata_number_++;
224}
225
226void DecoderCommon::common_error_callback_(::FLAC__StreamDecoderErrorStatus status)
227{
228 if(!ignore_errors_) {
229 printf("ERROR: got error callback: err = %u (%s)\n", (unsigned)status, ::FLAC__StreamDecoderErrorStatusString[status]);
230 error_occurred_ = true;
231 }
232}
233
234class StreamDecoder : public OggFLAC::Decoder::Stream, public DecoderCommon {
235public:
236 StreamDecoder(): OggFLAC::Decoder::Stream(), DecoderCommon() { }
237 ~StreamDecoder() { }
238
239 // from OggFLAC::Decoder::Stream
240 ::FLAC__StreamDecoderReadStatus read_callback(FLAC__byte buffer[], unsigned *bytes);
241 ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]);
242 void metadata_callback(const ::FLAC__StreamMetadata *metadata);
243 void error_callback(::FLAC__StreamDecoderErrorStatus status);
244
245 bool die(const char *msg = 0) const;
246
247 bool test_respond();
248};
249
250::FLAC__StreamDecoderReadStatus StreamDecoder::read_callback(FLAC__byte buffer[], unsigned *bytes)
251{
252 return common_read_callback_(buffer, bytes);
253}
254
255::FLAC__StreamDecoderWriteStatus StreamDecoder::write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[])
256{
257 (void)buffer;
258
259 return common_write_callback_(frame);
260}
261
262void StreamDecoder::metadata_callback(const ::FLAC__StreamMetadata *metadata)
263{
264 common_metadata_callback_(metadata);
265}
266
267void StreamDecoder::error_callback(::FLAC__StreamDecoderErrorStatus status)
268{
269 common_error_callback_(status);
270}
271
272bool StreamDecoder::die(const char *msg) const
273{
274 State state = get_state();
275
276 if(msg)
277 printf("FAILED, %s", msg);
278 else
279 printf("FAILED");
280
281 printf(", state = %u (%s)\n", (unsigned)((::OggFLAC__StreamDecoderState)state), state.as_cstring());
282
283 return false;
284}
285
286bool StreamDecoder::test_respond()
287{
288 printf("testing init()... ");
289 if(init() != ::OggFLAC__STREAM_DECODER_OK)
290 return die();
291 printf("OK\n");
292
293 current_metadata_number_ = 0;
294
295 if(::fseek(file_, 0, SEEK_SET) < 0) {
296 printf("FAILED rewinding input, errno = %d\n", errno);
297 return false;
298 }
299
300 printf("testing process_until_end_of_stream()... ");
301 if(!process_until_end_of_stream()) {
302 State state = get_state();
303 printf("FAILED, returned false, state = %u (%s)\n", (unsigned)((::OggFLAC__StreamDecoderState)state), state.as_cstring());
304 return false;
305 }
306 printf("OK\n");
307
308 printf("testing finish()... ");
309 finish();
310 printf("OK\n");
311
312 return true;
313}
314
315static bool test_stream_decoder()
316{
317 StreamDecoder *decoder;
318
319 printf("\n+++ libOggFLAC++ unit test: OggFLAC::Decoder::Stream\n\n");
320
321 //
322 // test new -> delete
323 //
324 printf("allocating decoder instance... ");
325 decoder = new StreamDecoder();
326 if(0 == decoder) {
327 printf("FAILED, new returned NULL\n");
328 return false;
329 }
330 printf("OK\n");
331
332 printf("testing is_valid()... ");
333 if(!decoder->is_valid()) {
334 printf("FAILED, returned false\n");
335 return false;
336 }
337 printf("OK\n");
338
339 printf("freeing decoder instance... ");
340 delete decoder;
341 printf("OK\n");
342
343 //
344 // test new -> init -> delete
345 //
346 printf("allocating decoder instance... ");
347 decoder = new StreamDecoder();
348 if(0 == decoder) {
349 printf("FAILED, new returned NULL\n");
350 return false;
351 }
352 printf("OK\n");
353
354 printf("testing is_valid()... ");
355 if(!decoder->is_valid()) {
356 printf("FAILED, returned false\n");
357 return false;
358 }
359 printf("OK\n");
360
361 printf("testing init()... ");
362 if(decoder->init() != ::OggFLAC__STREAM_DECODER_OK)
363 return decoder->die();
364 printf("OK\n");
365
366 printf("freeing decoder instance... ");
367 delete decoder;
368 printf("OK\n");
369
370 //
371 // test normal usage
372 //
373 num_expected_ = 0;
374 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
375
376 printf("allocating decoder instance... ");
377 decoder = new StreamDecoder();
378 if(0 == decoder) {
379 printf("FAILED, new returned NULL\n");
380 return false;
381 }
382 printf("OK\n");
383
384 printf("testing is_valid()... ");
385 if(!decoder->is_valid()) {
386 printf("FAILED, returned false\n");
387 return false;
388 }
389 printf("OK\n");
390
391 printf("testing init()... ");
392 if(decoder->init() != ::OggFLAC__STREAM_DECODER_OK)
393 return decoder->die();
394 printf("OK\n");
395
396 printf("testing get_state()... ");
397 OggFLAC::Decoder::Stream::State state = decoder->get_state();
398 printf("returned state = %u (%s)... OK\n", (unsigned)((::OggFLAC__StreamDecoderState)state), state.as_cstring());
399
400 printf("testing get_FLAC_stream_decoder_state()... ");
401 FLAC::Decoder::Stream::State state_ = decoder->get_FLAC_stream_decoder_state();
402 printf("returned state = %u (%s)... OK\n", (unsigned)((::FLAC__StreamDecoderState)state_), state_.as_cstring());
403
404 decoder->current_metadata_number_ = 0;
405 decoder->ignore_errors_ = false;
406 decoder->error_occurred_ = false;
407
408 printf("opening Ogg FLAC file... ");
409 decoder->file_ = ::fopen(oggflacfilename_, "rb");
410 if(0 == decoder->file_) {
411 printf("ERROR\n");
412 return false;
413 }
414 printf("OK\n");
415
416 printf("testing process_until_end_of_metadata()... ");
417 if(!decoder->process_until_end_of_metadata())
418 return decoder->die("returned false");
419 printf("OK\n");
420
421 printf("testing process_single()... ");
422 if(!decoder->process_single())
423 return decoder->die("returned false");
424 printf("OK\n");
425
426 printf("testing flush()... ");
427 if(!decoder->flush())
428 return decoder->die("returned false");
429 printf("OK\n");
430
431 decoder->ignore_errors_ = true;
432 printf("testing process_single()... ");
433 if(!decoder->process_single())
434 return decoder->die("returned false");
435 printf("OK\n");
436 decoder->ignore_errors_ = false;
437
438 printf("testing process_until_end_of_stream()... ");
439 if(!decoder->process_until_end_of_stream())
440 return decoder->die("returned false");
441 printf("OK\n");
442
443 printf("testing get_channels()... ");
444 {
445 unsigned channels = decoder->get_channels();
446 if(channels != streaminfo_.data.stream_info.channels) {
447 printf("FAILED, returned %u, expected %u\n", channels, streaminfo_.data.stream_info.channels);
448 return false;
449 }
450 }
451 printf("OK\n");
452
453 printf("testing get_bits_per_sample()... ");
454 {
455 unsigned bits_per_sample = decoder->get_bits_per_sample();
456 if(bits_per_sample != streaminfo_.data.stream_info.bits_per_sample) {
457 printf("FAILED, returned %u, expected %u\n", bits_per_sample, streaminfo_.data.stream_info.bits_per_sample);
458 return false;
459 }
460 }
461 printf("OK\n");
462
463 printf("testing get_sample_rate()... ");
464 {
465 unsigned sample_rate = decoder->get_sample_rate();
466 if(sample_rate != streaminfo_.data.stream_info.sample_rate) {
467 printf("FAILED, returned %u, expected %u\n", sample_rate, streaminfo_.data.stream_info.sample_rate);
468 return false;
469 }
470 }
471 printf("OK\n");
472
473 printf("testing get_blocksize()... ");
474 {
475 unsigned blocksize = decoder->get_blocksize();
476 /* value could be anything since we're at the last block, so accept any answer */
477 printf("returned %u... OK\n", blocksize);
478 }
479
480 printf("testing get_channel_assignment()... ");
481 {
482 ::FLAC__ChannelAssignment ca = decoder->get_channel_assignment();
483 printf("returned %u (%s)... OK\n", (unsigned)ca, ::FLAC__ChannelAssignmentString[ca]);
484 }
485
486 printf("testing reset()... ");
487 if(!decoder->reset())
488 return decoder->die("returned false");
489 printf("OK\n");
490
491 decoder->current_metadata_number_ = 0;
492
493 printf("rewinding input... ");
494 if(::fseek(decoder->file_, 0, SEEK_SET) < 0) {
495 printf("FAILED, errno = %d\n", errno);
496 return false;
497 }
498 printf("OK\n");
499
500 printf("testing process_until_end_of_stream()... ");
501 if(!decoder->process_until_end_of_stream())
502 return decoder->die("returned false");
503 printf("OK\n");
504
505 printf("testing finish()... ");
506 decoder->finish();
507 printf("OK\n");
508
509 /*
510 * respond all
511 */
512
513 printf("testing set_metadata_respond_all()... ");
514 if(!decoder->set_metadata_respond_all()) {
515 printf("FAILED, returned false\n");
516 return false;
517 }
518 printf("OK\n");
519
520 num_expected_ = 0;
521 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
522 expected_metadata_sequence_[num_expected_++] = &padding_;
523 expected_metadata_sequence_[num_expected_++] = &seektable_;
524 expected_metadata_sequence_[num_expected_++] = &application1_;
525 expected_metadata_sequence_[num_expected_++] = &application2_;
526 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
527
528 if(!decoder->test_respond())
529 return false;
530
531 /*
532 * ignore all
533 */
534
535 printf("testing set_metadata_ignore_all()... ");
536 if(!decoder->set_metadata_ignore_all()) {
537 printf("FAILED, returned false\n");
538 return false;
539 }
540 printf("OK\n");
541
542 num_expected_ = 0;
543
544 if(!decoder->test_respond())
545 return false;
546
547 /*
548 * respond all, ignore VORBIS_COMMENT
549 */
550
551 printf("testing set_metadata_respond_all()... ");
552 if(!decoder->set_metadata_respond_all()) {
553 printf("FAILED, returned false\n");
554 return false;
555 }
556 printf("OK\n");
557
558 printf("testing set_metadata_ignore(VORBIS_COMMENT)... ");
559 if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_VORBIS_COMMENT)) {
560 printf("FAILED, returned false\n");
561 return false;
562 }
563 printf("OK\n");
564
565 num_expected_ = 0;
566 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
567 expected_metadata_sequence_[num_expected_++] = &padding_;
568 expected_metadata_sequence_[num_expected_++] = &seektable_;
569 expected_metadata_sequence_[num_expected_++] = &application1_;
570 expected_metadata_sequence_[num_expected_++] = &application2_;
571
572 if(!decoder->test_respond())
573 return false;
574
575 /*
576 * respond all, ignore APPLICATION
577 */
578
579 printf("testing set_metadata_respond_all()... ");
580 if(!decoder->set_metadata_respond_all()) {
581 printf("FAILED, returned false\n");
582 return false;
583 }
584 printf("OK\n");
585
586 printf("testing set_metadata_ignore(APPLICATION)... ");
587 if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) {
588 printf("FAILED, returned false\n");
589 return false;
590 }
591 printf("OK\n");
592
593 num_expected_ = 0;
594 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
595 expected_metadata_sequence_[num_expected_++] = &padding_;
596 expected_metadata_sequence_[num_expected_++] = &seektable_;
597 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
598
599 if(!decoder->test_respond())
600 return false;
601
602 /*
603 * respond all, ignore APPLICATION id of app#1
604 */
605
606 printf("testing set_metadata_respond_all()... ");
607 if(!decoder->set_metadata_respond_all()) {
608 printf("FAILED, returned false\n");
609 return false;
610 }
611 printf("OK\n");
612
613 printf("testing set_metadata_ignore_application(of app block #1)... ");
614 if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
615 printf("FAILED, returned false\n");
616 return false;
617 }
618 printf("OK\n");
619
620 num_expected_ = 0;
621 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
622 expected_metadata_sequence_[num_expected_++] = &padding_;
623 expected_metadata_sequence_[num_expected_++] = &seektable_;
624 expected_metadata_sequence_[num_expected_++] = &application2_;
625 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
626
627 if(!decoder->test_respond())
628 return false;
629
630 /*
631 * respond all, ignore APPLICATION id of app#1 & app#2
632 */
633
634 printf("testing set_metadata_respond_all()... ");
635 if(!decoder->set_metadata_respond_all()) {
636 printf("FAILED, returned false\n");
637 return false;
638 }
639 printf("OK\n");
640
641 printf("testing set_metadata_ignore_application(of app block #1)... ");
642 if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
643 printf("FAILED, returned false\n");
644 return false;
645 }
646 printf("OK\n");
647
648 printf("testing set_metadata_ignore_application(of app block #2)... ");
649 if(!decoder->set_metadata_ignore_application(application2_.data.application.id)) {
650 printf("FAILED, returned false\n");
651 return false;
652 }
653 printf("OK\n");
654
655 num_expected_ = 0;
656 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
657 expected_metadata_sequence_[num_expected_++] = &padding_;
658 expected_metadata_sequence_[num_expected_++] = &seektable_;
659 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
660
661 if(!decoder->test_respond())
662 return false;
663
664 /*
665 * ignore all, respond VORBIS_COMMENT
666 */
667
668 printf("testing set_metadata_ignore_all()... ");
669 if(!decoder->set_metadata_ignore_all()) {
670 printf("FAILED, returned false\n");
671 return false;
672 }
673 printf("OK\n");
674
675 printf("testing set_metadata_respond(VORBIS_COMMENT)... ");
676 if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_VORBIS_COMMENT)) {
677 printf("FAILED, returned false\n");
678 return false;
679 }
680 printf("OK\n");
681
682 num_expected_ = 0;
683 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
684
685 if(!decoder->test_respond())
686 return false;
687
688 /*
689 * ignore all, respond APPLICATION
690 */
691
692 printf("testing set_metadata_ignore_all()... ");
693 if(!decoder->set_metadata_ignore_all()) {
694 printf("FAILED, returned false\n");
695 return false;
696 }
697 printf("OK\n");
698
699 printf("testing set_metadata_respond(APPLICATION)... ");
700 if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) {
701 printf("FAILED, returned false\n");
702 return false;
703 }
704 printf("OK\n");
705
706 num_expected_ = 0;
707 expected_metadata_sequence_[num_expected_++] = &application1_;
708 expected_metadata_sequence_[num_expected_++] = &application2_;
709
710 if(!decoder->test_respond())
711 return false;
712
713 /*
714 * ignore all, respond APPLICATION id of app#1
715 */
716
717 printf("testing set_metadata_ignore_all()... ");
718 if(!decoder->set_metadata_ignore_all()) {
719 printf("FAILED, returned false\n");
720 return false;
721 }
722 printf("OK\n");
723
724 printf("testing set_metadata_respond_application(of app block #1)... ");
725 if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
726 printf("FAILED, returned false\n");
727 return false;
728 }
729 printf("OK\n");
730
731 num_expected_ = 0;
732 expected_metadata_sequence_[num_expected_++] = &application1_;
733
734 if(!decoder->test_respond())
735 return false;
736
737 /*
738 * ignore all, respond APPLICATION id of app#1 & app#2
739 */
740
741 printf("testing set_metadata_ignore_all()... ");
742 if(!decoder->set_metadata_ignore_all()) {
743 printf("FAILED, returned false\n");
744 return false;
745 }
746 printf("OK\n");
747
748 printf("testing set_metadata_respond_application(of app block #1)... ");
749 if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
750 printf("FAILED, returned false\n");
751 return false;
752 }
753 printf("OK\n");
754
755 printf("testing set_metadata_respond_application(of app block #2)... ");
756 if(!decoder->set_metadata_respond_application(application2_.data.application.id)) {
757 printf("FAILED, returned false\n");
758 return false;
759 }
760 printf("OK\n");
761
762 num_expected_ = 0;
763 expected_metadata_sequence_[num_expected_++] = &application1_;
764 expected_metadata_sequence_[num_expected_++] = &application2_;
765
766 if(!decoder->test_respond())
767 return false;
768
769 /*
770 * respond all, ignore APPLICATION, respond APPLICATION id of app#1
771 */
772
773 printf("testing set_metadata_respond_all()... ");
774 if(!decoder->set_metadata_respond_all()) {
775 printf("FAILED, returned false\n");
776 return false;
777 }
778 printf("OK\n");
779
780 printf("testing set_metadata_ignore(APPLICATION)... ");
781 if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) {
782 printf("FAILED, returned false\n");
783 return false;
784 }
785 printf("OK\n");
786
787 printf("testing set_metadata_respond_application(of app block #1)... ");
788 if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
789 printf("FAILED, returned false\n");
790 return false;
791 }
792 printf("OK\n");
793
794 num_expected_ = 0;
795 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
796 expected_metadata_sequence_[num_expected_++] = &padding_;
797 expected_metadata_sequence_[num_expected_++] = &seektable_;
798 expected_metadata_sequence_[num_expected_++] = &application1_;
799 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
800
801 if(!decoder->test_respond())
802 return false;
803
804 /*
805 * ignore all, respond APPLICATION, ignore APPLICATION id of app#1
806 */
807
808 printf("testing set_metadata_ignore_all()... ");
809 if(!decoder->set_metadata_ignore_all()) {
810 printf("FAILED, returned false\n");
811 return false;
812 }
813 printf("OK\n");
814
815 printf("testing set_metadata_respond(APPLICATION)... ");
816 if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) {
817 printf("FAILED, returned false\n");
818 return false;
819 }
820 printf("OK\n");
821
822 printf("testing set_metadata_ignore_application(of app block #1)... ");
823 if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
824 printf("FAILED, returned false\n");
825 return false;
826 }
827 printf("OK\n");
828
829 num_expected_ = 0;
830 expected_metadata_sequence_[num_expected_++] = &application2_;
831
832 if(!decoder->test_respond())
833 return false;
834
835 /* done, now leave the sequence the way we found it... */
836 num_expected_ = 0;
837 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
838 expected_metadata_sequence_[num_expected_++] = &padding_;
839 expected_metadata_sequence_[num_expected_++] = &seektable_;
840 expected_metadata_sequence_[num_expected_++] = &application1_;
841 expected_metadata_sequence_[num_expected_++] = &application2_;
842 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
843
844 ::fclose(decoder->file_);
845
846 printf("freeing decoder instance... ");
847 delete decoder;
848 printf("OK\n");
849
850 printf("\nPASSED!\n");
851
852 return true;
853}
854
855bool test_decoders()
856{
857 init_metadata_blocks_();
858 if(!generate_file_())
859 return false;
860
861 if(!test_stream_decoder())
862 return false;
863
864 (void) file_utils__remove_file(oggflacfilename_);
865 free_metadata_blocks_();
866
867 return true;
868}