/* 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
* 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() */
-//@@@ [2G limit] hacks for MSVC6
-#define fseeko fseek
-#define ftello ftell
#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"
/******************************************************************************
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);
* 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);
return true;
}
-void cleanup_tempfile_(FILE **tempfile, char **tempfilename)
+static void cleanup_tempfile_(FILE **tempfile, char **tempfilename)
{
if(0 != *tempfile) {
(void)fclose(*tempfile);
}
}
-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);
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;
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
}
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))
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(!FLAC__metadata_chain_write_with_callbacks_and_tempfile(chain, use_padding, (FLAC__IOHandle)file, callbacks, (FLAC__IOHandle)tempfile, callbacks)) {
fclose(file);
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(!FLAC__metadata_chain_write_with_callbacks(chain, use_padding, (FLAC__IOHandle)file, callbacks))
return false;
fclose(file);
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;
FLAC__bool ret;
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);
+ return false; /*@@@@ chain status still says OK though */
+ 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;
}
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);
FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN +
FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN +
FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN +
+ FLAC__STREAM_METADATA_PICTURE_COLORS_LEN +
FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN /* will add the length for the data later */
) / 8
;
picture.data.picture.width = 300;
picture.data.picture.height = 300;
picture.data.picture.depth = 24;
+ picture.data.picture.colors = 0;
picture.data.picture.data = (FLAC__byte*)strdup_or_die_("SOMEJPEGDATA");
picture.data.picture.data_length = strlen((const char *)picture.data.picture.data);
picture.length += picture.data.picture.data_length;
)
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);
+ 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;
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) {
- FLAC__stream_decoder_finish(decoder);
+ 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");
}
if(!FLAC__stream_decoder_process_until_end_of_stream(decoder)) {
- FLAC__stream_decoder_finish(decoder);
+ (void)FLAC__stream_decoder_finish(decoder);
FLAC__stream_decoder_delete(decoder);
return die_("decoding file\n");
}
- FLAC__stream_decoder_finish(decoder);
+ (void)FLAC__stream_decoder_finish(decoder);
FLAC__stream_decoder_delete(decoder);
if(decoder_client_data.error_occurred)
return true;
}
-static FLAC__bool test_level_0_()
+static FLAC__bool test_level_0_(void)
{
FLAC__StreamMetadata streaminfo;
FLAC__StreamMetadata *tags = 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_()) */
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_()) */
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_()) */
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)))
+ 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_()) */
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;
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));
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");
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;
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");
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");
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");
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");
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");
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");
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");
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");
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");
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");
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");
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");
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");
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");
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");
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");
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");
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");
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");
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");
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");
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");
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");
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");
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");
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");
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");
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");
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");
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");
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");
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");
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");
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");
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");
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");
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;
/* 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");
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");
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");
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");
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");
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");
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");
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");
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");
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");
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");
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");
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");
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");
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");
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;
printf("generate file\n");
- if(!generate_file_(/*include_extras=*/false))
+ if(!generate_file_(/*include_extras=*/false, is_ogg))
return false;
printf("create chain\n");
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");
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");
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)) {
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)) {
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)) {
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");
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;
}