Add file include/share/compat.h and start moving CPP hackery into it.
[flac.git] / src / test_libFLAC++ / metadata_manip.cpp
index 89feae1..4ee4281 100644 (file)
@@ -1,5 +1,5 @@
 /* test_libFLAC++ - Unit tester for libFLAC++
- * Copyright (C) 2002,2003,2004,2005,2006  Josh Coalson
+ * Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009  Josh Coalson
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  */
 
+#if HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
 #include <stdio.h>
 #include <stdlib.h> /* for malloc() */
 #include <string.h> /* for memcpy()/memset() */
 #if defined _MSC_VER || defined __MINGW32__
 #include <sys/utime.h> /* for utime() */
 #include <io.h> /* for chmod() */
-#if _MSC_VER <= 1200 /* @@@ [2G limit] */
+#if _MSC_VER <= 1600 /* @@@ [2G limit] */
 #define fseeko fseek
 #define ftello ftell
 #endif
@@ -68,14 +72,17 @@ struct OurMetadata {
        unsigned num_blocks;
 };
 
-static const char *flacfile_ = "metadata.flac";
-
-/* our copy of the metadata in flacfile_ */
+/* our copy of the metadata in flacfilename() */
 static OurMetadata our_metadata_;
 
 /* the current block number that corresponds to the position of the iterator we are testing */
 static unsigned mc_our_block_number_ = 0;
 
+static const char *flacfilename(bool is_ogg)
+{
+       return is_ogg? "metadata.oga" : "metadata.flac";
+}
+
 static bool die_(const char *msg)
 {
        printf("ERROR: %s\n", msg);
@@ -330,11 +337,11 @@ static bool write_chain_(FLAC::Metadata::Chain &chain, bool use_padding, bool pr
                                        return false;
                        }
                        if(0 == (file = fopen(filename, "rb")))
-                               return false; /*@@@ chain status still says OK though */
+                               return false; /*@@@@ chain status still says OK though */
                        if(!open_tempfile_(filename, &tempfile, &tempfilename)) {
                                fclose(file);
                                cleanup_tempfile_(&tempfile, &tempfilename);
-                               return false; /*@@@ chain status still says OK though */
+                               return false; /*@@@@ chain status still says OK though */
                        }
                        if(!chain.write(use_padding, (::FLAC__IOHandle)file, callbacks, (::FLAC__IOHandle)tempfile, callbacks)) {
                                fclose(file);
@@ -352,7 +359,7 @@ static bool write_chain_(FLAC::Metadata::Chain &chain, bool use_padding, bool pr
                else {
                        FILE *file = fopen(filename, "r+b");
                        if(0 == file)
-                               return false; /*@@@ chain status still says OK though */
+                               return false; /*@@@@ chain status still says OK though */
                        if(!chain.write(use_padding, (::FLAC__IOHandle)file, callbacks))
                                return false;
                        fclose(file);
@@ -362,10 +369,10 @@ static bool write_chain_(FLAC::Metadata::Chain &chain, bool use_padding, bool pr
        return true;
 }
 
-static bool read_chain_(FLAC::Metadata::Chain &chain, const char *filename, bool filename_based)
+static bool read_chain_(FLAC::Metadata::Chain &chain, const char *filename, bool filename_based, bool is_ogg)
 {
        if(filename_based)
-               return chain.read(filename);
+               return chain.read(filename, is_ogg);
        else {
                ::FLAC__IOCallbacks callbacks;
 
@@ -378,8 +385,8 @@ static bool read_chain_(FLAC::Metadata::Chain &chain, const char *filename, bool
                        bool ret;
                        FILE *file = fopen(filename, "rb");
                        if(0 == file)
-                               return false; /*@@@ chain status still says OK though */
-                       ret = chain.read((::FLAC__IOHandle)file, callbacks);
+                               return false; /*@@@@ chain status still says OK though */
+                       ret = chain.read((::FLAC__IOHandle)file, callbacks, is_ogg);
                        fclose(file);
                        return ret;
                }
@@ -485,13 +492,13 @@ void OurFileDecoder::error_callback(::FLAC__StreamDecoderErrorStatus status)
        printf("ERROR: got error callback, status = %s (%u)\n", FLAC__StreamDecoderErrorStatusString[status], (unsigned)status);
 }
 
-static bool generate_file_(FLAC__bool include_extras)
+static bool generate_file_(bool include_extras, bool is_ogg)
 {
        ::FLAC__StreamMetadata streaminfo, vorbiscomment, *cuesheet, picture, padding;
        ::FLAC__StreamMetadata *metadata[4];
        unsigned i = 0, n = 0;
 
-       printf("generating FLAC file for test\n");
+       printf("generating %sFLAC file for test\n", is_ogg? "Ogg " : "");
 
        while(our_metadata_.num_blocks > 0)
                delete_from_our_metadata_(0);
@@ -589,20 +596,22 @@ static bool generate_file_(FLAC__bool include_extras)
        )
                return die_("priming our metadata");
 
-       if(!file_utils__generate_flacfile(flacfile_, 0, 512 * 1024, &streaminfo, metadata, n))
+       if(!file_utils__generate_flacfile(is_ogg, flacfilename(is_ogg), 0, 512 * 1024, &streaminfo, metadata, n))
                return die_("creating the encoded file");
 
        free(vorbiscomment.data.vorbis_comment.vendor_string.entry);
+       free(picture.data.picture.mime_type);
+       free(picture.data.picture.description);
+       free(picture.data.picture.data);
 
        return true;
 }
 
-static bool test_file_(const char *filename, bool ignore_metadata)
+static bool test_file_(bool is_ogg, bool ignore_metadata)
 {
+       const char *filename = flacfilename(is_ogg);
        OurFileDecoder decoder(ignore_metadata);
 
-       FLAC__ASSERT(0 != filename);
-
        mc_our_block_number_ = 0;
        decoder.error_occurred_ = false;
 
@@ -614,16 +623,16 @@ static bool test_file_(const char *filename, bool ignore_metadata)
 
        decoder.set_md5_checking(true);
        decoder.set_metadata_respond_all();
-       if(decoder.init(filename) != ::FLAC__STREAM_DECODER_INIT_STATUS_OK) {
-               decoder.finish();
+       if((is_ogg? decoder.init_ogg(filename) : decoder.init(filename)) != ::FLAC__STREAM_DECODER_INIT_STATUS_OK) {
+               (void)decoder.finish();
                return die_("initializing decoder\n");
        }
        if(!decoder.process_until_end_of_stream()) {
-               decoder.finish();
+               (void)decoder.finish();
                return die_("decoding file\n");
        }
 
-       decoder.finish();
+       (void)decoder.finish();
 
        if(decoder.error_occurred_)
                return false;
@@ -660,15 +669,15 @@ static bool test_level_0_()
 
        printf("\n\n++++++ testing level 0 interface\n");
 
-       if(!generate_file_(/*include_extras=*/true))
+       if(!generate_file_(/*include_extras=*/true, /*is_ogg=*/false))
                return false;
 
-       if(!test_file_(flacfile_, /*ignore_metadata=*/true))
+       if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/true))
                return false;
 
        printf("testing FLAC::Metadata::get_streaminfo()... ");
 
-       if(!FLAC::Metadata::get_streaminfo(flacfile_, streaminfo))
+       if(!FLAC::Metadata::get_streaminfo(flacfilename(/*is_ogg=*/false), streaminfo))
                return die_("during FLAC::Metadata::get_streaminfo()");
 
        /* check to see if some basic data matches (c.f. generate_file_()) */
@@ -690,7 +699,7 @@ static bool test_level_0_()
 
                FLAC::Metadata::VorbisComment *tags = 0;
 
-               if(!FLAC::Metadata::get_tags(flacfile_, tags))
+               if(!FLAC::Metadata::get_tags(flacfilename(/*is_ogg=*/false), tags))
                        return die_("during FLAC::Metadata::get_tags()");
 
                /* check to see if some basic data matches (c.f. generate_file_()) */
@@ -707,7 +716,7 @@ static bool test_level_0_()
 
                FLAC::Metadata::VorbisComment tags;
 
-               if(!FLAC::Metadata::get_tags(flacfile_, tags))
+               if(!FLAC::Metadata::get_tags(flacfilename(/*is_ogg=*/false), tags))
                        return die_("during FLAC::Metadata::get_tags()");
 
                /* check to see if some basic data matches (c.f. generate_file_()) */
@@ -722,7 +731,7 @@ static bool test_level_0_()
 
                FLAC::Metadata::CueSheet *cuesheet = 0;
 
-               if(!FLAC::Metadata::get_cuesheet(flacfile_, cuesheet))
+               if(!FLAC::Metadata::get_cuesheet(flacfilename(/*is_ogg=*/false), cuesheet))
                        return die_("during FLAC::Metadata::get_cuesheet()");
 
                /* check to see if some basic data matches (c.f. generate_file_()) */
@@ -739,7 +748,7 @@ static bool test_level_0_()
 
                FLAC::Metadata::CueSheet cuesheet;
 
-               if(!FLAC::Metadata::get_cuesheet(flacfile_, cuesheet))
+               if(!FLAC::Metadata::get_cuesheet(flacfilename(/*is_ogg=*/false), cuesheet))
                        return die_("during FLAC::Metadata::get_cuesheet()");
 
                /* check to see if some basic data matches (c.f. generate_file_()) */
@@ -754,7 +763,7 @@ static bool test_level_0_()
 
                FLAC::Metadata::Picture *picture = 0;
 
-               if(!FLAC::Metadata::get_picture(flacfile_, 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)))
+               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)))
                        return die_("during FLAC::Metadata::get_picture()");
 
                /* check to see if some basic data matches (c.f. generate_file_()) */
@@ -771,7 +780,7 @@ static bool test_level_0_()
 
                FLAC::Metadata::Picture picture;
 
-               if(!FLAC::Metadata::get_picture(flacfile_, 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)))
+               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)))
                        return die_("during FLAC::Metadata::get_picture()");
 
                /* check to see if some basic data matches (c.f. generate_file_()) */
@@ -781,7 +790,7 @@ static bool test_level_0_()
                printf("OK\n");
        }
 
-       if(!remove_file_(flacfile_))
+       if(!remove_file_(flacfilename(/*is_ogg=*/false)))
                return false;
 
        return true;
@@ -805,13 +814,13 @@ static bool test_level_1_()
        {
        printf("simple iterator on read-only file\n");
 
-       if(!generate_file_(/*include_extras=*/false))
+       if(!generate_file_(/*include_extras=*/false, /*is_ogg=*/false))
                return false;
 
-       if(!change_stats_(flacfile_, /*read_only=*/true))
+       if(!change_stats_(flacfilename(/*is_ogg=*/false), /*read_only=*/true))
                return false;
 
-       if(!test_file_(flacfile_, /*ignore_metadata=*/true))
+       if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/true))
                return false;
 
        FLAC::Metadata::SimpleIterator iterator;
@@ -819,7 +828,7 @@ static bool test_level_1_()
        if(!iterator.is_valid())
                return die_("iterator.is_valid() returned false");
 
-       if(!iterator.init(flacfile_, /*read_only=*/false, /*preserve_file_stats=*/false))
+       if(!iterator.init(flacfilename(/*is_ogg=*/false), /*read_only=*/false, /*preserve_file_stats=*/false))
                return die_("iterator.init() returned false");
 
        printf("is writable = %u\n", (unsigned)iterator.is_writable());
@@ -898,7 +907,7 @@ static bool test_level_1_()
        {
        printf("simple iterator on writable file\n");
 
-       if(!change_stats_(flacfile_, /*read-only=*/false))
+       if(!change_stats_(flacfilename(/*is_ogg=*/false), /*read-only=*/false))
                return false;
 
        printf("creating APPLICATION block\n");
@@ -918,7 +927,7 @@ static bool test_level_1_()
        if(!iterator.is_valid())
                return die_("iterator.is_valid() returned false");
 
-       if(!iterator.init(flacfile_, /*read_only=*/false, /*preserve_file_stats=*/false))
+       if(!iterator.init(flacfilename(/*is_ogg=*/false), /*read_only=*/false, /*preserve_file_stats=*/false))
                return die_("iterator.init() returned false");
        our_current_position = 0;
 
@@ -964,7 +973,7 @@ static bool test_level_1_()
        if(!insert_to_our_metadata_(padding, ++our_current_position, /*copy=*/true))
                return false;
 
-       if(!test_file_(flacfile_, /*ignore_metadata=*/false))
+       if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
                return false;
 
        printf("SV[P]PP\tprev\n");
@@ -981,7 +990,7 @@ static bool test_level_1_()
        if(iterator.delete_block(false))
                return die_ss_("iterator.delete_block(false) should have returned false", iterator);
 
-       if(!test_file_(flacfile_, /*ignore_metadata=*/false))
+       if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
                return false;
 
        printf("[S]VPPP\tnext\n");
@@ -1009,7 +1018,7 @@ static bool test_level_1_()
                return die_ss_("iterator.delete_block(false)", iterator);
        delete_from_our_metadata_(our_current_position--);
 
-       if(!test_file_(flacfile_, /*ignore_metadata=*/false))
+       if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
                return false;
 
        printf("S[V]PP\tnext\n");
@@ -1027,7 +1036,7 @@ static bool test_level_1_()
                return die_ss_("iterator.delete_block(false)", iterator);
        our_current_position--;
 
-       if(!test_file_(flacfile_, /*ignore_metadata=*/false))
+       if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
                return false;
 
        printf("SV[P]P\tnext\n");
@@ -1040,7 +1049,7 @@ static bool test_level_1_()
                return die_ss_("iterator.delete_block(false)", iterator);
        delete_from_our_metadata_(our_current_position--);
 
-       if(!test_file_(flacfile_, /*ignore_metadata=*/false))
+       if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
                return false;
 
        printf("SV[P]\tprev\n");
@@ -1065,7 +1074,7 @@ static bool test_level_1_()
                return die_ss_("iterator.set_block(block, false)", iterator);
        delete block;
 
-       if(!test_file_(flacfile_, /*ignore_metadata=*/false))
+       if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
                return false;
 
        printf("[S]VP\tnext\n");
@@ -1081,7 +1090,7 @@ static bool test_level_1_()
                return false;
        add_to_padding_length_(our_current_position+1, -((int)(FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) + (int)app->get_length()));
 
-       if(!test_file_(flacfile_, /*ignore_metadata=*/false))
+       if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
                return false;
 
        printf("SV[A]P\tnext\n");
@@ -1097,7 +1106,7 @@ static bool test_level_1_()
                return false;
        add_to_padding_length_(our_current_position+1, -((int)(FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) + (int)app->get_length()));
 
-       if(!test_file_(flacfile_, /*ignore_metadata=*/false))
+       if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
                return false;
 
        printf("SVA[A]P\tset APPLICATION (grow), don't expand into padding\n");
@@ -1109,7 +1118,7 @@ static bool test_level_1_()
        if(!iterator.set_block(app, false))
                return die_ss_("iterator.set_block(app, false)", iterator);
 
-       if(!test_file_(flacfile_, /*ignore_metadata=*/false))
+       if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
                return false;
 
        printf("SVA[A]P\tset APPLICATION (shrink), don't fill in with padding\n");
@@ -1121,7 +1130,7 @@ static bool test_level_1_()
        if(!iterator.set_block(app, false))
                return die_ss_("iterator.set_block(app, false)", iterator);
 
-       if(!test_file_(flacfile_, /*ignore_metadata=*/false))
+       if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
                return false;
 
        printf("SVA[A]P\tset APPLICATION (grow), expand into padding of exceeding size\n");
@@ -1134,7 +1143,7 @@ static bool test_level_1_()
        if(!iterator.set_block(app, true))
                return die_ss_("iterator.set_block(app, true)", iterator);
 
-       if(!test_file_(flacfile_, /*ignore_metadata=*/false))
+       if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
                return false;
 
        printf("SVA[A]P\tset APPLICATION (shrink), fill in with padding\n");
@@ -1149,7 +1158,7 @@ static bool test_level_1_()
        if(!iterator.set_block(app, true))
                return die_ss_("iterator.set_block(app, true)", iterator);
 
-       if(!test_file_(flacfile_, /*ignore_metadata=*/false))
+       if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
                return false;
 
        printf("SVA[A]PP\tnext\n");
@@ -1169,7 +1178,7 @@ static bool test_level_1_()
        if(!iterator.set_block(padding, false))
                return die_ss_("iterator.set_block(padding, false)", iterator);
 
-       if(!test_file_(flacfile_, /*ignore_metadata=*/false))
+       if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
                return false;
 
        printf("SVAAP[P]\tset APPLICATION (grow)\n");
@@ -1179,7 +1188,7 @@ static bool test_level_1_()
        if(!iterator.set_block(app, false))
                return die_ss_("iterator.set_block(app, false)", iterator);
 
-       if(!test_file_(flacfile_, /*ignore_metadata=*/false))
+       if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
                return false;
 
        printf("SVAAP[A]\tset PADDING (equal)\n");
@@ -1189,7 +1198,7 @@ static bool test_level_1_()
        if(!iterator.set_block(padding, false))
                return die_ss_("iterator.set_block(padding, false)", iterator);
 
-       if(!test_file_(flacfile_, /*ignore_metadata=*/false))
+       if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
                return false;
 
        printf("SVAAP[P]\tprev\n");
@@ -1202,7 +1211,7 @@ static bool test_level_1_()
                return die_ss_("iterator.delete_block(false)", iterator);
        delete_from_our_metadata_(our_current_position--);
 
-       if(!test_file_(flacfile_, /*ignore_metadata=*/false))
+       if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
                return false;
 
        printf("SVA[A]P\tdelete (middle block), don't replace with padding\n");
@@ -1210,7 +1219,7 @@ static bool test_level_1_()
                return die_ss_("iterator.delete_block(false)", iterator);
        delete_from_our_metadata_(our_current_position--);
 
-       if(!test_file_(flacfile_, /*ignore_metadata=*/false))
+       if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
                return false;
 
        printf("SV[A]P\tnext\n");
@@ -1225,7 +1234,7 @@ static bool test_level_1_()
        if(!insert_to_our_metadata_(padding, ++our_current_position, /*copy=*/true))
                return false;
 
-       if(!test_file_(flacfile_, /*ignore_metadata=*/false))
+       if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
                return false;
 
        printf("SVAP[P]\tprev\n");
@@ -1246,7 +1255,7 @@ static bool test_level_1_()
        if(!iterator.set_block(app, true))
                return die_ss_("iterator.set_block(app, true)", iterator);
 
-       if(!test_file_(flacfile_, /*ignore_metadata=*/false))
+       if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
                return false;
 
        printf("SV[A]PP\tset APPLICATION (grow), try to expand into padding which is 'close' but still too small\n");
@@ -1257,7 +1266,7 @@ static bool test_level_1_()
        if(!iterator.set_block(app, true))
                return die_ss_("iterator.set_block(app, true)", iterator);
 
-       if(!test_file_(flacfile_, /*ignore_metadata=*/false))
+       if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
                return false;
 
        printf("SV[A]PP\tset APPLICATION (grow), expand into padding which will leave 0-length pad\n");
@@ -1269,7 +1278,7 @@ static bool test_level_1_()
        if(!iterator.set_block(app, true))
                return die_ss_("iterator.set_block(app, true)", iterator);
 
-       if(!test_file_(flacfile_, /*ignore_metadata=*/false))
+       if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
                return false;
 
        printf("SV[A]PP\tset APPLICATION (grow), expand into padding which is exactly consumed\n");
@@ -1281,7 +1290,7 @@ static bool test_level_1_()
        if(!iterator.set_block(app, true))
                return die_ss_("iterator.set_block(app, true)", iterator);
 
-       if(!test_file_(flacfile_, /*ignore_metadata=*/false))
+       if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
                return false;
 
        printf("SV[A]P\tset APPLICATION (grow), expand into padding which is exactly consumed\n");
@@ -1294,7 +1303,7 @@ static bool test_level_1_()
        if(!iterator.set_block(app, true))
                return die_ss_("iterator.set_block(app, true)", iterator);
 
-       if(!test_file_(flacfile_, /*ignore_metadata=*/false))
+       if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
                return false;
 
        printf("SV[A]\tset PADDING (equal size)\n");
@@ -1304,7 +1313,7 @@ static bool test_level_1_()
        if(!iterator.set_block(padding, true))
                return die_ss_("iterator.set_block(padding, true)", iterator);
 
-       if(!test_file_(flacfile_, /*ignore_metadata=*/false))
+       if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
                return false;
 
        printf("SV[P]\tinsert PADDING after\n");
@@ -1313,7 +1322,7 @@ static bool test_level_1_()
        if(!insert_to_our_metadata_(padding, ++our_current_position, /*copy=*/true))
                return false;
 
-       if(!test_file_(flacfile_, /*ignore_metadata=*/false))
+       if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
                return false;
 
        printf("SVP[P]\tinsert PADDING after\n");
@@ -1323,7 +1332,7 @@ static bool test_level_1_()
        if(!insert_to_our_metadata_(padding, ++our_current_position, /*copy=*/true))
                return false;
 
-       if(!test_file_(flacfile_, /*ignore_metadata=*/false))
+       if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
                return false;
 
        printf("SVPP[P]\tprev\n");
@@ -1349,7 +1358,7 @@ static bool test_level_1_()
        if(!iterator.insert_block_after(app, true))
                return die_ss_("iterator.insert_block_after(app, true)", iterator);
 
-       if(!test_file_(flacfile_, /*ignore_metadata=*/false))
+       if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
                return false;
 
        printf("SV[A]PPP\tdelete (middle block), don't replace with padding\n");
@@ -1357,7 +1366,7 @@ static bool test_level_1_()
                return die_ss_("iterator.delete_block(false)", iterator);
        delete_from_our_metadata_(our_current_position--);
 
-       if(!test_file_(flacfile_, /*ignore_metadata=*/false))
+       if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
                return false;
 
        printf("S[V]PPP\tinsert APPLICATION after, try to expand into padding which is 'close' but still too small\n");
@@ -1368,7 +1377,7 @@ static bool test_level_1_()
        if(!iterator.insert_block_after(app, true))
                return die_ss_("iterator.insert_block_after(app, true)", iterator);
 
-       if(!test_file_(flacfile_, /*ignore_metadata=*/false))
+       if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
                return false;
 
        printf("SV[A]PPP\tdelete (middle block), don't replace with padding\n");
@@ -1376,7 +1385,7 @@ static bool test_level_1_()
                return die_ss_("iterator.delete_block(false)", iterator);
        delete_from_our_metadata_(our_current_position--);
 
-       if(!test_file_(flacfile_, /*ignore_metadata=*/false))
+       if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
                return false;
 
        printf("S[V]PPP\tinsert APPLICATION after, expand into padding which is exactly consumed\n");
@@ -1388,7 +1397,7 @@ static bool test_level_1_()
        if(!iterator.insert_block_after(app, true))
                return die_ss_("iterator.insert_block_after(app, true)", iterator);
 
-       if(!test_file_(flacfile_, /*ignore_metadata=*/false))
+       if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
                return false;
 
        printf("SV[A]PP\tdelete (middle block), don't replace with padding\n");
@@ -1396,7 +1405,7 @@ static bool test_level_1_()
                return die_ss_("iterator.delete_block(false)", iterator);
        delete_from_our_metadata_(our_current_position--);
 
-       if(!test_file_(flacfile_, /*ignore_metadata=*/false))
+       if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
                return false;
 
        printf("S[V]PP\tinsert APPLICATION after, expand into padding which will leave 0-length pad\n");
@@ -1408,7 +1417,7 @@ static bool test_level_1_()
        if(!iterator.insert_block_after(app, true))
                return die_ss_("iterator.insert_block_after(app, true)", iterator);
 
-       if(!test_file_(flacfile_, /*ignore_metadata=*/false))
+       if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
                return false;
 
        printf("SV[A]PP\tdelete (middle block), don't replace with padding\n");
@@ -1416,7 +1425,7 @@ static bool test_level_1_()
                return die_ss_("iterator.delete_block(false)", iterator);
        delete_from_our_metadata_(our_current_position--);
 
-       if(!test_file_(flacfile_, /*ignore_metadata=*/false))
+       if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
                return false;
 
        printf("S[V]PP\tnext\n");
@@ -1429,7 +1438,7 @@ static bool test_level_1_()
                return die_ss_("iterator.delete_block(false)", iterator);
        delete_from_our_metadata_(our_current_position--);
 
-       if(!test_file_(flacfile_, /*ignore_metadata=*/false))
+       if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
                return false;
 
        printf("S[V]P\tinsert APPLICATION after, expand into padding which is exactly consumed\n");
@@ -1441,20 +1450,20 @@ static bool test_level_1_()
        if(!iterator.insert_block_after(app, true))
                return die_ss_("iterator.insert_block_after(app, true)", iterator);
 
-       if(!test_file_(flacfile_, /*ignore_metadata=*/false))
+       if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
                return false;
        }
 
        delete app;
        delete padding;
 
-       if(!remove_file_(flacfile_))
+       if(!remove_file_(flacfilename(/*is_ogg=*/false)))
                return false;
 
        return true;
 }
 
-static bool test_level_2_(bool filename_based)
+static bool test_level_2_(bool filename_based, bool is_ogg)
 {
        FLAC::Metadata::Prototype *block;
        FLAC::Metadata::StreamInfo *streaminfo;
@@ -1466,14 +1475,14 @@ static bool test_level_2_(bool filename_based)
        // initialize 'data' to avoid Valgrind errors
        memset(data, 0, sizeof(data));
 
-       printf("\n\n++++++ testing level 2 interface (%s-based)\n", filename_based? "filename":"callback");
+       printf("\n\n++++++ testing level 2 interface (%s-based, %s FLAC)\n", filename_based? "filename":"callback", is_ogg? "Ogg":"native");
 
        printf("generate read-only file\n");
 
-       if(!generate_file_(/*include_extras=*/false))
+       if(!generate_file_(/*include_extras=*/false, is_ogg))
                return false;
 
-       if(!change_stats_(flacfile_, /*read_only=*/true))
+       if(!change_stats_(flacfilename(is_ogg), /*read_only=*/true))
                return false;
 
        printf("create chain\n");
@@ -1483,19 +1492,22 @@ static bool test_level_2_(bool filename_based)
 
        printf("read chain\n");
 
-       if(!read_chain_(chain, flacfile_, filename_based))
+       if(!read_chain_(chain, flacfilename(is_ogg), filename_based, is_ogg))
                return die_c_("reading chain", chain.status());
 
        printf("[S]VP\ttest initial metadata\n");
 
        if(!compare_chain_(chain, 0, 0))
                return false;
-       if(!test_file_(flacfile_, /*ignore_metadata=*/false))
+       if(!test_file_(is_ogg, /*ignore_metadata=*/false))
                return false;
 
+       if(is_ogg)
+               goto end;
+
        printf("switch file to read-write\n");
 
-       if(!change_stats_(flacfile_, /*read-only=*/false))
+       if(!change_stats_(flacfilename(is_ogg), /*read-only=*/false))
                return false;
 
        printf("create iterator\n");
@@ -1522,13 +1534,13 @@ static bool test_level_2_(bool filename_based)
                return die_("copying object");
        delete block;
 
-       if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/true, filename_based, flacfile_))
+       if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/true, filename_based, flacfilename(is_ogg)))
                return die_c_("during chain.write(false, true)", chain.status());
        block = iterator.get_block();
        if(!compare_chain_(chain, our_current_position, block))
                return false;
        delete block;
-       if(!test_file_(flacfile_, /*ignore_metadata=*/false))
+       if(!test_file_(is_ogg, /*ignore_metadata=*/false))
                return false;
 
        printf("[S]VP\tnext\n");
@@ -1555,13 +1567,13 @@ static bool test_level_2_(bool filename_based)
        if(!iterator.set_block(app))
                return die_c_("iterator.set_block(app)", chain.status());
 
-       if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/false, filename_based, flacfile_))
+       if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg)))
                return die_c_("during chain.write(false, false)", chain.status());
        block = iterator.get_block();
        if(!compare_chain_(chain, our_current_position, block))
                return false;
        delete block;
-       if(!test_file_(flacfile_, /*ignore_metadata=*/false))
+       if(!test_file_(is_ogg, /*ignore_metadata=*/false))
                return false;
 
        printf("SV[A]\tshrink APPLICATION, don't use padding\n");
@@ -1574,13 +1586,13 @@ static bool test_level_2_(bool filename_based)
        if(!iterator.set_block(app))
                return die_c_("iterator.set_block(app)", chain.status());
 
-       if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/false, filename_based, flacfile_))
+       if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg)))
                return die_c_("during chain.write(false, false)", chain.status());
        block = iterator.get_block();
        if(!compare_chain_(chain, our_current_position, block))
                return false;
        delete block;
-       if(!test_file_(flacfile_, /*ignore_metadata=*/false))
+       if(!test_file_(is_ogg, /*ignore_metadata=*/false))
                return false;
 
        printf("SV[A]\tgrow APPLICATION, don't use padding\n");
@@ -1593,13 +1605,13 @@ static bool test_level_2_(bool filename_based)
        if(!iterator.set_block(app))
                return die_c_("iterator.set_block(app)", chain.status());
 
-       if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/false, filename_based, flacfile_))
+       if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg)))
                return die_c_("during chain.write(false, false)", chain.status());
        block = iterator.get_block();
        if(!compare_chain_(chain, our_current_position, block))
                return false;
        delete block;
-       if(!test_file_(flacfile_, /*ignore_metadata=*/false))
+       if(!test_file_(is_ogg, /*ignore_metadata=*/false))
                return false;
 
        printf("SV[A]\tgrow APPLICATION, use padding, but last block is not padding\n");
@@ -1612,13 +1624,13 @@ static bool test_level_2_(bool filename_based)
        if(!iterator.set_block(app))
                return die_c_("iterator.set_block(app)", chain.status());
 
-       if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/false, filename_based, flacfile_))
+       if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg)))
                return die_c_("during chain.write(false, false)", chain.status());
        block = iterator.get_block();
        if(!compare_chain_(chain, our_current_position, block))
                return false;
        delete block;
-       if(!test_file_(flacfile_, /*ignore_metadata=*/false))
+       if(!test_file_(is_ogg, /*ignore_metadata=*/false))
                return false;
 
        printf("SV[A]\tshrink APPLICATION, use padding, last block is not padding, but delta is too small for new PADDING block\n");
@@ -1631,13 +1643,13 @@ static bool test_level_2_(bool filename_based)
        if(!iterator.set_block(app))
                return die_c_("iterator.set_block(app)", chain.status());
 
-       if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfile_))
+       if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg)))
                return die_c_("during chain.write(true, false)", chain.status());
        block = iterator.get_block();
        if(!compare_chain_(chain, our_current_position, block))
                return false;
        delete block;
-       if(!test_file_(flacfile_, /*ignore_metadata=*/false))
+       if(!test_file_(is_ogg, /*ignore_metadata=*/false))
                return false;
 
        printf("SV[A]\tshrink APPLICATION, use padding, last block is not padding, delta is enough for new PADDING block\n");
@@ -1655,13 +1667,13 @@ static bool test_level_2_(bool filename_based)
        if(!iterator.set_block(app))
                return die_c_("iterator.set_block(app)", chain.status());
 
-       if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfile_))
+       if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg)))
                return die_c_("during chain.write(true, false)", chain.status());
        block = iterator.get_block();
        if(!compare_chain_(chain, our_current_position, block))
                return false;
        delete block;
-       if(!test_file_(flacfile_, /*ignore_metadata=*/false))
+       if(!test_file_(is_ogg, /*ignore_metadata=*/false))
                return false;
 
        printf("SV[A]P\tshrink APPLICATION, use padding, last block is padding\n");
@@ -1675,13 +1687,13 @@ static bool test_level_2_(bool filename_based)
        if(!iterator.set_block(app))
                return die_c_("iterator.set_block(app)", chain.status());
 
-       if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfile_))
+       if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg)))
                return die_c_("during chain.write(true, false)", chain.status());
        block = iterator.get_block();
        if(!compare_chain_(chain, our_current_position, block))
                return false;
        delete block;
-       if(!test_file_(flacfile_, /*ignore_metadata=*/false))
+       if(!test_file_(is_ogg, /*ignore_metadata=*/false))
                return false;
 
        printf("SV[A]P\tgrow APPLICATION, use padding, last block is padding, but delta is too small\n");
@@ -1694,13 +1706,13 @@ static bool test_level_2_(bool filename_based)
        if(!iterator.set_block(app))
                return die_c_("iterator.set_block(app)", chain.status());
 
-       if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfile_))
+       if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg)))
                return die_c_("during chain.write(true, false)", chain.status());
        block = iterator.get_block();
        if(!compare_chain_(chain, our_current_position, block))
                return false;
        delete block;
-       if(!test_file_(flacfile_, /*ignore_metadata=*/false))
+       if(!test_file_(is_ogg, /*ignore_metadata=*/false))
                return false;
 
        printf("SV[A]P\tgrow APPLICATION, use padding, last block is padding of exceeding size\n");
@@ -1714,13 +1726,13 @@ static bool test_level_2_(bool filename_based)
        if(!iterator.set_block(app))
                return die_c_("iterator.set_block(app)", chain.status());
 
-       if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfile_))
+       if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg)))
                return die_c_("during chain.write(true, false)", chain.status());
        block = iterator.get_block();
        if(!compare_chain_(chain, our_current_position, block))
                return false;
        delete block;
-       if(!test_file_(flacfile_, /*ignore_metadata=*/false))
+       if(!test_file_(is_ogg, /*ignore_metadata=*/false))
                return false;
 
        printf("SV[A]P\tgrow APPLICATION, use padding, last block is padding of exact size\n");
@@ -1734,13 +1746,13 @@ static bool test_level_2_(bool filename_based)
        if(!iterator.set_block(app))
                return die_c_("iterator.set_block(app)", chain.status());
 
-       if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfile_))
+       if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg)))
                return die_c_("during chain.write(true, false)", chain.status());
        block = iterator.get_block();
        if(!compare_chain_(chain, our_current_position, block))
                return false;
        delete block;
-       if(!test_file_(flacfile_, /*ignore_metadata=*/false))
+       if(!test_file_(is_ogg, /*ignore_metadata=*/false))
                return false;
 
        printf("SV[A]\tprev\n");
@@ -1861,11 +1873,11 @@ static bool test_level_2_(bool filename_based)
        delete_from_our_metadata_(4);
        delete_from_our_metadata_(3);
 
-       if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfile_))
+       if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg)))
                return die_c_("during chain.write(true, false)", chain.status());
        if(!compare_chain_(chain, 0, 0))
                return false;
-       if(!test_file_(flacfile_, /*ignore_metadata=*/false))
+       if(!test_file_(is_ogg, /*ignore_metadata=*/false))
                return false;
 
        printf("SVPAP\tsort padding\n");
@@ -1873,11 +1885,11 @@ static bool test_level_2_(bool filename_based)
        add_to_padding_length_(4, FLAC__STREAM_METADATA_HEADER_LENGTH + our_metadata_.blocks[2]->get_length());
        delete_from_our_metadata_(2);
 
-       if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfile_))
+       if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg)))
                return die_c_("during chain.write(true, false)", chain.status());
        if(!compare_chain_(chain, 0, 0))
                return false;
-       if(!test_file_(flacfile_, /*ignore_metadata=*/false))
+       if(!test_file_(is_ogg, /*ignore_metadata=*/false))
                return false;
 
        printf("create iterator\n");
@@ -1983,30 +1995,31 @@ static bool test_level_2_(bool filename_based)
        printf("SV\tmerge padding\n");
        chain.merge_padding();
 
-       if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/false, filename_based, flacfile_))
+       if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg)))
                return die_c_("during chain.write(false, false)", chain.status());
        if(!compare_chain_(chain, 0, 0))
                return false;
-       if(!test_file_(flacfile_, /*ignore_metadata=*/false))
+       if(!test_file_(is_ogg, /*ignore_metadata=*/false))
                return false;
 
        printf("SV\tsort padding\n");
        chain.sort_padding();
 
-       if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/false, filename_based, flacfile_))
+       if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg)))
                return die_c_("during chain.write(false, false)", chain.status());
        if(!compare_chain_(chain, 0, 0))
                return false;
-       if(!test_file_(flacfile_, /*ignore_metadata=*/false))
+       if(!test_file_(is_ogg, /*ignore_metadata=*/false))
                return false;
 
-       if(!remove_file_(flacfile_))
+end:
+       if(!remove_file_(flacfilename(is_ogg)))
                return false;
 
        return true;
 }
 
-static bool test_level_2_misc_()
+static bool test_level_2_misc_(bool is_ogg)
 {
        ::FLAC__IOCallbacks callbacks;
 
@@ -2025,7 +2038,7 @@ static bool test_level_2_misc_()
 
        printf("generate file\n");
 
-       if(!generate_file_(/*include_extras=*/false))
+       if(!generate_file_(/*include_extras=*/false, is_ogg))
                return false;
 
        printf("create chain\n");
@@ -2035,7 +2048,7 @@ static bool test_level_2_misc_()
 
        printf("read chain (filename-based)\n");
 
-       if(!chain.read(flacfile_))
+       if(!chain.read(flacfilename(is_ogg)))
                return die_c_("reading chain", chain.status());
 
        printf("write chain with wrong method Chain::write(with callbacks)\n");
@@ -2049,7 +2062,7 @@ static bool test_level_2_misc_()
 
        printf("read chain (filename-based)\n");
 
-       if(!chain.read(flacfile_))
+       if(!chain.read(flacfilename(is_ogg)))
                return die_c_("reading chain", chain.status());
 
        printf("write chain with wrong method Chain::write(with callbacks and tempfile)\n");
@@ -2063,7 +2076,7 @@ static bool test_level_2_misc_()
 
        printf("read chain (callback-based)\n");
        {
-               FILE *file = fopen(flacfile_, "rb");
+               FILE *file = fopen(flacfilename(is_ogg), "rb");
                if(0 == file)
                        return die_("opening file");
                if(!chain.read((::FLAC__IOHandle)file, callbacks)) {
@@ -2084,7 +2097,7 @@ static bool test_level_2_misc_()
 
        printf("read chain (callback-based)\n");
        {
-               FILE *file = fopen(flacfile_, "rb");
+               FILE *file = fopen(flacfilename(is_ogg), "rb");
                if(0 == file)
                        return die_("opening file");
                if(!chain.read((::FLAC__IOHandle)file, callbacks)) {
@@ -2112,7 +2125,7 @@ static bool test_level_2_misc_()
 
        printf("read chain (callback-based)\n");
        {
-               FILE *file = fopen(flacfile_, "rb");
+               FILE *file = fopen(flacfilename(is_ogg), "rb");
                if(0 == file)
                        return die_("opening file");
                if(!chain.read((::FLAC__IOHandle)file, callbacks)) {
@@ -2156,7 +2169,7 @@ static bool test_level_2_misc_()
 
        } // delete iterator
 
-       if(!remove_file_(flacfile_))
+       if(!remove_file_(flacfilename(is_ogg)))
                return false;
 
        return true;
@@ -2174,12 +2187,24 @@ bool test_metadata_file_manipulation()
        if(!test_level_1_())
                return false;
 
-       if(!test_level_2_(/*filename_based=*/true)) /* filename-based */
+       if(!test_level_2_(/*filename_based=*/true, /*is_ogg=*/false)) /* filename-based */
                return false;
-       if(!test_level_2_(/*filename_based=*/false)) /* callback-based */
+       if(!test_level_2_(/*filename_based=*/false, /*is_ogg=*/false)) /* callback-based */
                return false;
-       if(!test_level_2_misc_())
+       if(!test_level_2_misc_(/*is_ogg=*/false))
                return false;
 
+       if(FLAC_API_SUPPORTS_OGG_FLAC) {
+               if(!test_level_2_(/*filename_based=*/true, /*is_ogg=*/true)) /* filename-based */
+                       return false;
+               if(!test_level_2_(/*filename_based=*/false, /*is_ogg=*/true)) /* callback-based */
+                       return false;
+#if 0
+               /* when ogg flac write is supported, will have to add this: */
+               if(!test_level_2_misc_(/*is_ogg=*/true))
+                       return false;
+#endif
+       }
+
        return true;
 }