add support for read-only operations for ogg flac to chain interface

This commit is contained in:
Josh Coalson 2006-11-15 06:12:30 +00:00
parent d037e887e8
commit 7d273b4bdb
7 changed files with 498 additions and 250 deletions

View File

@ -119,6 +119,7 @@
<li>
metaflac:
<ul>
<li>Added support for read-only operations on Ogg FLAC files.</li>
<li>Added a new option <span class="argument"><a href="documentation.html#metaflac_shorthand_set_tag_from_file">--set-tag-from-file</a></span> for setting a tag from file (e.g. for importing a cuesheet as a tag).</li>
<li>Added a new option <span class="argument"><a href="documentation.html#metaflac_shorthand_import_picture_from">--import-picture-from</a></span> for importing pictures.</li>
<li>Added a new option <span class="argument"><a href="documentation.html#metaflac_shorthand_export_picture_to">--export-picture-to</a></span> for exporting pictures.</li>
@ -191,6 +192,7 @@
<li><b>Added</b> FLAC__metadata_object_cuesheet_calculate_cddb_id()</li>
<li><b>Added</b> FLAC__metadata_get_cuesheet()</li>
<li><b>Added</b> FLAC__metadata_get_picture()</li>
<li><b>Added</b> FLAC__metadata_chain_read_ogg() and FLAC__metadata_chain_read_ogg_with_callbacks()</li>
<li><b>Changed</b> FLAC__stream_encoder_finish() now returns a FLAC__bool to signal a verify failure.</li>
<li><b>Changed</b> FLAC__StreamDecoderState: removed state FLAC__STREAM_DECODER_UNPARSEABLE_STREAM</li>
<li><b>Changed</b> FLAC__StreamDecoderErrorStatus: new error code FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM</li>
@ -206,6 +208,7 @@
<li><b>Added</b> FLAC::Metadata::CueSheet::calculate_cddb_id()</li>
<li><b>Added</b> FLAC::Metadata::get_cuesheet()</li>
<li><b>Added</b> FLAC::Metadata::get_picture()</li>
<li><b>Changed</b> FLAC::Metadata::Chain::read() to accept a flag denoting Ogg FLAC input</li>
<li><b>Changed</b> FLAC::Decoder::Stream::finish() now returns a bool to signal an MD5 failure like FLAC__stream_decoder_finish() does.</li>
<li><b>Changed</b> FLAC::Encoder::Stream::finish() now returns a bool to signal a verify failure.</li>
</ul>

View File

@ -1095,8 +1095,8 @@ namespace FLAC {
Status status(); ///< See FLAC__metadata_chain_status().
bool read(const char *filename); ///< See FLAC__metadata_chain_read().
bool read(FLAC__IOHandle handle, FLAC__IOCallbacks callbacks); ///< See FLAC__metadata_chain_read_with_callbacks().
bool read(const char *filename, bool is_ogg = false); ///< See FLAC__metadata_chain_read(), FLAC__metadata_chain_read_ogg().
bool read(FLAC__IOHandle handle, FLAC__IOCallbacks callbacks, bool is_ogg = false); ///< See FLAC__metadata_chain_read_with_callbacks(), FLAC__metadata_chain_read_ogg_with_callbacks().
bool check_if_tempfile_needed(bool use_padding); ///< See FLAC__metadata_chain_check_if_tempfile_needed().

View File

@ -584,12 +584,17 @@ FLAC_API FLAC__bool FLAC__metadata_simple_iterator_delete_block(FLAC__Metadata_S
* all metadata is read into memory, operated on in memory, and then written
* to file, which is more efficient than level 1 when editing multiple blocks.
*
* Currently Ogg FLAC is supported for read only, via
* FLAC__metadata_chain_read_ogg() but a subsequent
* FLAC__metadata_chain_write() will fail.
*
* The general usage of this interface is:
*
* - Create a new chain using FLAC__metadata_chain_new(). A chain is a
* linked list of FLAC metadata blocks.
* - Read all metadata into the the chain from a FLAC file using
* FLAC__metadata_chain_read() and check the status.
* FLAC__metadata_chain_read() or FLAC__metadata_chain_read_ogg() and
* check the status.
* - Optionally, consolidate the padding using
* FLAC__metadata_chain_merge_padding() or
* FLAC__metadata_chain_sort_padding().
@ -611,8 +616,8 @@ FLAC_API FLAC__bool FLAC__metadata_simple_iterator_delete_block(FLAC__Metadata_S
* Even though the FLAC file is not open while the chain is being
* manipulated, you must not alter the file externally during
* this time. The chain assumes the FLAC file will not change
* between the time of FLAC__metadata_chain_read() and
* FLAC__metadata_chain_write().
* between the time of FLAC__metadata_chain_read()/FLAC__metadata_chain_read_ogg()
* and FLAC__metadata_chain_write().
*
* \note
* Do not modify the is_last, length, or type fields of returned
@ -683,11 +688,12 @@ typedef enum {
FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH,
/**< FLAC__metadata_chain_write() was called on a chain read by
* FLAC__metadata_chain_read_with_callbacks(), or
* FLAC__metadata_chain_write_with_callbacks() or
* FLAC__metadata_chain_write_with_callbacks_and_tempfile() was
* called on a chain read by FLAC__metadata_chain_read(). Matching
* read/write methods must always be used. */
* FLAC__metadata_chain_read_with_callbacks()/FLAC__metadata_chain_read_ogg_with_callbacks(),
* or
* FLAC__metadata_chain_write_with_callbacks()/FLAC__metadata_chain_write_with_callbacks_and_tempfile()
* was called on a chain read by
* FLAC__metadata_chain_read()/FLAC__metadata_chain_read_ogg().
* Matching read/write methods must always be used. */
FLAC__METADATA_CHAIN_STATUS_WRONG_WRITE_CALL
/**< FLAC__metadata_chain_write_with_callbacks() was called when the
@ -751,6 +757,24 @@ FLAC_API FLAC__Metadata_ChainStatus FLAC__metadata_chain_status(FLAC__Metadata_C
*/
FLAC_API FLAC__bool FLAC__metadata_chain_read(FLAC__Metadata_Chain *chain, const char *filename);
/*@@@@ add to unit tests*/
/** Read all metadata from an Ogg FLAC file into the chain.
*
* \note Ogg FLAC metadata data writing is not supported yet and
* FLAC__metadata_chain_write() will fail.
*
* \param chain A pointer to an existing chain.
* \param filename The path to the Ogg FLAC file to read.
* \assert
* \code chain != NULL \endcode
* \code filename != NULL \endcode
* \retval FLAC__bool
* \c true if a valid list of metadata blocks was read from
* \a filename, else \c false. On failure, check the status with
* FLAC__metadata_chain_status().
*/
FLAC_API FLAC__bool FLAC__metadata_chain_read_ogg(FLAC__Metadata_Chain *chain, const char *filename);
/** Read all metadata from a FLAC stream into the chain via I/O callbacks.
*
* The \a handle need only be open for reading, but must be seekable.
@ -773,6 +797,32 @@ FLAC_API FLAC__bool FLAC__metadata_chain_read(FLAC__Metadata_Chain *chain, const
*/
FLAC_API FLAC__bool FLAC__metadata_chain_read_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
/*@@@@ add to unit tests*/
/** Read all metadata from an Ogg FLAC stream into the chain via I/O callbacks.
*
* The \a handle need only be open for reading, but must be seekable.
* The equivalent minimum stdio fopen() file mode is \c "r" (or \c "rb"
* for Windows).
*
* \note Ogg FLAC metadata data writing is not supported yet and
* FLAC__metadata_chain_write() will fail.
*
* \param chain A pointer to an existing chain.
* \param handle The I/O handle of the Ogg FLAC stream to read. The
* handle will NOT be closed after the metadata is read;
* that is the duty of the caller.
* \param callbacks
* A set of callbacks to use for I/O. The mandatory
* callbacks are \a read, \a seek, and \a tell.
* \assert
* \code chain != NULL \endcode
* \retval FLAC__bool
* \c true if a valid list of metadata blocks was read from
* \a handle, else \c false. On failure, check the status with
* FLAC__metadata_chain_status().
*/
FLAC_API FLAC__bool FLAC__metadata_chain_read_ogg_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
/** Checks if writing the given chain would require the use of a
* temporary file, or if it could be written in place.
*
@ -833,7 +883,8 @@ FLAC_API FLAC__bool FLAC__metadata_chain_check_if_tempfile_needed(FLAC__Metadata
* be preserved even if the FLAC file is written.
*
* For this write function to be used, the chain must have been read with
* FLAC__metadata_chain_read(), not FLAC__metadata_chain_read_with_callbacks().
* FLAC__metadata_chain_read()/FLAC__metadata_chain_read_ogg(), not
* FLAC__metadata_chain_read_with_callbacks()/FLAC__metadata_chain_read_ogg_with_callbacks().
*
* \param chain A pointer to an existing chain.
* \param use_padding See above.
@ -856,7 +907,8 @@ FLAC_API FLAC__bool FLAC__metadata_chain_write(FLAC__Metadata_Chain *chain, FLAC
* for Windows).
*
* For this write function to be used, the chain must have been read with
* FLAC__metadata_chain_read_with_callbacks(), not FLAC__metadata_chain_read().
* FLAC__metadata_chain_read_with_callbacks()/FLAC__metadata_chain_read_ogg_with_callbacks(),
* not FLAC__metadata_chain_read()/FLAC__metadata_chain_read_ogg().
* Also, FLAC__metadata_chain_check_if_tempfile_needed() must have returned
* \c false.
*
@ -899,7 +951,8 @@ FLAC_API FLAC__bool FLAC__metadata_chain_write_with_callbacks(FLAC__Metadata_Cha
* truncate it on return).
*
* For this write function to be used, the chain must have been read with
* FLAC__metadata_chain_read_with_callbacks(), not FLAC__metadata_chain_read().
* FLAC__metadata_chain_read_with_callbacks()/FLAC__metadata_chain_read_ogg_with_callbacks(),
* not FLAC__metadata_chain_read()/FLAC__metadata_chain_read_ogg().
* Also, FLAC__metadata_chain_check_if_tempfile_needed() must have returned
* \c true.
*

View File

@ -1402,17 +1402,23 @@ namespace FLAC {
return Status(::FLAC__metadata_chain_status(chain_));
}
bool Chain::read(const char *filename)
bool Chain::read(const char *filename, bool is_ogg)
{
FLAC__ASSERT(0 != filename);
FLAC__ASSERT(is_valid());
return (bool)::FLAC__metadata_chain_read(chain_, filename);
return is_ogg?
(bool)::FLAC__metadata_chain_read_ogg(chain_, filename) :
(bool)::FLAC__metadata_chain_read(chain_, filename)
;
}
bool Chain::read(FLAC__IOHandle handle, ::FLAC__IOCallbacks callbacks)
bool Chain::read(FLAC__IOHandle handle, ::FLAC__IOCallbacks callbacks, bool is_ogg)
{
FLAC__ASSERT(is_valid());
return (bool)::FLAC__metadata_chain_read_with_callbacks(chain_, handle, callbacks);
return is_ogg?
(bool)::FLAC__metadata_chain_read_ogg_with_callbacks(chain_, handle, callbacks) :
(bool)::FLAC__metadata_chain_read_with_callbacks(chain_, handle, callbacks)
;
}
bool Chain::check_if_tempfile_needed(bool use_padding)

View File

@ -839,6 +839,7 @@ typedef struct FLAC__Metadata_Node {
struct FLAC__Metadata_Chain {
char *filename; /* will be NULL if using callbacks */
FLAC__bool is_ogg;
FLAC__Metadata_Node *head;
FLAC__Metadata_Node *tail;
unsigned nodes;
@ -850,6 +851,9 @@ struct FLAC__Metadata_Chain {
* or not the whole file has to be rewritten.
*/
off_t initial_length;
/* @@@ hacky, these are currently only needed by ogg reader */
FLAC__IOHandle handle;
FLAC__IOCallback_Read read_cb;
};
struct FLAC__Metadata_Iterator {
@ -895,10 +899,12 @@ static void chain_init_(FLAC__Metadata_Chain *chain)
FLAC__ASSERT(0 != chain);
chain->filename = 0;
chain->is_ogg = false;
chain->head = chain->tail = 0;
chain->nodes = 0;
chain->status = FLAC__METADATA_CHAIN_STATUS_OK;
chain->initial_length = 0;
chain->read_cb = 0;
}
static void chain_clear_(FLAC__Metadata_Chain *chain)
@ -1188,6 +1194,95 @@ static FLAC__bool chain_read_cb_(FLAC__Metadata_Chain *chain, FLAC__IOHandle han
return true;
}
FLAC__StreamDecoderReadStatus chain_read_ogg_read_cb_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
{
FLAC__Metadata_Chain *chain = (FLAC__Metadata_Chain*)client_data;
(void)decoder;
if(*bytes > 0 && chain->status == FLAC__METADATA_CHAIN_STATUS_OK) {
*bytes = chain->read_cb(buffer, sizeof(FLAC__byte), *bytes, chain->handle);
if(*bytes == 0)
return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
else
return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
}
else
return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
}
static FLAC__StreamDecoderWriteStatus chain_read_ogg_write_cb_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data)
{
(void)decoder, (void)frame, (void)buffer, (void)client_data;
return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
}
static void chain_read_ogg_metadata_cb_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data)
{
FLAC__Metadata_Chain *chain = (FLAC__Metadata_Chain*)client_data;
(void)decoder;
FLAC__Metadata_Node *node = node_new_();
if(0 == node) {
chain->status = FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR;
return;
}
node->data = FLAC__metadata_object_clone(metadata);
if(0 == node->data) {
node_delete_(node);
chain->status = FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR;
return;
}
chain_append_node_(chain, node);
}
static void chain_read_ogg_error_cb_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data)
{
FLAC__Metadata_Chain *chain = (FLAC__Metadata_Chain*)client_data;
(void)decoder, (void)status;
chain->status = FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR; /*@@@ maybe needs better error code */
}
static FLAC__bool chain_read_ogg_cb_(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb)
{
FLAC__StreamDecoder *decoder;
FLAC__ASSERT(0 != chain);
/* we assume we're already at the beginning of the file */
chain->handle = handle;
chain->read_cb = read_cb;
if(0 == (decoder = FLAC__stream_decoder_new())) {
chain->status = FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR;
return false;
}
FLAC__stream_decoder_set_metadata_respond_all(decoder);
if(FLAC__stream_decoder_init_ogg_stream(decoder, chain_read_ogg_read_cb_, /*seek_callback=*/0, /*tell_callback=*/0, /*length_callback=*/0, /*eof_callback=*/0, chain_read_ogg_write_cb_, chain_read_ogg_metadata_cb_, chain_read_ogg_error_cb_, chain) != FLAC__STREAM_DECODER_INIT_STATUS_OK) {
FLAC__stream_decoder_delete(decoder);
chain->status = FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR; /*@@@ maybe needs better error code */
return false;
}
chain->first_offset = 0; /*@@@ wrong; will need to be set correctly to implement metadata writing for Ogg FLAC */
if(!FLAC__stream_decoder_process_until_end_of_metadata(decoder))
chain->status = FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR; /*@@@ maybe needs better error code */
if(chain->status != FLAC__METADATA_CHAIN_STATUS_OK) {
FLAC__stream_decoder_delete(decoder);
return false;
}
FLAC__stream_decoder_delete(decoder);
chain->last_offset = 0; /*@@@ wrong; will need to be set correctly to implement metadata writing for Ogg FLAC */
chain->initial_length = chain_calculate_length_(chain);
return true;
}
static FLAC__bool chain_rewrite_metadata_in_place_cb_(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, FLAC__IOCallback_Seek seek_cb)
{
FLAC__Metadata_Node *node;
@ -1369,7 +1464,7 @@ FLAC_API FLAC__Metadata_ChainStatus FLAC__metadata_chain_status(FLAC__Metadata_C
return status;
}
FLAC_API FLAC__bool FLAC__metadata_chain_read(FLAC__Metadata_Chain *chain, const char *filename)
static FLAC__bool chain_read_(FLAC__Metadata_Chain *chain, const char *filename, FLAC__bool is_ogg)
{
FILE *file;
FLAC__bool ret;
@ -1384,21 +1479,38 @@ FLAC_API FLAC__bool FLAC__metadata_chain_read(FLAC__Metadata_Chain *chain, const
return false;
}
chain->is_ogg = is_ogg;
if(0 == (file = fopen(filename, "rb"))) {
chain->status = FLAC__METADATA_CHAIN_STATUS_ERROR_OPENING_FILE;
return false;
}
/* chain_read_cb_() sets chain->status for us */
ret = chain_read_cb_(chain, file, (FLAC__IOCallback_Read)fread, fseek_wrapper_, ftell_wrapper_);
/* the function also sets chain->status for us */
ret = is_ogg?
chain_read_ogg_cb_(chain, file, (FLAC__IOCallback_Read)fread) :
chain_read_cb_(chain, file, (FLAC__IOCallback_Read)fread, fseek_wrapper_, ftell_wrapper_)
;
fclose(file);
return ret;
}
FLAC_API FLAC__bool FLAC__metadata_chain_read_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks)
FLAC_API FLAC__bool FLAC__metadata_chain_read(FLAC__Metadata_Chain *chain, const char *filename)
{
return chain_read_(chain, filename, /*is_ogg=*/false);
}
FLAC_API FLAC__bool FLAC__metadata_chain_read_ogg(FLAC__Metadata_Chain *chain, const char *filename)
{
return chain_read_(chain, filename, /*is_ogg=*/true);
}
static FLAC__bool chain_read_with_callbacks_(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks, FLAC__bool is_ogg)
{
FLAC__bool ret;
FLAC__ASSERT(0 != chain);
chain_clear_(chain);
@ -1408,16 +1520,31 @@ FLAC_API FLAC__bool FLAC__metadata_chain_read_with_callbacks(FLAC__Metadata_Chai
return false;
}
chain->is_ogg = is_ogg;
/* rewind */
if(0 != callbacks.seek(handle, 0, SEEK_SET)) {
chain->status = FLAC__METADATA_CHAIN_STATUS_SEEK_ERROR;
return false;
}
if(!chain_read_cb_(chain, handle, callbacks.read, callbacks.seek, callbacks.tell))
return false; /* chain->status is already set by chain_read_cb_ */
/* the function also sets chain->status for us */
ret = is_ogg?
chain_read_ogg_cb_(chain, handle, callbacks.read) :
chain_read_cb_(chain, handle, callbacks.read, callbacks.seek, callbacks.tell)
;
return true;
return ret;
}
FLAC_API FLAC__bool FLAC__metadata_chain_read_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks)
{
return chain_read_with_callbacks_(chain, handle, callbacks, /*is_ogg=*/false);
}
FLAC_API FLAC__bool FLAC__metadata_chain_read_ogg_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks)
{
return chain_read_with_callbacks_(chain, handle, callbacks, /*is_ogg=*/true);
}
FLAC_API FLAC__bool FLAC__metadata_chain_check_if_tempfile_needed(FLAC__Metadata_Chain *chain, FLAC__bool use_padding)
@ -1462,6 +1589,11 @@ FLAC_API FLAC__bool FLAC__metadata_chain_write(FLAC__Metadata_Chain *chain, FLAC
FLAC__ASSERT(0 != chain);
if (chain->is_ogg) { /* cannot write back to Ogg FLAC yet */
chain->status = FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR;
return false;
}
if (0 == chain->filename) {
chain->status = FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH;
return false;
@ -1506,6 +1638,11 @@ FLAC_API FLAC__bool FLAC__metadata_chain_write_with_callbacks(FLAC__Metadata_Cha
FLAC__ASSERT(0 != chain);
if (chain->is_ogg) { /* cannot write back to Ogg FLAC yet */
chain->status = FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR;
return false;
}
if (0 != chain->filename) {
chain->status = FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH;
return false;
@ -1538,6 +1675,11 @@ FLAC_API FLAC__bool FLAC__metadata_chain_write_with_callbacks_and_tempfile(FLAC_
FLAC__ASSERT(0 != chain);
if (chain->is_ogg) { /* cannot write back to Ogg FLAC yet */
chain->status = FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR;
return false;
}
if (0 != chain->filename) {
chain->status = FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH;
return false;

View File

@ -72,14 +72,17 @@ struct OurMetadata {
unsigned num_blocks;
};
static const char *flacfile_ = "metadata.flac";
/* our copy of the metadata in flacfile_ */
/* our copy of the metadata in flacfilename() */
static OurMetadata our_metadata_;
/* the current block number that corresponds to the position of the iterator we are testing */
static unsigned mc_our_block_number_ = 0;
static const char *flacfilename(bool is_ogg)
{
return is_ogg? "metadata.ogg" : "metadata.flac";
}
static bool die_(const char *msg)
{
printf("ERROR: %s\n", msg);
@ -366,10 +369,10 @@ static bool write_chain_(FLAC::Metadata::Chain &chain, bool use_padding, bool pr
return true;
}
static bool read_chain_(FLAC::Metadata::Chain &chain, const char *filename, bool filename_based)
static bool read_chain_(FLAC::Metadata::Chain &chain, const char *filename, bool filename_based, bool is_ogg)
{
if(filename_based)
return chain.read(filename);
return chain.read(filename, is_ogg);
else {
::FLAC__IOCallbacks callbacks;
@ -383,7 +386,7 @@ static bool read_chain_(FLAC::Metadata::Chain &chain, const char *filename, bool
FILE *file = fopen(filename, "rb");
if(0 == file)
return false; /*@@@@ chain status still says OK though */
ret = chain.read((::FLAC__IOHandle)file, callbacks);
ret = chain.read((::FLAC__IOHandle)file, callbacks, is_ogg);
fclose(file);
return ret;
}
@ -489,13 +492,13 @@ void OurFileDecoder::error_callback(::FLAC__StreamDecoderErrorStatus status)
printf("ERROR: got error callback, status = %s (%u)\n", FLAC__StreamDecoderErrorStatusString[status], (unsigned)status);
}
static bool generate_file_(FLAC__bool include_extras)
static bool generate_file_(bool include_extras, bool is_ogg)
{
::FLAC__StreamMetadata streaminfo, vorbiscomment, *cuesheet, picture, padding;
::FLAC__StreamMetadata *metadata[4];
unsigned i = 0, n = 0;
printf("generating FLAC file for test\n");
printf("generating %sFLAC file for test\n", is_ogg? "Ogg " : "");
while(our_metadata_.num_blocks > 0)
delete_from_our_metadata_(0);
@ -593,7 +596,7 @@ static 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);
@ -601,12 +604,11 @@ static bool generate_file_(FLAC__bool include_extras)
return true;
}
static bool test_file_(const char *filename, bool ignore_metadata)
static bool test_file_(bool is_ogg, bool ignore_metadata)
{
const char *filename = flacfilename(is_ogg);
OurFileDecoder decoder(ignore_metadata);
FLAC__ASSERT(0 != filename);
mc_our_block_number_ = 0;
decoder.error_occurred_ = false;
@ -618,7 +620,7 @@ static bool test_file_(const char *filename, bool ignore_metadata)
decoder.set_md5_checking(true);
decoder.set_metadata_respond_all();
if(decoder.init(filename) != ::FLAC__STREAM_DECODER_INIT_STATUS_OK) {
if((is_ogg? decoder.init_ogg(filename) : decoder.init(filename)) != ::FLAC__STREAM_DECODER_INIT_STATUS_OK) {
(void)decoder.finish();
return die_("initializing decoder\n");
}
@ -664,15 +666,15 @@ static bool test_level_0_()
printf("\n\n++++++ testing level 0 interface\n");
if(!generate_file_(/*include_extras=*/true))
if(!generate_file_(/*include_extras=*/true, /*is_ogg=*/false))
return false;
if(!test_file_(flacfile_, /*ignore_metadata=*/true))
if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/true))
return false;
printf("testing FLAC::Metadata::get_streaminfo()... ");
if(!FLAC::Metadata::get_streaminfo(flacfile_, streaminfo))
if(!FLAC::Metadata::get_streaminfo(flacfilename(/*is_ogg=*/false), streaminfo))
return die_("during FLAC::Metadata::get_streaminfo()");
/* check to see if some basic data matches (c.f. generate_file_()) */
@ -694,7 +696,7 @@ static bool test_level_0_()
FLAC::Metadata::VorbisComment *tags = 0;
if(!FLAC::Metadata::get_tags(flacfile_, tags))
if(!FLAC::Metadata::get_tags(flacfilename(/*is_ogg=*/false), tags))
return die_("during FLAC::Metadata::get_tags()");
/* check to see if some basic data matches (c.f. generate_file_()) */
@ -711,7 +713,7 @@ static bool test_level_0_()
FLAC::Metadata::VorbisComment tags;
if(!FLAC::Metadata::get_tags(flacfile_, tags))
if(!FLAC::Metadata::get_tags(flacfilename(/*is_ogg=*/false), tags))
return die_("during FLAC::Metadata::get_tags()");
/* check to see if some basic data matches (c.f. generate_file_()) */
@ -726,7 +728,7 @@ static bool test_level_0_()
FLAC::Metadata::CueSheet *cuesheet = 0;
if(!FLAC::Metadata::get_cuesheet(flacfile_, cuesheet))
if(!FLAC::Metadata::get_cuesheet(flacfilename(/*is_ogg=*/false), cuesheet))
return die_("during FLAC::Metadata::get_cuesheet()");
/* check to see if some basic data matches (c.f. generate_file_()) */
@ -743,7 +745,7 @@ static bool test_level_0_()
FLAC::Metadata::CueSheet cuesheet;
if(!FLAC::Metadata::get_cuesheet(flacfile_, cuesheet))
if(!FLAC::Metadata::get_cuesheet(flacfilename(/*is_ogg=*/false), cuesheet))
return die_("during FLAC::Metadata::get_cuesheet()");
/* check to see if some basic data matches (c.f. generate_file_()) */
@ -758,7 +760,7 @@ static bool test_level_0_()
FLAC::Metadata::Picture *picture = 0;
if(!FLAC::Metadata::get_picture(flacfile_, picture, /*type=*/(::FLAC__StreamMetadata_Picture_Type)(-1), /*mime_type=*/0, /*description=*/0, /*max_width=*/(unsigned)(-1), /*max_height=*/(unsigned)(-1), /*max_depth=*/(unsigned)(-1), /*max_colors=*/(unsigned)(-1)))
if(!FLAC::Metadata::get_picture(flacfilename(/*is_ogg=*/false), picture, /*type=*/(::FLAC__StreamMetadata_Picture_Type)(-1), /*mime_type=*/0, /*description=*/0, /*max_width=*/(unsigned)(-1), /*max_height=*/(unsigned)(-1), /*max_depth=*/(unsigned)(-1), /*max_colors=*/(unsigned)(-1)))
return die_("during FLAC::Metadata::get_picture()");
/* check to see if some basic data matches (c.f. generate_file_()) */
@ -775,7 +777,7 @@ static bool test_level_0_()
FLAC::Metadata::Picture picture;
if(!FLAC::Metadata::get_picture(flacfile_, picture, /*type=*/(::FLAC__StreamMetadata_Picture_Type)(-1), /*mime_type=*/0, /*description=*/0, /*max_width=*/(unsigned)(-1), /*max_height=*/(unsigned)(-1), /*max_depth=*/(unsigned)(-1), /*max_colors=*/(unsigned)(-1)))
if(!FLAC::Metadata::get_picture(flacfilename(/*is_ogg=*/false), picture, /*type=*/(::FLAC__StreamMetadata_Picture_Type)(-1), /*mime_type=*/0, /*description=*/0, /*max_width=*/(unsigned)(-1), /*max_height=*/(unsigned)(-1), /*max_depth=*/(unsigned)(-1), /*max_colors=*/(unsigned)(-1)))
return die_("during FLAC::Metadata::get_picture()");
/* check to see if some basic data matches (c.f. generate_file_()) */
@ -785,7 +787,7 @@ static bool test_level_0_()
printf("OK\n");
}
if(!remove_file_(flacfile_))
if(!remove_file_(flacfilename(/*is_ogg=*/false)))
return false;
return true;
@ -809,13 +811,13 @@ static bool test_level_1_()
{
printf("simple iterator on read-only file\n");
if(!generate_file_(/*include_extras=*/false))
if(!generate_file_(/*include_extras=*/false, /*is_ogg=*/false))
return false;
if(!change_stats_(flacfile_, /*read_only=*/true))
if(!change_stats_(flacfilename(/*is_ogg=*/false), /*read_only=*/true))
return false;
if(!test_file_(flacfile_, /*ignore_metadata=*/true))
if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/true))
return false;
FLAC::Metadata::SimpleIterator iterator;
@ -823,7 +825,7 @@ static bool test_level_1_()
if(!iterator.is_valid())
return die_("iterator.is_valid() returned false");
if(!iterator.init(flacfile_, /*read_only=*/false, /*preserve_file_stats=*/false))
if(!iterator.init(flacfilename(/*is_ogg=*/false), /*read_only=*/false, /*preserve_file_stats=*/false))
return die_("iterator.init() returned false");
printf("is writable = %u\n", (unsigned)iterator.is_writable());
@ -902,7 +904,7 @@ static bool test_level_1_()
{
printf("simple iterator on writable file\n");
if(!change_stats_(flacfile_, /*read-only=*/false))
if(!change_stats_(flacfilename(/*is_ogg=*/false), /*read-only=*/false))
return false;
printf("creating APPLICATION block\n");
@ -922,7 +924,7 @@ static bool test_level_1_()
if(!iterator.is_valid())
return die_("iterator.is_valid() returned false");
if(!iterator.init(flacfile_, /*read_only=*/false, /*preserve_file_stats=*/false))
if(!iterator.init(flacfilename(/*is_ogg=*/false), /*read_only=*/false, /*preserve_file_stats=*/false))
return die_("iterator.init() returned false");
our_current_position = 0;
@ -968,7 +970,7 @@ static bool test_level_1_()
if(!insert_to_our_metadata_(padding, ++our_current_position, /*copy=*/true))
return false;
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
return false;
printf("SV[P]PP\tprev\n");
@ -985,7 +987,7 @@ static bool test_level_1_()
if(iterator.delete_block(false))
return die_ss_("iterator.delete_block(false) should have returned false", iterator);
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
return false;
printf("[S]VPPP\tnext\n");
@ -1013,7 +1015,7 @@ static bool test_level_1_()
return die_ss_("iterator.delete_block(false)", iterator);
delete_from_our_metadata_(our_current_position--);
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
return false;
printf("S[V]PP\tnext\n");
@ -1031,7 +1033,7 @@ static bool test_level_1_()
return die_ss_("iterator.delete_block(false)", iterator);
our_current_position--;
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
return false;
printf("SV[P]P\tnext\n");
@ -1044,7 +1046,7 @@ static bool test_level_1_()
return die_ss_("iterator.delete_block(false)", iterator);
delete_from_our_metadata_(our_current_position--);
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
return false;
printf("SV[P]\tprev\n");
@ -1069,7 +1071,7 @@ static bool test_level_1_()
return die_ss_("iterator.set_block(block, false)", iterator);
delete block;
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
return false;
printf("[S]VP\tnext\n");
@ -1085,7 +1087,7 @@ static bool test_level_1_()
return false;
add_to_padding_length_(our_current_position+1, -((int)(FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) + (int)app->get_length()));
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
return false;
printf("SV[A]P\tnext\n");
@ -1101,7 +1103,7 @@ static bool test_level_1_()
return false;
add_to_padding_length_(our_current_position+1, -((int)(FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) + (int)app->get_length()));
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
return false;
printf("SVA[A]P\tset APPLICATION (grow), don't expand into padding\n");
@ -1113,7 +1115,7 @@ static bool test_level_1_()
if(!iterator.set_block(app, false))
return die_ss_("iterator.set_block(app, false)", iterator);
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
return false;
printf("SVA[A]P\tset APPLICATION (shrink), don't fill in with padding\n");
@ -1125,7 +1127,7 @@ static bool test_level_1_()
if(!iterator.set_block(app, false))
return die_ss_("iterator.set_block(app, false)", iterator);
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
return false;
printf("SVA[A]P\tset APPLICATION (grow), expand into padding of exceeding size\n");
@ -1138,7 +1140,7 @@ static bool test_level_1_()
if(!iterator.set_block(app, true))
return die_ss_("iterator.set_block(app, true)", iterator);
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
return false;
printf("SVA[A]P\tset APPLICATION (shrink), fill in with padding\n");
@ -1153,7 +1155,7 @@ static bool test_level_1_()
if(!iterator.set_block(app, true))
return die_ss_("iterator.set_block(app, true)", iterator);
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
return false;
printf("SVA[A]PP\tnext\n");
@ -1173,7 +1175,7 @@ static bool test_level_1_()
if(!iterator.set_block(padding, false))
return die_ss_("iterator.set_block(padding, false)", iterator);
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
return false;
printf("SVAAP[P]\tset APPLICATION (grow)\n");
@ -1183,7 +1185,7 @@ static bool test_level_1_()
if(!iterator.set_block(app, false))
return die_ss_("iterator.set_block(app, false)", iterator);
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
return false;
printf("SVAAP[A]\tset PADDING (equal)\n");
@ -1193,7 +1195,7 @@ static bool test_level_1_()
if(!iterator.set_block(padding, false))
return die_ss_("iterator.set_block(padding, false)", iterator);
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
return false;
printf("SVAAP[P]\tprev\n");
@ -1206,7 +1208,7 @@ static bool test_level_1_()
return die_ss_("iterator.delete_block(false)", iterator);
delete_from_our_metadata_(our_current_position--);
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
return false;
printf("SVA[A]P\tdelete (middle block), don't replace with padding\n");
@ -1214,7 +1216,7 @@ static bool test_level_1_()
return die_ss_("iterator.delete_block(false)", iterator);
delete_from_our_metadata_(our_current_position--);
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
return false;
printf("SV[A]P\tnext\n");
@ -1229,7 +1231,7 @@ static bool test_level_1_()
if(!insert_to_our_metadata_(padding, ++our_current_position, /*copy=*/true))
return false;
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
return false;
printf("SVAP[P]\tprev\n");
@ -1250,7 +1252,7 @@ static bool test_level_1_()
if(!iterator.set_block(app, true))
return die_ss_("iterator.set_block(app, true)", iterator);
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
return false;
printf("SV[A]PP\tset APPLICATION (grow), try to expand into padding which is 'close' but still too small\n");
@ -1261,7 +1263,7 @@ static bool test_level_1_()
if(!iterator.set_block(app, true))
return die_ss_("iterator.set_block(app, true)", iterator);
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
return false;
printf("SV[A]PP\tset APPLICATION (grow), expand into padding which will leave 0-length pad\n");
@ -1273,7 +1275,7 @@ static bool test_level_1_()
if(!iterator.set_block(app, true))
return die_ss_("iterator.set_block(app, true)", iterator);
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
return false;
printf("SV[A]PP\tset APPLICATION (grow), expand into padding which is exactly consumed\n");
@ -1285,7 +1287,7 @@ static bool test_level_1_()
if(!iterator.set_block(app, true))
return die_ss_("iterator.set_block(app, true)", iterator);
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
return false;
printf("SV[A]P\tset APPLICATION (grow), expand into padding which is exactly consumed\n");
@ -1298,7 +1300,7 @@ static bool test_level_1_()
if(!iterator.set_block(app, true))
return die_ss_("iterator.set_block(app, true)", iterator);
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
return false;
printf("SV[A]\tset PADDING (equal size)\n");
@ -1308,7 +1310,7 @@ static bool test_level_1_()
if(!iterator.set_block(padding, true))
return die_ss_("iterator.set_block(padding, true)", iterator);
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
return false;
printf("SV[P]\tinsert PADDING after\n");
@ -1317,7 +1319,7 @@ static bool test_level_1_()
if(!insert_to_our_metadata_(padding, ++our_current_position, /*copy=*/true))
return false;
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
return false;
printf("SVP[P]\tinsert PADDING after\n");
@ -1327,7 +1329,7 @@ static bool test_level_1_()
if(!insert_to_our_metadata_(padding, ++our_current_position, /*copy=*/true))
return false;
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
return false;
printf("SVPP[P]\tprev\n");
@ -1353,7 +1355,7 @@ static bool test_level_1_()
if(!iterator.insert_block_after(app, true))
return die_ss_("iterator.insert_block_after(app, true)", iterator);
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
return false;
printf("SV[A]PPP\tdelete (middle block), don't replace with padding\n");
@ -1361,7 +1363,7 @@ static bool test_level_1_()
return die_ss_("iterator.delete_block(false)", iterator);
delete_from_our_metadata_(our_current_position--);
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
return false;
printf("S[V]PPP\tinsert APPLICATION after, try to expand into padding which is 'close' but still too small\n");
@ -1372,7 +1374,7 @@ static bool test_level_1_()
if(!iterator.insert_block_after(app, true))
return die_ss_("iterator.insert_block_after(app, true)", iterator);
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
return false;
printf("SV[A]PPP\tdelete (middle block), don't replace with padding\n");
@ -1380,7 +1382,7 @@ static bool test_level_1_()
return die_ss_("iterator.delete_block(false)", iterator);
delete_from_our_metadata_(our_current_position--);
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
return false;
printf("S[V]PPP\tinsert APPLICATION after, expand into padding which is exactly consumed\n");
@ -1392,7 +1394,7 @@ static bool test_level_1_()
if(!iterator.insert_block_after(app, true))
return die_ss_("iterator.insert_block_after(app, true)", iterator);
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
return false;
printf("SV[A]PP\tdelete (middle block), don't replace with padding\n");
@ -1400,7 +1402,7 @@ static bool test_level_1_()
return die_ss_("iterator.delete_block(false)", iterator);
delete_from_our_metadata_(our_current_position--);
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
return false;
printf("S[V]PP\tinsert APPLICATION after, expand into padding which will leave 0-length pad\n");
@ -1412,7 +1414,7 @@ static bool test_level_1_()
if(!iterator.insert_block_after(app, true))
return die_ss_("iterator.insert_block_after(app, true)", iterator);
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
return false;
printf("SV[A]PP\tdelete (middle block), don't replace with padding\n");
@ -1420,7 +1422,7 @@ static bool test_level_1_()
return die_ss_("iterator.delete_block(false)", iterator);
delete_from_our_metadata_(our_current_position--);
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
return false;
printf("S[V]PP\tnext\n");
@ -1433,7 +1435,7 @@ static bool test_level_1_()
return die_ss_("iterator.delete_block(false)", iterator);
delete_from_our_metadata_(our_current_position--);
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
return false;
printf("S[V]P\tinsert APPLICATION after, expand into padding which is exactly consumed\n");
@ -1445,20 +1447,20 @@ static bool test_level_1_()
if(!iterator.insert_block_after(app, true))
return die_ss_("iterator.insert_block_after(app, true)", iterator);
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
return false;
}
delete app;
delete padding;
if(!remove_file_(flacfile_))
if(!remove_file_(flacfilename(/*is_ogg=*/false)))
return false;
return true;
}
static bool test_level_2_(bool filename_based)
static bool test_level_2_(bool filename_based, bool is_ogg)
{
FLAC::Metadata::Prototype *block;
FLAC::Metadata::StreamInfo *streaminfo;
@ -1470,14 +1472,14 @@ static bool test_level_2_(bool filename_based)
// initialize 'data' to avoid Valgrind errors
memset(data, 0, sizeof(data));
printf("\n\n++++++ testing level 2 interface (%s-based)\n", filename_based? "filename":"callback");
printf("\n\n++++++ testing level 2 interface (%s-based, %s FLAC)\n", filename_based? "filename":"callback", is_ogg? "Ogg":"native");
printf("generate read-only file\n");
if(!generate_file_(/*include_extras=*/false))
if(!generate_file_(/*include_extras=*/false, is_ogg))
return false;
if(!change_stats_(flacfile_, /*read_only=*/true))
if(!change_stats_(flacfilename(is_ogg), /*read_only=*/true))
return false;
printf("create chain\n");
@ -1487,19 +1489,22 @@ static bool test_level_2_(bool filename_based)
printf("read chain\n");
if(!read_chain_(chain, flacfile_, filename_based))
if(!read_chain_(chain, flacfilename(is_ogg), filename_based, is_ogg))
return die_c_("reading chain", chain.status());
printf("[S]VP\ttest initial metadata\n");
if(!compare_chain_(chain, 0, 0))
return false;
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
if(!test_file_(is_ogg, /*ignore_metadata=*/false))
return false;
if(is_ogg)
goto end;
printf("switch file to read-write\n");
if(!change_stats_(flacfile_, /*read-only=*/false))
if(!change_stats_(flacfilename(is_ogg), /*read-only=*/false))
return false;
printf("create iterator\n");
@ -1526,13 +1531,13 @@ static bool test_level_2_(bool filename_based)
return die_("copying object");
delete block;
if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/true, filename_based, flacfile_))
if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/true, filename_based, flacfilename(is_ogg)))
return die_c_("during chain.write(false, true)", chain.status());
block = iterator.get_block();
if(!compare_chain_(chain, our_current_position, block))
return false;
delete block;
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
if(!test_file_(is_ogg, /*ignore_metadata=*/false))
return false;
printf("[S]VP\tnext\n");
@ -1559,13 +1564,13 @@ static bool test_level_2_(bool filename_based)
if(!iterator.set_block(app))
return die_c_("iterator.set_block(app)", chain.status());
if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/false, filename_based, flacfile_))
if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg)))
return die_c_("during chain.write(false, false)", chain.status());
block = iterator.get_block();
if(!compare_chain_(chain, our_current_position, block))
return false;
delete block;
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
if(!test_file_(is_ogg, /*ignore_metadata=*/false))
return false;
printf("SV[A]\tshrink APPLICATION, don't use padding\n");
@ -1578,13 +1583,13 @@ static bool test_level_2_(bool filename_based)
if(!iterator.set_block(app))
return die_c_("iterator.set_block(app)", chain.status());
if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/false, filename_based, flacfile_))
if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg)))
return die_c_("during chain.write(false, false)", chain.status());
block = iterator.get_block();
if(!compare_chain_(chain, our_current_position, block))
return false;
delete block;
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
if(!test_file_(is_ogg, /*ignore_metadata=*/false))
return false;
printf("SV[A]\tgrow APPLICATION, don't use padding\n");
@ -1597,13 +1602,13 @@ static bool test_level_2_(bool filename_based)
if(!iterator.set_block(app))
return die_c_("iterator.set_block(app)", chain.status());
if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/false, filename_based, flacfile_))
if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg)))
return die_c_("during chain.write(false, false)", chain.status());
block = iterator.get_block();
if(!compare_chain_(chain, our_current_position, block))
return false;
delete block;
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
if(!test_file_(is_ogg, /*ignore_metadata=*/false))
return false;
printf("SV[A]\tgrow APPLICATION, use padding, but last block is not padding\n");
@ -1616,13 +1621,13 @@ static bool test_level_2_(bool filename_based)
if(!iterator.set_block(app))
return die_c_("iterator.set_block(app)", chain.status());
if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/false, filename_based, flacfile_))
if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg)))
return die_c_("during chain.write(false, false)", chain.status());
block = iterator.get_block();
if(!compare_chain_(chain, our_current_position, block))
return false;
delete block;
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
if(!test_file_(is_ogg, /*ignore_metadata=*/false))
return false;
printf("SV[A]\tshrink APPLICATION, use padding, last block is not padding, but delta is too small for new PADDING block\n");
@ -1635,13 +1640,13 @@ static bool test_level_2_(bool filename_based)
if(!iterator.set_block(app))
return die_c_("iterator.set_block(app)", chain.status());
if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfile_))
if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg)))
return die_c_("during chain.write(true, false)", chain.status());
block = iterator.get_block();
if(!compare_chain_(chain, our_current_position, block))
return false;
delete block;
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
if(!test_file_(is_ogg, /*ignore_metadata=*/false))
return false;
printf("SV[A]\tshrink APPLICATION, use padding, last block is not padding, delta is enough for new PADDING block\n");
@ -1659,13 +1664,13 @@ static bool test_level_2_(bool filename_based)
if(!iterator.set_block(app))
return die_c_("iterator.set_block(app)", chain.status());
if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfile_))
if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg)))
return die_c_("during chain.write(true, false)", chain.status());
block = iterator.get_block();
if(!compare_chain_(chain, our_current_position, block))
return false;
delete block;
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
if(!test_file_(is_ogg, /*ignore_metadata=*/false))
return false;
printf("SV[A]P\tshrink APPLICATION, use padding, last block is padding\n");
@ -1679,13 +1684,13 @@ static bool test_level_2_(bool filename_based)
if(!iterator.set_block(app))
return die_c_("iterator.set_block(app)", chain.status());
if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfile_))
if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg)))
return die_c_("during chain.write(true, false)", chain.status());
block = iterator.get_block();
if(!compare_chain_(chain, our_current_position, block))
return false;
delete block;
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
if(!test_file_(is_ogg, /*ignore_metadata=*/false))
return false;
printf("SV[A]P\tgrow APPLICATION, use padding, last block is padding, but delta is too small\n");
@ -1698,13 +1703,13 @@ static bool test_level_2_(bool filename_based)
if(!iterator.set_block(app))
return die_c_("iterator.set_block(app)", chain.status());
if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfile_))
if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg)))
return die_c_("during chain.write(true, false)", chain.status());
block = iterator.get_block();
if(!compare_chain_(chain, our_current_position, block))
return false;
delete block;
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
if(!test_file_(is_ogg, /*ignore_metadata=*/false))
return false;
printf("SV[A]P\tgrow APPLICATION, use padding, last block is padding of exceeding size\n");
@ -1718,13 +1723,13 @@ static bool test_level_2_(bool filename_based)
if(!iterator.set_block(app))
return die_c_("iterator.set_block(app)", chain.status());
if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfile_))
if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg)))
return die_c_("during chain.write(true, false)", chain.status());
block = iterator.get_block();
if(!compare_chain_(chain, our_current_position, block))
return false;
delete block;
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
if(!test_file_(is_ogg, /*ignore_metadata=*/false))
return false;
printf("SV[A]P\tgrow APPLICATION, use padding, last block is padding of exact size\n");
@ -1738,13 +1743,13 @@ static bool test_level_2_(bool filename_based)
if(!iterator.set_block(app))
return die_c_("iterator.set_block(app)", chain.status());
if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfile_))
if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg)))
return die_c_("during chain.write(true, false)", chain.status());
block = iterator.get_block();
if(!compare_chain_(chain, our_current_position, block))
return false;
delete block;
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
if(!test_file_(is_ogg, /*ignore_metadata=*/false))
return false;
printf("SV[A]\tprev\n");
@ -1865,11 +1870,11 @@ static bool test_level_2_(bool filename_based)
delete_from_our_metadata_(4);
delete_from_our_metadata_(3);
if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfile_))
if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg)))
return die_c_("during chain.write(true, false)", chain.status());
if(!compare_chain_(chain, 0, 0))
return false;
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
if(!test_file_(is_ogg, /*ignore_metadata=*/false))
return false;
printf("SVPAP\tsort padding\n");
@ -1877,11 +1882,11 @@ static bool test_level_2_(bool filename_based)
add_to_padding_length_(4, FLAC__STREAM_METADATA_HEADER_LENGTH + our_metadata_.blocks[2]->get_length());
delete_from_our_metadata_(2);
if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfile_))
if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg)))
return die_c_("during chain.write(true, false)", chain.status());
if(!compare_chain_(chain, 0, 0))
return false;
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
if(!test_file_(is_ogg, /*ignore_metadata=*/false))
return false;
printf("create iterator\n");
@ -1987,30 +1992,31 @@ static bool test_level_2_(bool filename_based)
printf("SV\tmerge padding\n");
chain.merge_padding();
if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/false, filename_based, flacfile_))
if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg)))
return die_c_("during chain.write(false, false)", chain.status());
if(!compare_chain_(chain, 0, 0))
return false;
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
if(!test_file_(is_ogg, /*ignore_metadata=*/false))
return false;
printf("SV\tsort padding\n");
chain.sort_padding();
if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/false, filename_based, flacfile_))
if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg)))
return die_c_("during chain.write(false, false)", chain.status());
if(!compare_chain_(chain, 0, 0))
return false;
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
if(!test_file_(is_ogg, /*ignore_metadata=*/false))
return false;
if(!remove_file_(flacfile_))
end:
if(!remove_file_(flacfilename(is_ogg)))
return false;
return true;
}
static bool test_level_2_misc_()
static bool test_level_2_misc_(bool is_ogg)
{
::FLAC__IOCallbacks callbacks;
@ -2029,7 +2035,7 @@ static bool test_level_2_misc_()
printf("generate file\n");
if(!generate_file_(/*include_extras=*/false))
if(!generate_file_(/*include_extras=*/false, is_ogg))
return false;
printf("create chain\n");
@ -2039,7 +2045,7 @@ static bool test_level_2_misc_()
printf("read chain (filename-based)\n");
if(!chain.read(flacfile_))
if(!chain.read(flacfilename(is_ogg)))
return die_c_("reading chain", chain.status());
printf("write chain with wrong method Chain::write(with callbacks)\n");
@ -2053,7 +2059,7 @@ static bool test_level_2_misc_()
printf("read chain (filename-based)\n");
if(!chain.read(flacfile_))
if(!chain.read(flacfilename(is_ogg)))
return die_c_("reading chain", chain.status());
printf("write chain with wrong method Chain::write(with callbacks and tempfile)\n");
@ -2067,7 +2073,7 @@ static bool test_level_2_misc_()
printf("read chain (callback-based)\n");
{
FILE *file = fopen(flacfile_, "rb");
FILE *file = fopen(flacfilename(is_ogg), "rb");
if(0 == file)
return die_("opening file");
if(!chain.read((::FLAC__IOHandle)file, callbacks)) {
@ -2088,7 +2094,7 @@ static bool test_level_2_misc_()
printf("read chain (callback-based)\n");
{
FILE *file = fopen(flacfile_, "rb");
FILE *file = fopen(flacfilename(is_ogg), "rb");
if(0 == file)
return die_("opening file");
if(!chain.read((::FLAC__IOHandle)file, callbacks)) {
@ -2116,7 +2122,7 @@ static bool test_level_2_misc_()
printf("read chain (callback-based)\n");
{
FILE *file = fopen(flacfile_, "rb");
FILE *file = fopen(flacfilename(is_ogg), "rb");
if(0 == file)
return die_("opening file");
if(!chain.read((::FLAC__IOHandle)file, callbacks)) {
@ -2160,7 +2166,7 @@ static bool test_level_2_misc_()
} // delete iterator
if(!remove_file_(flacfile_))
if(!remove_file_(flacfilename(is_ogg)))
return false;
return true;
@ -2178,12 +2184,22 @@ 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(!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;
}

View File

@ -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.ogg" : "metadata.flac";
}
static FLAC__bool die_(const char *msg)
{
printf("ERROR: %s\n", msg);
@ -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,7 +604,7 @@ 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);
@ -603,12 +612,12 @@ static FLAC__bool generate_file_(FLAC__bool include_extras)
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 +631,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");
@ -674,15 +688,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 +715,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 +728,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 +741,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,7 +752,7 @@ 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;
@ -760,19 +774,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 +863,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 +881,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 +927,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 +944,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 +972,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 +990,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 +1003,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 +1026,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 +1042,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 +1058,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 +1070,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 +1082,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 +1095,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 +1110,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 +1130,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 +1140,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 +1150,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 +1163,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 +1171,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 +1186,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 +1207,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 +1218,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 +1230,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 +1242,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 +1255,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 +1265,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 +1274,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 +1284,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 +1310,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 +1318,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 +1329,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 +1337,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 +1349,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 +1357,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 +1369,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 +1377,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 +1390,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 +1402,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 +1412,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 +1429,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 +1446,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 +1483,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 +1513,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 +1530,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 +1547,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 +1564,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 +1581,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 +1603,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 +1621,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 +1638,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 +1656,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 +1674,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 +1790,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 +1802,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 +1901,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 +1950,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 +1960,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 +1974,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 +1988,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 +2009,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 +2037,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,7 +2085,7 @@ 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;
@ -2085,12 +2103,22 @@ 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(!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;
}