~ubuntu-branches/ubuntu/raring/flac/raring

« back to all changes in this revision

Viewing changes to src/test_libOggFLAC++/decoders.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Joshua Kwan
  • Date: 2007-05-29 22:56:36 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070529225636-ljeff8xxip09qaap
Tags: 1.1.4-1
* New upstream release. closes: #405167, #411311
  - libOggFLAC and libOggFLAC++ have been merged into libFLAC, so
    remove their corresponding packages.
  - Because of the API changes required to effect the above, there has
    been yet another soname bump. libflac7 -> libflac8 and
    libflac++5 -> libflac++6. Emails have been dispatched to the
    maintainers of dependent packages.
* Some notes on patches that were removed:
  - 02_stdin_stdout, 06_manpage_mention_utf8_convert: merged upstream
  - 08_manpage_warnings: Upstream has changed the manpage so it defintely
    can't fit in in 80 cols, so just forget about it. We'll live.
  - 05_eof_warnings_are_errors: Upstream decided to add a -w option to
    flac to treat all warnings as errors. I am going to defer to that
    for now, but if people think it's stupid let me know and I'll port
    the patch forward.
  - 04_stack_smasher: was a backport from 1.1.3, so it's obsolete.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* test_libOggFLAC++ - Unit tester for libOggFLAC++
2
 
 * Copyright (C) 2002,2003,2004,2005  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"
20
 
extern "C" {
21
 
#include "file_utils.h"
22
 
#include "metadata_utils.h"
23
 
}
24
 
#include "FLAC/assert.h"
25
 
#include "FLAC/metadata.h" // for ::FLAC__metadata_object_is_equal()
26
 
#include "OggFLAC++/decoder.h"
27
 
#include "share/grabbag.h"
28
 
#include <errno.h>
29
 
#include <stdio.h>
30
 
#include <stdlib.h>
31
 
#include <string.h>
32
 
 
33
 
#ifdef _MSC_VER
34
 
// warning C4800: 'int' : forcing to bool 'true' or 'false' (performance warning)
35
 
#pragma warning ( disable : 4800 )
36
 
#endif
37
 
 
38
 
static ::FLAC__StreamMetadata streaminfo_, padding_, seektable_, application1_, application2_, vorbiscomment_, cuesheet_, unknown_;
39
 
static ::FLAC__StreamMetadata *expected_metadata_sequence_[8];
40
 
static unsigned num_expected_;
41
 
static const char *oggflacfilename_ = "metadata.ogg";
42
 
static unsigned oggflacfilesize_;
43
 
 
44
 
static bool die_(const char *msg)
45
 
{
46
 
        printf("ERROR: %s\n", msg);
47
 
        return false;
48
 
}
49
 
 
50
 
static void init_metadata_blocks_()
51
 
{
52
 
        mutils__init_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &unknown_);
53
 
}
54
 
 
55
 
static void free_metadata_blocks_()
56
 
{
57
 
        mutils__free_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &unknown_);
58
 
}
59
 
 
60
 
static bool generate_file_()
61
 
{
62
 
        printf("\n\ngenerating Ogg FLAC file for decoder tests...\n");
63
 
 
64
 
        num_expected_ = 0;
65
 
        expected_metadata_sequence_[num_expected_++] = &padding_;
66
 
        expected_metadata_sequence_[num_expected_++] = &seektable_;
67
 
        expected_metadata_sequence_[num_expected_++] = &application1_;
68
 
        expected_metadata_sequence_[num_expected_++] = &application2_;
69
 
        expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
70
 
        expected_metadata_sequence_[num_expected_++] = &cuesheet_;
71
 
        expected_metadata_sequence_[num_expected_++] = &unknown_;
72
 
        /* WATCHOUT: the encoder should move the VORBIS_COMMENT block to the front, right after STREAMINFO */
73
 
 
74
 
        if(!file_utils__generate_oggflacfile(oggflacfilename_, &oggflacfilesize_, 512 * 1024, &streaminfo_, expected_metadata_sequence_, num_expected_))
75
 
                return die_("creating the encoded file");
76
 
 
77
 
        return true;
78
 
}
79
 
 
80
 
 
81
 
class DecoderCommon {
82
 
public:
83
 
        FILE *file_;
84
 
        unsigned current_metadata_number_;
85
 
        bool ignore_errors_;
86
 
        bool error_occurred_;
87
 
 
88
 
        DecoderCommon(): file_(0), current_metadata_number_(0), ignore_errors_(false), error_occurred_(false) { }
89
 
        ::FLAC__StreamDecoderReadStatus common_read_callback_(FLAC__byte buffer[], unsigned *bytes);
90
 
        ::FLAC__StreamDecoderWriteStatus common_write_callback_(const ::FLAC__Frame *frame);
91
 
        void common_metadata_callback_(const ::FLAC__StreamMetadata *metadata);
92
 
        void common_error_callback_(::FLAC__StreamDecoderErrorStatus status);
93
 
};
94
 
 
95
 
::FLAC__StreamDecoderReadStatus DecoderCommon::common_read_callback_(FLAC__byte buffer[], unsigned *bytes)
96
 
{
97
 
        if(error_occurred_)
98
 
                return ::FLAC__STREAM_DECODER_READ_STATUS_ABORT;
99
 
 
100
 
        if(feof(file_)) {
101
 
                *bytes = 0;
102
 
                return ::FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
103
 
        }
104
 
        else if(*bytes > 0) {
105
 
                *bytes = ::fread(buffer, 1, *bytes, file_);
106
 
                if(*bytes == 0) {
107
 
                        if(feof(file_))
108
 
                                return ::FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
109
 
                        else
110
 
                                return ::FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
111
 
                }
112
 
                else {
113
 
                        return ::FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
114
 
                }
115
 
        }
116
 
        else
117
 
                return ::FLAC__STREAM_DECODER_READ_STATUS_ABORT; /* abort to avoid a deadlock */
118
 
}
119
 
 
120
 
::FLAC__StreamDecoderWriteStatus DecoderCommon::common_write_callback_(const ::FLAC__Frame *frame)
121
 
{
122
 
        if(error_occurred_)
123
 
                return ::FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
124
 
 
125
 
        if(
126
 
                (frame->header.number_type == ::FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER && frame->header.number.frame_number == 0) ||
127
 
                (frame->header.number_type == ::FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER && frame->header.number.sample_number == 0)
128
 
        ) {
129
 
                printf("content... ");
130
 
                fflush(stdout);
131
 
        }
132
 
 
133
 
        return ::FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
134
 
}
135
 
 
136
 
void DecoderCommon::common_metadata_callback_(const ::FLAC__StreamMetadata *metadata)
137
 
{
138
 
        if(error_occurred_)
139
 
                return;
140
 
 
141
 
        printf("%d... ", current_metadata_number_);
142
 
        fflush(stdout);
143
 
 
144
 
        if(current_metadata_number_ >= num_expected_) {
145
 
                (void)die_("got more metadata blocks than expected");
146
 
                error_occurred_ = true;
147
 
        }
148
 
        else {
149
 
                if(!::FLAC__metadata_object_is_equal(expected_metadata_sequence_[current_metadata_number_], metadata)) {
150
 
                        (void)die_("metadata block mismatch");
151
 
                        error_occurred_ = true;
152
 
                }
153
 
        }
154
 
        current_metadata_number_++;
155
 
}
156
 
 
157
 
void DecoderCommon::common_error_callback_(::FLAC__StreamDecoderErrorStatus status)
158
 
{
159
 
        if(!ignore_errors_) {
160
 
                printf("ERROR: got error callback: err = %u (%s)\n", (unsigned)status, ::FLAC__StreamDecoderErrorStatusString[status]);
161
 
                error_occurred_ = true;
162
 
        }
163
 
}
164
 
 
165
 
class StreamDecoder : public OggFLAC::Decoder::Stream, public DecoderCommon {
166
 
public:
167
 
        StreamDecoder(): OggFLAC::Decoder::Stream(), DecoderCommon() { }
168
 
        ~StreamDecoder() { }
169
 
 
170
 
        // from OggFLAC::Decoder::Stream
171
 
        ::FLAC__StreamDecoderReadStatus read_callback(FLAC__byte buffer[], unsigned *bytes);
172
 
        ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]);
173
 
        void metadata_callback(const ::FLAC__StreamMetadata *metadata);
174
 
        void error_callback(::FLAC__StreamDecoderErrorStatus status);
175
 
 
176
 
        bool die(const char *msg = 0) const;
177
 
 
178
 
        bool test_respond();
179
 
};
180
 
 
181
 
::FLAC__StreamDecoderReadStatus StreamDecoder::read_callback(FLAC__byte buffer[], unsigned *bytes)
182
 
{
183
 
        return common_read_callback_(buffer, bytes);
184
 
}
185
 
 
186
 
::FLAC__StreamDecoderWriteStatus StreamDecoder::write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[])
187
 
{
188
 
        (void)buffer;
189
 
 
190
 
        return common_write_callback_(frame);
191
 
}
192
 
 
193
 
void StreamDecoder::metadata_callback(const ::FLAC__StreamMetadata *metadata)
194
 
{
195
 
        common_metadata_callback_(metadata);
196
 
}
197
 
 
198
 
void StreamDecoder::error_callback(::FLAC__StreamDecoderErrorStatus status)
199
 
{
200
 
        common_error_callback_(status);
201
 
}
202
 
 
203
 
bool StreamDecoder::die(const char *msg) const
204
 
{
205
 
        State state = get_state();
206
 
 
207
 
        if(msg)
208
 
                printf("FAILED, %s", msg);
209
 
        else
210
 
                printf("FAILED");
211
 
 
212
 
        printf(", state = %u (%s)\n", (unsigned)((::OggFLAC__StreamDecoderState)state), state.as_cstring());
213
 
 
214
 
        return false;
215
 
}
216
 
 
217
 
bool StreamDecoder::test_respond()
218
 
{
219
 
        printf("testing init()... ");
220
 
        if(init() != ::OggFLAC__STREAM_DECODER_OK)
221
 
                return die();
222
 
        printf("OK\n");
223
 
 
224
 
        current_metadata_number_ = 0;
225
 
 
226
 
        if(::fseek(file_, 0, SEEK_SET) < 0) {
227
 
                printf("FAILED rewinding input, errno = %d\n", errno);
228
 
                return false;
229
 
        }
230
 
 
231
 
        printf("testing process_until_end_of_stream()... ");
232
 
        if(!process_until_end_of_stream()) {
233
 
                State state = get_state();
234
 
                printf("FAILED, returned false, state = %u (%s)\n", (unsigned)((::OggFLAC__StreamDecoderState)state), state.as_cstring());
235
 
                return false;
236
 
        }
237
 
        printf("OK\n");
238
 
 
239
 
        printf("testing finish()... ");
240
 
        finish();
241
 
        printf("OK\n");
242
 
 
243
 
        return true;
244
 
}
245
 
 
246
 
static bool test_stream_decoder()
247
 
{
248
 
        StreamDecoder *decoder;
249
 
 
250
 
        printf("\n+++ libOggFLAC++ unit test: OggFLAC::Decoder::Stream\n\n");
251
 
 
252
 
        //
253
 
        // test new -> delete
254
 
        //
255
 
        printf("allocating decoder instance... ");
256
 
        decoder = new StreamDecoder();
257
 
        if(0 == decoder) {
258
 
                printf("FAILED, new returned NULL\n");
259
 
                return false;
260
 
        }
261
 
        printf("OK\n");
262
 
 
263
 
        printf("testing is_valid()... ");
264
 
        if(!decoder->is_valid()) {
265
 
                printf("FAILED, returned false\n");
266
 
                return false;
267
 
        }
268
 
        printf("OK\n");
269
 
 
270
 
        printf("freeing decoder instance... ");
271
 
        delete decoder;
272
 
        printf("OK\n");
273
 
 
274
 
        //
275
 
        // test new -> init -> delete
276
 
        //
277
 
        printf("allocating decoder instance... ");
278
 
        decoder = new StreamDecoder();
279
 
        if(0 == decoder) {
280
 
                printf("FAILED, new returned NULL\n");
281
 
                return false;
282
 
        }
283
 
        printf("OK\n");
284
 
 
285
 
        printf("testing is_valid()... ");
286
 
        if(!decoder->is_valid()) {
287
 
                printf("FAILED, returned false\n");
288
 
                return false;
289
 
        }
290
 
        printf("OK\n");
291
 
 
292
 
        printf("testing init()... ");
293
 
        if(decoder->init() != ::OggFLAC__STREAM_DECODER_OK)
294
 
                return decoder->die();
295
 
        printf("OK\n");
296
 
 
297
 
        printf("freeing decoder instance... ");
298
 
        delete decoder;
299
 
        printf("OK\n");
300
 
 
301
 
        //
302
 
        // test normal usage
303
 
        //
304
 
        num_expected_ = 0;
305
 
        expected_metadata_sequence_[num_expected_++] = &streaminfo_;
306
 
 
307
 
        printf("allocating decoder instance... ");
308
 
        decoder = new StreamDecoder();
309
 
        if(0 == decoder) {
310
 
                printf("FAILED, new returned NULL\n");
311
 
                return false;
312
 
        }
313
 
        printf("OK\n");
314
 
 
315
 
        printf("testing is_valid()... ");
316
 
        if(!decoder->is_valid()) {
317
 
                printf("FAILED, returned false\n");
318
 
                return false;
319
 
        }
320
 
        printf("OK\n");
321
 
 
322
 
        printf("testing set_serial_number()... ");
323
 
        if(!decoder->set_serial_number(file_utils__serial_number))
324
 
                return decoder->die("returned false");
325
 
        printf("OK\n");
326
 
 
327
 
        printf("testing init()... ");
328
 
        if(decoder->init() != ::OggFLAC__STREAM_DECODER_OK)
329
 
                return decoder->die();
330
 
        printf("OK\n");
331
 
 
332
 
        printf("testing get_state()... ");
333
 
        OggFLAC::Decoder::Stream::State state = decoder->get_state();
334
 
        printf("returned state = %u (%s)... OK\n", (unsigned)((::OggFLAC__StreamDecoderState)state), state.as_cstring());
335
 
 
336
 
        printf("testing get_FLAC_stream_decoder_state()... ");
337
 
        FLAC::Decoder::Stream::State state_ = decoder->get_FLAC_stream_decoder_state();
338
 
        printf("returned state = %u (%s)... OK\n", (unsigned)((::FLAC__StreamDecoderState)state_), state_.as_cstring());
339
 
 
340
 
        decoder->current_metadata_number_ = 0;
341
 
        decoder->ignore_errors_ = false;
342
 
        decoder->error_occurred_ = false;
343
 
 
344
 
        printf("opening Ogg FLAC file... ");
345
 
        decoder->file_ = ::fopen(oggflacfilename_, "rb");
346
 
        if(0 == decoder->file_) {
347
 
                printf("ERROR\n");
348
 
                return false;
349
 
        }
350
 
        printf("OK\n");
351
 
 
352
 
        printf("testing process_until_end_of_metadata()... ");
353
 
        if(!decoder->process_until_end_of_metadata())
354
 
                return decoder->die("returned false");
355
 
        printf("OK\n");
356
 
 
357
 
        printf("testing process_single()... ");
358
 
        if(!decoder->process_single())
359
 
                return decoder->die("returned false");
360
 
        printf("OK\n");
361
 
 
362
 
        printf("testing flush()... ");
363
 
        if(!decoder->flush())
364
 
                return decoder->die("returned false");
365
 
        printf("OK\n");
366
 
 
367
 
        decoder->ignore_errors_ = true;
368
 
        printf("testing process_single()... ");
369
 
        if(!decoder->process_single())
370
 
                return decoder->die("returned false");
371
 
        printf("OK\n");
372
 
        decoder->ignore_errors_ = false;
373
 
 
374
 
        printf("testing process_until_end_of_stream()... ");
375
 
        if(!decoder->process_until_end_of_stream())
376
 
                return decoder->die("returned false");
377
 
        printf("OK\n");
378
 
 
379
 
        printf("testing get_channels()... ");
380
 
        {
381
 
                unsigned channels = decoder->get_channels();
382
 
                if(channels != streaminfo_.data.stream_info.channels) {
383
 
                        printf("FAILED, returned %u, expected %u\n", channels, streaminfo_.data.stream_info.channels);
384
 
                        return false;
385
 
                }
386
 
        }
387
 
        printf("OK\n");
388
 
 
389
 
        printf("testing get_bits_per_sample()... ");
390
 
        {
391
 
                unsigned bits_per_sample = decoder->get_bits_per_sample();
392
 
                if(bits_per_sample != streaminfo_.data.stream_info.bits_per_sample) {
393
 
                        printf("FAILED, returned %u, expected %u\n", bits_per_sample, streaminfo_.data.stream_info.bits_per_sample);
394
 
                        return false;
395
 
                }
396
 
        }
397
 
        printf("OK\n");
398
 
 
399
 
        printf("testing get_sample_rate()... ");
400
 
        {
401
 
                unsigned sample_rate = decoder->get_sample_rate();
402
 
                if(sample_rate != streaminfo_.data.stream_info.sample_rate) {
403
 
                        printf("FAILED, returned %u, expected %u\n", sample_rate, streaminfo_.data.stream_info.sample_rate);
404
 
                        return false;
405
 
                }
406
 
        }
407
 
        printf("OK\n");
408
 
 
409
 
        printf("testing get_blocksize()... ");
410
 
        {
411
 
                unsigned blocksize = decoder->get_blocksize();
412
 
                /* value could be anything since we're at the last block, so accept any answer */
413
 
                printf("returned %u... OK\n", blocksize);
414
 
        }
415
 
 
416
 
        printf("testing get_channel_assignment()... ");
417
 
        {
418
 
                ::FLAC__ChannelAssignment ca = decoder->get_channel_assignment();
419
 
                printf("returned %u (%s)... OK\n", (unsigned)ca, ::FLAC__ChannelAssignmentString[ca]);
420
 
        }
421
 
 
422
 
        printf("testing reset()... ");
423
 
        if(!decoder->reset())
424
 
                return decoder->die("returned false");
425
 
        printf("OK\n");
426
 
 
427
 
        decoder->current_metadata_number_ = 0;
428
 
 
429
 
        printf("rewinding input... ");
430
 
        if(::fseek(decoder->file_, 0, SEEK_SET) < 0) {
431
 
                printf("FAILED, errno = %d\n", errno);
432
 
                return false;
433
 
        }
434
 
        printf("OK\n");
435
 
 
436
 
        printf("testing process_until_end_of_stream()... ");
437
 
        if(!decoder->process_until_end_of_stream())
438
 
                return decoder->die("returned false");
439
 
        printf("OK\n");
440
 
 
441
 
        printf("testing finish()... ");
442
 
        decoder->finish();
443
 
        printf("OK\n");
444
 
 
445
 
        /*
446
 
         * respond all
447
 
         */
448
 
 
449
 
        printf("testing set_metadata_respond_all()... ");
450
 
        if(!decoder->set_metadata_respond_all()) {
451
 
                printf("FAILED, returned false\n");
452
 
                return false;
453
 
        }
454
 
        printf("OK\n");
455
 
 
456
 
        num_expected_ = 0;
457
 
        expected_metadata_sequence_[num_expected_++] = &streaminfo_;
458
 
        expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
459
 
        expected_metadata_sequence_[num_expected_++] = &padding_;
460
 
        expected_metadata_sequence_[num_expected_++] = &seektable_;
461
 
        expected_metadata_sequence_[num_expected_++] = &application1_;
462
 
        expected_metadata_sequence_[num_expected_++] = &application2_;
463
 
        expected_metadata_sequence_[num_expected_++] = &cuesheet_;
464
 
        expected_metadata_sequence_[num_expected_++] = &unknown_;
465
 
 
466
 
        if(!decoder->test_respond())
467
 
                return false;
468
 
 
469
 
        /*
470
 
         * ignore all
471
 
         */
472
 
 
473
 
        printf("testing set_metadata_ignore_all()... ");
474
 
        if(!decoder->set_metadata_ignore_all()) {
475
 
                printf("FAILED, returned false\n");
476
 
                return false;
477
 
        }
478
 
        printf("OK\n");
479
 
 
480
 
        num_expected_ = 0;
481
 
 
482
 
        if(!decoder->test_respond())
483
 
                return false;
484
 
 
485
 
        /*
486
 
         * respond all, ignore VORBIS_COMMENT
487
 
         */
488
 
 
489
 
        printf("testing set_metadata_respond_all()... ");
490
 
        if(!decoder->set_metadata_respond_all()) {
491
 
                printf("FAILED, returned false\n");
492
 
                return false;
493
 
        }
494
 
        printf("OK\n");
495
 
 
496
 
        printf("testing set_metadata_ignore(VORBIS_COMMENT)... ");
497
 
        if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_VORBIS_COMMENT)) {
498
 
                printf("FAILED, returned false\n");
499
 
                return false;
500
 
        }
501
 
        printf("OK\n");
502
 
 
503
 
        num_expected_ = 0;
504
 
        expected_metadata_sequence_[num_expected_++] = &streaminfo_;
505
 
        expected_metadata_sequence_[num_expected_++] = &padding_;
506
 
        expected_metadata_sequence_[num_expected_++] = &seektable_;
507
 
        expected_metadata_sequence_[num_expected_++] = &application1_;
508
 
        expected_metadata_sequence_[num_expected_++] = &application2_;
509
 
        expected_metadata_sequence_[num_expected_++] = &cuesheet_;
510
 
        expected_metadata_sequence_[num_expected_++] = &unknown_;
511
 
 
512
 
        if(!decoder->test_respond())
513
 
                return false;
514
 
 
515
 
        /*
516
 
         * respond all, ignore APPLICATION
517
 
         */
518
 
 
519
 
        printf("testing set_metadata_respond_all()... ");
520
 
        if(!decoder->set_metadata_respond_all()) {
521
 
                printf("FAILED, returned false\n");
522
 
                return false;
523
 
        }
524
 
        printf("OK\n");
525
 
 
526
 
        printf("testing set_metadata_ignore(APPLICATION)... ");
527
 
        if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) {
528
 
                printf("FAILED, returned false\n");
529
 
                return false;
530
 
        }
531
 
        printf("OK\n");
532
 
 
533
 
        num_expected_ = 0;
534
 
        expected_metadata_sequence_[num_expected_++] = &streaminfo_;
535
 
        expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
536
 
        expected_metadata_sequence_[num_expected_++] = &padding_;
537
 
        expected_metadata_sequence_[num_expected_++] = &seektable_;
538
 
        expected_metadata_sequence_[num_expected_++] = &cuesheet_;
539
 
        expected_metadata_sequence_[num_expected_++] = &unknown_;
540
 
 
541
 
        if(!decoder->test_respond())
542
 
                return false;
543
 
 
544
 
        /*
545
 
         * respond all, ignore APPLICATION id of app#1
546
 
         */
547
 
 
548
 
        printf("testing set_metadata_respond_all()... ");
549
 
        if(!decoder->set_metadata_respond_all()) {
550
 
                printf("FAILED, returned false\n");
551
 
                return false;
552
 
        }
553
 
        printf("OK\n");
554
 
 
555
 
        printf("testing set_metadata_ignore_application(of app block #1)... ");
556
 
        if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
557
 
                printf("FAILED, returned false\n");
558
 
                return false;
559
 
        }
560
 
        printf("OK\n");
561
 
 
562
 
        num_expected_ = 0;
563
 
        expected_metadata_sequence_[num_expected_++] = &streaminfo_;
564
 
        expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
565
 
        expected_metadata_sequence_[num_expected_++] = &padding_;
566
 
        expected_metadata_sequence_[num_expected_++] = &seektable_;
567
 
        expected_metadata_sequence_[num_expected_++] = &application2_;
568
 
        expected_metadata_sequence_[num_expected_++] = &cuesheet_;
569
 
        expected_metadata_sequence_[num_expected_++] = &unknown_;
570
 
 
571
 
        if(!decoder->test_respond())
572
 
                return false;
573
 
 
574
 
        /*
575
 
         * respond all, ignore APPLICATION id of app#1 & app#2
576
 
         */
577
 
 
578
 
        printf("testing set_metadata_respond_all()... ");
579
 
        if(!decoder->set_metadata_respond_all()) {
580
 
                printf("FAILED, returned false\n");
581
 
                return false;
582
 
        }
583
 
        printf("OK\n");
584
 
 
585
 
        printf("testing set_metadata_ignore_application(of app block #1)... ");
586
 
        if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
587
 
                printf("FAILED, returned false\n");
588
 
                return false;
589
 
        }
590
 
        printf("OK\n");
591
 
 
592
 
        printf("testing set_metadata_ignore_application(of app block #2)... ");
593
 
        if(!decoder->set_metadata_ignore_application(application2_.data.application.id)) {
594
 
                printf("FAILED, returned false\n");
595
 
                return false;
596
 
        }
597
 
        printf("OK\n");
598
 
 
599
 
        num_expected_ = 0;
600
 
        expected_metadata_sequence_[num_expected_++] = &streaminfo_;
601
 
        expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
602
 
        expected_metadata_sequence_[num_expected_++] = &padding_;
603
 
        expected_metadata_sequence_[num_expected_++] = &seektable_;
604
 
        expected_metadata_sequence_[num_expected_++] = &cuesheet_;
605
 
        expected_metadata_sequence_[num_expected_++] = &unknown_;
606
 
 
607
 
        if(!decoder->test_respond())
608
 
                return false;
609
 
 
610
 
        /*
611
 
         * ignore all, respond VORBIS_COMMENT
612
 
         */
613
 
 
614
 
        printf("testing set_metadata_ignore_all()... ");
615
 
        if(!decoder->set_metadata_ignore_all()) {
616
 
                printf("FAILED, returned false\n");
617
 
                return false;
618
 
        }
619
 
        printf("OK\n");
620
 
 
621
 
        printf("testing set_metadata_respond(VORBIS_COMMENT)... ");
622
 
        if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_VORBIS_COMMENT)) {
623
 
                printf("FAILED, returned false\n");
624
 
                return false;
625
 
        }
626
 
        printf("OK\n");
627
 
 
628
 
        num_expected_ = 0;
629
 
        expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
630
 
 
631
 
        if(!decoder->test_respond())
632
 
                return false;
633
 
 
634
 
        /*
635
 
         * ignore all, respond APPLICATION
636
 
         */
637
 
 
638
 
        printf("testing set_metadata_ignore_all()... ");
639
 
        if(!decoder->set_metadata_ignore_all()) {
640
 
                printf("FAILED, returned false\n");
641
 
                return false;
642
 
        }
643
 
        printf("OK\n");
644
 
 
645
 
        printf("testing set_metadata_respond(APPLICATION)... ");
646
 
        if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) {
647
 
                printf("FAILED, returned false\n");
648
 
                return false;
649
 
        }
650
 
        printf("OK\n");
651
 
 
652
 
        num_expected_ = 0;
653
 
        expected_metadata_sequence_[num_expected_++] = &application1_;
654
 
        expected_metadata_sequence_[num_expected_++] = &application2_;
655
 
 
656
 
        if(!decoder->test_respond())
657
 
                return false;
658
 
 
659
 
        /*
660
 
         * ignore all, respond APPLICATION id of app#1
661
 
         */
662
 
 
663
 
        printf("testing set_metadata_ignore_all()... ");
664
 
        if(!decoder->set_metadata_ignore_all()) {
665
 
                printf("FAILED, returned false\n");
666
 
                return false;
667
 
        }
668
 
        printf("OK\n");
669
 
 
670
 
        printf("testing set_metadata_respond_application(of app block #1)... ");
671
 
        if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
672
 
                printf("FAILED, returned false\n");
673
 
                return false;
674
 
        }
675
 
        printf("OK\n");
676
 
 
677
 
        num_expected_ = 0;
678
 
        expected_metadata_sequence_[num_expected_++] = &application1_;
679
 
 
680
 
        if(!decoder->test_respond())
681
 
                return false;
682
 
 
683
 
        /*
684
 
         * ignore all, respond APPLICATION id of app#1 & app#2
685
 
         */
686
 
 
687
 
        printf("testing set_metadata_ignore_all()... ");
688
 
        if(!decoder->set_metadata_ignore_all()) {
689
 
                printf("FAILED, returned false\n");
690
 
                return false;
691
 
        }
692
 
        printf("OK\n");
693
 
 
694
 
        printf("testing set_metadata_respond_application(of app block #1)... ");
695
 
        if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
696
 
                printf("FAILED, returned false\n");
697
 
                return false;
698
 
        }
699
 
        printf("OK\n");
700
 
 
701
 
        printf("testing set_metadata_respond_application(of app block #2)... ");
702
 
        if(!decoder->set_metadata_respond_application(application2_.data.application.id)) {
703
 
                printf("FAILED, returned false\n");
704
 
                return false;
705
 
        }
706
 
        printf("OK\n");
707
 
 
708
 
        num_expected_ = 0;
709
 
        expected_metadata_sequence_[num_expected_++] = &application1_;
710
 
        expected_metadata_sequence_[num_expected_++] = &application2_;
711
 
 
712
 
        if(!decoder->test_respond())
713
 
                return false;
714
 
 
715
 
        /*
716
 
         * respond all, ignore APPLICATION, respond APPLICATION id of app#1
717
 
         */
718
 
 
719
 
        printf("testing set_metadata_respond_all()... ");
720
 
        if(!decoder->set_metadata_respond_all()) {
721
 
                printf("FAILED, returned false\n");
722
 
                return false;
723
 
        }
724
 
        printf("OK\n");
725
 
 
726
 
        printf("testing set_metadata_ignore(APPLICATION)... ");
727
 
        if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) {
728
 
                printf("FAILED, returned false\n");
729
 
                return false;
730
 
        }
731
 
        printf("OK\n");
732
 
 
733
 
        printf("testing set_metadata_respond_application(of app block #1)... ");
734
 
        if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
735
 
                printf("FAILED, returned false\n");
736
 
                return false;
737
 
        }
738
 
        printf("OK\n");
739
 
 
740
 
        num_expected_ = 0;
741
 
        expected_metadata_sequence_[num_expected_++] = &streaminfo_;
742
 
        expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
743
 
        expected_metadata_sequence_[num_expected_++] = &padding_;
744
 
        expected_metadata_sequence_[num_expected_++] = &seektable_;
745
 
        expected_metadata_sequence_[num_expected_++] = &application1_;
746
 
        expected_metadata_sequence_[num_expected_++] = &cuesheet_;
747
 
        expected_metadata_sequence_[num_expected_++] = &unknown_;
748
 
 
749
 
        if(!decoder->test_respond())
750
 
                return false;
751
 
 
752
 
        /*
753
 
         * ignore all, respond APPLICATION, ignore APPLICATION id of app#1
754
 
         */
755
 
 
756
 
        printf("testing set_metadata_ignore_all()... ");
757
 
        if(!decoder->set_metadata_ignore_all()) {
758
 
                printf("FAILED, returned false\n");
759
 
                return false;
760
 
        }
761
 
        printf("OK\n");
762
 
 
763
 
        printf("testing set_metadata_respond(APPLICATION)... ");
764
 
        if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) {
765
 
                printf("FAILED, returned false\n");
766
 
                return false;
767
 
        }
768
 
        printf("OK\n");
769
 
 
770
 
        printf("testing set_metadata_ignore_application(of app block #1)... ");
771
 
        if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
772
 
                printf("FAILED, returned false\n");
773
 
                return false;
774
 
        }
775
 
        printf("OK\n");
776
 
 
777
 
        num_expected_ = 0;
778
 
        expected_metadata_sequence_[num_expected_++] = &application2_;
779
 
 
780
 
        if(!decoder->test_respond())
781
 
                return false;
782
 
 
783
 
        /* done, now leave the sequence the way we found it... */
784
 
        num_expected_ = 0;
785
 
        expected_metadata_sequence_[num_expected_++] = &streaminfo_;
786
 
        expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
787
 
        expected_metadata_sequence_[num_expected_++] = &padding_;
788
 
        expected_metadata_sequence_[num_expected_++] = &seektable_;
789
 
        expected_metadata_sequence_[num_expected_++] = &application1_;
790
 
        expected_metadata_sequence_[num_expected_++] = &application2_;
791
 
        expected_metadata_sequence_[num_expected_++] = &cuesheet_;
792
 
        expected_metadata_sequence_[num_expected_++] = &unknown_;
793
 
 
794
 
        ::fclose(decoder->file_);
795
 
 
796
 
        printf("freeing decoder instance... ");
797
 
        delete decoder;
798
 
        printf("OK\n");
799
 
 
800
 
        printf("\nPASSED!\n");
801
 
 
802
 
        return true;
803
 
}
804
 
 
805
 
class SeekableStreamDecoder : public OggFLAC::Decoder::SeekableStream, public DecoderCommon {
806
 
public:
807
 
        SeekableStreamDecoder(): OggFLAC::Decoder::SeekableStream(), DecoderCommon() { }
808
 
        ~SeekableStreamDecoder() { }
809
 
 
810
 
        // from OggFLAC::Decoder::SeekableStream
811
 
        ::OggFLAC__SeekableStreamDecoderReadStatus read_callback(FLAC__byte buffer[], unsigned *bytes);
812
 
        ::OggFLAC__SeekableStreamDecoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset);
813
 
        ::OggFLAC__SeekableStreamDecoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset);
814
 
        ::OggFLAC__SeekableStreamDecoderLengthStatus length_callback(FLAC__uint64 *stream_length);
815
 
        bool eof_callback();
816
 
        ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]);
817
 
        void metadata_callback(const ::FLAC__StreamMetadata *metadata);
818
 
        void error_callback(::FLAC__StreamDecoderErrorStatus status);
819
 
 
820
 
        bool die(const char *msg = 0) const;
821
 
 
822
 
        bool test_respond();
823
 
};
824
 
 
825
 
::OggFLAC__SeekableStreamDecoderReadStatus SeekableStreamDecoder::read_callback(FLAC__byte buffer[], unsigned *bytes)
826
 
{
827
 
        switch(common_read_callback_(buffer, bytes)) {
828
 
                case ::FLAC__STREAM_DECODER_READ_STATUS_CONTINUE:
829
 
                case ::FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM:
830
 
                        return ::OggFLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_OK;
831
 
                case ::FLAC__STREAM_DECODER_READ_STATUS_ABORT:
832
 
                        return ::OggFLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_ERROR;
833
 
                default:
834
 
                        FLAC__ASSERT(0);
835
 
                        return ::OggFLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_ERROR;
836
 
        }
837
 
}
838
 
 
839
 
::OggFLAC__SeekableStreamDecoderSeekStatus SeekableStreamDecoder::seek_callback(FLAC__uint64 absolute_byte_offset)
840
 
{
841
 
        if(error_occurred_)
842
 
                return ::OggFLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_ERROR;
843
 
 
844
 
        if(::fseek(file_, (long)absolute_byte_offset, SEEK_SET) < 0) {
845
 
                error_occurred_ = true;
846
 
                return ::OggFLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_ERROR;
847
 
        }
848
 
 
849
 
        return ::OggFLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_OK;
850
 
}
851
 
 
852
 
::OggFLAC__SeekableStreamDecoderTellStatus SeekableStreamDecoder::tell_callback(FLAC__uint64 *absolute_byte_offset)
853
 
{
854
 
        if(error_occurred_)
855
 
                return ::OggFLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_ERROR;
856
 
 
857
 
        long offset = ::ftell(file_);
858
 
        *absolute_byte_offset = (FLAC__uint64)offset;
859
 
 
860
 
        if(offset < 0) {
861
 
                error_occurred_ = true;
862
 
                return ::OggFLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_ERROR;
863
 
        }
864
 
 
865
 
        return ::OggFLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_OK;
866
 
}
867
 
 
868
 
::OggFLAC__SeekableStreamDecoderLengthStatus SeekableStreamDecoder::length_callback(FLAC__uint64 *stream_length)
869
 
{
870
 
        if(error_occurred_)
871
 
                return ::OggFLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_ERROR;
872
 
 
873
 
        *stream_length = (FLAC__uint64)oggflacfilesize_;
874
 
        return ::OggFLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_OK;
875
 
}
876
 
 
877
 
bool SeekableStreamDecoder::eof_callback()
878
 
{
879
 
        if(error_occurred_)
880
 
                return true;
881
 
 
882
 
        return (bool)feof(file_);
883
 
}
884
 
 
885
 
::FLAC__StreamDecoderWriteStatus SeekableStreamDecoder::write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[])
886
 
{
887
 
        (void)buffer;
888
 
 
889
 
        return common_write_callback_(frame);
890
 
}
891
 
 
892
 
void SeekableStreamDecoder::metadata_callback(const ::FLAC__StreamMetadata *metadata)
893
 
{
894
 
        common_metadata_callback_(metadata);
895
 
}
896
 
 
897
 
void SeekableStreamDecoder::error_callback(::FLAC__StreamDecoderErrorStatus status)
898
 
{
899
 
        common_error_callback_(status);
900
 
}
901
 
 
902
 
bool SeekableStreamDecoder::die(const char *msg) const
903
 
{
904
 
        State state = get_state();
905
 
 
906
 
        if(msg)
907
 
                printf("FAILED, %s", msg);
908
 
        else
909
 
                printf("FAILED");
910
 
 
911
 
        printf(", state = %u (%s)\n", (unsigned)((::OggFLAC__SeekableStreamDecoderState)state), state.as_cstring());
912
 
        if(state == ::OggFLAC__SEEKABLE_STREAM_DECODER_STREAM_DECODER_ERROR) {
913
 
                OggFLAC::Decoder::Stream::State state_ = get_stream_decoder_state();
914
 
                printf("      stream decoder state = %u (%s)\n", (unsigned)((::OggFLAC__StreamDecoderState)state_), state_.as_cstring());
915
 
                if(state_ == ::OggFLAC__STREAM_DECODER_FLAC_STREAM_DECODER_ERROR) {
916
 
                        FLAC::Decoder::Stream::State state__ = get_FLAC_stream_decoder_state();
917
 
                        printf("      FLAC stream decoder state = %u (%s)\n", (unsigned)((::FLAC__StreamDecoderState)state__), state__.as_cstring());
918
 
                }
919
 
        }
920
 
 
921
 
        return false;
922
 
}
923
 
 
924
 
bool SeekableStreamDecoder::test_respond()
925
 
{
926
 
        if(!set_md5_checking(true)) {
927
 
                printf("FAILED at set_md5_checking(), returned false\n");
928
 
                return false;
929
 
        }
930
 
 
931
 
        printf("testing init()... ");
932
 
        if(init() != ::OggFLAC__SEEKABLE_STREAM_DECODER_OK)
933
 
                return die();
934
 
        printf("OK\n");
935
 
 
936
 
        current_metadata_number_ = 0;
937
 
 
938
 
        if(::fseek(file_, 0, SEEK_SET) < 0) {
939
 
                printf("FAILED rewinding input, errno = %d\n", errno);
940
 
                return false;
941
 
        }
942
 
 
943
 
        printf("testing process_until_end_of_stream()... ");
944
 
        if(!process_until_end_of_stream()) {
945
 
                State state = get_state();
946
 
                printf("FAILED, returned false, state = %u (%s)\n", (unsigned)((::OggFLAC__SeekableStreamDecoderState)state), state.as_cstring());
947
 
                return false;
948
 
        }
949
 
        printf("OK\n");
950
 
 
951
 
        printf("testing finish()... ");
952
 
        finish();
953
 
        printf("OK\n");
954
 
 
955
 
        return true;
956
 
}
957
 
 
958
 
static bool test_seekable_stream_decoder()
959
 
{
960
 
        SeekableStreamDecoder *decoder;
961
 
 
962
 
        printf("\n+++ libOggFLAC++ unit test: OggFLAC::Decoder::SeekableStream\n\n");
963
 
 
964
 
        //
965
 
        // test new -> delete
966
 
        //
967
 
        printf("allocating decoder instance... ");
968
 
        decoder = new SeekableStreamDecoder();
969
 
        if(0 == decoder) {
970
 
                printf("FAILED, new returned NULL\n");
971
 
                return false;
972
 
        }
973
 
        printf("OK\n");
974
 
 
975
 
        printf("testing is_valid()... ");
976
 
        if(!decoder->is_valid()) {
977
 
                printf("FAILED, returned false\n");
978
 
                return false;
979
 
        }
980
 
        printf("OK\n");
981
 
 
982
 
        printf("freeing decoder instance... ");
983
 
        delete decoder;
984
 
        printf("OK\n");
985
 
 
986
 
        //
987
 
        // test new -> init -> delete
988
 
        //
989
 
        printf("allocating decoder instance... ");
990
 
        decoder = new SeekableStreamDecoder();
991
 
        if(0 == decoder) {
992
 
                printf("FAILED, new returned NULL\n");
993
 
                return false;
994
 
        }
995
 
        printf("OK\n");
996
 
 
997
 
        printf("testing is_valid()... ");
998
 
        if(!decoder->is_valid()) {
999
 
                printf("FAILED, returned false\n");
1000
 
                return false;
1001
 
        }
1002
 
        printf("OK\n");
1003
 
 
1004
 
        printf("testing init()... ");
1005
 
        if(decoder->init() != ::OggFLAC__SEEKABLE_STREAM_DECODER_OK)
1006
 
                return decoder->die();
1007
 
        printf("OK\n");
1008
 
 
1009
 
        printf("freeing decoder instance... ");
1010
 
        delete decoder;
1011
 
        printf("OK\n");
1012
 
 
1013
 
        //
1014
 
        // test normal usage
1015
 
        //
1016
 
        num_expected_ = 0;
1017
 
        expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1018
 
 
1019
 
        printf("allocating decoder instance... ");
1020
 
        decoder = new SeekableStreamDecoder();
1021
 
        if(0 == decoder) {
1022
 
                printf("FAILED, new returned NULL\n");
1023
 
                return false;
1024
 
        }
1025
 
        printf("OK\n");
1026
 
 
1027
 
        printf("testing is_valid()... ");
1028
 
        if(!decoder->is_valid()) {
1029
 
                printf("FAILED, returned false\n");
1030
 
                return false;
1031
 
        }
1032
 
        printf("OK\n");
1033
 
 
1034
 
        printf("testing set_md5_checking()... ");
1035
 
        if(!decoder->set_md5_checking(true)) {
1036
 
                printf("FAILED, returned false\n");
1037
 
                return false;
1038
 
        }
1039
 
        printf("OK\n");
1040
 
 
1041
 
        printf("testing set_serial_number()... ");
1042
 
        if(!decoder->set_serial_number(file_utils__serial_number))
1043
 
                return decoder->die("returned false");
1044
 
        printf("OK\n");
1045
 
 
1046
 
        printf("testing init()... ");
1047
 
        if(decoder->init() != ::OggFLAC__SEEKABLE_STREAM_DECODER_OK)
1048
 
                return decoder->die();
1049
 
        printf("OK\n");
1050
 
 
1051
 
        printf("testing get_state()... ");
1052
 
        OggFLAC::Decoder::SeekableStream::State state = decoder->get_state();
1053
 
        printf("returned state = %u (%s)... OK\n", (unsigned)((::OggFLAC__SeekableStreamDecoderState)state), state.as_cstring());
1054
 
 
1055
 
        printf("testing get_stream_decoder_state()... ");
1056
 
        OggFLAC::Decoder::Stream::State state_ = decoder->get_stream_decoder_state();
1057
 
        printf("returned state = %u (%s)... OK\n", (unsigned)((::OggFLAC__StreamDecoderState)state_), state_.as_cstring());
1058
 
 
1059
 
        printf("testing get_FLAC_stream_decoder_state()... ");
1060
 
        FLAC::Decoder::Stream::State state__ = decoder->get_FLAC_stream_decoder_state();
1061
 
        printf("returned state = %u (%s)... OK\n", (unsigned)((::FLAC__StreamDecoderState)state__), state__.as_cstring());
1062
 
 
1063
 
        decoder->current_metadata_number_ = 0;
1064
 
        decoder->ignore_errors_ = false;
1065
 
        decoder->error_occurred_ = false;
1066
 
 
1067
 
        printf("opening Ogg FLAC file... ");
1068
 
        decoder->file_ = ::fopen(oggflacfilename_, "rb");
1069
 
        if(0 == decoder->file_) {
1070
 
                printf("ERROR\n");
1071
 
                return false;
1072
 
        }
1073
 
        printf("OK\n");
1074
 
 
1075
 
        printf("testing get_md5_checking()... ");
1076
 
        if(!decoder->get_md5_checking()) {
1077
 
                printf("FAILED, returned false, expected true\n");
1078
 
                return false;
1079
 
        }
1080
 
        printf("OK\n");
1081
 
 
1082
 
        printf("testing process_until_end_of_metadata()... ");
1083
 
        if(!decoder->process_until_end_of_metadata())
1084
 
                return decoder->die("returned false");
1085
 
        printf("OK\n");
1086
 
 
1087
 
        printf("testing process_single()... ");
1088
 
        if(!decoder->process_single())
1089
 
                return decoder->die("returned false");
1090
 
        printf("OK\n");
1091
 
 
1092
 
        printf("testing flush()... ");
1093
 
        if(!decoder->flush())
1094
 
                return decoder->die("returned false");
1095
 
        printf("OK\n");
1096
 
 
1097
 
        decoder->ignore_errors_ = true;
1098
 
        printf("testing process_single()... ");
1099
 
        if(!decoder->process_single())
1100
 
                return decoder->die("returned false");
1101
 
        printf("OK\n");
1102
 
        decoder->ignore_errors_ = false;
1103
 
 
1104
 
        printf("testing seek_absolute()... ");
1105
 
        if(!decoder->seek_absolute(0))
1106
 
                return decoder->die("returned false");
1107
 
        printf("OK\n");
1108
 
 
1109
 
        printf("testing process_until_end_of_stream()... ");
1110
 
        if(!decoder->process_until_end_of_stream())
1111
 
                return decoder->die("returned false");
1112
 
        printf("OK\n");
1113
 
 
1114
 
        printf("testing get_channels()... ");
1115
 
        {
1116
 
                unsigned channels = decoder->get_channels();
1117
 
                if(channels != streaminfo_.data.stream_info.channels) {
1118
 
                        printf("FAILED, returned %u, expected %u\n", channels, streaminfo_.data.stream_info.channels);
1119
 
                        return false;
1120
 
                }
1121
 
        }
1122
 
        printf("OK\n");
1123
 
 
1124
 
        printf("testing get_bits_per_sample()... ");
1125
 
        {
1126
 
                unsigned bits_per_sample = decoder->get_bits_per_sample();
1127
 
                if(bits_per_sample != streaminfo_.data.stream_info.bits_per_sample) {
1128
 
                        printf("FAILED, returned %u, expected %u\n", bits_per_sample, streaminfo_.data.stream_info.bits_per_sample);
1129
 
                        return false;
1130
 
                }
1131
 
        }
1132
 
        printf("OK\n");
1133
 
 
1134
 
        printf("testing get_sample_rate()... ");
1135
 
        {
1136
 
                unsigned sample_rate = decoder->get_sample_rate();
1137
 
                if(sample_rate != streaminfo_.data.stream_info.sample_rate) {
1138
 
                        printf("FAILED, returned %u, expected %u\n", sample_rate, streaminfo_.data.stream_info.sample_rate);
1139
 
                        return false;
1140
 
                }
1141
 
        }
1142
 
        printf("OK\n");
1143
 
 
1144
 
        printf("testing get_blocksize()... ");
1145
 
        {
1146
 
                unsigned blocksize = decoder->get_blocksize();
1147
 
                /* value could be anything since we're at the last block, so accept any answer */
1148
 
                printf("returned %u... OK\n", blocksize);
1149
 
        }
1150
 
 
1151
 
        printf("testing get_channel_assignment()... ");
1152
 
        {
1153
 
                ::FLAC__ChannelAssignment ca = decoder->get_channel_assignment();
1154
 
                printf("returned %u (%s)... OK\n", (unsigned)ca, ::FLAC__ChannelAssignmentString[ca]);
1155
 
        }
1156
 
 
1157
 
        printf("testing reset()... ");
1158
 
        if(!decoder->reset())
1159
 
                return decoder->die("returned false");
1160
 
        printf("OK\n");
1161
 
 
1162
 
        decoder->current_metadata_number_ = 0;
1163
 
 
1164
 
        printf("rewinding input... ");
1165
 
        if(::fseek(decoder->file_, 0, SEEK_SET) < 0) {
1166
 
                printf("FAILED, errno = %d\n", errno);
1167
 
                return false;
1168
 
        }
1169
 
        printf("OK\n");
1170
 
 
1171
 
        printf("testing process_until_end_of_stream()... ");
1172
 
        if(!decoder->process_until_end_of_stream())
1173
 
                return decoder->die("returned false");
1174
 
        printf("OK\n");
1175
 
 
1176
 
        printf("testing finish()... ");
1177
 
        decoder->finish();
1178
 
        printf("OK\n");
1179
 
 
1180
 
        /*
1181
 
         * respond all
1182
 
         */
1183
 
 
1184
 
        printf("testing set_metadata_respond_all()... ");
1185
 
        if(!decoder->set_metadata_respond_all()) {
1186
 
                printf("FAILED, returned false\n");
1187
 
                return false;
1188
 
        }
1189
 
        printf("OK\n");
1190
 
 
1191
 
        num_expected_ = 0;
1192
 
        expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1193
 
        expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1194
 
        expected_metadata_sequence_[num_expected_++] = &padding_;
1195
 
        expected_metadata_sequence_[num_expected_++] = &seektable_;
1196
 
        expected_metadata_sequence_[num_expected_++] = &application1_;
1197
 
        expected_metadata_sequence_[num_expected_++] = &application2_;
1198
 
        expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1199
 
        expected_metadata_sequence_[num_expected_++] = &unknown_;
1200
 
 
1201
 
        if(!decoder->test_respond())
1202
 
                return false;
1203
 
 
1204
 
        /*
1205
 
         * ignore all
1206
 
         */
1207
 
 
1208
 
        printf("testing set_metadata_ignore_all()... ");
1209
 
        if(!decoder->set_metadata_ignore_all()) {
1210
 
                printf("FAILED, returned false\n");
1211
 
                return false;
1212
 
        }
1213
 
        printf("OK\n");
1214
 
 
1215
 
        num_expected_ = 0;
1216
 
 
1217
 
        if(!decoder->test_respond())
1218
 
                return false;
1219
 
 
1220
 
        /*
1221
 
         * respond all, ignore VORBIS_COMMENT
1222
 
         */
1223
 
 
1224
 
        printf("testing set_metadata_respond_all()... ");
1225
 
        if(!decoder->set_metadata_respond_all()) {
1226
 
                printf("FAILED, returned false\n");
1227
 
                return false;
1228
 
        }
1229
 
        printf("OK\n");
1230
 
 
1231
 
        printf("testing set_metadata_ignore(VORBIS_COMMENT)... ");
1232
 
        if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_VORBIS_COMMENT)) {
1233
 
                printf("FAILED, returned false\n");
1234
 
                return false;
1235
 
        }
1236
 
        printf("OK\n");
1237
 
 
1238
 
        num_expected_ = 0;
1239
 
        expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1240
 
        expected_metadata_sequence_[num_expected_++] = &padding_;
1241
 
        expected_metadata_sequence_[num_expected_++] = &seektable_;
1242
 
        expected_metadata_sequence_[num_expected_++] = &application1_;
1243
 
        expected_metadata_sequence_[num_expected_++] = &application2_;
1244
 
        expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1245
 
        expected_metadata_sequence_[num_expected_++] = &unknown_;
1246
 
 
1247
 
        if(!decoder->test_respond())
1248
 
                return false;
1249
 
 
1250
 
        /*
1251
 
         * respond all, ignore APPLICATION
1252
 
         */
1253
 
 
1254
 
        printf("testing set_metadata_respond_all()... ");
1255
 
        if(!decoder->set_metadata_respond_all()) {
1256
 
                printf("FAILED, returned false\n");
1257
 
                return false;
1258
 
        }
1259
 
        printf("OK\n");
1260
 
 
1261
 
        printf("testing set_metadata_ignore(APPLICATION)... ");
1262
 
        if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) {
1263
 
                printf("FAILED, returned false\n");
1264
 
                return false;
1265
 
        }
1266
 
        printf("OK\n");
1267
 
 
1268
 
        num_expected_ = 0;
1269
 
        expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1270
 
        expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1271
 
        expected_metadata_sequence_[num_expected_++] = &padding_;
1272
 
        expected_metadata_sequence_[num_expected_++] = &seektable_;
1273
 
        expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1274
 
        expected_metadata_sequence_[num_expected_++] = &unknown_;
1275
 
 
1276
 
        if(!decoder->test_respond())
1277
 
                return false;
1278
 
 
1279
 
        /*
1280
 
         * respond all, ignore APPLICATION id of app#1
1281
 
         */
1282
 
 
1283
 
        printf("testing set_metadata_respond_all()... ");
1284
 
        if(!decoder->set_metadata_respond_all()) {
1285
 
                printf("FAILED, returned false\n");
1286
 
                return false;
1287
 
        }
1288
 
        printf("OK\n");
1289
 
 
1290
 
        printf("testing set_metadata_ignore_application(of app block #1)... ");
1291
 
        if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
1292
 
                printf("FAILED, returned false\n");
1293
 
                return false;
1294
 
        }
1295
 
        printf("OK\n");
1296
 
 
1297
 
        num_expected_ = 0;
1298
 
        expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1299
 
        expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1300
 
        expected_metadata_sequence_[num_expected_++] = &padding_;
1301
 
        expected_metadata_sequence_[num_expected_++] = &seektable_;
1302
 
        expected_metadata_sequence_[num_expected_++] = &application2_;
1303
 
        expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1304
 
        expected_metadata_sequence_[num_expected_++] = &unknown_;
1305
 
 
1306
 
        if(!decoder->test_respond())
1307
 
                return false;
1308
 
 
1309
 
        /*
1310
 
         * respond all, ignore APPLICATION id of app#1 & app#2
1311
 
         */
1312
 
 
1313
 
        printf("testing set_metadata_respond_all()... ");
1314
 
        if(!decoder->set_metadata_respond_all()) {
1315
 
                printf("FAILED, returned false\n");
1316
 
                return false;
1317
 
        }
1318
 
        printf("OK\n");
1319
 
 
1320
 
        printf("testing set_metadata_ignore_application(of app block #1)... ");
1321
 
        if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
1322
 
                printf("FAILED, returned false\n");
1323
 
                return false;
1324
 
        }
1325
 
        printf("OK\n");
1326
 
 
1327
 
        printf("testing set_metadata_ignore_application(of app block #2)... ");
1328
 
        if(!decoder->set_metadata_ignore_application(application2_.data.application.id)) {
1329
 
                printf("FAILED, returned false\n");
1330
 
                return false;
1331
 
        }
1332
 
        printf("OK\n");
1333
 
 
1334
 
        num_expected_ = 0;
1335
 
        expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1336
 
        expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1337
 
        expected_metadata_sequence_[num_expected_++] = &padding_;
1338
 
        expected_metadata_sequence_[num_expected_++] = &seektable_;
1339
 
        expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1340
 
        expected_metadata_sequence_[num_expected_++] = &unknown_;
1341
 
 
1342
 
        if(!decoder->test_respond())
1343
 
                return false;
1344
 
 
1345
 
        /*
1346
 
         * ignore all, respond VORBIS_COMMENT
1347
 
         */
1348
 
 
1349
 
        printf("testing set_metadata_ignore_all()... ");
1350
 
        if(!decoder->set_metadata_ignore_all()) {
1351
 
                printf("FAILED, returned false\n");
1352
 
                return false;
1353
 
        }
1354
 
        printf("OK\n");
1355
 
 
1356
 
        printf("testing set_metadata_respond(VORBIS_COMMENT)... ");
1357
 
        if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_VORBIS_COMMENT)) {
1358
 
                printf("FAILED, returned false\n");
1359
 
                return false;
1360
 
        }
1361
 
        printf("OK\n");
1362
 
 
1363
 
        num_expected_ = 0;
1364
 
        expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1365
 
 
1366
 
        if(!decoder->test_respond())
1367
 
                return false;
1368
 
 
1369
 
        /*
1370
 
         * ignore all, respond APPLICATION
1371
 
         */
1372
 
 
1373
 
        printf("testing set_metadata_ignore_all()... ");
1374
 
        if(!decoder->set_metadata_ignore_all()) {
1375
 
                printf("FAILED, returned false\n");
1376
 
                return false;
1377
 
        }
1378
 
        printf("OK\n");
1379
 
 
1380
 
        printf("testing set_metadata_respond(APPLICATION)... ");
1381
 
        if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) {
1382
 
                printf("FAILED, returned false\n");
1383
 
                return false;
1384
 
        }
1385
 
        printf("OK\n");
1386
 
 
1387
 
        num_expected_ = 0;
1388
 
        expected_metadata_sequence_[num_expected_++] = &application1_;
1389
 
        expected_metadata_sequence_[num_expected_++] = &application2_;
1390
 
 
1391
 
        if(!decoder->test_respond())
1392
 
                return false;
1393
 
 
1394
 
        /*
1395
 
         * ignore all, respond APPLICATION id of app#1
1396
 
         */
1397
 
 
1398
 
        printf("testing set_metadata_ignore_all()... ");
1399
 
        if(!decoder->set_metadata_ignore_all()) {
1400
 
                printf("FAILED, returned false\n");
1401
 
                return false;
1402
 
        }
1403
 
        printf("OK\n");
1404
 
 
1405
 
        printf("testing set_metadata_respond_application(of app block #1)... ");
1406
 
        if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
1407
 
                printf("FAILED, returned false\n");
1408
 
                return false;
1409
 
        }
1410
 
        printf("OK\n");
1411
 
 
1412
 
        num_expected_ = 0;
1413
 
        expected_metadata_sequence_[num_expected_++] = &application1_;
1414
 
 
1415
 
        if(!decoder->test_respond())
1416
 
                return false;
1417
 
 
1418
 
        /*
1419
 
         * ignore all, respond APPLICATION id of app#1 & app#2
1420
 
         */
1421
 
 
1422
 
        printf("testing set_metadata_ignore_all()... ");
1423
 
        if(!decoder->set_metadata_ignore_all()) {
1424
 
                printf("FAILED, returned false\n");
1425
 
                return false;
1426
 
        }
1427
 
        printf("OK\n");
1428
 
 
1429
 
        printf("testing set_metadata_respond_application(of app block #1)... ");
1430
 
        if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
1431
 
                printf("FAILED, returned false\n");
1432
 
                return false;
1433
 
        }
1434
 
        printf("OK\n");
1435
 
 
1436
 
        printf("testing set_metadata_respond_application(of app block #2)... ");
1437
 
        if(!decoder->set_metadata_respond_application(application2_.data.application.id)) {
1438
 
                printf("FAILED, returned false\n");
1439
 
                return false;
1440
 
        }
1441
 
        printf("OK\n");
1442
 
 
1443
 
        num_expected_ = 0;
1444
 
        expected_metadata_sequence_[num_expected_++] = &application1_;
1445
 
        expected_metadata_sequence_[num_expected_++] = &application2_;
1446
 
 
1447
 
        if(!decoder->test_respond())
1448
 
                return false;
1449
 
 
1450
 
        /*
1451
 
         * respond all, ignore APPLICATION, respond APPLICATION id of app#1
1452
 
         */
1453
 
 
1454
 
        printf("testing set_metadata_respond_all()... ");
1455
 
        if(!decoder->set_metadata_respond_all()) {
1456
 
                printf("FAILED, returned false\n");
1457
 
                return false;
1458
 
        }
1459
 
        printf("OK\n");
1460
 
 
1461
 
        printf("testing set_metadata_ignore(APPLICATION)... ");
1462
 
        if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) {
1463
 
                printf("FAILED, returned false\n");
1464
 
                return false;
1465
 
        }
1466
 
        printf("OK\n");
1467
 
 
1468
 
        printf("testing set_metadata_respond_application(of app block #1)... ");
1469
 
        if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
1470
 
                printf("FAILED, returned false\n");
1471
 
                return false;
1472
 
        }
1473
 
        printf("OK\n");
1474
 
 
1475
 
        num_expected_ = 0;
1476
 
        expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1477
 
        expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1478
 
        expected_metadata_sequence_[num_expected_++] = &padding_;
1479
 
        expected_metadata_sequence_[num_expected_++] = &seektable_;
1480
 
        expected_metadata_sequence_[num_expected_++] = &application1_;
1481
 
        expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1482
 
        expected_metadata_sequence_[num_expected_++] = &unknown_;
1483
 
 
1484
 
        if(!decoder->test_respond())
1485
 
                return false;
1486
 
 
1487
 
        /*
1488
 
         * ignore all, respond APPLICATION, ignore APPLICATION id of app#1
1489
 
         */
1490
 
 
1491
 
        printf("testing set_metadata_ignore_all()... ");
1492
 
        if(!decoder->set_metadata_ignore_all()) {
1493
 
                printf("FAILED, returned false\n");
1494
 
                return false;
1495
 
        }
1496
 
        printf("OK\n");
1497
 
 
1498
 
        printf("testing set_metadata_respond(APPLICATION)... ");
1499
 
        if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) {
1500
 
                printf("FAILED, returned false\n");
1501
 
                return false;
1502
 
        }
1503
 
        printf("OK\n");
1504
 
 
1505
 
        printf("testing set_metadata_ignore_application(of app block #1)... ");
1506
 
        if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
1507
 
                printf("FAILED, returned false\n");
1508
 
                return false;
1509
 
        }
1510
 
        printf("OK\n");
1511
 
 
1512
 
        num_expected_ = 0;
1513
 
        expected_metadata_sequence_[num_expected_++] = &application2_;
1514
 
 
1515
 
        if(!decoder->test_respond())
1516
 
                return false;
1517
 
 
1518
 
        /* done, now leave the sequence the way we found it... */
1519
 
        num_expected_ = 0;
1520
 
        expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1521
 
        expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1522
 
        expected_metadata_sequence_[num_expected_++] = &padding_;
1523
 
        expected_metadata_sequence_[num_expected_++] = &seektable_;
1524
 
        expected_metadata_sequence_[num_expected_++] = &application1_;
1525
 
        expected_metadata_sequence_[num_expected_++] = &application2_;
1526
 
        expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1527
 
        expected_metadata_sequence_[num_expected_++] = &unknown_;
1528
 
 
1529
 
        ::fclose(decoder->file_);
1530
 
 
1531
 
        printf("freeing decoder instance... ");
1532
 
        delete decoder;
1533
 
        printf("OK\n");
1534
 
 
1535
 
        printf("\nPASSED!\n");
1536
 
 
1537
 
        return true;
1538
 
}
1539
 
 
1540
 
class FileDecoder : public OggFLAC::Decoder::File, public DecoderCommon {
1541
 
public:
1542
 
        FileDecoder(): OggFLAC::Decoder::File(), DecoderCommon() { }
1543
 
        ~FileDecoder() { }
1544
 
 
1545
 
        // from OggFLAC::Decoder::File
1546
 
        ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]);
1547
 
        void metadata_callback(const ::FLAC__StreamMetadata *metadata);
1548
 
        void error_callback(::FLAC__StreamDecoderErrorStatus status);
1549
 
 
1550
 
        bool die(const char *msg = 0) const;
1551
 
 
1552
 
        bool test_respond();
1553
 
};
1554
 
 
1555
 
::FLAC__StreamDecoderWriteStatus FileDecoder::write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[])
1556
 
{
1557
 
        (void)buffer;
1558
 
        return common_write_callback_(frame);
1559
 
}
1560
 
 
1561
 
void FileDecoder::metadata_callback(const ::FLAC__StreamMetadata *metadata)
1562
 
{
1563
 
        common_metadata_callback_(metadata);
1564
 
}
1565
 
 
1566
 
void FileDecoder::error_callback(::FLAC__StreamDecoderErrorStatus status)
1567
 
{
1568
 
        common_error_callback_(status);
1569
 
}
1570
 
 
1571
 
bool FileDecoder::die(const char *msg) const
1572
 
{
1573
 
        State state = get_state();
1574
 
 
1575
 
        if(msg)
1576
 
                printf("FAILED, %s", msg);
1577
 
        else
1578
 
                printf("FAILED");
1579
 
 
1580
 
        printf(", state = %u (%s)\n", (unsigned)((::OggFLAC__FileDecoderState)state), state.as_cstring());
1581
 
        if(state == ::OggFLAC__FILE_DECODER_SEEKABLE_STREAM_DECODER_ERROR) {
1582
 
                OggFLAC::Decoder::SeekableStream::State state_ = get_seekable_stream_decoder_state();
1583
 
                printf("      seekable stream decoder state = %u (%s)\n", (unsigned)((::OggFLAC__SeekableStreamDecoderState)state_), state_.as_cstring());
1584
 
                if(state_ == ::OggFLAC__SEEKABLE_STREAM_DECODER_STREAM_DECODER_ERROR) {
1585
 
                        OggFLAC::Decoder::Stream::State state__ = get_stream_decoder_state();
1586
 
                        printf("      stream decoder state = %u (%s)\n", (unsigned)((::OggFLAC__StreamDecoderState)state__), state__.as_cstring());
1587
 
                        if(state__ == ::OggFLAC__STREAM_DECODER_FLAC_STREAM_DECODER_ERROR) {
1588
 
                                FLAC::Decoder::Stream::State state___ = get_FLAC_stream_decoder_state();
1589
 
                                printf("      FLAC stream decoder state = %u (%s)\n", (unsigned)((::FLAC__StreamDecoderState)state___), state___.as_cstring());
1590
 
                        }
1591
 
                }
1592
 
        }
1593
 
 
1594
 
        return false;
1595
 
}
1596
 
 
1597
 
bool FileDecoder::test_respond()
1598
 
{
1599
 
        if(!set_filename(oggflacfilename_)) {
1600
 
                printf("FAILED at set_filename(), returned false\n");
1601
 
                return false;
1602
 
        }
1603
 
 
1604
 
        if(!set_md5_checking(true)) {
1605
 
                printf("FAILED at set_md5_checking(), returned false\n");
1606
 
                return false;
1607
 
        }
1608
 
 
1609
 
        printf("testing init()... ");
1610
 
        if(init() != ::OggFLAC__FILE_DECODER_OK)
1611
 
                return die();
1612
 
        printf("OK\n");
1613
 
 
1614
 
        current_metadata_number_ = 0;
1615
 
 
1616
 
        printf("testing process_until_end_of_file()... ");
1617
 
        if(!process_until_end_of_file()) {
1618
 
                State state = get_state();
1619
 
                printf("FAILED, returned false, state = %u (%s)\n", (unsigned)((::OggFLAC__FileDecoderState)state), state.as_cstring());
1620
 
                return false;
1621
 
        }
1622
 
        printf("OK\n");
1623
 
 
1624
 
        printf("testing finish()... ");
1625
 
        finish();
1626
 
        printf("OK\n");
1627
 
 
1628
 
        return true;
1629
 
}
1630
 
 
1631
 
static bool test_file_decoder()
1632
 
{
1633
 
        FileDecoder *decoder;
1634
 
 
1635
 
        printf("\n+++ libOggFLAC++ unit test: OggFLAC::Decoder::File\n\n");
1636
 
 
1637
 
        //
1638
 
        // test new -> delete
1639
 
        //
1640
 
        printf("allocating decoder instance... ");
1641
 
        decoder = new FileDecoder();
1642
 
        if(0 == decoder) {
1643
 
                printf("FAILED, new returned NULL\n");
1644
 
                return false;
1645
 
        }
1646
 
        printf("OK\n");
1647
 
 
1648
 
        printf("testing is_valid()... ");
1649
 
        if(!decoder->is_valid()) {
1650
 
                printf("FAILED, returned false\n");
1651
 
                return false;
1652
 
        }
1653
 
        printf("OK\n");
1654
 
 
1655
 
        printf("freeing decoder instance... ");
1656
 
        delete decoder;
1657
 
        printf("OK\n");
1658
 
 
1659
 
        //
1660
 
        // test new -> init -> delete
1661
 
        //
1662
 
        printf("allocating decoder instance... ");
1663
 
        decoder = new FileDecoder();
1664
 
        if(0 == decoder) {
1665
 
                printf("FAILED, new returned NULL\n");
1666
 
                return false;
1667
 
        }
1668
 
        printf("OK\n");
1669
 
 
1670
 
        printf("testing is_valid()... ");
1671
 
        if(!decoder->is_valid()) {
1672
 
                printf("FAILED, returned false\n");
1673
 
                return false;
1674
 
        }
1675
 
        printf("OK\n");
1676
 
 
1677
 
        printf("testing init()... ");
1678
 
        if(decoder->init() != ::OggFLAC__FILE_DECODER_OK)
1679
 
                return decoder->die();
1680
 
        printf("OK\n");
1681
 
 
1682
 
        printf("freeing decoder instance... ");
1683
 
        delete decoder;
1684
 
        printf("OK\n");
1685
 
 
1686
 
        //
1687
 
        // test normal usage
1688
 
        //
1689
 
        num_expected_ = 0;
1690
 
        expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1691
 
 
1692
 
        printf("allocating decoder instance... ");
1693
 
        decoder = new FileDecoder();
1694
 
        if(0 == decoder) {
1695
 
                printf("FAILED, new returned NULL\n");
1696
 
                return false;
1697
 
        }
1698
 
        printf("OK\n");
1699
 
 
1700
 
        printf("testing is_valid()... ");
1701
 
        if(!decoder->is_valid()) {
1702
 
                printf("FAILED, returned false\n");
1703
 
                return false;
1704
 
        }
1705
 
        printf("OK\n");
1706
 
 
1707
 
        printf("testing set_filename()... ");
1708
 
        if(!decoder->set_filename(oggflacfilename_)) {
1709
 
                printf("FAILED, returned false\n");
1710
 
                return false;
1711
 
        }
1712
 
        printf("OK\n");
1713
 
 
1714
 
        printf("testing set_md5_checking()... ");
1715
 
        if(!decoder->set_md5_checking(true)) {
1716
 
                printf("FAILED, returned false\n");
1717
 
                return false;
1718
 
        }
1719
 
        printf("OK\n");
1720
 
 
1721
 
        printf("testing set_serial_number()... ");
1722
 
        if(!decoder->set_serial_number(file_utils__serial_number))
1723
 
                return decoder->die("returned false");
1724
 
        printf("OK\n");
1725
 
 
1726
 
        printf("testing init()... ");
1727
 
        if(decoder->init() != ::OggFLAC__FILE_DECODER_OK)
1728
 
                return decoder->die();
1729
 
        printf("OK\n");
1730
 
 
1731
 
        printf("testing get_state()... ");
1732
 
        OggFLAC::Decoder::File::State state = decoder->get_state();
1733
 
        printf("returned state = %u (%s)... OK\n", (unsigned)((::OggFLAC__FileDecoderState)state), state.as_cstring());
1734
 
 
1735
 
        printf("testing get_seekable_stream_decoder_state()... ");
1736
 
        OggFLAC::Decoder::SeekableStream::State state_ = decoder->get_seekable_stream_decoder_state();
1737
 
        printf("returned state = %u (%s)... OK\n", (unsigned)((::OggFLAC__SeekableStreamDecoderState)state_), state_.as_cstring());
1738
 
 
1739
 
        printf("testing get_stream_decoder_state()... ");
1740
 
        OggFLAC::Decoder::Stream::State state__ = decoder->get_stream_decoder_state();
1741
 
        printf("returned state = %u (%s)... OK\n", (unsigned)((::OggFLAC__StreamDecoderState)state__), state__.as_cstring());
1742
 
 
1743
 
        printf("testing get_FLAC_stream_decoder_state()... ");
1744
 
        FLAC::Decoder::Stream::State state___ = decoder->get_FLAC_stream_decoder_state();
1745
 
        printf("returned state = %u (%s)... OK\n", (unsigned)((::FLAC__StreamDecoderState)state___), state___.as_cstring());
1746
 
 
1747
 
        decoder->current_metadata_number_ = 0;
1748
 
        decoder->ignore_errors_ = false;
1749
 
        decoder->error_occurred_ = false;
1750
 
 
1751
 
        printf("testing get_md5_checking()... ");
1752
 
        if(!decoder->get_md5_checking()) {
1753
 
                printf("FAILED, returned false, expected true\n");
1754
 
                return false;
1755
 
        }
1756
 
        printf("OK\n");
1757
 
 
1758
 
        printf("testing process_until_end_of_metadata()... ");
1759
 
        if(!decoder->process_until_end_of_metadata())
1760
 
                return decoder->die("returned false");
1761
 
        printf("OK\n");
1762
 
 
1763
 
        printf("testing process_single()... ");
1764
 
        if(!decoder->process_single())
1765
 
                return decoder->die("returned false");
1766
 
        printf("OK\n");
1767
 
 
1768
 
        printf("testing seek_absolute()... ");
1769
 
        if(!decoder->seek_absolute(0))
1770
 
                return decoder->die("returned false");
1771
 
        printf("OK\n");
1772
 
 
1773
 
        printf("testing process_until_end_of_file()... ");
1774
 
        if(!decoder->process_until_end_of_file())
1775
 
                return decoder->die("returned false");
1776
 
        printf("OK\n");
1777
 
 
1778
 
        printf("testing get_channels()... ");
1779
 
        {
1780
 
                unsigned channels = decoder->get_channels();
1781
 
                if(channels != streaminfo_.data.stream_info.channels) {
1782
 
                        printf("FAILED, returned %u, expected %u\n", channels, streaminfo_.data.stream_info.channels);
1783
 
                        return false;
1784
 
                }
1785
 
        }
1786
 
        printf("OK\n");
1787
 
 
1788
 
        printf("testing get_bits_per_sample()... ");
1789
 
        {
1790
 
                unsigned bits_per_sample = decoder->get_bits_per_sample();
1791
 
                if(bits_per_sample != streaminfo_.data.stream_info.bits_per_sample) {
1792
 
                        printf("FAILED, returned %u, expected %u\n", bits_per_sample, streaminfo_.data.stream_info.bits_per_sample);
1793
 
                        return false;
1794
 
                }
1795
 
        }
1796
 
        printf("OK\n");
1797
 
 
1798
 
        printf("testing get_sample_rate()... ");
1799
 
        {
1800
 
                unsigned sample_rate = decoder->get_sample_rate();
1801
 
                if(sample_rate != streaminfo_.data.stream_info.sample_rate) {
1802
 
                        printf("FAILED, returned %u, expected %u\n", sample_rate, streaminfo_.data.stream_info.sample_rate);
1803
 
                        return false;
1804
 
                }
1805
 
        }
1806
 
        printf("OK\n");
1807
 
 
1808
 
        printf("testing get_blocksize()... ");
1809
 
        {
1810
 
                unsigned blocksize = decoder->get_blocksize();
1811
 
                /* value could be anything since we're at the last block, so accept any answer */
1812
 
                printf("returned %u... OK\n", blocksize);
1813
 
        }
1814
 
 
1815
 
        printf("testing get_channel_assignment()... ");
1816
 
        {
1817
 
                ::FLAC__ChannelAssignment ca = decoder->get_channel_assignment();
1818
 
                printf("returned %u (%s)... OK\n", (unsigned)ca, ::FLAC__ChannelAssignmentString[ca]);
1819
 
        }
1820
 
 
1821
 
        printf("testing finish()... ");
1822
 
        decoder->finish();
1823
 
        printf("OK\n");
1824
 
 
1825
 
        /*
1826
 
         * respond all
1827
 
         */
1828
 
 
1829
 
        printf("testing set_metadata_respond_all()... ");
1830
 
        if(!decoder->set_metadata_respond_all()) {
1831
 
                printf("FAILED, returned false\n");
1832
 
                return false;
1833
 
        }
1834
 
        printf("OK\n");
1835
 
 
1836
 
        num_expected_ = 0;
1837
 
        expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1838
 
        expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1839
 
        expected_metadata_sequence_[num_expected_++] = &padding_;
1840
 
        expected_metadata_sequence_[num_expected_++] = &seektable_;
1841
 
        expected_metadata_sequence_[num_expected_++] = &application1_;
1842
 
        expected_metadata_sequence_[num_expected_++] = &application2_;
1843
 
        expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1844
 
        expected_metadata_sequence_[num_expected_++] = &unknown_;
1845
 
 
1846
 
        if(!decoder->test_respond())
1847
 
                return false;
1848
 
 
1849
 
        /*
1850
 
         * ignore all
1851
 
         */
1852
 
 
1853
 
        printf("testing set_metadata_ignore_all()... ");
1854
 
        if(!decoder->set_metadata_ignore_all()) {
1855
 
                printf("FAILED, returned false\n");
1856
 
                return false;
1857
 
        }
1858
 
        printf("OK\n");
1859
 
 
1860
 
        num_expected_ = 0;
1861
 
 
1862
 
        if(!decoder->test_respond())
1863
 
                return false;
1864
 
 
1865
 
        /*
1866
 
         * respond all, ignore VORBIS_COMMENT
1867
 
         */
1868
 
 
1869
 
        printf("testing set_metadata_respond_all()... ");
1870
 
        if(!decoder->set_metadata_respond_all()) {
1871
 
                printf("FAILED, returned false\n");
1872
 
                return false;
1873
 
        }
1874
 
        printf("OK\n");
1875
 
 
1876
 
        printf("testing set_metadata_ignore(VORBIS_COMMENT)... ");
1877
 
        if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_VORBIS_COMMENT)) {
1878
 
                printf("FAILED, returned false\n");
1879
 
                return false;
1880
 
        }
1881
 
        printf("OK\n");
1882
 
 
1883
 
        num_expected_ = 0;
1884
 
        expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1885
 
        expected_metadata_sequence_[num_expected_++] = &padding_;
1886
 
        expected_metadata_sequence_[num_expected_++] = &seektable_;
1887
 
        expected_metadata_sequence_[num_expected_++] = &application1_;
1888
 
        expected_metadata_sequence_[num_expected_++] = &application2_;
1889
 
        expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1890
 
        expected_metadata_sequence_[num_expected_++] = &unknown_;
1891
 
 
1892
 
        if(!decoder->test_respond())
1893
 
                return false;
1894
 
 
1895
 
        /*
1896
 
         * respond all, ignore APPLICATION
1897
 
         */
1898
 
 
1899
 
        printf("testing set_metadata_respond_all()... ");
1900
 
        if(!decoder->set_metadata_respond_all()) {
1901
 
                printf("FAILED, returned false\n");
1902
 
                return false;
1903
 
        }
1904
 
        printf("OK\n");
1905
 
 
1906
 
        printf("testing set_metadata_ignore(APPLICATION)... ");
1907
 
        if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) {
1908
 
                printf("FAILED, returned false\n");
1909
 
                return false;
1910
 
        }
1911
 
        printf("OK\n");
1912
 
 
1913
 
        num_expected_ = 0;
1914
 
        expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1915
 
        expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1916
 
        expected_metadata_sequence_[num_expected_++] = &padding_;
1917
 
        expected_metadata_sequence_[num_expected_++] = &seektable_;
1918
 
        expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1919
 
        expected_metadata_sequence_[num_expected_++] = &unknown_;
1920
 
 
1921
 
        if(!decoder->test_respond())
1922
 
                return false;
1923
 
 
1924
 
        /*
1925
 
         * respond all, ignore APPLICATION id of app#1
1926
 
         */
1927
 
 
1928
 
        printf("testing set_metadata_respond_all()... ");
1929
 
        if(!decoder->set_metadata_respond_all()) {
1930
 
                printf("FAILED, returned false\n");
1931
 
                return false;
1932
 
        }
1933
 
        printf("OK\n");
1934
 
 
1935
 
        printf("testing set_metadata_ignore_application(of app block #1)... ");
1936
 
        if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
1937
 
                printf("FAILED, returned false\n");
1938
 
                return false;
1939
 
        }
1940
 
        printf("OK\n");
1941
 
 
1942
 
        num_expected_ = 0;
1943
 
        expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1944
 
        expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1945
 
        expected_metadata_sequence_[num_expected_++] = &padding_;
1946
 
        expected_metadata_sequence_[num_expected_++] = &seektable_;
1947
 
        expected_metadata_sequence_[num_expected_++] = &application2_;
1948
 
        expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1949
 
        expected_metadata_sequence_[num_expected_++] = &unknown_;
1950
 
 
1951
 
        if(!decoder->test_respond())
1952
 
                return false;
1953
 
 
1954
 
        /*
1955
 
         * respond all, ignore APPLICATION id of app#1 & app#2
1956
 
         */
1957
 
 
1958
 
        printf("testing set_metadata_respond_all()... ");
1959
 
        if(!decoder->set_metadata_respond_all()) {
1960
 
                printf("FAILED, returned false\n");
1961
 
                return false;
1962
 
        }
1963
 
        printf("OK\n");
1964
 
 
1965
 
        printf("testing set_metadata_ignore_application(of app block #1)... ");
1966
 
        if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
1967
 
                printf("FAILED, returned false\n");
1968
 
                return false;
1969
 
        }
1970
 
        printf("OK\n");
1971
 
 
1972
 
        printf("testing set_metadata_ignore_application(of app block #2)... ");
1973
 
        if(!decoder->set_metadata_ignore_application(application2_.data.application.id)) {
1974
 
                printf("FAILED, returned false\n");
1975
 
                return false;
1976
 
        }
1977
 
        printf("OK\n");
1978
 
 
1979
 
        num_expected_ = 0;
1980
 
        expected_metadata_sequence_[num_expected_++] = &streaminfo_;
1981
 
        expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
1982
 
        expected_metadata_sequence_[num_expected_++] = &padding_;
1983
 
        expected_metadata_sequence_[num_expected_++] = &seektable_;
1984
 
        expected_metadata_sequence_[num_expected_++] = &cuesheet_;
1985
 
        expected_metadata_sequence_[num_expected_++] = &unknown_;
1986
 
 
1987
 
        if(!decoder->test_respond())
1988
 
                return false;
1989
 
 
1990
 
        /*
1991
 
         * ignore all, respond VORBIS_COMMENT
1992
 
         */
1993
 
 
1994
 
        printf("testing set_metadata_ignore_all()... ");
1995
 
        if(!decoder->set_metadata_ignore_all()) {
1996
 
                printf("FAILED, returned false\n");
1997
 
                return false;
1998
 
        }
1999
 
        printf("OK\n");
2000
 
 
2001
 
        printf("testing set_metadata_respond(VORBIS_COMMENT)... ");
2002
 
        if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_VORBIS_COMMENT)) {
2003
 
                printf("FAILED, returned false\n");
2004
 
                return false;
2005
 
        }
2006
 
        printf("OK\n");
2007
 
 
2008
 
        num_expected_ = 0;
2009
 
        expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
2010
 
 
2011
 
        if(!decoder->test_respond())
2012
 
                return false;
2013
 
 
2014
 
        /*
2015
 
         * ignore all, respond APPLICATION
2016
 
         */
2017
 
 
2018
 
        printf("testing set_metadata_ignore_all()... ");
2019
 
        if(!decoder->set_metadata_ignore_all()) {
2020
 
                printf("FAILED, returned false\n");
2021
 
                return false;
2022
 
        }
2023
 
        printf("OK\n");
2024
 
 
2025
 
        printf("testing set_metadata_respond(APPLICATION)... ");
2026
 
        if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) {
2027
 
                printf("FAILED, returned false\n");
2028
 
                return false;
2029
 
        }
2030
 
        printf("OK\n");
2031
 
 
2032
 
        num_expected_ = 0;
2033
 
        expected_metadata_sequence_[num_expected_++] = &application1_;
2034
 
        expected_metadata_sequence_[num_expected_++] = &application2_;
2035
 
 
2036
 
        if(!decoder->test_respond())
2037
 
                return false;
2038
 
 
2039
 
        /*
2040
 
         * ignore all, respond APPLICATION id of app#1
2041
 
         */
2042
 
 
2043
 
        printf("testing set_metadata_ignore_all()... ");
2044
 
        if(!decoder->set_metadata_ignore_all()) {
2045
 
                printf("FAILED, returned false\n");
2046
 
                return false;
2047
 
        }
2048
 
        printf("OK\n");
2049
 
 
2050
 
        printf("testing set_metadata_respond_application(of app block #1)... ");
2051
 
        if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
2052
 
                printf("FAILED, returned false\n");
2053
 
                return false;
2054
 
        }
2055
 
        printf("OK\n");
2056
 
 
2057
 
        num_expected_ = 0;
2058
 
        expected_metadata_sequence_[num_expected_++] = &application1_;
2059
 
 
2060
 
        if(!decoder->test_respond())
2061
 
                return false;
2062
 
 
2063
 
        /*
2064
 
         * ignore all, respond APPLICATION id of app#1 & app#2
2065
 
         */
2066
 
 
2067
 
        printf("testing set_metadata_ignore_all()... ");
2068
 
        if(!decoder->set_metadata_ignore_all()) {
2069
 
                printf("FAILED, returned false\n");
2070
 
                return false;
2071
 
        }
2072
 
        printf("OK\n");
2073
 
 
2074
 
        printf("testing set_metadata_respond_application(of app block #1)... ");
2075
 
        if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
2076
 
                printf("FAILED, returned false\n");
2077
 
                return false;
2078
 
        }
2079
 
        printf("OK\n");
2080
 
 
2081
 
        printf("testing set_metadata_respond_application(of app block #2)... ");
2082
 
        if(!decoder->set_metadata_respond_application(application2_.data.application.id)) {
2083
 
                printf("FAILED, returned false\n");
2084
 
                return false;
2085
 
        }
2086
 
        printf("OK\n");
2087
 
 
2088
 
        num_expected_ = 0;
2089
 
        expected_metadata_sequence_[num_expected_++] = &application1_;
2090
 
        expected_metadata_sequence_[num_expected_++] = &application2_;
2091
 
 
2092
 
        if(!decoder->test_respond())
2093
 
                return false;
2094
 
 
2095
 
        /*
2096
 
         * respond all, ignore APPLICATION, respond APPLICATION id of app#1
2097
 
         */
2098
 
 
2099
 
        printf("testing set_metadata_respond_all()... ");
2100
 
        if(!decoder->set_metadata_respond_all()) {
2101
 
                printf("FAILED, returned false\n");
2102
 
                return false;
2103
 
        }
2104
 
        printf("OK\n");
2105
 
 
2106
 
        printf("testing set_metadata_ignore(APPLICATION)... ");
2107
 
        if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) {
2108
 
                printf("FAILED, returned false\n");
2109
 
                return false;
2110
 
        }
2111
 
        printf("OK\n");
2112
 
 
2113
 
        printf("testing set_metadata_respond_application(of app block #1)... ");
2114
 
        if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
2115
 
                printf("FAILED, returned false\n");
2116
 
                return false;
2117
 
        }
2118
 
        printf("OK\n");
2119
 
 
2120
 
        num_expected_ = 0;
2121
 
        expected_metadata_sequence_[num_expected_++] = &streaminfo_;
2122
 
        expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
2123
 
        expected_metadata_sequence_[num_expected_++] = &padding_;
2124
 
        expected_metadata_sequence_[num_expected_++] = &seektable_;
2125
 
        expected_metadata_sequence_[num_expected_++] = &application1_;
2126
 
        expected_metadata_sequence_[num_expected_++] = &cuesheet_;
2127
 
        expected_metadata_sequence_[num_expected_++] = &unknown_;
2128
 
 
2129
 
        if(!decoder->test_respond())
2130
 
                return false;
2131
 
 
2132
 
        /*
2133
 
         * ignore all, respond APPLICATION, ignore APPLICATION id of app#1
2134
 
         */
2135
 
 
2136
 
        printf("testing set_metadata_ignore_all()... ");
2137
 
        if(!decoder->set_metadata_ignore_all()) {
2138
 
                printf("FAILED, returned false\n");
2139
 
                return false;
2140
 
        }
2141
 
        printf("OK\n");
2142
 
 
2143
 
        printf("testing set_metadata_respond(APPLICATION)... ");
2144
 
        if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) {
2145
 
                printf("FAILED, returned false\n");
2146
 
                return false;
2147
 
        }
2148
 
        printf("OK\n");
2149
 
 
2150
 
        printf("testing set_metadata_ignore_application(of app block #1)... ");
2151
 
        if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
2152
 
                printf("FAILED, returned false\n");
2153
 
                return false;
2154
 
        }
2155
 
        printf("OK\n");
2156
 
 
2157
 
        num_expected_ = 0;
2158
 
        expected_metadata_sequence_[num_expected_++] = &application2_;
2159
 
 
2160
 
        if(!decoder->test_respond())
2161
 
                return false;
2162
 
 
2163
 
        /* done, now leave the sequence the way we found it... */
2164
 
        num_expected_ = 0;
2165
 
        expected_metadata_sequence_[num_expected_++] = &streaminfo_;
2166
 
        expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
2167
 
        expected_metadata_sequence_[num_expected_++] = &padding_;
2168
 
        expected_metadata_sequence_[num_expected_++] = &seektable_;
2169
 
        expected_metadata_sequence_[num_expected_++] = &application1_;
2170
 
        expected_metadata_sequence_[num_expected_++] = &application2_;
2171
 
        expected_metadata_sequence_[num_expected_++] = &cuesheet_;
2172
 
        expected_metadata_sequence_[num_expected_++] = &unknown_;
2173
 
 
2174
 
        printf("freeing decoder instance... ");
2175
 
        delete decoder;
2176
 
        printf("OK\n");
2177
 
 
2178
 
        printf("\nPASSED!\n");
2179
 
 
2180
 
        return true;
2181
 
}
2182
 
 
2183
 
bool test_decoders()
2184
 
{
2185
 
        init_metadata_blocks_();
2186
 
 
2187
 
        if(!generate_file_())
2188
 
                return false;
2189
 
 
2190
 
        if(!test_stream_decoder())
2191
 
                return false;
2192
 
 
2193
 
        if(!test_seekable_stream_decoder())
2194
 
                return false;
2195
 
 
2196
 
        if(!test_file_decoder())
2197
 
                return false;
2198
 
 
2199
 
        (void) grabbag__file_remove_file(oggflacfilename_);
2200
 
 
2201
 
        free_metadata_blocks_();
2202
 
 
2203
 
        return true;
2204
 
}