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

« back to all changes in this revision

Viewing changes to src/test_libFLAC++/metadata_manip.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
1
/* test_libFLAC++ - Unit tester for libFLAC++
2
 
 * Copyright (C) 2002,2003,2004,2005  Josh Coalson
 
2
 * Copyright (C) 2002,2003,2004,2005,2006,2007  Josh Coalson
3
3
 *
4
4
 * This program is free software; you can redistribute it and/or
5
5
 * modify it under the terms of the GNU General Public License
16
16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17
17
 */
18
18
 
19
 
extern "C" {
20
 
#include "file_utils.h"
21
 
}
22
 
#include "FLAC/assert.h"
23
 
#include "FLAC++/decoder.h"
24
 
#include "FLAC++/metadata.h"
25
 
#include "share/grabbag.h"
 
19
#if HAVE_CONFIG_H
 
20
#  include <config.h>
 
21
#endif
 
22
 
26
23
#include <stdio.h>
27
24
#include <stdlib.h> /* for malloc() */
28
25
#include <string.h> /* for memcpy()/memset() */
29
 
 
30
26
#if defined _MSC_VER || defined __MINGW32__
31
27
#include <sys/utime.h> /* for utime() */
32
28
#include <io.h> /* for chmod() */
 
29
#if _MSC_VER <= 1600 /* @@@ [2G limit] */
 
30
#define fseeko fseek
 
31
#define ftello ftell
 
32
#endif
33
33
#else
34
34
#include <sys/types.h> /* some flavors of BSD (like OS X) require this to get time_t */
35
35
#include <utime.h> /* for utime() */
36
36
#include <unistd.h> /* for chown(), unlink() */
37
37
#endif
38
38
#include <sys/stat.h> /* for stat(), maybe chmod() */
 
39
#include "FLAC/assert.h"
 
40
#include "FLAC++/decoder.h"
 
41
#include "FLAC++/metadata.h"
 
42
#include "share/grabbag.h"
 
43
extern "C" {
 
44
#include "test_libs_common/file_utils_flac.h"
 
45
}
39
46
 
40
47
/******************************************************************************
41
48
        The general strategy of these tests (for interface levels 1 and 2) is
65
72
        unsigned num_blocks;
66
73
};
67
74
 
68
 
static const char *flacfile_ = "metadata.flac";
69
 
 
70
 
/* our copy of the metadata in flacfile_ */
 
75
/* our copy of the metadata in flacfilename() */
71
76
static OurMetadata our_metadata_;
72
77
 
73
78
/* the current block number that corresponds to the position of the iterator we are testing */
74
79
static unsigned mc_our_block_number_ = 0;
75
80
 
 
81
static const char *flacfilename(bool is_ogg)
 
82
{
 
83
        return is_ogg? "metadata.ogg" : "metadata.flac";
 
84
}
 
85
 
76
86
static bool die_(const char *msg)
77
87
{
78
88
        printf("ERROR: %s\n", msg);
104
114
        return x;
105
115
}
106
116
 
 
117
static char *strdup_or_die_(const char *s)
 
118
{
 
119
        char *x = strdup(s);
 
120
        if(0 == x) {
 
121
                fprintf(stderr, "ERROR: out of memory copying string \"%s\"\n", s);
 
122
                exit(1);
 
123
        }
 
124
        return x;
 
125
}
 
126
 
107
127
/* functions for working with our metadata copy */
108
128
 
109
129
static bool replace_in_our_metadata_(FLAC::Metadata::Prototype *block, unsigned position, bool copy)
221
241
                *tempfile = 0;
222
242
        }
223
243
 
224
 
#if defined _MSC_VER || defined __MINGW32__
 
244
#if defined _MSC_VER || defined __MINGW32__ || defined __EMX__
 
245
        /* on some flavors of windows, rename() will fail if the destination already exists */
225
246
        if(unlink(filename) < 0) {
226
247
                cleanup_tempfile_(tempfile, tempfilename);
227
248
                return false;
256
277
        srctime.modtime = stats->st_mtime;
257
278
        (void)chmod(filename, stats->st_mode);
258
279
        (void)utime(filename, &srctime);
259
 
#if !defined _MSC_VER && !defined __MINGW32__
 
280
#if !defined _MSC_VER && !defined __MINGW32__ && !defined __EMX__
260
281
        (void)chown(filename, stats->st_uid, (gid_t)(-1));
261
282
        (void)chown(filename, (uid_t)(-1), stats->st_gid);
262
283
#endif
275
296
 
276
297
static int chain_seek_cb_(::FLAC__IOHandle handle, FLAC__int64 offset, int whence)
277
298
{
278
 
        long o = (long)offset;
 
299
        off_t o = (off_t)offset;
279
300
        FLAC__ASSERT(offset == o);
280
 
        return fseek((FILE*)handle, o, whence);
 
301
        return fseeko((FILE*)handle, o, whence);
281
302
}
282
303
 
283
304
static FLAC__int64 chain_tell_cb_(::FLAC__IOHandle handle)
284
305
{
285
 
        return ftell((FILE*)handle);
 
306
        return ftello((FILE*)handle);
286
307
}
287
308
 
288
309
static int chain_eof_cb_(::FLAC__IOHandle handle)
316
337
                                        return false;
317
338
                        }
318
339
                        if(0 == (file = fopen(filename, "rb")))
319
 
                                return false; /*@@@ chain status still says OK though */
 
340
                                return false; /*@@@@ chain status still says OK though */
320
341
                        if(!open_tempfile_(filename, &tempfile, &tempfilename)) {
321
342
                                fclose(file);
322
343
                                cleanup_tempfile_(&tempfile, &tempfilename);
323
 
                                return false; /*@@@ chain status still says OK though */
 
344
                                return false; /*@@@@ chain status still says OK though */
324
345
                        }
325
346
                        if(!chain.write(use_padding, (::FLAC__IOHandle)file, callbacks, (::FLAC__IOHandle)tempfile, callbacks)) {
326
347
                                fclose(file);
338
359
                else {
339
360
                        FILE *file = fopen(filename, "r+b");
340
361
                        if(0 == file)
341
 
                                return false; /*@@@ chain status still says OK though */
 
362
                                return false; /*@@@@ chain status still says OK though */
342
363
                        if(!chain.write(use_padding, (::FLAC__IOHandle)file, callbacks))
343
364
                                return false;
344
365
                        fclose(file);
348
369
        return true;
349
370
}
350
371
 
351
 
static bool read_chain_(FLAC::Metadata::Chain &chain, const char *filename, bool filename_based)
 
372
static bool read_chain_(FLAC::Metadata::Chain &chain, const char *filename, bool filename_based, bool is_ogg)
352
373
{
353
374
        if(filename_based)
354
 
                return chain.read(filename);
 
375
                return chain.read(filename, is_ogg);
355
376
        else {
356
377
                ::FLAC__IOCallbacks callbacks;
357
378
 
364
385
                        bool ret;
365
386
                        FILE *file = fopen(filename, "rb");
366
387
                        if(0 == file)
367
 
                                return false; /*@@@ chain status still says OK though */
368
 
                        ret = chain.read((::FLAC__IOHandle)file, callbacks);
 
388
                                return false; /*@@@@ chain status still says OK though */
 
389
                        ret = chain.read((::FLAC__IOHandle)file, callbacks, is_ogg);
369
390
                        fclose(file);
370
391
                        return ret;
371
392
                }
471
492
        printf("ERROR: got error callback, status = %s (%u)\n", FLAC__StreamDecoderErrorStatusString[status], (unsigned)status);
472
493
}
473
494
 
474
 
static bool generate_file_()
 
495
static bool generate_file_(bool include_extras, bool is_ogg)
475
496
{
476
 
        ::FLAC__StreamMetadata streaminfo, vorbiscomment, padding;
477
 
        ::FLAC__StreamMetadata *metadata[1];
 
497
        ::FLAC__StreamMetadata streaminfo, vorbiscomment, *cuesheet, picture, padding;
 
498
        ::FLAC__StreamMetadata *metadata[4];
 
499
        unsigned i = 0, n = 0;
478
500
 
479
 
        printf("generating FLAC file for test\n");
 
501
        printf("generating %sFLAC file for test\n", is_ogg? "Ogg " : "");
480
502
 
481
503
        while(our_metadata_.num_blocks > 0)
482
504
                delete_from_our_metadata_(0);
497
519
        {
498
520
                const unsigned vendor_string_length = (unsigned)strlen(FLAC__VENDOR_STRING);
499
521
                vorbiscomment.is_last = false;
500
 
                vorbiscomment.type = FLAC__METADATA_TYPE_VORBIS_COMMENT;
 
522
                vorbiscomment.type = ::FLAC__METADATA_TYPE_VORBIS_COMMENT;
501
523
                vorbiscomment.length = (4 + vendor_string_length) + 4;
502
524
                vorbiscomment.data.vorbis_comment.vendor_string.length = vendor_string_length;
503
525
                vorbiscomment.data.vorbis_comment.vendor_string.entry = (FLAC__byte*)malloc_or_die_(vendor_string_length+1);
506
528
                vorbiscomment.data.vorbis_comment.comments = 0;
507
529
        }
508
530
 
 
531
        {
 
532
                if (0 == (cuesheet = ::FLAC__metadata_object_new(::FLAC__METADATA_TYPE_CUESHEET)))
 
533
                        return die_("priming our metadata");
 
534
                cuesheet->is_last = false;
 
535
                strcpy(cuesheet->data.cue_sheet.media_catalog_number, "bogo-MCN");
 
536
                cuesheet->data.cue_sheet.lead_in = 123;
 
537
                cuesheet->data.cue_sheet.is_cd = false;
 
538
                if (!FLAC__metadata_object_cuesheet_insert_blank_track(cuesheet, 0))
 
539
                        return die_("priming our metadata");
 
540
                cuesheet->data.cue_sheet.tracks[0].number = 1;
 
541
                if (!FLAC__metadata_object_cuesheet_track_insert_blank_index(cuesheet, 0, 0))
 
542
                        return die_("priming our metadata");
 
543
        }
 
544
 
 
545
        {
 
546
                picture.is_last = false;
 
547
                picture.type = ::FLAC__METADATA_TYPE_PICTURE;
 
548
                picture.length =
 
549
                        (
 
550
                                FLAC__STREAM_METADATA_PICTURE_TYPE_LEN +
 
551
                                FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN + /* will add the length for the string later */
 
552
                                FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN + /* will add the length for the string later */
 
553
                                FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN +
 
554
                                FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN +
 
555
                                FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN +
 
556
                                FLAC__STREAM_METADATA_PICTURE_COLORS_LEN +
 
557
                                FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN /* will add the length for the data later */
 
558
                        ) / 8
 
559
                ;
 
560
                picture.data.picture.type = ::FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER;
 
561
                picture.data.picture.mime_type = strdup_or_die_("image/jpeg");
 
562
                picture.length += strlen(picture.data.picture.mime_type);
 
563
                picture.data.picture.description = (FLAC__byte*)strdup_or_die_("desc");
 
564
                picture.length += strlen((const char *)picture.data.picture.description);
 
565
                picture.data.picture.width = 300;
 
566
                picture.data.picture.height = 300;
 
567
                picture.data.picture.depth = 24;
 
568
                picture.data.picture.colors = 0;
 
569
                picture.data.picture.data = (FLAC__byte*)strdup_or_die_("SOMEJPEGDATA");
 
570
                picture.data.picture.data_length = strlen((const char *)picture.data.picture.data);
 
571
                picture.length += picture.data.picture.data_length;
 
572
        }
 
573
 
509
574
        padding.is_last = true;
510
575
        padding.type = ::FLAC__METADATA_TYPE_PADDING;
511
576
        padding.length = 1234;
512
577
 
513
 
        metadata[0] = &padding;
 
578
        metadata[n++] = &vorbiscomment;
 
579
        if(include_extras) {
 
580
                metadata[n++] = cuesheet;
 
581
                metadata[n++] = &picture;
 
582
        }
 
583
        metadata[n++] = &padding;
514
584
 
515
585
        FLAC::Metadata::StreamInfo s(&streaminfo);
516
586
        FLAC::Metadata::VorbisComment v(&vorbiscomment);
 
587
        FLAC::Metadata::CueSheet c(cuesheet, /*copy=*/false);
 
588
        FLAC::Metadata::Picture pi(&picture);
517
589
        FLAC::Metadata::Padding p(&padding);
518
590
        if(
519
 
                !insert_to_our_metadata_(&s, 0, /*copy=*/true) ||
520
 
                !insert_to_our_metadata_(&v, 1, /*copy=*/true) ||
521
 
                !insert_to_our_metadata_(&p, 2, /*copy=*/true)
 
591
                !insert_to_our_metadata_(&s, i++, /*copy=*/true) ||
 
592
                !insert_to_our_metadata_(&v, i++, /*copy=*/true) ||
 
593
                (include_extras && !insert_to_our_metadata_(&c, i++, /*copy=*/true)) ||
 
594
                (include_extras && !insert_to_our_metadata_(&pi, i++, /*copy=*/true)) ||
 
595
                !insert_to_our_metadata_(&p, i++, /*copy=*/true)
522
596
        )
523
597
                return die_("priming our metadata");
524
598
 
525
 
        if(!file_utils__generate_flacfile(flacfile_, 0, 512 * 1024, &streaminfo, metadata, 1))
 
599
        if(!file_utils__generate_flacfile(is_ogg, flacfilename(is_ogg), 0, 512 * 1024, &streaminfo, metadata, n))
526
600
                return die_("creating the encoded file");
527
601
 
528
602
        free(vorbiscomment.data.vorbis_comment.vendor_string.entry);
 
603
        free(picture.data.picture.mime_type);
 
604
        free(picture.data.picture.description);
 
605
        free(picture.data.picture.data);
529
606
 
530
607
        return true;
531
608
}
532
609
 
533
 
static bool test_file_(const char *filename, bool ignore_metadata)
 
610
static bool test_file_(bool is_ogg, bool ignore_metadata)
534
611
{
 
612
        const char *filename = flacfilename(is_ogg);
535
613
        OurFileDecoder decoder(ignore_metadata);
536
614
 
537
 
        FLAC__ASSERT(0 != filename);
538
 
 
539
615
        mc_our_block_number_ = 0;
540
616
        decoder.error_occurred_ = false;
541
617
 
546
622
                return die_("couldn't allocate decoder instance");
547
623
 
548
624
        decoder.set_md5_checking(true);
549
 
        decoder.set_filename(filename);
550
625
        decoder.set_metadata_respond_all();
551
 
        if(decoder.init() != ::FLAC__FILE_DECODER_OK) {
552
 
                decoder.finish();
 
626
        if((is_ogg? decoder.init_ogg(filename) : decoder.init(filename)) != ::FLAC__STREAM_DECODER_INIT_STATUS_OK) {
 
627
                (void)decoder.finish();
553
628
                return die_("initializing decoder\n");
554
629
        }
555
 
        if(!decoder.process_until_end_of_file()) {
556
 
                decoder.finish();
 
630
        if(!decoder.process_until_end_of_stream()) {
 
631
                (void)decoder.finish();
557
632
                return die_("decoding file\n");
558
633
        }
559
634
 
560
 
        decoder.finish();
 
635
        (void)decoder.finish();
561
636
 
562
637
        if(decoder.error_occurred_)
563
638
                return false;
594
669
 
595
670
        printf("\n\n++++++ testing level 0 interface\n");
596
671
 
597
 
        if(!generate_file_())
 
672
        if(!generate_file_(/*include_extras=*/true, /*is_ogg=*/false))
598
673
                return false;
599
674
 
600
 
        if(!test_file_(flacfile_, /*ignore_metadata=*/true))
 
675
        if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/true))
601
676
                return false;
602
677
 
603
678
        printf("testing FLAC::Metadata::get_streaminfo()... ");
604
679
 
605
 
        if(!FLAC::Metadata::get_streaminfo(flacfile_, streaminfo))
 
680
        if(!FLAC::Metadata::get_streaminfo(flacfilename(/*is_ogg=*/false), streaminfo))
606
681
                return die_("during FLAC::Metadata::get_streaminfo()");
607
682
 
608
683
        /* check to see if some basic data matches (c.f. generate_file_()) */
624
699
 
625
700
                FLAC::Metadata::VorbisComment *tags = 0;
626
701
 
627
 
                if(!FLAC::Metadata::get_tags(flacfile_, tags))
 
702
                if(!FLAC::Metadata::get_tags(flacfilename(/*is_ogg=*/false), tags))
628
703
                        return die_("during FLAC::Metadata::get_tags()");
629
704
 
630
705
                /* check to see if some basic data matches (c.f. generate_file_()) */
641
716
 
642
717
                FLAC::Metadata::VorbisComment tags;
643
718
 
644
 
                if(!FLAC::Metadata::get_tags(flacfile_, tags))
 
719
                if(!FLAC::Metadata::get_tags(flacfilename(/*is_ogg=*/false), tags))
645
720
                        return die_("during FLAC::Metadata::get_tags()");
646
721
 
647
722
                /* check to see if some basic data matches (c.f. generate_file_()) */
651
726
                printf("OK\n");
652
727
        }
653
728
 
654
 
        if(!remove_file_(flacfile_))
 
729
        {
 
730
                printf("testing FLAC::Metadata::get_cuesheet(CueSheet *&)... ");
 
731
 
 
732
                FLAC::Metadata::CueSheet *cuesheet = 0;
 
733
 
 
734
                if(!FLAC::Metadata::get_cuesheet(flacfilename(/*is_ogg=*/false), cuesheet))
 
735
                        return die_("during FLAC::Metadata::get_cuesheet()");
 
736
 
 
737
                /* check to see if some basic data matches (c.f. generate_file_()) */
 
738
                if(cuesheet->get_lead_in() != 123)
 
739
                        return die_("mismatch in cuesheet->get_lead_in()");
 
740
 
 
741
                printf("OK\n");
 
742
 
 
743
                delete cuesheet;
 
744
        }
 
745
 
 
746
        {
 
747
                printf("testing FLAC::Metadata::get_cuesheet(CueSheet &)... ");
 
748
 
 
749
                FLAC::Metadata::CueSheet cuesheet;
 
750
 
 
751
                if(!FLAC::Metadata::get_cuesheet(flacfilename(/*is_ogg=*/false), cuesheet))
 
752
                        return die_("during FLAC::Metadata::get_cuesheet()");
 
753
 
 
754
                /* check to see if some basic data matches (c.f. generate_file_()) */
 
755
                if(cuesheet.get_lead_in() != 123)
 
756
                        return die_("mismatch in cuesheet.get_lead_in()");
 
757
 
 
758
                printf("OK\n");
 
759
        }
 
760
 
 
761
        {
 
762
                printf("testing FLAC::Metadata::get_picture(Picture *&)... ");
 
763
 
 
764
                FLAC::Metadata::Picture *picture = 0;
 
765
 
 
766
                if(!FLAC::Metadata::get_picture(flacfilename(/*is_ogg=*/false), picture, /*type=*/(::FLAC__StreamMetadata_Picture_Type)(-1), /*mime_type=*/0, /*description=*/0, /*max_width=*/(unsigned)(-1), /*max_height=*/(unsigned)(-1), /*max_depth=*/(unsigned)(-1), /*max_colors=*/(unsigned)(-1)))
 
767
                        return die_("during FLAC::Metadata::get_picture()");
 
768
 
 
769
                /* check to see if some basic data matches (c.f. generate_file_()) */
 
770
                if(picture->get_type () != ::FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER)
 
771
                        return die_("mismatch in picture->get_type ()");
 
772
 
 
773
                printf("OK\n");
 
774
 
 
775
                delete picture;
 
776
        }
 
777
 
 
778
        {
 
779
                printf("testing FLAC::Metadata::get_picture(Picture &)... ");
 
780
 
 
781
                FLAC::Metadata::Picture picture;
 
782
 
 
783
                if(!FLAC::Metadata::get_picture(flacfilename(/*is_ogg=*/false), picture, /*type=*/(::FLAC__StreamMetadata_Picture_Type)(-1), /*mime_type=*/0, /*description=*/0, /*max_width=*/(unsigned)(-1), /*max_height=*/(unsigned)(-1), /*max_depth=*/(unsigned)(-1), /*max_colors=*/(unsigned)(-1)))
 
784
                        return die_("during FLAC::Metadata::get_picture()");
 
785
 
 
786
                /* check to see if some basic data matches (c.f. generate_file_()) */
 
787
                if(picture.get_type () != ::FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER)
 
788
                        return die_("mismatch in picture->get_type ()");
 
789
 
 
790
                printf("OK\n");
 
791
        }
 
792
 
 
793
        if(!remove_file_(flacfilename(/*is_ogg=*/false)))
655
794
                return false;
656
795
 
657
796
        return true;
675
814
        {
676
815
        printf("simple iterator on read-only file\n");
677
816
 
678
 
        if(!generate_file_())
679
 
                return false;
680
 
 
681
 
        if(!change_stats_(flacfile_, /*read_only=*/true))
682
 
                return false;
683
 
 
684
 
        if(!test_file_(flacfile_, /*ignore_metadata=*/true))
 
817
        if(!generate_file_(/*include_extras=*/false, /*is_ogg=*/false))
 
818
                return false;
 
819
 
 
820
        if(!change_stats_(flacfilename(/*is_ogg=*/false), /*read_only=*/true))
 
821
                return false;
 
822
 
 
823
        if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/true))
685
824
                return false;
686
825
 
687
826
        FLAC::Metadata::SimpleIterator iterator;
689
828
        if(!iterator.is_valid())
690
829
                return die_("iterator.is_valid() returned false");
691
830
 
692
 
        if(!iterator.init(flacfile_, /*read_only=*/false, /*preserve_file_stats=*/false))
 
831
        if(!iterator.init(flacfilename(/*is_ogg=*/false), /*read_only=*/false, /*preserve_file_stats=*/false))
693
832
                return die_("iterator.init() returned false");
694
833
 
695
834
        printf("is writable = %u\n", (unsigned)iterator.is_writable());
768
907
        {
769
908
        printf("simple iterator on writable file\n");
770
909
 
771
 
        if(!change_stats_(flacfile_, /*read-only=*/false))
 
910
        if(!change_stats_(flacfilename(/*is_ogg=*/false), /*read-only=*/false))
772
911
                return false;
773
912
 
774
913
        printf("creating APPLICATION block\n");
788
927
        if(!iterator.is_valid())
789
928
                return die_("iterator.is_valid() returned false");
790
929
 
791
 
        if(!iterator.init(flacfile_, /*read_only=*/false, /*preserve_file_stats=*/false))
 
930
        if(!iterator.init(flacfilename(/*is_ogg=*/false), /*read_only=*/false, /*preserve_file_stats=*/false))
792
931
                return die_("iterator.init() returned false");
793
932
        our_current_position = 0;
794
933
 
834
973
        if(!insert_to_our_metadata_(padding, ++our_current_position, /*copy=*/true))
835
974
                return false;
836
975
 
837
 
        if(!test_file_(flacfile_, /*ignore_metadata=*/false))
 
976
        if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
838
977
                return false;
839
978
 
840
979
        printf("SV[P]PP\tprev\n");
851
990
        if(iterator.delete_block(false))
852
991
                return die_ss_("iterator.delete_block(false) should have returned false", iterator);
853
992
 
854
 
        if(!test_file_(flacfile_, /*ignore_metadata=*/false))
 
993
        if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
855
994
                return false;
856
995
 
857
996
        printf("[S]VPPP\tnext\n");
879
1018
                return die_ss_("iterator.delete_block(false)", iterator);
880
1019
        delete_from_our_metadata_(our_current_position--);
881
1020
 
882
 
        if(!test_file_(flacfile_, /*ignore_metadata=*/false))
 
1021
        if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
883
1022
                return false;
884
1023
 
885
1024
        printf("S[V]PP\tnext\n");
897
1036
                return die_ss_("iterator.delete_block(false)", iterator);
898
1037
        our_current_position--;
899
1038
 
900
 
        if(!test_file_(flacfile_, /*ignore_metadata=*/false))
 
1039
        if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
901
1040
                return false;
902
1041
 
903
1042
        printf("SV[P]P\tnext\n");
910
1049
                return die_ss_("iterator.delete_block(false)", iterator);
911
1050
        delete_from_our_metadata_(our_current_position--);
912
1051
 
913
 
        if(!test_file_(flacfile_, /*ignore_metadata=*/false))
 
1052
        if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
914
1053
                return false;
915
1054
 
916
1055
        printf("SV[P]\tprev\n");
935
1074
                return die_ss_("iterator.set_block(block, false)", iterator);
936
1075
        delete block;
937
1076
 
938
 
        if(!test_file_(flacfile_, /*ignore_metadata=*/false))
 
1077
        if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
939
1078
                return false;
940
1079
 
941
1080
        printf("[S]VP\tnext\n");
951
1090
                return false;
952
1091
        add_to_padding_length_(our_current_position+1, -((int)(FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) + (int)app->get_length()));
953
1092
 
954
 
        if(!test_file_(flacfile_, /*ignore_metadata=*/false))
 
1093
        if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
955
1094
                return false;
956
1095
 
957
1096
        printf("SV[A]P\tnext\n");
967
1106
                return false;
968
1107
        add_to_padding_length_(our_current_position+1, -((int)(FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) + (int)app->get_length()));
969
1108
 
970
 
        if(!test_file_(flacfile_, /*ignore_metadata=*/false))
 
1109
        if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
971
1110
                return false;
972
1111
 
973
1112
        printf("SVA[A]P\tset APPLICATION (grow), don't expand into padding\n");
979
1118
        if(!iterator.set_block(app, false))
980
1119
                return die_ss_("iterator.set_block(app, false)", iterator);
981
1120
 
982
 
        if(!test_file_(flacfile_, /*ignore_metadata=*/false))
 
1121
        if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
983
1122
                return false;
984
1123
 
985
1124
        printf("SVA[A]P\tset APPLICATION (shrink), don't fill in with padding\n");
991
1130
        if(!iterator.set_block(app, false))
992
1131
                return die_ss_("iterator.set_block(app, false)", iterator);
993
1132
 
994
 
        if(!test_file_(flacfile_, /*ignore_metadata=*/false))
 
1133
        if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
995
1134
                return false;
996
1135
 
997
1136
        printf("SVA[A]P\tset APPLICATION (grow), expand into padding of exceeding size\n");
1004
1143
        if(!iterator.set_block(app, true))
1005
1144
                return die_ss_("iterator.set_block(app, true)", iterator);
1006
1145
 
1007
 
        if(!test_file_(flacfile_, /*ignore_metadata=*/false))
 
1146
        if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
1008
1147
                return false;
1009
1148
 
1010
1149
        printf("SVA[A]P\tset APPLICATION (shrink), fill in with padding\n");
1019
1158
        if(!iterator.set_block(app, true))
1020
1159
                return die_ss_("iterator.set_block(app, true)", iterator);
1021
1160
 
1022
 
        if(!test_file_(flacfile_, /*ignore_metadata=*/false))
 
1161
        if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
1023
1162
                return false;
1024
1163
 
1025
1164
        printf("SVA[A]PP\tnext\n");
1039
1178
        if(!iterator.set_block(padding, false))
1040
1179
                return die_ss_("iterator.set_block(padding, false)", iterator);
1041
1180
 
1042
 
        if(!test_file_(flacfile_, /*ignore_metadata=*/false))
 
1181
        if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
1043
1182
                return false;
1044
1183
 
1045
1184
        printf("SVAAP[P]\tset APPLICATION (grow)\n");
1049
1188
        if(!iterator.set_block(app, false))
1050
1189
                return die_ss_("iterator.set_block(app, false)", iterator);
1051
1190
 
1052
 
        if(!test_file_(flacfile_, /*ignore_metadata=*/false))
 
1191
        if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
1053
1192
                return false;
1054
1193
 
1055
1194
        printf("SVAAP[A]\tset PADDING (equal)\n");
1059
1198
        if(!iterator.set_block(padding, false))
1060
1199
                return die_ss_("iterator.set_block(padding, false)", iterator);
1061
1200
 
1062
 
        if(!test_file_(flacfile_, /*ignore_metadata=*/false))
 
1201
        if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
1063
1202
                return false;
1064
1203
 
1065
1204
        printf("SVAAP[P]\tprev\n");
1072
1211
                return die_ss_("iterator.delete_block(false)", iterator);
1073
1212
        delete_from_our_metadata_(our_current_position--);
1074
1213
 
1075
 
        if(!test_file_(flacfile_, /*ignore_metadata=*/false))
 
1214
        if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
1076
1215
                return false;
1077
1216
 
1078
1217
        printf("SVA[A]P\tdelete (middle block), don't replace with padding\n");
1080
1219
                return die_ss_("iterator.delete_block(false)", iterator);
1081
1220
        delete_from_our_metadata_(our_current_position--);
1082
1221
 
1083
 
        if(!test_file_(flacfile_, /*ignore_metadata=*/false))
 
1222
        if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
1084
1223
                return false;
1085
1224
 
1086
1225
        printf("SV[A]P\tnext\n");
1095
1234
        if(!insert_to_our_metadata_(padding, ++our_current_position, /*copy=*/true))
1096
1235
                return false;
1097
1236
 
1098
 
        if(!test_file_(flacfile_, /*ignore_metadata=*/false))
 
1237
        if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
1099
1238
                return false;
1100
1239
 
1101
1240
        printf("SVAP[P]\tprev\n");
1116
1255
        if(!iterator.set_block(app, true))
1117
1256
                return die_ss_("iterator.set_block(app, true)", iterator);
1118
1257
 
1119
 
        if(!test_file_(flacfile_, /*ignore_metadata=*/false))
 
1258
        if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
1120
1259
                return false;
1121
1260
 
1122
1261
        printf("SV[A]PP\tset APPLICATION (grow), try to expand into padding which is 'close' but still too small\n");
1127
1266
        if(!iterator.set_block(app, true))
1128
1267
                return die_ss_("iterator.set_block(app, true)", iterator);
1129
1268
 
1130
 
        if(!test_file_(flacfile_, /*ignore_metadata=*/false))
 
1269
        if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
1131
1270
                return false;
1132
1271
 
1133
1272
        printf("SV[A]PP\tset APPLICATION (grow), expand into padding which will leave 0-length pad\n");
1139
1278
        if(!iterator.set_block(app, true))
1140
1279
                return die_ss_("iterator.set_block(app, true)", iterator);
1141
1280
 
1142
 
        if(!test_file_(flacfile_, /*ignore_metadata=*/false))
 
1281
        if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
1143
1282
                return false;
1144
1283
 
1145
1284
        printf("SV[A]PP\tset APPLICATION (grow), expand into padding which is exactly consumed\n");
1151
1290
        if(!iterator.set_block(app, true))
1152
1291
                return die_ss_("iterator.set_block(app, true)", iterator);
1153
1292
 
1154
 
        if(!test_file_(flacfile_, /*ignore_metadata=*/false))
 
1293
        if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
1155
1294
                return false;
1156
1295
 
1157
1296
        printf("SV[A]P\tset APPLICATION (grow), expand into padding which is exactly consumed\n");
1164
1303
        if(!iterator.set_block(app, true))
1165
1304
                return die_ss_("iterator.set_block(app, true)", iterator);
1166
1305
 
1167
 
        if(!test_file_(flacfile_, /*ignore_metadata=*/false))
 
1306
        if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
1168
1307
                return false;
1169
1308
 
1170
1309
        printf("SV[A]\tset PADDING (equal size)\n");
1174
1313
        if(!iterator.set_block(padding, true))
1175
1314
                return die_ss_("iterator.set_block(padding, true)", iterator);
1176
1315
 
1177
 
        if(!test_file_(flacfile_, /*ignore_metadata=*/false))
 
1316
        if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
1178
1317
                return false;
1179
1318
 
1180
1319
        printf("SV[P]\tinsert PADDING after\n");
1183
1322
        if(!insert_to_our_metadata_(padding, ++our_current_position, /*copy=*/true))
1184
1323
                return false;
1185
1324
 
1186
 
        if(!test_file_(flacfile_, /*ignore_metadata=*/false))
 
1325
        if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
1187
1326
                return false;
1188
1327
 
1189
1328
        printf("SVP[P]\tinsert PADDING after\n");
1193
1332
        if(!insert_to_our_metadata_(padding, ++our_current_position, /*copy=*/true))
1194
1333
                return false;
1195
1334
 
1196
 
        if(!test_file_(flacfile_, /*ignore_metadata=*/false))
 
1335
        if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
1197
1336
                return false;
1198
1337
 
1199
1338
        printf("SVPP[P]\tprev\n");
1219
1358
        if(!iterator.insert_block_after(app, true))
1220
1359
                return die_ss_("iterator.insert_block_after(app, true)", iterator);
1221
1360
 
1222
 
        if(!test_file_(flacfile_, /*ignore_metadata=*/false))
 
1361
        if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
1223
1362
                return false;
1224
1363
 
1225
1364
        printf("SV[A]PPP\tdelete (middle block), don't replace with padding\n");
1227
1366
                return die_ss_("iterator.delete_block(false)", iterator);
1228
1367
        delete_from_our_metadata_(our_current_position--);
1229
1368
 
1230
 
        if(!test_file_(flacfile_, /*ignore_metadata=*/false))
 
1369
        if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
1231
1370
                return false;
1232
1371
 
1233
1372
        printf("S[V]PPP\tinsert APPLICATION after, try to expand into padding which is 'close' but still too small\n");
1238
1377
        if(!iterator.insert_block_after(app, true))
1239
1378
                return die_ss_("iterator.insert_block_after(app, true)", iterator);
1240
1379
 
1241
 
        if(!test_file_(flacfile_, /*ignore_metadata=*/false))
 
1380
        if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
1242
1381
                return false;
1243
1382
 
1244
1383
        printf("SV[A]PPP\tdelete (middle block), don't replace with padding\n");
1246
1385
                return die_ss_("iterator.delete_block(false)", iterator);
1247
1386
        delete_from_our_metadata_(our_current_position--);
1248
1387
 
1249
 
        if(!test_file_(flacfile_, /*ignore_metadata=*/false))
 
1388
        if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
1250
1389
                return false;
1251
1390
 
1252
1391
        printf("S[V]PPP\tinsert APPLICATION after, expand into padding which is exactly consumed\n");
1258
1397
        if(!iterator.insert_block_after(app, true))
1259
1398
                return die_ss_("iterator.insert_block_after(app, true)", iterator);
1260
1399
 
1261
 
        if(!test_file_(flacfile_, /*ignore_metadata=*/false))
 
1400
        if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
1262
1401
                return false;
1263
1402
 
1264
1403
        printf("SV[A]PP\tdelete (middle block), don't replace with padding\n");
1266
1405
                return die_ss_("iterator.delete_block(false)", iterator);
1267
1406
        delete_from_our_metadata_(our_current_position--);
1268
1407
 
1269
 
        if(!test_file_(flacfile_, /*ignore_metadata=*/false))
 
1408
        if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
1270
1409
                return false;
1271
1410
 
1272
1411
        printf("S[V]PP\tinsert APPLICATION after, expand into padding which will leave 0-length pad\n");
1278
1417
        if(!iterator.insert_block_after(app, true))
1279
1418
                return die_ss_("iterator.insert_block_after(app, true)", iterator);
1280
1419
 
1281
 
        if(!test_file_(flacfile_, /*ignore_metadata=*/false))
 
1420
        if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
1282
1421
                return false;
1283
1422
 
1284
1423
        printf("SV[A]PP\tdelete (middle block), don't replace with padding\n");
1286
1425
                return die_ss_("iterator.delete_block(false)", iterator);
1287
1426
        delete_from_our_metadata_(our_current_position--);
1288
1427
 
1289
 
        if(!test_file_(flacfile_, /*ignore_metadata=*/false))
 
1428
        if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
1290
1429
                return false;
1291
1430
 
1292
1431
        printf("S[V]PP\tnext\n");
1299
1438
                return die_ss_("iterator.delete_block(false)", iterator);
1300
1439
        delete_from_our_metadata_(our_current_position--);
1301
1440
 
1302
 
        if(!test_file_(flacfile_, /*ignore_metadata=*/false))
 
1441
        if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
1303
1442
                return false;
1304
1443
 
1305
1444
        printf("S[V]P\tinsert APPLICATION after, expand into padding which is exactly consumed\n");
1311
1450
        if(!iterator.insert_block_after(app, true))
1312
1451
                return die_ss_("iterator.insert_block_after(app, true)", iterator);
1313
1452
 
1314
 
        if(!test_file_(flacfile_, /*ignore_metadata=*/false))
 
1453
        if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
1315
1454
                return false;
1316
1455
        }
1317
1456
 
1318
1457
        delete app;
1319
1458
        delete padding;
1320
1459
 
1321
 
        if(!remove_file_(flacfile_))
 
1460
        if(!remove_file_(flacfilename(/*is_ogg=*/false)))
1322
1461
                return false;
1323
1462
 
1324
1463
        return true;
1325
1464
}
1326
1465
 
1327
 
static bool test_level_2_(bool filename_based)
 
1466
static bool test_level_2_(bool filename_based, bool is_ogg)
1328
1467
{
1329
1468
        FLAC::Metadata::Prototype *block;
1330
1469
        FLAC::Metadata::StreamInfo *streaminfo;
1336
1475
        // initialize 'data' to avoid Valgrind errors
1337
1476
        memset(data, 0, sizeof(data));
1338
1477
 
1339
 
        printf("\n\n++++++ testing level 2 interface (%s-based)\n", filename_based? "filename":"callback");
 
1478
        printf("\n\n++++++ testing level 2 interface (%s-based, %s FLAC)\n", filename_based? "filename":"callback", is_ogg? "Ogg":"native");
1340
1479
 
1341
1480
        printf("generate read-only file\n");
1342
1481
 
1343
 
        if(!generate_file_())
 
1482
        if(!generate_file_(/*include_extras=*/false, is_ogg))
1344
1483
                return false;
1345
1484
 
1346
 
        if(!change_stats_(flacfile_, /*read_only=*/true))
 
1485
        if(!change_stats_(flacfilename(is_ogg), /*read_only=*/true))
1347
1486
                return false;
1348
1487
 
1349
1488
        printf("create chain\n");
1353
1492
 
1354
1493
        printf("read chain\n");
1355
1494
 
1356
 
        if(!read_chain_(chain, flacfile_, filename_based))
 
1495
        if(!read_chain_(chain, flacfilename(is_ogg), filename_based, is_ogg))
1357
1496
                return die_c_("reading chain", chain.status());
1358
1497
 
1359
1498
        printf("[S]VP\ttest initial metadata\n");
1360
1499
 
1361
1500
        if(!compare_chain_(chain, 0, 0))
1362
1501
                return false;
1363
 
        if(!test_file_(flacfile_, /*ignore_metadata=*/false))
 
1502
        if(!test_file_(is_ogg, /*ignore_metadata=*/false))
1364
1503
                return false;
1365
1504
 
 
1505
        if(is_ogg)
 
1506
                goto end;
 
1507
 
1366
1508
        printf("switch file to read-write\n");
1367
1509
 
1368
 
        if(!change_stats_(flacfile_, /*read-only=*/false))
 
1510
        if(!change_stats_(flacfilename(is_ogg), /*read-only=*/false))
1369
1511
                return false;
1370
1512
 
1371
1513
        printf("create iterator\n");
1392
1534
                return die_("copying object");
1393
1535
        delete block;
1394
1536
 
1395
 
        if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/true, filename_based, flacfile_))
 
1537
        if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/true, filename_based, flacfilename(is_ogg)))
1396
1538
                return die_c_("during chain.write(false, true)", chain.status());
1397
1539
        block = iterator.get_block();
1398
1540
        if(!compare_chain_(chain, our_current_position, block))
1399
1541
                return false;
1400
1542
        delete block;
1401
 
        if(!test_file_(flacfile_, /*ignore_metadata=*/false))
 
1543
        if(!test_file_(is_ogg, /*ignore_metadata=*/false))
1402
1544
                return false;
1403
1545
 
1404
1546
        printf("[S]VP\tnext\n");
1425
1567
        if(!iterator.set_block(app))
1426
1568
                return die_c_("iterator.set_block(app)", chain.status());
1427
1569
 
1428
 
        if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/false, filename_based, flacfile_))
 
1570
        if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg)))
1429
1571
                return die_c_("during chain.write(false, false)", chain.status());
1430
1572
        block = iterator.get_block();
1431
1573
        if(!compare_chain_(chain, our_current_position, block))
1432
1574
                return false;
1433
1575
        delete block;
1434
 
        if(!test_file_(flacfile_, /*ignore_metadata=*/false))
 
1576
        if(!test_file_(is_ogg, /*ignore_metadata=*/false))
1435
1577
                return false;
1436
1578
 
1437
1579
        printf("SV[A]\tshrink APPLICATION, don't use padding\n");
1444
1586
        if(!iterator.set_block(app))
1445
1587
                return die_c_("iterator.set_block(app)", chain.status());
1446
1588
 
1447
 
        if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/false, filename_based, flacfile_))
 
1589
        if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg)))
1448
1590
                return die_c_("during chain.write(false, false)", chain.status());
1449
1591
        block = iterator.get_block();
1450
1592
        if(!compare_chain_(chain, our_current_position, block))
1451
1593
                return false;
1452
1594
        delete block;
1453
 
        if(!test_file_(flacfile_, /*ignore_metadata=*/false))
 
1595
        if(!test_file_(is_ogg, /*ignore_metadata=*/false))
1454
1596
                return false;
1455
1597
 
1456
1598
        printf("SV[A]\tgrow APPLICATION, don't use padding\n");
1463
1605
        if(!iterator.set_block(app))
1464
1606
                return die_c_("iterator.set_block(app)", chain.status());
1465
1607
 
1466
 
        if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/false, filename_based, flacfile_))
 
1608
        if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg)))
1467
1609
                return die_c_("during chain.write(false, false)", chain.status());
1468
1610
        block = iterator.get_block();
1469
1611
        if(!compare_chain_(chain, our_current_position, block))
1470
1612
                return false;
1471
1613
        delete block;
1472
 
        if(!test_file_(flacfile_, /*ignore_metadata=*/false))
 
1614
        if(!test_file_(is_ogg, /*ignore_metadata=*/false))
1473
1615
                return false;
1474
1616
 
1475
1617
        printf("SV[A]\tgrow APPLICATION, use padding, but last block is not padding\n");
1482
1624
        if(!iterator.set_block(app))
1483
1625
                return die_c_("iterator.set_block(app)", chain.status());
1484
1626
 
1485
 
        if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/false, filename_based, flacfile_))
 
1627
        if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg)))
1486
1628
                return die_c_("during chain.write(false, false)", chain.status());
1487
1629
        block = iterator.get_block();
1488
1630
        if(!compare_chain_(chain, our_current_position, block))
1489
1631
                return false;
1490
1632
        delete block;
1491
 
        if(!test_file_(flacfile_, /*ignore_metadata=*/false))
 
1633
        if(!test_file_(is_ogg, /*ignore_metadata=*/false))
1492
1634
                return false;
1493
1635
 
1494
1636
        printf("SV[A]\tshrink APPLICATION, use padding, last block is not padding, but delta is too small for new PADDING block\n");
1501
1643
        if(!iterator.set_block(app))
1502
1644
                return die_c_("iterator.set_block(app)", chain.status());
1503
1645
 
1504
 
        if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfile_))
 
1646
        if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg)))
1505
1647
                return die_c_("during chain.write(true, false)", chain.status());
1506
1648
        block = iterator.get_block();
1507
1649
        if(!compare_chain_(chain, our_current_position, block))
1508
1650
                return false;
1509
1651
        delete block;
1510
 
        if(!test_file_(flacfile_, /*ignore_metadata=*/false))
 
1652
        if(!test_file_(is_ogg, /*ignore_metadata=*/false))
1511
1653
                return false;
1512
1654
 
1513
1655
        printf("SV[A]\tshrink APPLICATION, use padding, last block is not padding, delta is enough for new PADDING block\n");
1525
1667
        if(!iterator.set_block(app))
1526
1668
                return die_c_("iterator.set_block(app)", chain.status());
1527
1669
 
1528
 
        if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfile_))
 
1670
        if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg)))
1529
1671
                return die_c_("during chain.write(true, false)", chain.status());
1530
1672
        block = iterator.get_block();
1531
1673
        if(!compare_chain_(chain, our_current_position, block))
1532
1674
                return false;
1533
1675
        delete block;
1534
 
        if(!test_file_(flacfile_, /*ignore_metadata=*/false))
 
1676
        if(!test_file_(is_ogg, /*ignore_metadata=*/false))
1535
1677
                return false;
1536
1678
 
1537
1679
        printf("SV[A]P\tshrink APPLICATION, use padding, last block is padding\n");
1545
1687
        if(!iterator.set_block(app))
1546
1688
                return die_c_("iterator.set_block(app)", chain.status());
1547
1689
 
1548
 
        if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfile_))
 
1690
        if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg)))
1549
1691
                return die_c_("during chain.write(true, false)", chain.status());
1550
1692
        block = iterator.get_block();
1551
1693
        if(!compare_chain_(chain, our_current_position, block))
1552
1694
                return false;
1553
1695
        delete block;
1554
 
        if(!test_file_(flacfile_, /*ignore_metadata=*/false))
 
1696
        if(!test_file_(is_ogg, /*ignore_metadata=*/false))
1555
1697
                return false;
1556
1698
 
1557
1699
        printf("SV[A]P\tgrow APPLICATION, use padding, last block is padding, but delta is too small\n");
1564
1706
        if(!iterator.set_block(app))
1565
1707
                return die_c_("iterator.set_block(app)", chain.status());
1566
1708
 
1567
 
        if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfile_))
 
1709
        if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg)))
1568
1710
                return die_c_("during chain.write(true, false)", chain.status());
1569
1711
        block = iterator.get_block();
1570
1712
        if(!compare_chain_(chain, our_current_position, block))
1571
1713
                return false;
1572
1714
        delete block;
1573
 
        if(!test_file_(flacfile_, /*ignore_metadata=*/false))
 
1715
        if(!test_file_(is_ogg, /*ignore_metadata=*/false))
1574
1716
                return false;
1575
1717
 
1576
1718
        printf("SV[A]P\tgrow APPLICATION, use padding, last block is padding of exceeding size\n");
1584
1726
        if(!iterator.set_block(app))
1585
1727
                return die_c_("iterator.set_block(app)", chain.status());
1586
1728
 
1587
 
        if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfile_))
 
1729
        if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg)))
1588
1730
                return die_c_("during chain.write(true, false)", chain.status());
1589
1731
        block = iterator.get_block();
1590
1732
        if(!compare_chain_(chain, our_current_position, block))
1591
1733
                return false;
1592
1734
        delete block;
1593
 
        if(!test_file_(flacfile_, /*ignore_metadata=*/false))
 
1735
        if(!test_file_(is_ogg, /*ignore_metadata=*/false))
1594
1736
                return false;
1595
1737
 
1596
1738
        printf("SV[A]P\tgrow APPLICATION, use padding, last block is padding of exact size\n");
1604
1746
        if(!iterator.set_block(app))
1605
1747
                return die_c_("iterator.set_block(app)", chain.status());
1606
1748
 
1607
 
        if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfile_))
 
1749
        if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg)))
1608
1750
                return die_c_("during chain.write(true, false)", chain.status());
1609
1751
        block = iterator.get_block();
1610
1752
        if(!compare_chain_(chain, our_current_position, block))
1611
1753
                return false;
1612
1754
        delete block;
1613
 
        if(!test_file_(flacfile_, /*ignore_metadata=*/false))
 
1755
        if(!test_file_(is_ogg, /*ignore_metadata=*/false))
1614
1756
                return false;
1615
1757
 
1616
1758
        printf("SV[A]\tprev\n");
1731
1873
        delete_from_our_metadata_(4);
1732
1874
        delete_from_our_metadata_(3);
1733
1875
 
1734
 
        if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfile_))
 
1876
        if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg)))
1735
1877
                return die_c_("during chain.write(true, false)", chain.status());
1736
1878
        if(!compare_chain_(chain, 0, 0))
1737
1879
                return false;
1738
 
        if(!test_file_(flacfile_, /*ignore_metadata=*/false))
 
1880
        if(!test_file_(is_ogg, /*ignore_metadata=*/false))
1739
1881
                return false;
1740
1882
 
1741
1883
        printf("SVPAP\tsort padding\n");
1743
1885
        add_to_padding_length_(4, FLAC__STREAM_METADATA_HEADER_LENGTH + our_metadata_.blocks[2]->get_length());
1744
1886
        delete_from_our_metadata_(2);
1745
1887
 
1746
 
        if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfile_))
 
1888
        if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg)))
1747
1889
                return die_c_("during chain.write(true, false)", chain.status());
1748
1890
        if(!compare_chain_(chain, 0, 0))
1749
1891
                return false;
1750
 
        if(!test_file_(flacfile_, /*ignore_metadata=*/false))
 
1892
        if(!test_file_(is_ogg, /*ignore_metadata=*/false))
1751
1893
                return false;
1752
1894
 
1753
1895
        printf("create iterator\n");
1853
1995
        printf("SV\tmerge padding\n");
1854
1996
        chain.merge_padding();
1855
1997
 
1856
 
        if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/false, filename_based, flacfile_))
 
1998
        if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg)))
1857
1999
                return die_c_("during chain.write(false, false)", chain.status());
1858
2000
        if(!compare_chain_(chain, 0, 0))
1859
2001
                return false;
1860
 
        if(!test_file_(flacfile_, /*ignore_metadata=*/false))
 
2002
        if(!test_file_(is_ogg, /*ignore_metadata=*/false))
1861
2003
                return false;
1862
2004
 
1863
2005
        printf("SV\tsort padding\n");
1864
2006
        chain.sort_padding();
1865
2007
 
1866
 
        if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/false, filename_based, flacfile_))
 
2008
        if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg)))
1867
2009
                return die_c_("during chain.write(false, false)", chain.status());
1868
2010
        if(!compare_chain_(chain, 0, 0))
1869
2011
                return false;
1870
 
        if(!test_file_(flacfile_, /*ignore_metadata=*/false))
 
2012
        if(!test_file_(is_ogg, /*ignore_metadata=*/false))
1871
2013
                return false;
1872
2014
 
1873
 
        if(!remove_file_(flacfile_))
 
2015
end:
 
2016
        if(!remove_file_(flacfilename(is_ogg)))
1874
2017
                return false;
1875
2018
 
1876
2019
        return true;
1877
2020
}
1878
2021
 
1879
 
static bool test_level_2_misc_()
 
2022
static bool test_level_2_misc_(bool is_ogg)
1880
2023
{
1881
2024
        ::FLAC__IOCallbacks callbacks;
1882
2025
 
1895
2038
 
1896
2039
        printf("generate file\n");
1897
2040
 
1898
 
        if(!generate_file_())
 
2041
        if(!generate_file_(/*include_extras=*/false, is_ogg))
1899
2042
                return false;
1900
2043
 
1901
2044
        printf("create chain\n");
1905
2048
 
1906
2049
        printf("read chain (filename-based)\n");
1907
2050
 
1908
 
        if(!chain.read(flacfile_))
 
2051
        if(!chain.read(flacfilename(is_ogg)))
1909
2052
                return die_c_("reading chain", chain.status());
1910
2053
 
1911
2054
        printf("write chain with wrong method Chain::write(with callbacks)\n");
1919
2062
 
1920
2063
        printf("read chain (filename-based)\n");
1921
2064
 
1922
 
        if(!chain.read(flacfile_))
 
2065
        if(!chain.read(flacfilename(is_ogg)))
1923
2066
                return die_c_("reading chain", chain.status());
1924
2067
 
1925
2068
        printf("write chain with wrong method Chain::write(with callbacks and tempfile)\n");
1933
2076
 
1934
2077
        printf("read chain (callback-based)\n");
1935
2078
        {
1936
 
                FILE *file = fopen(flacfile_, "rb");
 
2079
                FILE *file = fopen(flacfilename(is_ogg), "rb");
1937
2080
                if(0 == file)
1938
2081
                        return die_("opening file");
1939
2082
                if(!chain.read((::FLAC__IOHandle)file, callbacks)) {
1954
2097
 
1955
2098
        printf("read chain (callback-based)\n");
1956
2099
        {
1957
 
                FILE *file = fopen(flacfile_, "rb");
 
2100
                FILE *file = fopen(flacfilename(is_ogg), "rb");
1958
2101
                if(0 == file)
1959
2102
                        return die_("opening file");
1960
2103
                if(!chain.read((::FLAC__IOHandle)file, callbacks)) {
1982
2125
 
1983
2126
        printf("read chain (callback-based)\n");
1984
2127
        {
1985
 
                FILE *file = fopen(flacfile_, "rb");
 
2128
                FILE *file = fopen(flacfilename(is_ogg), "rb");
1986
2129
                if(0 == file)
1987
2130
                        return die_("opening file");
1988
2131
                if(!chain.read((::FLAC__IOHandle)file, callbacks)) {
2026
2169
 
2027
2170
        } // delete iterator
2028
2171
 
2029
 
        if(!remove_file_(flacfile_))
 
2172
        if(!remove_file_(flacfilename(is_ogg)))
2030
2173
                return false;
2031
2174
 
2032
2175
        return true;
2044
2187
        if(!test_level_1_())
2045
2188
                return false;
2046
2189
 
2047
 
        if(!test_level_2_(/*filename_based=*/true)) /* filename-based */
2048
 
                return false;
2049
 
        if(!test_level_2_(/*filename_based=*/false)) /* callback-based */
2050
 
                return false;
2051
 
        if(!test_level_2_misc_())
2052
 
                return false;
 
2190
        if(!test_level_2_(/*filename_based=*/true, /*is_ogg=*/false)) /* filename-based */
 
2191
                return false;
 
2192
        if(!test_level_2_(/*filename_based=*/false, /*is_ogg=*/false)) /* callback-based */
 
2193
                return false;
 
2194
        if(!test_level_2_misc_(/*is_ogg=*/false))
 
2195
                return false;
 
2196
 
 
2197
        if(FLAC_API_SUPPORTS_OGG_FLAC) {
 
2198
                if(!test_level_2_(/*filename_based=*/true, /*is_ogg=*/true)) /* filename-based */
 
2199
                        return false;
 
2200
                if(!test_level_2_(/*filename_based=*/false, /*is_ogg=*/true)) /* callback-based */
 
2201
                        return false;
 
2202
#if 0
 
2203
                /* when ogg flac write is supported, will have to add this: */
 
2204
                if(!test_level_2_misc_(/*is_ogg=*/true))
 
2205
                        return false;
 
2206
#endif
 
2207
        }
2053
2208
 
2054
2209
        return true;
2055
2210
}