configure.ac : Detect the size of off_t.
[platform/upstream/flac.git] / src / test_libFLAC / metadata_manip.c
index f9cfc19..e720056 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
@@ -11,9 +11,9 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #if HAVE_CONFIG_H
 
 #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] */
-#define fseeko fseek
-#define ftello ftell
-#endif
 #else
 #include <sys/types.h> /* some flavors of BSD (like OS X) require this to get time_t */
 #include <utime.h> /* for utime() */
 #include "FLAC/stream_decoder.h"
 #include "FLAC/metadata.h"
 #include "share/grabbag.h"
+#include "share/compat.h"
+#include "share/macros.h"
 #include "test_libs_common/file_utils_flac.h"
 #include "test_libs_common/metadata_utils.h"
+#include "metadata.h"
 
 
 /******************************************************************************
@@ -63,14 +63,17 @@ typedef struct {
        unsigned num_blocks;
 } our_metadata_struct;
 
-static const char *flacfile_ = "metadata.flac";
-
-/* our copy of the metadata in flacfile_ */
+/* our copy of the metadata in flacfilename() */
 static our_metadata_struct 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(FLAC__bool is_ogg)
+{
+       return is_ogg? "metadata.oga" : "metadata.flac";
+}
+
 static FLAC__bool die_(const char *msg)
 {
        printf("ERROR: %s\n", msg);
@@ -180,11 +183,11 @@ static void delete_from_our_metadata_(unsigned position)
  * This wad of functions supports filename- and callback-based chain reading/writing.
  * Everything up to set_file_stats_() is copied from libFLAC/metadata_iterators.c
  */
-FLAC__bool open_tempfile_(const char *filename, FILE **tempfile, char **tempfilename)
+static FLAC__bool open_tempfile_(const char *filename, FILE **tempfile, char **tempfilename)
 {
        static const char *tempfile_suffix = ".metadata_edit";
 
-       if(0 == (*tempfilename = (char*)malloc(strlen(filename) + strlen(tempfile_suffix) + 1)))
+       if(0 == (*tempfilename = malloc(strlen(filename) + strlen(tempfile_suffix) + 1)))
                return false;
        strcpy(*tempfilename, filename);
        strcat(*tempfilename, tempfile_suffix);
@@ -195,7 +198,7 @@ FLAC__bool open_tempfile_(const char *filename, FILE **tempfile, char **tempfile
        return true;
 }
 
-void cleanup_tempfile_(FILE **tempfile, char **tempfilename)
+static void cleanup_tempfile_(FILE **tempfile, char **tempfilename)
 {
        if(0 != *tempfile) {
                (void)fclose(*tempfile);
@@ -209,7 +212,7 @@ void cleanup_tempfile_(FILE **tempfile, char **tempfilename)
        }
 }
 
-FLAC__bool transport_tempfile_(const char *filename, FILE **tempfile, char **tempfilename)
+static FLAC__bool transport_tempfile_(const char *filename, FILE **tempfile, char **tempfilename)
 {
        FLAC__ASSERT(0 != filename);
        FLAC__ASSERT(0 != tempfile);
@@ -239,14 +242,14 @@ FLAC__bool transport_tempfile_(const char *filename, FILE **tempfile, char **tem
        return true;
 }
 
-FLAC__bool get_file_stats_(const char *filename, struct stat *stats)
+static FLAC__bool get_file_stats_(const char *filename, struct stat *stats)
 {
        FLAC__ASSERT(0 != filename);
        FLAC__ASSERT(0 != stats);
        return (0 == stat(filename, stats));
 }
 
-void set_file_stats_(const char *filename, struct stat *stats)
+static void set_file_stats_(const char *filename, struct stat *stats)
 {
        struct utimbuf srctime;
 
@@ -257,9 +260,9 @@ void set_file_stats_(const char *filename, struct stat *stats)
        srctime.modtime = stats->st_mtime;
        (void)chmod(filename, stats->st_mode);
        (void)utime(filename, &srctime);
-#if !defined _MSC_VER && !defined __MINGW32__ && !defined __EMX__
-       (void)chown(filename, stats->st_uid, -1);
-       (void)chown(filename, -1, stats->st_gid);
+#if !defined _MSC_VER && !defined __MINGW32__
+       FLAC_CHECK_RETURN(chown(filename, stats->st_uid, -1));
+       FLAC_CHECK_RETURN(chown(filename, -1, stats->st_gid));
 #endif
 }
 
@@ -310,7 +313,7 @@ static FLAC__bool write_chain_(FLAC__Metadata_Chain *chain, FLAC__bool use_paddi
 
                if(FLAC__metadata_chain_check_if_tempfile_needed(chain, use_padding)) {
                        struct stat stats;
-                       FILE *file, *tempfile;
+                       FILE *file, *tempfile = 0;
                        char *tempfilename;
                        if(preserve_file_stats) {
                                if(!get_file_stats_(filename, &stats))
@@ -349,10 +352,13 @@ static FLAC__bool write_chain_(FLAC__Metadata_Chain *chain, FLAC__bool use_paddi
        return true;
 }
 
-static FLAC__bool read_chain_(FLAC__Metadata_Chain *chain, const char *filename, FLAC__bool filename_based)
+static FLAC__bool read_chain_(FLAC__Metadata_Chain *chain, const char *filename, FLAC__bool filename_based, FLAC__bool is_ogg)
 {
        if(filename_based)
-               return FLAC__metadata_chain_read(chain, flacfile_);
+               return is_ogg?
+                       FLAC__metadata_chain_read_ogg(chain, flacfilename(is_ogg)) :
+                       FLAC__metadata_chain_read(chain, flacfilename(is_ogg))
+               ;
        else {
                FLAC__IOCallbacks callbacks;
 
@@ -366,7 +372,10 @@ static FLAC__bool read_chain_(FLAC__Metadata_Chain *chain, const char *filename,
                        FILE *file = fopen(filename, "rb");
                        if(0 == file)
                                return false; /*@@@@ chain status still says OK though */
-                       ret = FLAC__metadata_chain_read_with_callbacks(chain, (FLAC__IOHandle)file, callbacks);
+                       ret = is_ogg?
+                               FLAC__metadata_chain_read_ogg_with_callbacks(chain, (FLAC__IOHandle)file, callbacks) :
+                               FLAC__metadata_chain_read_with_callbacks(chain, (FLAC__IOHandle)file, callbacks)
+                       ;
                        fclose(file);
                        return ret;
                }
@@ -496,13 +505,13 @@ static void decoder_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__St
        printf("ERROR: got error callback, status = %s (%u)\n", FLAC__StreamDecoderErrorStatusString[status], (unsigned)status);
 }
 
-static FLAC__bool generate_file_(FLAC__bool include_extras)
+static FLAC__bool generate_file_(FLAC__bool include_extras, FLAC__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);
@@ -595,20 +604,25 @@ static FLAC__bool generate_file_(FLAC__bool include_extras)
        )
                return die_("priming our metadata");
 
-       if(!file_utils__generate_flacfile(/*is_ogg=*/false, 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);
+       if(!include_extras)
+               FLAC__metadata_object_delete(cuesheet);
 
        return true;
 }
 
-static FLAC__bool test_file_(const char *filename, FLAC__StreamDecoderMetadataCallback metadata_callback)
+static FLAC__bool test_file_(FLAC__bool is_ogg, FLAC__StreamDecoderMetadataCallback metadata_callback)
 {
+       const char *filename = flacfilename(is_ogg);
        FLAC__StreamDecoder *decoder;
        decoder_client_struct decoder_client_data;
 
-       FLAC__ASSERT(0 != filename);
        FLAC__ASSERT(0 != metadata_callback);
 
        mc_our_block_number_ = 0;
@@ -622,7 +636,12 @@ static FLAC__bool test_file_(const char *filename, FLAC__StreamDecoderMetadataCa
 
        FLAC__stream_decoder_set_md5_checking(decoder, true);
        FLAC__stream_decoder_set_metadata_respond_all(decoder);
-       if(FLAC__stream_decoder_init_file(decoder, filename, decoder_write_callback_, metadata_callback, decoder_error_callback_, &decoder_client_data) != FLAC__STREAM_DECODER_INIT_STATUS_OK) {
+       if(
+               (is_ogg?
+                       FLAC__stream_decoder_init_ogg_file(decoder, filename, decoder_write_callback_, metadata_callback, decoder_error_callback_, &decoder_client_data) :
+                       FLAC__stream_decoder_init_file(decoder, filename, decoder_write_callback_, metadata_callback, decoder_error_callback_, &decoder_client_data)
+               ) != FLAC__STREAM_DECODER_INIT_STATUS_OK
+       ) {
                (void)FLAC__stream_decoder_finish(decoder);
                FLAC__stream_decoder_delete(decoder);
                return die_("initializing decoder\n");
@@ -665,7 +684,7 @@ static FLAC__bool remove_file_(const char *filename)
        return true;
 }
 
-static FLAC__bool test_level_0_()
+static FLAC__bool test_level_0_(void)
 {
        FLAC__StreamMetadata streaminfo;
        FLAC__StreamMetadata *tags = 0;
@@ -674,15 +693,15 @@ static FLAC__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_, decoder_metadata_callback_null_))
+       if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_null_))
                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_()) */
@@ -701,7 +720,7 @@ static FLAC__bool test_level_0_()
 
        printf("testing FLAC__metadata_get_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_()) */
@@ -714,7 +733,7 @@ static FLAC__bool test_level_0_()
 
        printf("testing FLAC__metadata_get_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_()) */
@@ -727,7 +746,7 @@ static FLAC__bool test_level_0_()
 
        printf("testing FLAC__metadata_get_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_()) */
@@ -738,13 +757,13 @@ static FLAC__bool test_level_0_()
 
        FLAC__metadata_object_delete(picture);
 
-       if(!remove_file_(flacfile_))
+       if(!remove_file_(flacfilename(/*is_ogg=*/false)))
                return false;
 
        return true;
 }
 
-static FLAC__bool test_level_1_()
+static FLAC__bool test_level_1_(void)
 {
        FLAC__Metadata_SimpleIterator *iterator;
        FLAC__StreamMetadata *block, *app, *padding;
@@ -760,19 +779,19 @@ static FLAC__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_, decoder_metadata_callback_null_))
+       if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_null_))
                return false;
 
        if(0 == (iterator = FLAC__metadata_simple_iterator_new()))
                return die_("FLAC__metadata_simple_iterator_new()");
 
-       if(!FLAC__metadata_simple_iterator_init(iterator, flacfile_, /*read_only=*/false, /*preserve_file_stats=*/false))
+       if(!FLAC__metadata_simple_iterator_init(iterator, flacfilename(/*is_ogg=*/false), /*read_only=*/false, /*preserve_file_stats=*/false))
                return die_("FLAC__metadata_simple_iterator_init() returned false");
 
        printf("is writable = %u\n", (unsigned)FLAC__metadata_simple_iterator_is_writable(iterator));
@@ -849,7 +868,7 @@ static FLAC__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");
@@ -867,7 +886,7 @@ static FLAC__bool test_level_1_()
        if(0 == (iterator = FLAC__metadata_simple_iterator_new()))
                return die_("FLAC__metadata_simple_iterator_new()");
 
-       if(!FLAC__metadata_simple_iterator_init(iterator, flacfile_, /*read_only=*/false, /*preserve_file_stats=*/false))
+       if(!FLAC__metadata_simple_iterator_init(iterator, flacfilename(/*is_ogg=*/false), /*read_only=*/false, /*preserve_file_stats=*/false))
                return die_("FLAC__metadata_simple_iterator_init() returned false");
        our_current_position = 0;
 
@@ -913,7 +932,7 @@ static FLAC__bool test_level_1_()
        if(!insert_to_our_metadata_(padding, ++our_current_position, /*copy=*/true))
                return false;
 
-       if(!test_file_(flacfile_, decoder_metadata_callback_compare_))
+       if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_))
                return false;
 
        printf("SV[P]PP\tprev\n");
@@ -930,7 +949,7 @@ static FLAC__bool test_level_1_()
        if(FLAC__metadata_simple_iterator_delete_block(iterator, false))
                return die_ss_("FLAC__metadata_simple_iterator_delete_block(iterator, false) should have returned false", iterator);
 
-       if(!test_file_(flacfile_, decoder_metadata_callback_compare_))
+       if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_))
                return false;
 
        printf("[S]VPPP\tnext\n");
@@ -958,7 +977,7 @@ static FLAC__bool test_level_1_()
                return die_ss_("FLAC__metadata_simple_iterator_delete_block(iterator, false)", iterator);
        delete_from_our_metadata_(our_current_position--);
 
-       if(!test_file_(flacfile_, decoder_metadata_callback_compare_))
+       if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_))
                return false;
 
        printf("S[V]PP\tnext\n");
@@ -976,7 +995,7 @@ static FLAC__bool test_level_1_()
                return die_ss_("FLAC__metadata_simple_iterator_delete_block(iterator, false)", iterator);
        our_current_position--;
 
-       if(!test_file_(flacfile_, decoder_metadata_callback_compare_))
+       if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_))
                return false;
 
        printf("SV[P]P\tnext\n");
@@ -989,7 +1008,7 @@ static FLAC__bool test_level_1_()
                return die_ss_("FLAC__metadata_simple_iterator_delete_block(iterator, false)", iterator);
        delete_from_our_metadata_(our_current_position--);
 
-       if(!test_file_(flacfile_, decoder_metadata_callback_compare_))
+       if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_))
                return false;
 
        printf("SV[P]\tprev\n");
@@ -1012,7 +1031,7 @@ static FLAC__bool test_level_1_()
                return die_ss_("FLAC__metadata_simple_iterator_set_block(iterator, block, false)", iterator);
        FLAC__metadata_object_delete(block);
 
-       if(!test_file_(flacfile_, decoder_metadata_callback_compare_))
+       if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_))
                return false;
 
        printf("[S]VP\tnext\n");
@@ -1028,7 +1047,7 @@ static FLAC__bool test_level_1_()
                return false;
        our_metadata_.blocks[our_current_position+1]->length -= (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) + app->length;
 
-       if(!test_file_(flacfile_, decoder_metadata_callback_compare_))
+       if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_))
                return false;
 
        printf("SV[A]P\tnext\n");
@@ -1044,7 +1063,7 @@ static FLAC__bool test_level_1_()
                return false;
        our_metadata_.blocks[our_current_position+1]->length -= (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) + app->length;
 
-       if(!test_file_(flacfile_, decoder_metadata_callback_compare_))
+       if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_))
                return false;
 
        printf("SVA[A]P\tset APPLICATION (grow), don't expand into padding\n");
@@ -1056,7 +1075,7 @@ static FLAC__bool test_level_1_()
        if(!FLAC__metadata_simple_iterator_set_block(iterator, app, false))
                return die_ss_("FLAC__metadata_simple_iterator_set_block(iterator, app, false)", iterator);
 
-       if(!test_file_(flacfile_, decoder_metadata_callback_compare_))
+       if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_))
                return false;
 
        printf("SVA[A]P\tset APPLICATION (shrink), don't fill in with padding\n");
@@ -1068,7 +1087,7 @@ static FLAC__bool test_level_1_()
        if(!FLAC__metadata_simple_iterator_set_block(iterator, app, false))
                return die_ss_("FLAC__metadata_simple_iterator_set_block(iterator, app, false)", iterator);
 
-       if(!test_file_(flacfile_, decoder_metadata_callback_compare_))
+       if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_))
                return false;
 
        printf("SVA[A]P\tset APPLICATION (grow), expand into padding of exceeding size\n");
@@ -1081,7 +1100,7 @@ static FLAC__bool test_level_1_()
        if(!FLAC__metadata_simple_iterator_set_block(iterator, app, true))
                return die_ss_("FLAC__metadata_simple_iterator_set_block(iterator, app, true)", iterator);
 
-       if(!test_file_(flacfile_, decoder_metadata_callback_compare_))
+       if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_))
                return false;
 
        printf("SVA[A]P\tset APPLICATION (shrink), fill in with padding\n");
@@ -1096,7 +1115,7 @@ static FLAC__bool test_level_1_()
        if(!FLAC__metadata_simple_iterator_set_block(iterator, app, true))
                return die_ss_("FLAC__metadata_simple_iterator_set_block(iterator, app, true)", iterator);
 
-       if(!test_file_(flacfile_, decoder_metadata_callback_compare_))
+       if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_))
                return false;
 
        printf("SVA[A]PP\tnext\n");
@@ -1116,7 +1135,7 @@ static FLAC__bool test_level_1_()
        if(!FLAC__metadata_simple_iterator_set_block(iterator, padding, false))
                return die_ss_("FLAC__metadata_simple_iterator_set_block(iterator, padding, false)", iterator);
 
-       if(!test_file_(flacfile_, decoder_metadata_callback_compare_))
+       if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_))
                return false;
 
        printf("SVAAP[P]\tset APPLICATION (grow)\n");
@@ -1126,7 +1145,7 @@ static FLAC__bool test_level_1_()
        if(!FLAC__metadata_simple_iterator_set_block(iterator, app, false))
                return die_ss_("FLAC__metadata_simple_iterator_set_block(iterator, app, false)", iterator);
 
-       if(!test_file_(flacfile_, decoder_metadata_callback_compare_))
+       if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_))
                return false;
 
        printf("SVAAP[A]\tset PADDING (equal)\n");
@@ -1136,7 +1155,7 @@ static FLAC__bool test_level_1_()
        if(!FLAC__metadata_simple_iterator_set_block(iterator, padding, false))
                return die_ss_("FLAC__metadata_simple_iterator_set_block(iterator, padding, false)", iterator);
 
-       if(!test_file_(flacfile_, decoder_metadata_callback_compare_))
+       if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_))
                return false;
 
        printf("SVAAP[P]\tprev\n");
@@ -1149,7 +1168,7 @@ static FLAC__bool test_level_1_()
                return die_ss_("FLAC__metadata_simple_iterator_delete_block(iterator, false)", iterator);
        delete_from_our_metadata_(our_current_position--);
 
-       if(!test_file_(flacfile_, decoder_metadata_callback_compare_))
+       if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_))
                return false;
 
        printf("SVA[A]P\tdelete (middle block), don't replace with padding\n");
@@ -1157,7 +1176,7 @@ static FLAC__bool test_level_1_()
                return die_ss_("FLAC__metadata_simple_iterator_delete_block(iterator, false)", iterator);
        delete_from_our_metadata_(our_current_position--);
 
-       if(!test_file_(flacfile_, decoder_metadata_callback_compare_))
+       if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_))
                return false;
 
        printf("SV[A]P\tnext\n");
@@ -1172,7 +1191,7 @@ static FLAC__bool test_level_1_()
        if(!insert_to_our_metadata_(padding, ++our_current_position, /*copy=*/true))
                return false;
 
-       if(!test_file_(flacfile_, decoder_metadata_callback_compare_))
+       if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_))
                return false;
 
        printf("SVAP[P]\tprev\n");
@@ -1193,7 +1212,7 @@ static FLAC__bool test_level_1_()
        if(!FLAC__metadata_simple_iterator_set_block(iterator, app, true))
                return die_ss_("FLAC__metadata_simple_iterator_set_block(iterator, app, true)", iterator);
 
-       if(!test_file_(flacfile_, decoder_metadata_callback_compare_))
+       if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_))
                return false;
 
        printf("SV[A]PP\tset APPLICATION (grow), try to expand into padding which is 'close' but still too small\n");
@@ -1204,7 +1223,7 @@ static FLAC__bool test_level_1_()
        if(!FLAC__metadata_simple_iterator_set_block(iterator, app, true))
                return die_ss_("FLAC__metadata_simple_iterator_set_block(iterator, app, true)", iterator);
 
-       if(!test_file_(flacfile_, decoder_metadata_callback_compare_))
+       if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_))
                return false;
 
        printf("SV[A]PP\tset APPLICATION (grow), expand into padding which will leave 0-length pad\n");
@@ -1216,7 +1235,7 @@ static FLAC__bool test_level_1_()
        if(!FLAC__metadata_simple_iterator_set_block(iterator, app, true))
                return die_ss_("FLAC__metadata_simple_iterator_set_block(iterator, app, true)", iterator);
 
-       if(!test_file_(flacfile_, decoder_metadata_callback_compare_))
+       if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_))
                return false;
 
        printf("SV[A]PP\tset APPLICATION (grow), expand into padding which is exactly consumed\n");
@@ -1228,7 +1247,7 @@ static FLAC__bool test_level_1_()
        if(!FLAC__metadata_simple_iterator_set_block(iterator, app, true))
                return die_ss_("FLAC__metadata_simple_iterator_set_block(iterator, app, true)", iterator);
 
-       if(!test_file_(flacfile_, decoder_metadata_callback_compare_))
+       if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_))
                return false;
 
        printf("SV[A]P\tset APPLICATION (grow), expand into padding which is exactly consumed\n");
@@ -1241,7 +1260,7 @@ static FLAC__bool test_level_1_()
        if(!FLAC__metadata_simple_iterator_set_block(iterator, app, true))
                return die_ss_("FLAC__metadata_simple_iterator_set_block(iterator, app, true)", iterator);
 
-       if(!test_file_(flacfile_, decoder_metadata_callback_compare_))
+       if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_))
                return false;
 
        printf("SV[A]\tset PADDING (equal size)\n");
@@ -1251,7 +1270,7 @@ static FLAC__bool test_level_1_()
        if(!FLAC__metadata_simple_iterator_set_block(iterator, padding, true))
                return die_ss_("FLAC__metadata_simple_iterator_set_block(iterator, padding, true)", iterator);
 
-       if(!test_file_(flacfile_, decoder_metadata_callback_compare_))
+       if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_))
                return false;
 
        printf("SV[P]\tinsert PADDING after\n");
@@ -1260,7 +1279,7 @@ static FLAC__bool test_level_1_()
        if(!insert_to_our_metadata_(padding, ++our_current_position, /*copy=*/true))
                return false;
 
-       if(!test_file_(flacfile_, decoder_metadata_callback_compare_))
+       if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_))
                return false;
 
        printf("SVP[P]\tinsert PADDING after\n");
@@ -1270,7 +1289,7 @@ static FLAC__bool test_level_1_()
        if(!insert_to_our_metadata_(padding, ++our_current_position, /*copy=*/true))
                return false;
 
-       if(!test_file_(flacfile_, decoder_metadata_callback_compare_))
+       if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_))
                return false;
 
        printf("SVPP[P]\tprev\n");
@@ -1296,7 +1315,7 @@ static FLAC__bool test_level_1_()
        if(!FLAC__metadata_simple_iterator_insert_block_after(iterator, app, true))
                return die_ss_("FLAC__metadata_simple_iterator_insert_block_after(iterator, app, true)", iterator);
 
-       if(!test_file_(flacfile_, decoder_metadata_callback_compare_))
+       if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_))
                return false;
 
        printf("SV[A]PPP\tdelete (middle block), don't replace with padding\n");
@@ -1304,7 +1323,7 @@ static FLAC__bool test_level_1_()
                return die_ss_("FLAC__metadata_simple_iterator_delete_block(iterator, false)", iterator);
        delete_from_our_metadata_(our_current_position--);
 
-       if(!test_file_(flacfile_, decoder_metadata_callback_compare_))
+       if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_))
                return false;
 
        printf("S[V]PPP\tinsert APPLICATION after, try to expand into padding which is 'close' but still too small\n");
@@ -1315,7 +1334,7 @@ static FLAC__bool test_level_1_()
        if(!FLAC__metadata_simple_iterator_insert_block_after(iterator, app, true))
                return die_ss_("FLAC__metadata_simple_iterator_insert_block_after(iterator, app, true)", iterator);
 
-       if(!test_file_(flacfile_, decoder_metadata_callback_compare_))
+       if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_))
                return false;
 
        printf("SV[A]PPP\tdelete (middle block), don't replace with padding\n");
@@ -1323,7 +1342,7 @@ static FLAC__bool test_level_1_()
                return die_ss_("FLAC__metadata_simple_iterator_delete_block(iterator, false)", iterator);
        delete_from_our_metadata_(our_current_position--);
 
-       if(!test_file_(flacfile_, decoder_metadata_callback_compare_))
+       if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_))
                return false;
 
        printf("S[V]PPP\tinsert APPLICATION after, expand into padding which is exactly consumed\n");
@@ -1335,7 +1354,7 @@ static FLAC__bool test_level_1_()
        if(!FLAC__metadata_simple_iterator_insert_block_after(iterator, app, true))
                return die_ss_("FLAC__metadata_simple_iterator_insert_block_after(iterator, app, true)", iterator);
 
-       if(!test_file_(flacfile_, decoder_metadata_callback_compare_))
+       if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_))
                return false;
 
        printf("SV[A]PP\tdelete (middle block), don't replace with padding\n");
@@ -1343,7 +1362,7 @@ static FLAC__bool test_level_1_()
                return die_ss_("FLAC__metadata_simple_iterator_delete_block(iterator, false)", iterator);
        delete_from_our_metadata_(our_current_position--);
 
-       if(!test_file_(flacfile_, decoder_metadata_callback_compare_))
+       if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_))
                return false;
 
        printf("S[V]PP\tinsert APPLICATION after, expand into padding which will leave 0-length pad\n");
@@ -1355,7 +1374,7 @@ static FLAC__bool test_level_1_()
        if(!FLAC__metadata_simple_iterator_insert_block_after(iterator, app, true))
                return die_ss_("FLAC__metadata_simple_iterator_insert_block_after(iterator, app, true)", iterator);
 
-       if(!test_file_(flacfile_, decoder_metadata_callback_compare_))
+       if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_))
                return false;
 
        printf("SV[A]PP\tdelete (middle block), don't replace with padding\n");
@@ -1363,7 +1382,7 @@ static FLAC__bool test_level_1_()
                return die_ss_("FLAC__metadata_simple_iterator_delete_block(iterator, false)", iterator);
        delete_from_our_metadata_(our_current_position--);
 
-       if(!test_file_(flacfile_, decoder_metadata_callback_compare_))
+       if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_))
                return false;
 
        printf("S[V]PP\tnext\n");
@@ -1376,7 +1395,7 @@ static FLAC__bool test_level_1_()
                return die_ss_("FLAC__metadata_simple_iterator_delete_block(iterator, false)", iterator);
        delete_from_our_metadata_(our_current_position--);
 
-       if(!test_file_(flacfile_, decoder_metadata_callback_compare_))
+       if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_))
                return false;
 
        printf("S[V]P\tinsert APPLICATION after, expand into padding which is exactly consumed\n");
@@ -1388,7 +1407,7 @@ static FLAC__bool test_level_1_()
        if(!FLAC__metadata_simple_iterator_insert_block_after(iterator, app, true))
                return die_ss_("FLAC__metadata_simple_iterator_insert_block_after(iterator, app, true)", iterator);
 
-       if(!test_file_(flacfile_, decoder_metadata_callback_compare_))
+       if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_))
                return false;
 
        printf("delete simple iterator\n");
@@ -1398,13 +1417,13 @@ static FLAC__bool test_level_1_()
        FLAC__metadata_object_delete(app);
        FLAC__metadata_object_delete(padding);
 
-       if(!remove_file_(flacfile_))
+       if(!remove_file_(flacfilename(/*is_ogg=*/false)))
                return false;
 
        return true;
 }
 
-static FLAC__bool test_level_2_(FLAC__bool filename_based)
+static FLAC__bool test_level_2_(FLAC__bool filename_based, FLAC__bool is_ogg)
 {
        FLAC__Metadata_Iterator *iterator;
        FLAC__Metadata_Chain *chain;
@@ -1415,14 +1434,14 @@ static FLAC__bool test_level_2_(FLAC__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");
@@ -1432,19 +1451,22 @@ static FLAC__bool test_level_2_(FLAC__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", FLAC__metadata_chain_status(chain));
 
        printf("[S]VP\ttest initial metadata\n");
 
        if(!compare_chain_(chain, 0, 0))
                return false;
-       if(!test_file_(flacfile_, decoder_metadata_callback_compare_))
+       if(!test_file_(is_ogg, decoder_metadata_callback_compare_))
                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");
@@ -1466,11 +1488,11 @@ static FLAC__bool test_level_2_(FLAC__bool filename_based)
        if(!replace_in_our_metadata_(block, our_current_position, /*copy=*/true))
                return die_("copying object");
 
-       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 FLAC__metadata_chain_write(chain, false, true)", FLAC__metadata_chain_status(chain));
        if(!compare_chain_(chain, our_current_position, FLAC__metadata_iterator_get_block(iterator)))
                return false;
-       if(!test_file_(flacfile_, decoder_metadata_callback_compare_))
+       if(!test_file_(is_ogg, decoder_metadata_callback_compare_))
                return false;
 
        printf("[S]VP\tnext\n");
@@ -1496,11 +1518,11 @@ static FLAC__bool test_level_2_(FLAC__bool filename_based)
        if(!FLAC__metadata_iterator_set_block(iterator, app))
                return die_c_("FLAC__metadata_iterator_set_block(iterator, app)", FLAC__metadata_chain_status(chain));
 
-       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 FLAC__metadata_chain_write(chain, false, false)", FLAC__metadata_chain_status(chain));
        if(!compare_chain_(chain, our_current_position, FLAC__metadata_iterator_get_block(iterator)))
                return false;
-       if(!test_file_(flacfile_, decoder_metadata_callback_compare_))
+       if(!test_file_(is_ogg, decoder_metadata_callback_compare_))
                return false;
 
        printf("SV[A]\tshrink APPLICATION, don't use padding\n");
@@ -1513,11 +1535,11 @@ static FLAC__bool test_level_2_(FLAC__bool filename_based)
        if(!FLAC__metadata_iterator_set_block(iterator, app))
                return die_c_("FLAC__metadata_iterator_set_block(iterator, app)", FLAC__metadata_chain_status(chain));
 
-       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 FLAC__metadata_chain_write(chain, false, false)", FLAC__metadata_chain_status(chain));
        if(!compare_chain_(chain, our_current_position, FLAC__metadata_iterator_get_block(iterator)))
                return false;
-       if(!test_file_(flacfile_, decoder_metadata_callback_compare_))
+       if(!test_file_(is_ogg, decoder_metadata_callback_compare_))
                return false;
 
        printf("SV[A]\tgrow APPLICATION, don't use padding\n");
@@ -1530,11 +1552,11 @@ static FLAC__bool test_level_2_(FLAC__bool filename_based)
        if(!FLAC__metadata_iterator_set_block(iterator, app))
                return die_c_("FLAC__metadata_iterator_set_block(iterator, app)", FLAC__metadata_chain_status(chain));
 
-       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 FLAC__metadata_chain_write(chain, false, false)", FLAC__metadata_chain_status(chain));
        if(!compare_chain_(chain, our_current_position, FLAC__metadata_iterator_get_block(iterator)))
                return false;
-       if(!test_file_(flacfile_, decoder_metadata_callback_compare_))
+       if(!test_file_(is_ogg, decoder_metadata_callback_compare_))
                return false;
 
        printf("SV[A]\tgrow APPLICATION, use padding, but last block is not padding\n");
@@ -1547,11 +1569,11 @@ static FLAC__bool test_level_2_(FLAC__bool filename_based)
        if(!FLAC__metadata_iterator_set_block(iterator, app))
                return die_c_("FLAC__metadata_iterator_set_block(iterator, app)", FLAC__metadata_chain_status(chain));
 
-       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 FLAC__metadata_chain_write(chain, false, false)", FLAC__metadata_chain_status(chain));
        if(!compare_chain_(chain, our_current_position, FLAC__metadata_iterator_get_block(iterator)))
                return false;
-       if(!test_file_(flacfile_, decoder_metadata_callback_compare_))
+       if(!test_file_(is_ogg, decoder_metadata_callback_compare_))
                return false;
 
        printf("SV[A]\tshrink APPLICATION, use padding, last block is not padding, but delta is too small for new PADDING block\n");
@@ -1564,11 +1586,11 @@ static FLAC__bool test_level_2_(FLAC__bool filename_based)
        if(!FLAC__metadata_iterator_set_block(iterator, app))
                return die_c_("FLAC__metadata_iterator_set_block(iterator, app)", FLAC__metadata_chain_status(chain));
 
-       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 FLAC__metadata_chain_write(chain, true, false)", FLAC__metadata_chain_status(chain));
        if(!compare_chain_(chain, our_current_position, FLAC__metadata_iterator_get_block(iterator)))
                return false;
-       if(!test_file_(flacfile_, decoder_metadata_callback_compare_))
+       if(!test_file_(is_ogg, decoder_metadata_callback_compare_))
                return false;
 
        printf("SV[A]\tshrink APPLICATION, use padding, last block is not padding, delta is enough for new PADDING block\n");
@@ -1586,11 +1608,11 @@ static FLAC__bool test_level_2_(FLAC__bool filename_based)
        if(!FLAC__metadata_iterator_set_block(iterator, app))
                return die_c_("FLAC__metadata_iterator_set_block(iterator, app)", FLAC__metadata_chain_status(chain));
 
-       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 FLAC__metadata_chain_write(chain, true, false)", FLAC__metadata_chain_status(chain));
        if(!compare_chain_(chain, our_current_position, FLAC__metadata_iterator_get_block(iterator)))
                return false;
-       if(!test_file_(flacfile_, decoder_metadata_callback_compare_))
+       if(!test_file_(is_ogg, decoder_metadata_callback_compare_))
                return false;
 
        printf("SV[A]P\tshrink APPLICATION, use padding, last block is padding\n");
@@ -1604,11 +1626,11 @@ static FLAC__bool test_level_2_(FLAC__bool filename_based)
        if(!FLAC__metadata_iterator_set_block(iterator, app))
                return die_c_("FLAC__metadata_iterator_set_block(iterator, app)", FLAC__metadata_chain_status(chain));
 
-       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 FLAC__metadata_chain_write(chain, true, false)", FLAC__metadata_chain_status(chain));
        if(!compare_chain_(chain, our_current_position, FLAC__metadata_iterator_get_block(iterator)))
                return false;
-       if(!test_file_(flacfile_, decoder_metadata_callback_compare_))
+       if(!test_file_(is_ogg, decoder_metadata_callback_compare_))
                return false;
 
        printf("SV[A]P\tgrow APPLICATION, use padding, last block is padding, but delta is too small\n");
@@ -1621,11 +1643,11 @@ static FLAC__bool test_level_2_(FLAC__bool filename_based)
        if(!FLAC__metadata_iterator_set_block(iterator, app))
                return die_c_("FLAC__metadata_iterator_set_block(iterator, app)", FLAC__metadata_chain_status(chain));
 
-       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 FLAC__metadata_chain_write(chain, true, false)", FLAC__metadata_chain_status(chain));
        if(!compare_chain_(chain, our_current_position, FLAC__metadata_iterator_get_block(iterator)))
                return false;
-       if(!test_file_(flacfile_, decoder_metadata_callback_compare_))
+       if(!test_file_(is_ogg, decoder_metadata_callback_compare_))
                return false;
 
        printf("SV[A]P\tgrow APPLICATION, use padding, last block is padding of exceeding size\n");
@@ -1639,11 +1661,11 @@ static FLAC__bool test_level_2_(FLAC__bool filename_based)
        if(!FLAC__metadata_iterator_set_block(iterator, app))
                return die_c_("FLAC__metadata_iterator_set_block(iterator, app)", FLAC__metadata_chain_status(chain));
 
-       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 FLAC__metadata_chain_write(chain, true, false)", FLAC__metadata_chain_status(chain));
        if(!compare_chain_(chain, our_current_position, FLAC__metadata_iterator_get_block(iterator)))
                return false;
-       if(!test_file_(flacfile_, decoder_metadata_callback_compare_))
+       if(!test_file_(is_ogg, decoder_metadata_callback_compare_))
                return false;
 
        printf("SV[A]P\tgrow APPLICATION, use padding, last block is padding of exact size\n");
@@ -1657,11 +1679,11 @@ static FLAC__bool test_level_2_(FLAC__bool filename_based)
        if(!FLAC__metadata_iterator_set_block(iterator, app))
                return die_c_("FLAC__metadata_iterator_set_block(iterator, app)", FLAC__metadata_chain_status(chain));
 
-       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 FLAC__metadata_chain_write(chain, true, false)", FLAC__metadata_chain_status(chain));
        if(!compare_chain_(chain, our_current_position, FLAC__metadata_iterator_get_block(iterator)))
                return false;
-       if(!test_file_(flacfile_, decoder_metadata_callback_compare_))
+       if(!test_file_(is_ogg, decoder_metadata_callback_compare_))
                return false;
 
        printf("SV[A]\tprev\n");
@@ -1773,11 +1795,11 @@ static FLAC__bool test_level_2_(FLAC__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 FLAC__metadata_chain_write(chain, true, false)", FLAC__metadata_chain_status(chain));
        if(!compare_chain_(chain, 0, 0))
                return false;
-       if(!test_file_(flacfile_, decoder_metadata_callback_compare_))
+       if(!test_file_(is_ogg, decoder_metadata_callback_compare_))
                return false;
 
        printf("SVPAP\tsort padding\n");
@@ -1785,11 +1807,11 @@ static FLAC__bool test_level_2_(FLAC__bool filename_based)
        our_metadata_.blocks[4]->length += (FLAC__STREAM_METADATA_HEADER_LENGTH + our_metadata_.blocks[2]->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 FLAC__metadata_chain_write(chain, true, false)", FLAC__metadata_chain_status(chain));
        if(!compare_chain_(chain, 0, 0))
                return false;
-       if(!test_file_(flacfile_, decoder_metadata_callback_compare_))
+       if(!test_file_(is_ogg, decoder_metadata_callback_compare_))
                return false;
 
        printf("create iterator\n");
@@ -1884,34 +1906,35 @@ static FLAC__bool test_level_2_(FLAC__bool filename_based)
        printf("SV\tmerge padding\n");
        FLAC__metadata_chain_merge_padding(chain);
 
-       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 FLAC__metadata_chain_write(chain, false, false)", FLAC__metadata_chain_status(chain));
        if(!compare_chain_(chain, 0, 0))
                return false;
-       if(!test_file_(flacfile_, decoder_metadata_callback_compare_))
+       if(!test_file_(is_ogg, decoder_metadata_callback_compare_))
                return false;
 
        printf("SV\tsort padding\n");
        FLAC__metadata_chain_sort_padding(chain);
 
-       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 FLAC__metadata_chain_write(chain, false, false)", FLAC__metadata_chain_status(chain));
        if(!compare_chain_(chain, 0, 0))
                return false;
-       if(!test_file_(flacfile_, decoder_metadata_callback_compare_))
+       if(!test_file_(is_ogg, decoder_metadata_callback_compare_))
                return false;
 
+end:
        printf("delete chain\n");
 
        FLAC__metadata_chain_delete(chain);
 
-       if(!remove_file_(flacfile_))
+       if(!remove_file_(flacfilename(is_ogg)))
                return false;
 
        return true;
 }
 
-static FLAC__bool test_level_2_misc_()
+static FLAC__bool test_level_2_misc_(FLAC__bool is_ogg)
 {
        FLAC__Metadata_Iterator *iterator;
        FLAC__Metadata_Chain *chain;
@@ -1932,7 +1955,7 @@ static FLAC__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");
@@ -1942,7 +1965,7 @@ static FLAC__bool test_level_2_misc_()
 
        printf("read chain (filename-based)\n");
 
-       if(!FLAC__metadata_chain_read(chain, flacfile_))
+       if(!FLAC__metadata_chain_read(chain, flacfilename(is_ogg)))
                return die_c_("reading chain", FLAC__metadata_chain_status(chain));
 
        printf("write chain with wrong method FLAC__metadata_chain_write_with_callbacks()\n");
@@ -1956,7 +1979,7 @@ static FLAC__bool test_level_2_misc_()
 
        printf("read chain (filename-based)\n");
 
-       if(!FLAC__metadata_chain_read(chain, flacfile_))
+       if(!FLAC__metadata_chain_read(chain, flacfilename(is_ogg)))
                return die_c_("reading chain", FLAC__metadata_chain_status(chain));
 
        printf("write chain with wrong method FLAC__metadata_chain_write_with_callbacks_and_tempfile()\n");
@@ -1970,7 +1993,7 @@ static FLAC__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(!FLAC__metadata_chain_read_with_callbacks(chain, (FLAC__IOHandle)file, callbacks)) {
@@ -1991,7 +2014,7 @@ static FLAC__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(!FLAC__metadata_chain_read_with_callbacks(chain, (FLAC__IOHandle)file, callbacks)) {
@@ -2019,7 +2042,7 @@ static FLAC__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(!FLAC__metadata_chain_read_with_callbacks(chain, (FLAC__IOHandle)file, callbacks)) {
@@ -2067,13 +2090,13 @@ static FLAC__bool test_level_2_misc_()
 
        FLAC__metadata_chain_delete(chain);
 
-       if(!remove_file_(flacfile_))
+       if(!remove_file_(flacfilename(is_ogg)))
                return false;
 
        return true;
 }
 
-FLAC__bool test_metadata_file_manipulation()
+FLAC__bool test_metadata_file_manipulation(void)
 {
        printf("\n+++ libFLAC unit test: metadata manipulation\n\n");
 
@@ -2085,12 +2108,24 @@ FLAC__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;
 }