2002-06-07 05:27:37 +00:00
|
|
|
/* test_libFLAC++ - Unit tester for libFLAC++
|
|
|
|
|
* Copyright (C) 2002 Josh Coalson
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
|
#include "file_utils.h"
|
|
|
|
|
}
|
|
|
|
|
#include "FLAC/assert.h"
|
2002-06-08 04:53:42 +00:00
|
|
|
#include "FLAC++/decoder.h"
|
|
|
|
|
#include "FLAC++/metadata.h"
|
2002-06-07 05:27:37 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h> /* for malloc() */
|
|
|
|
|
#include <string.h> /* for memcpy()/memset() */
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
|
The general strategy of these tests (for interface levels 1 and 2) is
|
|
|
|
|
to create a dummy FLAC file with a known set of initial metadata
|
|
|
|
|
blocks, then keep a mirror locally of what we expect the metadata to be
|
|
|
|
|
after each operation. Then testing becomes a simple matter of running
|
2002-06-10 04:42:35 +00:00
|
|
|
a FLAC::Decoder::File over the dummy file after each operation, comparing
|
2002-06-07 05:27:37 +00:00
|
|
|
the decoded metadata to what's in our local copy. If there are any
|
2002-06-08 04:53:42 +00:00
|
|
|
differences in the metadata, or the actual audio data is corrupted, we
|
2002-06-07 05:27:37 +00:00
|
|
|
will catch it while decoding.
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
2002-06-10 04:42:35 +00:00
|
|
|
class OurFileDecoder: public FLAC::Decoder::File {
|
2002-06-08 04:53:42 +00:00
|
|
|
public:
|
2002-06-10 04:42:35 +00:00
|
|
|
inline OurFileDecoder(bool ignore_metadata): ignore_metadata_(ignore_metadata), error_occurred_(false) { }
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
bool ignore_metadata_;;
|
|
|
|
|
bool error_occurred_;
|
|
|
|
|
protected:
|
|
|
|
|
::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]);
|
|
|
|
|
void metadata_callback(const ::FLAC__StreamMetadata *metadata);
|
|
|
|
|
void error_callback(::FLAC__StreamDecoderErrorStatus status);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct OurMetadata {
|
|
|
|
|
FLAC::Metadata::Prototype *blocks[64];
|
2002-06-07 05:27:37 +00:00
|
|
|
unsigned num_blocks;
|
2002-06-08 04:53:42 +00:00
|
|
|
};
|
2002-06-07 05:27:37 +00:00
|
|
|
|
|
|
|
|
static const char *flacfile_ = "metadata.flac";
|
|
|
|
|
|
|
|
|
|
/* our copy of the metadata in flacfile_ */
|
2002-06-08 04:53:42 +00:00
|
|
|
static OurMetadata our_metadata_;
|
2002-06-07 05:27:37 +00:00
|
|
|
|
|
|
|
|
/* the current block number that corresponds to the position of the iterator we are testing */
|
|
|
|
|
static unsigned mc_our_block_number_ = 0;
|
|
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
static bool die_(const char *msg)
|
2002-06-07 05:27:37 +00:00
|
|
|
{
|
|
|
|
|
printf("ERROR: %s\n", msg);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
static bool die_c_(const char *msg, FLAC::Metadata::Chain::Status status)
|
2002-06-07 05:27:37 +00:00
|
|
|
{
|
|
|
|
|
printf("ERROR: %s\n", msg);
|
2002-06-08 04:53:42 +00:00
|
|
|
printf(" status=%u (%s)\n", (unsigned)((::FLAC__Metadata_ChainStatus)status), status.as_cstring());
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
static bool die_ss_(const char *msg, FLAC::Metadata::SimpleIterator &iterator)
|
2002-06-07 05:27:37 +00:00
|
|
|
{
|
2002-06-08 04:53:42 +00:00
|
|
|
const FLAC::Metadata::SimpleIterator::Status status = iterator.status();
|
2002-06-07 05:27:37 +00:00
|
|
|
printf("ERROR: %s\n", msg);
|
2002-06-08 04:53:42 +00:00
|
|
|
printf(" status=%u (%s)\n", (unsigned)((::FLAC__Metadata_SimpleIteratorStatus)status), status.as_cstring());
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
static void *malloc_or_die_(size_t size)
|
|
|
|
|
{
|
|
|
|
|
void *x = malloc(size);
|
|
|
|
|
if(0 == x) {
|
|
|
|
|
fprintf(stderr, "ERROR: out of memory allocating %u bytes\n", (unsigned)size);
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
return x;
|
|
|
|
|
}
|
|
|
|
|
|
2002-06-07 05:27:37 +00:00
|
|
|
/* functions for working with our metadata copy */
|
|
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
static bool replace_in_our_metadata_(FLAC::Metadata::Prototype *block, unsigned position, bool copy)
|
2002-06-07 05:27:37 +00:00
|
|
|
{
|
|
|
|
|
unsigned i;
|
2002-06-08 04:53:42 +00:00
|
|
|
FLAC::Metadata::Prototype *obj = block;
|
2002-06-07 05:27:37 +00:00
|
|
|
FLAC__ASSERT(position < our_metadata_.num_blocks);
|
|
|
|
|
if(copy) {
|
2002-06-08 04:53:42 +00:00
|
|
|
if(0 == (obj = FLAC::Metadata::clone(block)))
|
|
|
|
|
return die_("during FLAC::Metadata::clone()");
|
2002-06-07 05:27:37 +00:00
|
|
|
}
|
2002-06-08 04:53:42 +00:00
|
|
|
delete our_metadata_.blocks[position];
|
2002-06-07 05:27:37 +00:00
|
|
|
our_metadata_.blocks[position] = obj;
|
|
|
|
|
|
|
|
|
|
/* set the is_last flags */
|
|
|
|
|
for(i = 0; i < our_metadata_.num_blocks - 1; i++)
|
2002-06-08 04:53:42 +00:00
|
|
|
our_metadata_.blocks[i]->set_is_last(false);
|
|
|
|
|
our_metadata_.blocks[i]->set_is_last(true);
|
2002-06-07 05:27:37 +00:00
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
static bool insert_to_our_metadata_(FLAC::Metadata::Prototype *block, unsigned position, bool copy)
|
2002-06-07 05:27:37 +00:00
|
|
|
{
|
|
|
|
|
unsigned i;
|
2002-06-08 04:53:42 +00:00
|
|
|
FLAC::Metadata::Prototype *obj = block;
|
2002-06-07 05:27:37 +00:00
|
|
|
if(copy) {
|
2002-06-08 04:53:42 +00:00
|
|
|
if(0 == (obj = FLAC::Metadata::clone(block)))
|
|
|
|
|
return die_("during FLAC::Metadata::clone()");
|
2002-06-07 05:27:37 +00:00
|
|
|
}
|
|
|
|
|
if(position > our_metadata_.num_blocks) {
|
|
|
|
|
position = our_metadata_.num_blocks;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
for(i = our_metadata_.num_blocks; i > position; i--)
|
|
|
|
|
our_metadata_.blocks[i] = our_metadata_.blocks[i-1];
|
|
|
|
|
}
|
|
|
|
|
our_metadata_.blocks[position] = obj;
|
|
|
|
|
our_metadata_.num_blocks++;
|
|
|
|
|
|
|
|
|
|
/* set the is_last flags */
|
|
|
|
|
for(i = 0; i < our_metadata_.num_blocks - 1; i++)
|
2002-06-08 04:53:42 +00:00
|
|
|
our_metadata_.blocks[i]->set_is_last(false);
|
|
|
|
|
our_metadata_.blocks[i]->set_is_last(true);
|
2002-06-07 05:27:37 +00:00
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void delete_from_our_metadata_(unsigned position)
|
|
|
|
|
{
|
|
|
|
|
unsigned i;
|
|
|
|
|
FLAC__ASSERT(position < our_metadata_.num_blocks);
|
2002-06-08 04:53:42 +00:00
|
|
|
delete our_metadata_.blocks[position];
|
2002-06-07 05:27:37 +00:00
|
|
|
for(i = position; i < our_metadata_.num_blocks - 1; i++)
|
|
|
|
|
our_metadata_.blocks[i] = our_metadata_.blocks[i+1];
|
|
|
|
|
our_metadata_.num_blocks--;
|
|
|
|
|
|
|
|
|
|
/* set the is_last flags */
|
|
|
|
|
if(our_metadata_.num_blocks > 0) {
|
|
|
|
|
for(i = 0; i < our_metadata_.num_blocks - 1; i++)
|
2002-06-08 04:53:42 +00:00
|
|
|
our_metadata_.blocks[i]->set_is_last(false);
|
|
|
|
|
our_metadata_.blocks[i]->set_is_last(true);
|
2002-06-07 05:27:37 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2002-06-10 04:42:35 +00:00
|
|
|
void add_to_padding_length_(unsigned index, int delta)
|
|
|
|
|
{
|
|
|
|
|
FLAC::Metadata::Padding *padding = dynamic_cast<FLAC::Metadata::Padding *>(our_metadata_.blocks[index]);
|
|
|
|
|
FLAC__ASSERT(0 != padding);
|
|
|
|
|
padding->set_length((unsigned)((int)padding->get_length() + delta));
|
|
|
|
|
}
|
|
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
/* function for comparing our metadata to a FLAC::Metadata::Chain */
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-06-10 04:42:35 +00:00
|
|
|
static bool compare_chain_(FLAC::Metadata::Chain &chain, unsigned current_position, FLAC::Metadata::Prototype *current_block)
|
2002-06-07 05:27:37 +00:00
|
|
|
{
|
|
|
|
|
unsigned i;
|
2002-06-08 04:53:42 +00:00
|
|
|
FLAC::Metadata::Iterator iterator;
|
|
|
|
|
FLAC::Metadata::Prototype *block;
|
|
|
|
|
bool next_ok = true;
|
2002-06-07 05:27:37 +00:00
|
|
|
|
|
|
|
|
printf("\tcomparing chain... ");
|
|
|
|
|
fflush(stdout);
|
|
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.is_valid())
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("allocating memory for iterator");
|
|
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
iterator.init(chain);
|
2002-06-07 05:27:37 +00:00
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
|
do {
|
|
|
|
|
printf("%u... ", i);
|
|
|
|
|
fflush(stdout);
|
|
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(0 == (block = iterator.get_block()))
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("getting block from iterator");
|
|
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(*block != *our_metadata_.blocks[i])
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("metadata block mismatch");
|
|
|
|
|
|
|
|
|
|
i++;
|
2002-06-08 04:53:42 +00:00
|
|
|
next_ok = iterator.next();
|
2002-06-07 05:27:37 +00:00
|
|
|
} while(i < our_metadata_.num_blocks && next_ok);
|
|
|
|
|
|
|
|
|
|
if(next_ok)
|
|
|
|
|
return die_("chain has more blocks than expected");
|
|
|
|
|
|
|
|
|
|
if(i < our_metadata_.num_blocks)
|
|
|
|
|
return die_("short block count in chain");
|
|
|
|
|
|
|
|
|
|
if(0 != current_block) {
|
|
|
|
|
printf("CURRENT_POSITION... ");
|
|
|
|
|
fflush(stdout);
|
|
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(*current_block != *our_metadata_.blocks[current_position])
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("metadata block mismatch");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
printf("PASSED\n");
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2002-06-10 04:42:35 +00:00
|
|
|
::FLAC__StreamDecoderWriteStatus OurFileDecoder::write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[])
|
2002-06-07 05:27:37 +00:00
|
|
|
{
|
2002-06-08 04:53:42 +00:00
|
|
|
(void)buffer;
|
2002-06-07 05:27:37 +00:00
|
|
|
|
|
|
|
|
if(
|
|
|
|
|
(frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER && frame->header.number.frame_number == 0) ||
|
|
|
|
|
(frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER && frame->header.number.sample_number == 0)
|
|
|
|
|
) {
|
|
|
|
|
printf("content... ");
|
|
|
|
|
fflush(stdout);
|
|
|
|
|
}
|
|
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
return ::FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
|
2002-06-07 05:27:37 +00:00
|
|
|
}
|
|
|
|
|
|
2002-06-10 04:42:35 +00:00
|
|
|
void OurFileDecoder::metadata_callback(const ::FLAC__StreamMetadata *metadata)
|
2002-06-07 05:27:37 +00:00
|
|
|
{
|
|
|
|
|
/* don't bother checking if we've already hit an error */
|
2002-06-08 04:53:42 +00:00
|
|
|
if(error_occurred_)
|
2002-06-07 05:27:37 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
printf("%d... ", mc_our_block_number_);
|
|
|
|
|
fflush(stdout);
|
|
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!ignore_metadata_) {
|
|
|
|
|
if(mc_our_block_number_ >= our_metadata_.num_blocks) {
|
|
|
|
|
(void)die_("got more metadata blocks than expected");
|
|
|
|
|
error_occurred_ = true;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if(*our_metadata_.blocks[mc_our_block_number_] != metadata) {
|
|
|
|
|
(void)die_("metadata block mismatch");
|
|
|
|
|
error_occurred_ = true;
|
|
|
|
|
}
|
2002-06-07 05:27:37 +00:00
|
|
|
}
|
|
|
|
|
}
|
2002-06-08 04:53:42 +00:00
|
|
|
|
2002-06-07 05:27:37 +00:00
|
|
|
mc_our_block_number_++;
|
|
|
|
|
}
|
|
|
|
|
|
2002-06-10 04:42:35 +00:00
|
|
|
void OurFileDecoder::error_callback(::FLAC__StreamDecoderErrorStatus status)
|
2002-06-08 04:53:42 +00:00
|
|
|
{
|
|
|
|
|
error_occurred_ = true;
|
|
|
|
|
printf("ERROR: got error callback, status = %s (%u)\n", FLAC__StreamDecoderErrorStatusString[status], (unsigned)status);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool generate_file_()
|
2002-06-07 05:27:37 +00:00
|
|
|
{
|
2002-08-25 05:10:37 +00:00
|
|
|
::FLAC__StreamMetadata streaminfo, vorbiscomment, padding;
|
2002-06-08 04:53:42 +00:00
|
|
|
::FLAC__StreamMetadata *metadata[1];
|
2002-06-07 05:27:37 +00:00
|
|
|
|
|
|
|
|
printf("generating FLAC file for test\n");
|
|
|
|
|
|
|
|
|
|
while(our_metadata_.num_blocks > 0)
|
|
|
|
|
delete_from_our_metadata_(0);
|
|
|
|
|
|
|
|
|
|
streaminfo.is_last = false;
|
2002-06-08 04:53:42 +00:00
|
|
|
streaminfo.type = ::FLAC__METADATA_TYPE_STREAMINFO;
|
2002-06-07 05:27:37 +00:00
|
|
|
streaminfo.length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH;
|
|
|
|
|
streaminfo.data.stream_info.min_blocksize = 576;
|
|
|
|
|
streaminfo.data.stream_info.max_blocksize = 576;
|
|
|
|
|
streaminfo.data.stream_info.min_framesize = 0;
|
|
|
|
|
streaminfo.data.stream_info.max_framesize = 0;
|
|
|
|
|
streaminfo.data.stream_info.sample_rate = 44100;
|
|
|
|
|
streaminfo.data.stream_info.channels = 1;
|
|
|
|
|
streaminfo.data.stream_info.bits_per_sample = 8;
|
|
|
|
|
streaminfo.data.stream_info.total_samples = 0;
|
|
|
|
|
memset(streaminfo.data.stream_info.md5sum, 0, 16);
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
{
|
|
|
|
|
const unsigned vendor_string_length = (unsigned)strlen((const char*)FLAC__VENDOR_STRING);
|
|
|
|
|
vorbiscomment.is_last = false;
|
|
|
|
|
vorbiscomment.type = FLAC__METADATA_TYPE_VORBIS_COMMENT;
|
|
|
|
|
vorbiscomment.length = (4 + vendor_string_length) + 4;
|
|
|
|
|
vorbiscomment.data.vorbis_comment.vendor_string.length = vendor_string_length;
|
|
|
|
|
vorbiscomment.data.vorbis_comment.vendor_string.entry = (FLAC__byte*)malloc_or_die_(vendor_string_length);
|
|
|
|
|
memcpy(vorbiscomment.data.vorbis_comment.vendor_string.entry, FLAC__VENDOR_STRING, vendor_string_length);
|
|
|
|
|
vorbiscomment.data.vorbis_comment.num_comments = 0;
|
|
|
|
|
vorbiscomment.data.vorbis_comment.comments = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2002-06-07 05:27:37 +00:00
|
|
|
padding.is_last = true;
|
2002-06-08 04:53:42 +00:00
|
|
|
padding.type = ::FLAC__METADATA_TYPE_PADDING;
|
2002-06-07 05:27:37 +00:00
|
|
|
padding.length = 1234;
|
|
|
|
|
|
|
|
|
|
metadata[0] = &padding;
|
|
|
|
|
|
2002-06-10 04:42:35 +00:00
|
|
|
FLAC::Metadata::StreamInfo s(&streaminfo);
|
2002-08-25 05:10:37 +00:00
|
|
|
FLAC::Metadata::VorbisComment v(&vorbiscomment);
|
2002-06-10 04:42:35 +00:00
|
|
|
FLAC::Metadata::Padding p(&padding);
|
2002-08-25 05:10:37 +00:00
|
|
|
if(
|
|
|
|
|
!insert_to_our_metadata_(&s, 0, /*copy=*/true) ||
|
|
|
|
|
!insert_to_our_metadata_(&v, 1, /*copy=*/true) ||
|
|
|
|
|
!insert_to_our_metadata_(&p, 2, /*copy=*/true)
|
|
|
|
|
)
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("priming our metadata");
|
|
|
|
|
|
|
|
|
|
if(!file_utils__generate_flacfile(flacfile_, 0, 512 * 1024, &streaminfo, metadata, 1))
|
|
|
|
|
return die_("creating the encoded file");
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
free(vorbiscomment.data.vorbis_comment.vendor_string.entry);
|
|
|
|
|
|
2002-06-07 05:27:37 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
static bool test_file_(const char *filename, bool ignore_metadata)
|
2002-06-07 05:27:37 +00:00
|
|
|
{
|
2002-06-10 04:42:35 +00:00
|
|
|
OurFileDecoder decoder(ignore_metadata);
|
2002-06-07 05:27:37 +00:00
|
|
|
|
|
|
|
|
FLAC__ASSERT(0 != filename);
|
|
|
|
|
|
|
|
|
|
mc_our_block_number_ = 0;
|
2002-06-08 04:53:42 +00:00
|
|
|
decoder.error_occurred_ = false;
|
2002-06-07 05:27:37 +00:00
|
|
|
|
|
|
|
|
printf("\ttesting '%s'... ", filename);
|
|
|
|
|
fflush(stdout);
|
|
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!decoder.is_valid())
|
|
|
|
|
return die_("couldn't allocate decoder instance");
|
|
|
|
|
|
|
|
|
|
decoder.set_md5_checking(true);
|
|
|
|
|
decoder.set_filename(filename);
|
|
|
|
|
decoder.set_metadata_respond_all();
|
|
|
|
|
if(decoder.init() != ::FLAC__FILE_DECODER_OK) {
|
|
|
|
|
decoder.finish();
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("initializing decoder\n");
|
|
|
|
|
}
|
2002-08-02 06:12:36 +00:00
|
|
|
if(!decoder.process_until_end_of_file()) {
|
2002-06-08 04:53:42 +00:00
|
|
|
decoder.finish();
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("decoding file\n");
|
|
|
|
|
}
|
|
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
decoder.finish();
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(decoder.error_occurred_)
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if(mc_our_block_number_ != our_metadata_.num_blocks)
|
|
|
|
|
return die_("short metadata block count");
|
|
|
|
|
|
|
|
|
|
printf("PASSED\n");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
static bool change_stats_(const char *filename, bool read_only)
|
2002-06-07 05:27:37 +00:00
|
|
|
{
|
|
|
|
|
if(!file_utils__change_stats(filename, read_only))
|
|
|
|
|
return die_("during file_utils__change_stats()");
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
static bool remove_file_(const char *filename)
|
2002-06-07 05:27:37 +00:00
|
|
|
{
|
|
|
|
|
while(our_metadata_.num_blocks > 0)
|
|
|
|
|
delete_from_our_metadata_(0);
|
|
|
|
|
|
|
|
|
|
if(!file_utils__remove_file(filename))
|
|
|
|
|
return die_("removing file");
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
static bool test_level_0_()
|
2002-06-07 05:27:37 +00:00
|
|
|
{
|
2002-06-08 04:53:42 +00:00
|
|
|
FLAC::Metadata::StreamInfo streaminfo;
|
2002-06-07 05:27:37 +00:00
|
|
|
|
|
|
|
|
printf("\n\n++++++ testing level 0 interface\n");
|
|
|
|
|
|
|
|
|
|
if(!generate_file_())
|
|
|
|
|
return false;
|
|
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!test_file_(flacfile_, /*ignore_metadata=*/true))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!FLAC::Metadata::get_streaminfo(flacfile_, streaminfo))
|
|
|
|
|
return die_("during FLAC::Metadata::get_streaminfo()");
|
2002-06-07 05:27:37 +00:00
|
|
|
|
|
|
|
|
/* check to see if some basic data matches (c.f. generate_file_()) */
|
2002-06-08 04:53:42 +00:00
|
|
|
if(streaminfo.get_channels() != 1)
|
|
|
|
|
return die_("mismatch in streaminfo.get_channels()");
|
|
|
|
|
if(streaminfo.get_bits_per_sample() != 8)
|
|
|
|
|
return die_("mismatch in streaminfo.get_bits_per_sample()");
|
|
|
|
|
if(streaminfo.get_sample_rate() != 44100)
|
|
|
|
|
return die_("mismatch in streaminfo.get_sample_rate()");
|
|
|
|
|
if(streaminfo.get_min_blocksize() != 576)
|
|
|
|
|
return die_("mismatch in streaminfo.get_min_blocksize()");
|
|
|
|
|
if(streaminfo.get_max_blocksize() != 576)
|
|
|
|
|
return die_("mismatch in streaminfo.get_max_blocksize()");
|
2002-06-07 05:27:37 +00:00
|
|
|
|
|
|
|
|
if(!remove_file_(flacfile_))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
static bool test_level_1_()
|
2002-06-07 05:27:37 +00:00
|
|
|
{
|
2002-06-08 04:53:42 +00:00
|
|
|
FLAC::Metadata::Prototype *block;
|
|
|
|
|
FLAC::Metadata::StreamInfo *streaminfo;
|
|
|
|
|
FLAC::Metadata::Padding *padding;
|
|
|
|
|
FLAC::Metadata::Application *app;
|
2002-06-07 05:27:37 +00:00
|
|
|
FLAC__byte data[1000];
|
|
|
|
|
unsigned our_current_position = 0;
|
|
|
|
|
|
|
|
|
|
printf("\n\n++++++ testing level 1 interface\n");
|
|
|
|
|
|
|
|
|
|
/************************************************************/
|
2002-06-08 04:53:42 +00:00
|
|
|
{
|
2002-06-07 05:27:37 +00:00
|
|
|
printf("simple iterator on read-only file\n");
|
|
|
|
|
|
|
|
|
|
if(!generate_file_())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if(!change_stats_(flacfile_, /*read_only=*/true))
|
|
|
|
|
return false;
|
|
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!test_file_(flacfile_, /*ignore_metadata=*/true))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
FLAC::Metadata::SimpleIterator iterator;
|
|
|
|
|
|
|
|
|
|
if(!iterator.is_valid())
|
|
|
|
|
return die_("iterator.is_valid() returned false");
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.init(flacfile_, false))
|
|
|
|
|
return die_("iterator.init() returned false");
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
printf("is writable = %u\n", (unsigned)iterator.is_writable());
|
|
|
|
|
if(iterator.is_writable())
|
2002-06-13 05:40:14 +00:00
|
|
|
return die_("iterator claims file is writable when tester thinks it should not be; are you running as root?\n");
|
2002-06-07 05:27:37 +00:00
|
|
|
|
|
|
|
|
printf("iterate forwards\n");
|
|
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(iterator.get_block_type() != ::FLAC__METADATA_TYPE_STREAMINFO)
|
|
|
|
|
return die_("expected STREAMINFO type from iterator.get_block_type()");
|
|
|
|
|
if(0 == (block = iterator.get_block()))
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("getting block 0");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(block->get_type() != ::FLAC__METADATA_TYPE_STREAMINFO)
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("expected STREAMINFO type");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(block->get_is_last())
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("expected is_last to be false");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(block->get_length() != FLAC__STREAM_METADATA_STREAMINFO_LENGTH)
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("bad STREAMINFO length");
|
|
|
|
|
/* check to see if some basic data matches (c.f. generate_file_()) */
|
2002-06-08 04:53:42 +00:00
|
|
|
streaminfo = dynamic_cast<FLAC::Metadata::StreamInfo *>(block);
|
|
|
|
|
FLAC__ASSERT(0 != streaminfo);
|
|
|
|
|
if(streaminfo->get_channels() != 1)
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("mismatch in channels");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(streaminfo->get_bits_per_sample() != 8)
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("mismatch in bits_per_sample");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(streaminfo->get_sample_rate() != 44100)
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("mismatch in sample_rate");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(streaminfo->get_min_blocksize() != 576)
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("mismatch in min_blocksize");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(streaminfo->get_max_blocksize() != 576)
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("mismatch in max_blocksize");
|
|
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.next())
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("forward iterator ended early");
|
|
|
|
|
our_current_position++;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
if(!iterator.next())
|
|
|
|
|
return die_("forward iterator ended early");
|
|
|
|
|
our_current_position++;
|
|
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(iterator.get_block_type() != ::FLAC__METADATA_TYPE_PADDING)
|
|
|
|
|
return die_("expected PADDING type from iterator.get_block_type()");
|
|
|
|
|
if(0 == (block = iterator.get_block()))
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("getting block 1");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(block->get_type() != ::FLAC__METADATA_TYPE_PADDING)
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("expected PADDING type");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!block->get_is_last())
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("expected is_last to be true");
|
|
|
|
|
/* check to see if some basic data matches (c.f. generate_file_()) */
|
2002-06-08 04:53:42 +00:00
|
|
|
if(block->get_length() != 1234)
|
|
|
|
|
return die_("bad PADDING length");
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(iterator.next())
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("forward iterator returned true but should have returned false");
|
|
|
|
|
|
|
|
|
|
printf("iterate backwards\n");
|
2002-08-25 05:10:37 +00:00
|
|
|
if(!iterator.prev())
|
|
|
|
|
return die_("reverse iterator ended early");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.prev())
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("reverse iterator ended early");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(iterator.prev())
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("reverse iterator returned true but should have returned false");
|
|
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
printf("testing iterator.set_block() on read-only file...\n");
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.set_block(streaminfo, false))
|
|
|
|
|
printf("PASSED. iterator.set_block() returned false like it should\n");
|
2002-06-07 05:27:37 +00:00
|
|
|
else
|
2002-06-08 04:53:42 +00:00
|
|
|
return die_("iterator.set_block() returned true but shouldn't have");
|
|
|
|
|
}
|
2002-06-07 05:27:37 +00:00
|
|
|
|
|
|
|
|
/************************************************************/
|
2002-06-08 04:53:42 +00:00
|
|
|
{
|
2002-06-07 05:27:37 +00:00
|
|
|
printf("simple iterator on writable file\n");
|
|
|
|
|
|
|
|
|
|
if(!change_stats_(flacfile_, /*read-only=*/false))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
printf("creating APPLICATION block\n");
|
|
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(0 == (app = new FLAC::Metadata::Application()))
|
|
|
|
|
return die_("new FLAC::Metadata::Application()");
|
|
|
|
|
app->set_id((const unsigned char *)"duh");
|
2002-06-07 05:27:37 +00:00
|
|
|
|
|
|
|
|
printf("creating PADDING block\n");
|
|
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(0 == (padding = new FLAC::Metadata::Padding()))
|
|
|
|
|
return die_("new FLAC::Metadata::Padding()");
|
|
|
|
|
padding->set_length(20);
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
FLAC::Metadata::SimpleIterator iterator;
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.is_valid())
|
|
|
|
|
return die_("iterator.is_valid() returned false");
|
|
|
|
|
|
|
|
|
|
if(!iterator.init(flacfile_, /*preserve_file_stats=*/false))
|
|
|
|
|
return die_("iterator.init() returned false");
|
2002-06-07 05:27:37 +00:00
|
|
|
our_current_position = 0;
|
|
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
printf("is writable = %u\n", (unsigned)iterator.is_writable());
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("[S]VP\ttry to write over STREAMINFO block...\n");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.set_block(app, false))
|
|
|
|
|
printf("\titerator.set_block() returned false like it should\n");
|
2002-06-07 05:27:37 +00:00
|
|
|
else
|
2002-06-08 04:53:42 +00:00
|
|
|
return die_("iterator.set_block() returned true but shouldn't have");
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("[S]VP\tnext\n");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.next())
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("iterator ended early\n");
|
|
|
|
|
our_current_position++;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("S[V]P\tnext\n");
|
|
|
|
|
if(!iterator.next())
|
|
|
|
|
return die_("iterator ended early\n");
|
|
|
|
|
our_current_position++;
|
|
|
|
|
|
|
|
|
|
printf("SV[P]\tinsert PADDING after, don't expand into padding\n");
|
2002-06-08 04:53:42 +00:00
|
|
|
padding->set_length(25);
|
|
|
|
|
if(!iterator.insert_block_after(padding, false))
|
|
|
|
|
return die_ss_("iterator.insert_block_after(padding, false)", iterator);
|
2002-06-07 05:27:37 +00:00
|
|
|
if(!insert_to_our_metadata_(padding, ++our_current_position, /*copy=*/true))
|
|
|
|
|
return false;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SVP[P]\tprev\n");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.prev())
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("iterator ended early\n");
|
|
|
|
|
our_current_position--;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SV[P]P\tprev\n");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.prev())
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("iterator ended early\n");
|
|
|
|
|
our_current_position--;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("S[V]PP\tinsert PADDING after, don't expand into padding\n");
|
2002-06-08 04:53:42 +00:00
|
|
|
padding->set_length(30);
|
|
|
|
|
if(!iterator.insert_block_after(padding, false))
|
|
|
|
|
return die_ss_("iterator.insert_block_after(padding, false)", iterator);
|
2002-06-07 05:27:37 +00:00
|
|
|
if(!insert_to_our_metadata_(padding, ++our_current_position, /*copy=*/true))
|
|
|
|
|
return false;
|
|
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SV[P]PP\tprev\n");
|
|
|
|
|
if(!iterator.prev())
|
|
|
|
|
return die_("iterator ended early\n");
|
|
|
|
|
our_current_position--;
|
|
|
|
|
|
|
|
|
|
printf("S[V]PPP\tprev\n");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.prev())
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("iterator ended early\n");
|
|
|
|
|
our_current_position--;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("[S]VPPP\tdelete (STREAMINFO block), must fail\n");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(iterator.delete_block(false))
|
|
|
|
|
return die_ss_("iterator.delete_block(false) should have returned false", iterator);
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("[S]VPPP\tnext\n");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.next())
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("iterator ended early\n");
|
|
|
|
|
our_current_position++;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("S[V]PPP\tnext\n");
|
|
|
|
|
if(!iterator.next())
|
|
|
|
|
return die_("iterator ended early\n");
|
|
|
|
|
our_current_position++;
|
|
|
|
|
|
|
|
|
|
printf("SV[P]PP\tdelete (middle block), replace with padding\n");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.delete_block(true))
|
|
|
|
|
return die_ss_("iterator.delete_block(true)", iterator);
|
2002-06-07 05:27:37 +00:00
|
|
|
our_current_position--;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("S[V]PPP\tnext\n");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.next())
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("iterator ended early\n");
|
|
|
|
|
our_current_position++;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SV[P]PP\tdelete (middle block), don't replace with padding\n");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.delete_block(false))
|
|
|
|
|
return die_ss_("iterator.delete_block(false)", iterator);
|
2002-06-07 05:27:37 +00:00
|
|
|
delete_from_our_metadata_(our_current_position--);
|
|
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("S[V]PP\tnext\n");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.next())
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("iterator ended early\n");
|
|
|
|
|
our_current_position++;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SV[P]P\tnext\n");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.next())
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("iterator ended early\n");
|
|
|
|
|
our_current_position++;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SVP[P]\tdelete (last block), replace with padding\n");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.delete_block(true))
|
|
|
|
|
return die_ss_("iterator.delete_block(false)", iterator);
|
2002-06-07 05:27:37 +00:00
|
|
|
our_current_position--;
|
|
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SV[P]P\tnext\n");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.next())
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("iterator ended early\n");
|
|
|
|
|
our_current_position++;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SVP[P]\tdelete (last block), don't replace with padding\n");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.delete_block(false))
|
|
|
|
|
return die_ss_("iterator.delete_block(false)", iterator);
|
2002-06-07 05:27:37 +00:00
|
|
|
delete_from_our_metadata_(our_current_position--);
|
|
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SV[P]\tprev\n");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.prev())
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("iterator ended early\n");
|
|
|
|
|
our_current_position--;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("S[V]P\tprev\n");
|
|
|
|
|
if(!iterator.prev())
|
|
|
|
|
return die_("iterator ended early\n");
|
|
|
|
|
our_current_position--;
|
|
|
|
|
|
|
|
|
|
printf("[S]VP\tset STREAMINFO (change sample rate)\n");
|
2002-06-07 05:27:37 +00:00
|
|
|
FLAC__ASSERT(our_current_position == 0);
|
2002-06-08 04:53:42 +00:00
|
|
|
block = iterator.get_block();
|
|
|
|
|
streaminfo = dynamic_cast<FLAC::Metadata::StreamInfo *>(block);
|
|
|
|
|
FLAC__ASSERT(0 != streaminfo);
|
|
|
|
|
streaminfo->set_sample_rate(32000);
|
2002-06-07 05:27:37 +00:00
|
|
|
if(!replace_in_our_metadata_(block, our_current_position, /*copy=*/true))
|
|
|
|
|
return die_("copying object");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.set_block(block, false))
|
|
|
|
|
return die_ss_("iterator.set_block(block, false)", iterator);
|
|
|
|
|
delete block;
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("[S]VP\tnext\n");
|
|
|
|
|
if(!iterator.next())
|
|
|
|
|
return die_("iterator ended early\n");
|
|
|
|
|
our_current_position++;
|
|
|
|
|
|
|
|
|
|
printf("S[V]P\tinsert APPLICATION after, expand into padding of exceeding size\n");
|
2002-06-08 04:53:42 +00:00
|
|
|
app->set_id((const unsigned char *)"euh"); /* twiddle the id so that our comparison doesn't miss transposition */
|
|
|
|
|
if(!iterator.insert_block_after(app, true))
|
|
|
|
|
return die_ss_("iterator.insert_block_after(app, true)", iterator);
|
2002-06-07 05:27:37 +00:00
|
|
|
if(!insert_to_our_metadata_(app, ++our_current_position, /*copy=*/true))
|
|
|
|
|
return false;
|
2002-06-11 06:15:28 +00:00
|
|
|
add_to_padding_length_(our_current_position+1, -((int)(FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) + (int)app->get_length()));
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SV[A]P\tnext\n");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.next())
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("iterator ended early\n");
|
|
|
|
|
our_current_position++;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SVA[P]\tset APPLICATION, expand into padding of exceeding size\n");
|
2002-06-08 04:53:42 +00:00
|
|
|
app->set_id((const unsigned char *)"fuh"); /* twiddle the id */
|
|
|
|
|
if(!iterator.set_block(app, true))
|
|
|
|
|
return die_ss_("iterator.set_block(app, true)", iterator);
|
2002-06-07 05:27:37 +00:00
|
|
|
if(!insert_to_our_metadata_(app, our_current_position, /*copy=*/true))
|
|
|
|
|
return false;
|
2002-06-11 06:15:28 +00:00
|
|
|
add_to_padding_length_(our_current_position+1, -((int)(FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) + (int)app->get_length()));
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SVA[A]P\tset APPLICATION (grow), don't expand into padding\n");
|
2002-06-08 04:53:42 +00:00
|
|
|
app->set_id((const unsigned char *)"guh"); /* twiddle the id */
|
2002-06-10 04:42:35 +00:00
|
|
|
if(!app->set_data(data, sizeof(data), true))
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("setting APPLICATION data");
|
|
|
|
|
if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true))
|
|
|
|
|
return die_("copying object");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.set_block(app, false))
|
|
|
|
|
return die_ss_("iterator.set_block(app, false)", iterator);
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SVA[A]P\tset APPLICATION (shrink), don't fill in with padding\n");
|
2002-06-08 04:53:42 +00:00
|
|
|
app->set_id((const unsigned char *)"huh"); /* twiddle the id */
|
2002-06-10 04:42:35 +00:00
|
|
|
if(!app->set_data(data, 12, true))
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("setting APPLICATION data");
|
|
|
|
|
if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true))
|
|
|
|
|
return die_("copying object");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.set_block(app, false))
|
|
|
|
|
return die_ss_("iterator.set_block(app, false)", iterator);
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SVA[A]P\tset APPLICATION (grow), expand into padding of exceeding size\n");
|
2002-06-08 04:53:42 +00:00
|
|
|
app->set_id((const unsigned char *)"iuh"); /* twiddle the id */
|
2002-06-10 04:42:35 +00:00
|
|
|
if(!app->set_data(data, sizeof(data), true))
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("setting APPLICATION data");
|
|
|
|
|
if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true))
|
|
|
|
|
return die_("copying object");
|
2002-06-11 06:15:28 +00:00
|
|
|
add_to_padding_length_(our_current_position+1, -((int)sizeof(data) - 12));
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.set_block(app, true))
|
|
|
|
|
return die_ss_("iterator.set_block(app, true)", iterator);
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SVA[A]P\tset APPLICATION (shrink), fill in with padding\n");
|
2002-06-08 04:53:42 +00:00
|
|
|
app->set_id((const unsigned char *)"juh"); /* twiddle the id */
|
2002-06-10 04:42:35 +00:00
|
|
|
if(!app->set_data(data, 23, true))
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("setting APPLICATION data");
|
|
|
|
|
if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true))
|
|
|
|
|
return die_("copying object");
|
|
|
|
|
if(!insert_to_our_metadata_(padding, our_current_position+1, /*copy=*/true))
|
|
|
|
|
return die_("copying object");
|
2002-06-10 04:42:35 +00:00
|
|
|
dynamic_cast<FLAC::Metadata::Padding *>(our_metadata_.blocks[our_current_position+1])->set_length(sizeof(data) - 23 - FLAC__STREAM_METADATA_HEADER_LENGTH);
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.set_block(app, true))
|
|
|
|
|
return die_ss_("iterator.set_block(app, true)", iterator);
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SVA[A]PP\tnext\n");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.next())
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("iterator ended early\n");
|
|
|
|
|
our_current_position++;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SVAA[P]P\tnext\n");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.next())
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("iterator ended early\n");
|
|
|
|
|
our_current_position++;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SVAAP[P]\tset PADDING (shrink), don't fill in with padding\n");
|
2002-06-10 04:42:35 +00:00
|
|
|
padding->set_length(5);
|
2002-06-07 05:27:37 +00:00
|
|
|
if(!replace_in_our_metadata_(padding, our_current_position, /*copy=*/true))
|
|
|
|
|
return die_("copying object");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.set_block(padding, false))
|
|
|
|
|
return die_ss_("iterator.set_block(padding, false)", iterator);
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SVAAP[P]\tset APPLICATION (grow)\n");
|
2002-06-08 04:53:42 +00:00
|
|
|
app->set_id((const unsigned char *)"kuh"); /* twiddle the id */
|
2002-06-07 05:27:37 +00:00
|
|
|
if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true))
|
|
|
|
|
return die_("copying object");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.set_block(app, false))
|
|
|
|
|
return die_ss_("iterator.set_block(app, false)", iterator);
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SVAAP[A]\tset PADDING (equal)\n");
|
2002-06-10 04:42:35 +00:00
|
|
|
padding->set_length(27);
|
2002-06-07 05:27:37 +00:00
|
|
|
if(!replace_in_our_metadata_(padding, our_current_position, /*copy=*/true))
|
|
|
|
|
return die_("copying object");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.set_block(padding, false))
|
|
|
|
|
return die_ss_("iterator.set_block(padding, false)", iterator);
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SVAAP[P]\tprev\n");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.prev())
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("iterator ended early\n");
|
|
|
|
|
our_current_position--;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SVAA[P]P\tdelete (middle block), don't replace with padding\n");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.delete_block(false))
|
|
|
|
|
return die_ss_("iterator.delete_block(false)", iterator);
|
2002-06-07 05:27:37 +00:00
|
|
|
delete_from_our_metadata_(our_current_position--);
|
|
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SVA[A]P\tdelete (middle block), don't replace with padding\n");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.delete_block(false))
|
|
|
|
|
return die_ss_("iterator.delete_block(false)", iterator);
|
2002-06-07 05:27:37 +00:00
|
|
|
delete_from_our_metadata_(our_current_position--);
|
|
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SV[A]P\tnext\n");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.next())
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("iterator ended early\n");
|
|
|
|
|
our_current_position++;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SVA[P]\tinsert PADDING after\n");
|
2002-06-10 04:42:35 +00:00
|
|
|
padding->set_length(5);
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.insert_block_after(padding, false))
|
|
|
|
|
return die_ss_("iterator.insert_block_after(padding, false)", iterator);
|
2002-06-07 05:27:37 +00:00
|
|
|
if(!insert_to_our_metadata_(padding, ++our_current_position, /*copy=*/true))
|
|
|
|
|
return false;
|
|
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SVAP[P]\tprev\n");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.prev())
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("iterator ended early\n");
|
|
|
|
|
our_current_position--;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SVA[P]P\tprev\n");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.prev())
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("iterator ended early\n");
|
|
|
|
|
our_current_position--;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SV[A]PP\tset APPLICATION (grow), try to expand into padding which is too small\n");
|
2002-06-10 04:42:35 +00:00
|
|
|
if(!app->set_data(data, 32, true))
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("setting APPLICATION data");
|
|
|
|
|
if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true))
|
|
|
|
|
return die_("copying object");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.set_block(app, true))
|
|
|
|
|
return die_ss_("iterator.set_block(app, true)", iterator);
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SV[A]PP\tset APPLICATION (grow), try to expand into padding which is 'close' but still too small\n");
|
2002-06-10 04:42:35 +00:00
|
|
|
if(!app->set_data(data, 60, true))
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("setting APPLICATION data");
|
|
|
|
|
if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true))
|
|
|
|
|
return die_("copying object");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.set_block(app, true))
|
|
|
|
|
return die_ss_("iterator.set_block(app, true)", iterator);
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SV[A]PP\tset APPLICATION (grow), expand into padding which will leave 0-length pad\n");
|
2002-06-10 04:42:35 +00:00
|
|
|
if(!app->set_data(data, 87, true))
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("setting APPLICATION data");
|
|
|
|
|
if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true))
|
|
|
|
|
return die_("copying object");
|
2002-06-10 04:42:35 +00:00
|
|
|
dynamic_cast<FLAC::Metadata::Padding *>(our_metadata_.blocks[our_current_position+1])->set_length(0);
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.set_block(app, true))
|
|
|
|
|
return die_ss_("iterator.set_block(app, true)", iterator);
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SV[A]PP\tset APPLICATION (grow), expand into padding which is exactly consumed\n");
|
2002-06-10 04:42:35 +00:00
|
|
|
if(!app->set_data(data, 91, true))
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("setting APPLICATION data");
|
|
|
|
|
if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true))
|
|
|
|
|
return die_("copying object");
|
|
|
|
|
delete_from_our_metadata_(our_current_position+1);
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.set_block(app, true))
|
|
|
|
|
return die_ss_("iterator.set_block(app, true)", iterator);
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SV[A]P\tset APPLICATION (grow), expand into padding which is exactly consumed\n");
|
2002-06-10 04:42:35 +00:00
|
|
|
if(!app->set_data(data, 100, true))
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("setting APPLICATION data");
|
|
|
|
|
if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true))
|
|
|
|
|
return die_("copying object");
|
|
|
|
|
delete_from_our_metadata_(our_current_position+1);
|
2002-06-10 04:42:35 +00:00
|
|
|
our_metadata_.blocks[our_current_position]->set_is_last(true);
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.set_block(app, true))
|
|
|
|
|
return die_ss_("iterator.set_block(app, true)", iterator);
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SV[A]\tset PADDING (equal size)\n");
|
2002-06-10 04:42:35 +00:00
|
|
|
padding->set_length(app->get_length());
|
2002-06-07 05:27:37 +00:00
|
|
|
if(!replace_in_our_metadata_(padding, our_current_position, /*copy=*/true))
|
|
|
|
|
return die_("copying object");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.set_block(padding, true))
|
|
|
|
|
return die_ss_("iterator.set_block(padding, true)", iterator);
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SV[P]\tinsert PADDING after\n");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.insert_block_after(padding, false))
|
|
|
|
|
return die_ss_("iterator.insert_block_after(padding, false)", iterator);
|
2002-06-07 05:27:37 +00:00
|
|
|
if(!insert_to_our_metadata_(padding, ++our_current_position, /*copy=*/true))
|
|
|
|
|
return false;
|
|
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SVP[P]\tinsert PADDING after\n");
|
2002-06-10 04:42:35 +00:00
|
|
|
padding->set_length(5);
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.insert_block_after(padding, false))
|
|
|
|
|
return die_ss_("iterator.insert_block_after(padding, false)", iterator);
|
2002-06-07 05:27:37 +00:00
|
|
|
if(!insert_to_our_metadata_(padding, ++our_current_position, /*copy=*/true))
|
|
|
|
|
return false;
|
|
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SVPP[P]\tprev\n");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.prev())
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("iterator ended early\n");
|
|
|
|
|
our_current_position--;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SVP[P]P\tprev\n");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.prev())
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("iterator ended early\n");
|
|
|
|
|
our_current_position--;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SV[P]PP\tprev\n");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.prev())
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("iterator ended early\n");
|
|
|
|
|
our_current_position--;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("S[V]PPP\tinsert APPLICATION after, try to expand into padding which is too small\n");
|
2002-06-10 04:42:35 +00:00
|
|
|
if(!app->set_data(data, 101, true))
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("setting APPLICATION data");
|
|
|
|
|
if(!insert_to_our_metadata_(app, ++our_current_position, /*copy=*/true))
|
|
|
|
|
return die_("copying object");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.insert_block_after(app, true))
|
|
|
|
|
return die_ss_("iterator.insert_block_after(app, true)", iterator);
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SV[A]PPP\tdelete (middle block), don't replace with padding\n");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.delete_block(false))
|
|
|
|
|
return die_ss_("iterator.delete_block(false)", iterator);
|
2002-06-07 05:27:37 +00:00
|
|
|
delete_from_our_metadata_(our_current_position--);
|
|
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("S[V]PPP\tinsert APPLICATION after, try to expand into padding which is 'close' but still too small\n");
|
2002-06-10 04:42:35 +00:00
|
|
|
if(!app->set_data(data, 97, true))
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("setting APPLICATION data");
|
|
|
|
|
if(!insert_to_our_metadata_(app, ++our_current_position, /*copy=*/true))
|
|
|
|
|
return die_("copying object");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.insert_block_after(app, true))
|
|
|
|
|
return die_ss_("iterator.insert_block_after(app, true)", iterator);
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SV[A]PPP\tdelete (middle block), don't replace with padding\n");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.delete_block(false))
|
|
|
|
|
return die_ss_("iterator.delete_block(false)", iterator);
|
2002-06-07 05:27:37 +00:00
|
|
|
delete_from_our_metadata_(our_current_position--);
|
|
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("S[V]PPP\tinsert APPLICATION after, expand into padding which is exactly consumed\n");
|
2002-06-10 04:42:35 +00:00
|
|
|
if(!app->set_data(data, 100, true))
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("setting APPLICATION data");
|
|
|
|
|
if(!insert_to_our_metadata_(app, ++our_current_position, /*copy=*/true))
|
|
|
|
|
return die_("copying object");
|
|
|
|
|
delete_from_our_metadata_(our_current_position+1);
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.insert_block_after(app, true))
|
|
|
|
|
return die_ss_("iterator.insert_block_after(app, true)", iterator);
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SV[A]PP\tdelete (middle block), don't replace with padding\n");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.delete_block(false))
|
|
|
|
|
return die_ss_("iterator.delete_block(false)", iterator);
|
2002-06-07 05:27:37 +00:00
|
|
|
delete_from_our_metadata_(our_current_position--);
|
|
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("S[V]PP\tinsert APPLICATION after, expand into padding which will leave 0-length pad\n");
|
2002-06-10 04:42:35 +00:00
|
|
|
if(!app->set_data(data, 96, true))
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("setting APPLICATION data");
|
|
|
|
|
if(!insert_to_our_metadata_(app, ++our_current_position, /*copy=*/true))
|
|
|
|
|
return die_("copying object");
|
2002-06-10 04:42:35 +00:00
|
|
|
dynamic_cast<FLAC::Metadata::Padding *>(our_metadata_.blocks[our_current_position+1])->set_length(0);
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.insert_block_after(app, true))
|
|
|
|
|
return die_ss_("iterator.insert_block_after(app, true)", iterator);
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SV[A]PP\tdelete (middle block), don't replace with padding\n");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.delete_block(false))
|
|
|
|
|
return die_ss_("iterator.delete_block(false)", iterator);
|
2002-06-07 05:27:37 +00:00
|
|
|
delete_from_our_metadata_(our_current_position--);
|
|
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("S[V]PP\tnext\n");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.next())
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("iterator ended early\n");
|
|
|
|
|
our_current_position++;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SV[P]P\tdelete (middle block), don't replace with padding\n");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.delete_block(false))
|
|
|
|
|
return die_ss_("iterator.delete_block(false)", iterator);
|
2002-06-07 05:27:37 +00:00
|
|
|
delete_from_our_metadata_(our_current_position--);
|
|
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("S[V]P\tinsert APPLICATION after, expand into padding which is exactly consumed\n");
|
2002-06-10 04:42:35 +00:00
|
|
|
if(!app->set_data(data, 1, true))
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("setting APPLICATION data");
|
|
|
|
|
if(!insert_to_our_metadata_(app, ++our_current_position, /*copy=*/true))
|
|
|
|
|
return die_("copying object");
|
|
|
|
|
delete_from_our_metadata_(our_current_position+1);
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.insert_block_after(app, true))
|
|
|
|
|
return die_ss_("iterator.insert_block_after(app, true)", iterator);
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
2002-06-08 04:53:42 +00:00
|
|
|
}
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-06-10 04:42:35 +00:00
|
|
|
delete app;
|
|
|
|
|
delete padding;
|
2002-06-07 05:27:37 +00:00
|
|
|
|
|
|
|
|
if(!remove_file_(flacfile_))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
static bool test_level_2_()
|
2002-06-07 05:27:37 +00:00
|
|
|
{
|
2002-06-10 04:42:35 +00:00
|
|
|
FLAC::Metadata::Prototype *block;
|
|
|
|
|
FLAC::Metadata::StreamInfo *streaminfo;
|
|
|
|
|
FLAC::Metadata::Application *app;
|
|
|
|
|
FLAC::Metadata::Padding *padding;
|
2002-06-07 05:27:37 +00:00
|
|
|
FLAC__byte data[2000];
|
|
|
|
|
unsigned our_current_position;
|
|
|
|
|
|
|
|
|
|
printf("\n\n++++++ testing level 2 interface\n");
|
|
|
|
|
|
|
|
|
|
printf("generate read-only file\n");
|
|
|
|
|
|
|
|
|
|
if(!generate_file_())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if(!change_stats_(flacfile_, /*read_only=*/true))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
printf("create chain\n");
|
2002-06-10 04:42:35 +00:00
|
|
|
FLAC::Metadata::Chain chain;
|
|
|
|
|
if(!chain.is_valid())
|
|
|
|
|
return die_("allocating memory for chain");
|
2002-06-07 05:27:37 +00:00
|
|
|
|
|
|
|
|
printf("read chain\n");
|
|
|
|
|
|
2002-06-10 04:42:35 +00:00
|
|
|
if(!chain.read(flacfile_))
|
|
|
|
|
return die_c_("reading chain", chain.status());
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("[S]VP\ttest initial metadata\n");
|
2002-06-07 05:27:37 +00:00
|
|
|
|
|
|
|
|
if(!compare_chain_(chain, 0, 0))
|
|
|
|
|
return false;
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
printf("switch file to read-write\n");
|
|
|
|
|
|
|
|
|
|
if(!change_stats_(flacfile_, /*read-only=*/false))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
printf("create iterator\n");
|
2002-06-10 04:42:35 +00:00
|
|
|
{
|
|
|
|
|
FLAC::Metadata::Iterator iterator;
|
|
|
|
|
if(!iterator.is_valid())
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("allocating memory for iterator");
|
|
|
|
|
|
|
|
|
|
our_current_position = 0;
|
|
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
iterator.init(chain);
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(0 == (block = iterator.get_block()))
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("getting block from iterator");
|
|
|
|
|
|
2002-06-10 04:42:35 +00:00
|
|
|
FLAC__ASSERT(block->get_type() == FLAC__METADATA_TYPE_STREAMINFO);
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("[S]VP\tmodify STREAMINFO, write\n");
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-06-10 04:42:35 +00:00
|
|
|
streaminfo = dynamic_cast<FLAC::Metadata::StreamInfo *>(block);
|
|
|
|
|
FLAC__ASSERT(0 != streaminfo);
|
|
|
|
|
streaminfo->set_sample_rate(32000);
|
2002-06-07 05:27:37 +00:00
|
|
|
if(!replace_in_our_metadata_(block, our_current_position, /*copy=*/true))
|
|
|
|
|
return die_("copying object");
|
|
|
|
|
|
2002-06-10 04:42:35 +00:00
|
|
|
if(!chain.write(/*use_padding=*/false, /*preserve_file_stats=*/true))
|
|
|
|
|
return die_c_("during chain.write(false, true)", chain.status());
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!compare_chain_(chain, our_current_position, iterator.get_block()))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("[S]VP\tnext\n");
|
|
|
|
|
if(!iterator.next())
|
|
|
|
|
return die_("iterator ended early\n");
|
|
|
|
|
our_current_position++;
|
|
|
|
|
|
|
|
|
|
printf("S[V]P\tnext\n");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.next())
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("iterator ended early\n");
|
|
|
|
|
our_current_position++;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SV[P]\treplace PADDING with identical-size APPLICATION\n");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(0 == (block = iterator.get_block()))
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("getting block from iterator");
|
2002-06-10 04:42:35 +00:00
|
|
|
if(0 == (app = new FLAC::Metadata::Application()))
|
|
|
|
|
return die_("new FLAC::Metadata::Application()");
|
|
|
|
|
app->set_id((const unsigned char *)"duh");
|
|
|
|
|
if(!app->set_data(data, block->get_length()-(FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8), true))
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("setting APPLICATION data");
|
|
|
|
|
if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true))
|
|
|
|
|
return die_("copying object");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.set_block(app))
|
2002-06-10 04:42:35 +00:00
|
|
|
return die_c_("iterator.set_block(app)", chain.status());
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-06-10 04:42:35 +00:00
|
|
|
if(!chain.write(/*use_padding=*/false, /*preserve_file_stats=*/false))
|
|
|
|
|
return die_c_("during chain.write(false, false)", chain.status());
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!compare_chain_(chain, our_current_position, iterator.get_block()))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SV[A]\tshrink APPLICATION, don't use padding\n");
|
2002-06-10 04:42:35 +00:00
|
|
|
if(0 == (app = dynamic_cast<FLAC::Metadata::Application *>(FLAC::Metadata::clone(our_metadata_.blocks[our_current_position]))))
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("copying object");
|
2002-06-10 04:42:35 +00:00
|
|
|
if(!app->set_data(data, 26, true))
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("setting APPLICATION data");
|
|
|
|
|
if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true))
|
|
|
|
|
return die_("copying object");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.set_block(app))
|
2002-06-10 04:42:35 +00:00
|
|
|
return die_c_("iterator.set_block(app)", chain.status());
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-06-10 04:42:35 +00:00
|
|
|
if(!chain.write(/*use_padding=*/false, /*preserve_file_stats=*/false))
|
|
|
|
|
return die_c_("during chain.write(false, false)", chain.status());
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!compare_chain_(chain, our_current_position, iterator.get_block()))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SV[A]\tgrow APPLICATION, don't use padding\n");
|
2002-06-10 04:42:35 +00:00
|
|
|
if(0 == (app = dynamic_cast<FLAC::Metadata::Application *>(FLAC::Metadata::clone(our_metadata_.blocks[our_current_position]))))
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("copying object");
|
2002-06-10 04:42:35 +00:00
|
|
|
if(!app->set_data(data, 28, true))
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("setting APPLICATION data");
|
|
|
|
|
if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true))
|
|
|
|
|
return die_("copying object");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.set_block(app))
|
2002-06-10 04:42:35 +00:00
|
|
|
return die_c_("iterator.set_block(app)", chain.status());
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-06-10 04:42:35 +00:00
|
|
|
if(!chain.write(/*use_padding=*/false, /*preserve_file_stats=*/false))
|
|
|
|
|
return die_c_("during chain.write(false, false)", chain.status());
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!compare_chain_(chain, our_current_position, iterator.get_block()))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SV[A]\tgrow APPLICATION, use padding, but last block is not padding\n");
|
2002-06-10 04:42:35 +00:00
|
|
|
if(0 == (app = dynamic_cast<FLAC::Metadata::Application *>(FLAC::Metadata::clone(our_metadata_.blocks[our_current_position]))))
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("copying object");
|
2002-06-10 04:42:35 +00:00
|
|
|
if(!app->set_data(data, 36, true))
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("setting APPLICATION data");
|
|
|
|
|
if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true))
|
|
|
|
|
return die_("copying object");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.set_block(app))
|
2002-06-10 04:42:35 +00:00
|
|
|
return die_c_("iterator.set_block(app)", chain.status());
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-06-10 04:42:35 +00:00
|
|
|
if(!chain.write(/*use_padding=*/false, /*preserve_file_stats=*/false))
|
|
|
|
|
return die_c_("during chain.write(false, false)", chain.status());
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!compare_chain_(chain, our_current_position, iterator.get_block()))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SV[A]\tshrink APPLICATION, use padding, last block is not padding, but delta is too small for new PADDING block\n");
|
2002-06-10 04:42:35 +00:00
|
|
|
if(0 == (app = dynamic_cast<FLAC::Metadata::Application *>(FLAC::Metadata::clone(our_metadata_.blocks[our_current_position]))))
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("copying object");
|
2002-06-10 04:42:35 +00:00
|
|
|
if(!app->set_data(data, 33, true))
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("setting APPLICATION data");
|
|
|
|
|
if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true))
|
|
|
|
|
return die_("copying object");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.set_block(app))
|
2002-06-10 04:42:35 +00:00
|
|
|
return die_c_("iterator.set_block(app)", chain.status());
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-06-10 04:42:35 +00:00
|
|
|
if(!chain.write(/*use_padding=*/true, /*preserve_file_stats=*/false))
|
|
|
|
|
return die_c_("during chain.write(true, false)", chain.status());
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!compare_chain_(chain, our_current_position, iterator.get_block()))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SV[A]\tshrink APPLICATION, use padding, last block is not padding, delta is enough for new PADDING block\n");
|
2002-06-10 04:42:35 +00:00
|
|
|
if(0 == (padding = new FLAC::Metadata::Padding()))
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("creating PADDING block");
|
2002-06-10 04:42:35 +00:00
|
|
|
if(0 == (app = dynamic_cast<FLAC::Metadata::Application *>(FLAC::Metadata::clone(our_metadata_.blocks[our_current_position]))))
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("copying object");
|
2002-06-10 04:42:35 +00:00
|
|
|
if(!app->set_data(data, 29, true))
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("setting APPLICATION data");
|
|
|
|
|
if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true))
|
|
|
|
|
return die_("copying object");
|
2002-06-10 04:42:35 +00:00
|
|
|
padding->set_length(0);
|
2002-06-07 05:27:37 +00:00
|
|
|
if(!insert_to_our_metadata_(padding, our_current_position+1, /*copy=*/false))
|
|
|
|
|
return die_("internal error");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.set_block(app))
|
2002-06-10 04:42:35 +00:00
|
|
|
return die_c_("iterator.set_block(app)", chain.status());
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-06-10 04:42:35 +00:00
|
|
|
if(!chain.write(/*use_padding=*/true, /*preserve_file_stats=*/false))
|
|
|
|
|
return die_c_("during chain.write(true, false)", chain.status());
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!compare_chain_(chain, our_current_position, iterator.get_block()))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SV[A]P\tshrink APPLICATION, use padding, last block is padding\n");
|
2002-06-10 04:42:35 +00:00
|
|
|
if(0 == (app = dynamic_cast<FLAC::Metadata::Application *>(FLAC::Metadata::clone(our_metadata_.blocks[our_current_position]))))
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("copying object");
|
2002-06-10 04:42:35 +00:00
|
|
|
if(!app->set_data(data, 16, true))
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("setting APPLICATION data");
|
|
|
|
|
if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true))
|
|
|
|
|
return die_("copying object");
|
2002-06-10 04:42:35 +00:00
|
|
|
dynamic_cast<FLAC::Metadata::Padding *>(our_metadata_.blocks[our_current_position+1])->set_length(13);
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.set_block(app))
|
2002-06-10 04:42:35 +00:00
|
|
|
return die_c_("iterator.set_block(app)", chain.status());
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-06-10 04:42:35 +00:00
|
|
|
if(!chain.write(/*use_padding=*/true, /*preserve_file_stats=*/false))
|
|
|
|
|
return die_c_("during chain.write(true, false)", chain.status());
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!compare_chain_(chain, our_current_position, iterator.get_block()))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SV[A]P\tgrow APPLICATION, use padding, last block is padding, but delta is too small\n");
|
2002-06-10 04:42:35 +00:00
|
|
|
if(0 == (app = dynamic_cast<FLAC::Metadata::Application *>(FLAC::Metadata::clone(our_metadata_.blocks[our_current_position]))))
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("copying object");
|
2002-06-10 04:42:35 +00:00
|
|
|
if(!app->set_data(data, 50, true))
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("setting APPLICATION data");
|
|
|
|
|
if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true))
|
|
|
|
|
return die_("copying object");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.set_block(app))
|
2002-06-10 04:42:35 +00:00
|
|
|
return die_c_("iterator.set_block(app)", chain.status());
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-06-10 04:42:35 +00:00
|
|
|
if(!chain.write(/*use_padding=*/true, /*preserve_file_stats=*/false))
|
|
|
|
|
return die_c_("during chain.write(true, false)", chain.status());
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!compare_chain_(chain, our_current_position, iterator.get_block()))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SV[A]P\tgrow APPLICATION, use padding, last block is padding of exceeding size\n");
|
2002-06-10 04:42:35 +00:00
|
|
|
if(0 == (app = dynamic_cast<FLAC::Metadata::Application *>(FLAC::Metadata::clone(our_metadata_.blocks[our_current_position]))))
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("copying object");
|
2002-06-10 04:42:35 +00:00
|
|
|
if(!app->set_data(data, 56, true))
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("setting APPLICATION data");
|
|
|
|
|
if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true))
|
|
|
|
|
return die_("copying object");
|
2002-06-10 04:42:35 +00:00
|
|
|
add_to_padding_length_(our_current_position+1, -(56 - 50));
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.set_block(app))
|
2002-06-10 04:42:35 +00:00
|
|
|
return die_c_("iterator.set_block(app)", chain.status());
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-06-10 04:42:35 +00:00
|
|
|
if(!chain.write(/*use_padding=*/true, /*preserve_file_stats=*/false))
|
|
|
|
|
return die_c_("during chain.write(true, false)", chain.status());
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!compare_chain_(chain, our_current_position, iterator.get_block()))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SV[A]P\tgrow APPLICATION, use padding, last block is padding of exact size\n");
|
2002-06-10 04:42:35 +00:00
|
|
|
if(0 == (app = dynamic_cast<FLAC::Metadata::Application *>(FLAC::Metadata::clone(our_metadata_.blocks[our_current_position]))))
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("copying object");
|
2002-06-10 04:42:35 +00:00
|
|
|
if(!app->set_data(data, 67, true))
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("setting APPLICATION data");
|
|
|
|
|
if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true))
|
|
|
|
|
return die_("copying object");
|
|
|
|
|
delete_from_our_metadata_(our_current_position+1);
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.set_block(app))
|
2002-06-10 04:42:35 +00:00
|
|
|
return die_c_("iterator.set_block(app)", chain.status());
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-06-10 04:42:35 +00:00
|
|
|
if(!chain.write(/*use_padding=*/true, /*preserve_file_stats=*/false))
|
|
|
|
|
return die_c_("during chain.write(true, false)", chain.status());
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!compare_chain_(chain, our_current_position, iterator.get_block()))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SV[A]\tprev\n");
|
|
|
|
|
if(!iterator.prev())
|
|
|
|
|
return die_("iterator ended early\n");
|
|
|
|
|
our_current_position--;
|
|
|
|
|
|
|
|
|
|
printf("S[V]A\tprev\n");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.prev())
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("iterator ended early\n");
|
|
|
|
|
our_current_position--;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("[S]VA\tinsert PADDING before STREAMINFO (should fail)\n");
|
2002-06-10 04:42:35 +00:00
|
|
|
if(0 == (padding = new FLAC::Metadata::Padding()))
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("creating PADDING block");
|
2002-06-10 04:42:35 +00:00
|
|
|
padding->set_length(30);
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.insert_block_before(padding))
|
|
|
|
|
printf("\titerator.insert_block_before() returned false like it should\n");
|
2002-06-07 05:27:37 +00:00
|
|
|
else
|
2002-06-08 04:53:42 +00:00
|
|
|
return die_("iterator.insert_block_before() should have returned false");
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("[S]VA\tnext\n");
|
|
|
|
|
if(!iterator.next())
|
|
|
|
|
return die_("iterator ended early\n");
|
|
|
|
|
our_current_position++;
|
|
|
|
|
|
|
|
|
|
printf("S[V]A\tinsert PADDING after\n");
|
2002-06-07 05:27:37 +00:00
|
|
|
if(!insert_to_our_metadata_(padding, ++our_current_position, /*copy=*/true))
|
|
|
|
|
return die_("copying metadata");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.insert_block_after(padding))
|
|
|
|
|
return die_("iterator.insert_block_after(padding)");
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!compare_chain_(chain, our_current_position, iterator.get_block()))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SV[P]A\tinsert PADDING before\n");
|
2002-06-10 04:42:35 +00:00
|
|
|
if(0 == (padding = dynamic_cast<FLAC::Metadata::Padding *>(FLAC::Metadata::clone(our_metadata_.blocks[our_current_position]))))
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("creating PADDING block");
|
2002-06-10 04:42:35 +00:00
|
|
|
padding->set_length(17);
|
2002-06-07 05:27:37 +00:00
|
|
|
if(!insert_to_our_metadata_(padding, our_current_position, /*copy=*/true))
|
|
|
|
|
return die_("copying metadata");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.insert_block_before(padding))
|
|
|
|
|
return die_("iterator.insert_block_before(padding)");
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!compare_chain_(chain, our_current_position, iterator.get_block()))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SV[P]PA\tinsert PADDING before\n");
|
2002-06-10 04:42:35 +00:00
|
|
|
if(0 == (padding = dynamic_cast<FLAC::Metadata::Padding *>(FLAC::Metadata::clone(our_metadata_.blocks[our_current_position]))))
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("creating PADDING block");
|
2002-06-10 04:42:35 +00:00
|
|
|
padding->set_length(0);
|
2002-06-07 05:27:37 +00:00
|
|
|
if(!insert_to_our_metadata_(padding, our_current_position, /*copy=*/true))
|
|
|
|
|
return die_("copying metadata");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.insert_block_before(padding))
|
|
|
|
|
return die_("iterator.insert_block_before(padding)");
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!compare_chain_(chain, our_current_position, iterator.get_block()))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SV[P]PPA\tnext\n");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.next())
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("iterator ended early\n");
|
|
|
|
|
our_current_position++;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SVP[P]PA\tnext\n");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.next())
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("iterator ended early\n");
|
|
|
|
|
our_current_position++;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SVPP[P]A\tnext\n");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.next())
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("iterator ended early\n");
|
|
|
|
|
our_current_position++;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SVPPP[A]\tinsert PADDING after\n");
|
|
|
|
|
if(0 == (padding = dynamic_cast<FLAC::Metadata::Padding *>(FLAC::Metadata::clone(our_metadata_.blocks[2]))))
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("creating PADDING block");
|
2002-06-10 04:42:35 +00:00
|
|
|
padding->set_length(57);
|
2002-06-07 05:27:37 +00:00
|
|
|
if(!insert_to_our_metadata_(padding, ++our_current_position, /*copy=*/true))
|
|
|
|
|
return die_("copying metadata");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.insert_block_after(padding))
|
|
|
|
|
return die_("iterator.insert_block_after(padding)");
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!compare_chain_(chain, our_current_position, iterator.get_block()))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SVPPPA[P]\tinsert PADDING before\n");
|
|
|
|
|
if(0 == (padding = dynamic_cast<FLAC::Metadata::Padding *>(FLAC::Metadata::clone(our_metadata_.blocks[2]))))
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("creating PADDING block");
|
2002-06-10 04:42:35 +00:00
|
|
|
padding->set_length(99);
|
2002-06-07 05:27:37 +00:00
|
|
|
if(!insert_to_our_metadata_(padding, our_current_position, /*copy=*/true))
|
|
|
|
|
return die_("copying metadata");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.insert_block_before(padding))
|
|
|
|
|
return die_("iterator.insert_block_before(padding)");
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!compare_chain_(chain, our_current_position, iterator.get_block()))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
2002-06-10 04:42:35 +00:00
|
|
|
}
|
2002-06-07 05:27:37 +00:00
|
|
|
our_current_position = 0;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SVPPPAPP\tmerge padding\n");
|
2002-06-10 04:42:35 +00:00
|
|
|
chain.merge_padding();
|
2002-08-25 05:10:37 +00:00
|
|
|
add_to_padding_length_(2, FLAC__STREAM_METADATA_HEADER_LENGTH + our_metadata_.blocks[3]->get_length());
|
|
|
|
|
add_to_padding_length_(2, FLAC__STREAM_METADATA_HEADER_LENGTH + our_metadata_.blocks[4]->get_length());
|
|
|
|
|
add_to_padding_length_(6, FLAC__STREAM_METADATA_HEADER_LENGTH + our_metadata_.blocks[7]->get_length());
|
|
|
|
|
delete_from_our_metadata_(7);
|
|
|
|
|
delete_from_our_metadata_(4);
|
2002-06-07 05:27:37 +00:00
|
|
|
delete_from_our_metadata_(3);
|
|
|
|
|
|
2002-06-10 04:42:35 +00:00
|
|
|
if(!chain.write(/*use_padding=*/true, /*preserve_file_stats=*/false))
|
|
|
|
|
return die_c_("during chain.write(true, false)", chain.status());
|
2002-06-07 05:27:37 +00:00
|
|
|
if(!compare_chain_(chain, 0, 0))
|
|
|
|
|
return false;
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SVPAP\tsort padding\n");
|
2002-06-10 04:42:35 +00:00
|
|
|
chain.sort_padding();
|
2002-08-25 05:10:37 +00:00
|
|
|
add_to_padding_length_(4, FLAC__STREAM_METADATA_HEADER_LENGTH + our_metadata_.blocks[2]->get_length());
|
|
|
|
|
delete_from_our_metadata_(2);
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-06-10 04:42:35 +00:00
|
|
|
if(!chain.write(/*use_padding=*/true, /*preserve_file_stats=*/false))
|
|
|
|
|
return die_c_("during chain.write(true, false)", chain.status());
|
2002-06-07 05:27:37 +00:00
|
|
|
if(!compare_chain_(chain, 0, 0))
|
|
|
|
|
return false;
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
printf("create iterator\n");
|
2002-06-10 04:42:35 +00:00
|
|
|
{
|
|
|
|
|
FLAC::Metadata::Iterator iterator;
|
|
|
|
|
if(!iterator.is_valid())
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("allocating memory for iterator");
|
|
|
|
|
|
|
|
|
|
our_current_position = 0;
|
|
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
iterator.init(chain);
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("[S]VAP\tnext\n");
|
|
|
|
|
if(!iterator.next())
|
|
|
|
|
return die_("iterator ended early\n");
|
|
|
|
|
our_current_position++;
|
|
|
|
|
|
|
|
|
|
printf("S[V]AP\tnext\n");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.next())
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("iterator ended early\n");
|
|
|
|
|
our_current_position++;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SV[A]P\tdelete middle block, replace with padding\n");
|
2002-06-10 04:42:35 +00:00
|
|
|
if(0 == (padding = new FLAC::Metadata::Padding()))
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("creating PADDING block");
|
2002-06-10 04:42:35 +00:00
|
|
|
padding->set_length(71);
|
2002-06-07 05:27:37 +00:00
|
|
|
if(!replace_in_our_metadata_(padding, our_current_position--, /*copy=*/false))
|
|
|
|
|
return die_("copying object");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.delete_block(/*replace_with_padding=*/true))
|
2002-06-10 04:42:35 +00:00
|
|
|
return die_c_("iterator.delete_block(true)", chain.status());
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!compare_chain_(chain, our_current_position, iterator.get_block()))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("S[V]PP\tnext\n");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.next())
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("iterator ended early\n");
|
|
|
|
|
our_current_position++;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SV[P]P\tdelete middle block, don't replace with padding\n");
|
2002-06-07 05:27:37 +00:00
|
|
|
delete_from_our_metadata_(our_current_position--);
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.delete_block(/*replace_with_padding=*/false))
|
2002-06-10 04:42:35 +00:00
|
|
|
return die_c_("iterator.delete_block(false)", chain.status());
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!compare_chain_(chain, our_current_position, iterator.get_block()))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("S[V]P\tnext\n");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.next())
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("iterator ended early\n");
|
|
|
|
|
our_current_position++;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SV[P]\tdelete last block, replace with padding\n");
|
2002-06-10 04:42:35 +00:00
|
|
|
if(0 == (padding = new FLAC::Metadata::Padding()))
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("creating PADDING block");
|
2002-06-10 04:42:35 +00:00
|
|
|
padding->set_length(219);
|
2002-06-07 05:27:37 +00:00
|
|
|
if(!replace_in_our_metadata_(padding, our_current_position--, /*copy=*/false))
|
|
|
|
|
return die_("copying object");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.delete_block(/*replace_with_padding=*/true))
|
2002-06-10 04:42:35 +00:00
|
|
|
return die_c_("iterator.delete_block(true)", chain.status());
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!compare_chain_(chain, our_current_position, iterator.get_block()))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("S[V]P\tnext\n");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.next())
|
2002-06-07 05:27:37 +00:00
|
|
|
return die_("iterator ended early\n");
|
|
|
|
|
our_current_position++;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SV[P]\tdelete last block, don't replace with padding\n");
|
2002-06-07 05:27:37 +00:00
|
|
|
delete_from_our_metadata_(our_current_position--);
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!iterator.delete_block(/*replace_with_padding=*/false))
|
2002-06-10 04:42:35 +00:00
|
|
|
return die_c_("iterator.delete_block(false)", chain.status());
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!compare_chain_(chain, our_current_position, iterator.get_block()))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("S[V]\tprev\n");
|
|
|
|
|
if(!iterator.prev())
|
|
|
|
|
return die_("iterator ended early\n");
|
|
|
|
|
our_current_position--;
|
|
|
|
|
|
|
|
|
|
printf("[S]V\tdelete STREAMINFO block, should fail\n");
|
2002-06-08 04:53:42 +00:00
|
|
|
if(iterator.delete_block(/*replace_with_padding=*/false))
|
|
|
|
|
return die_("iterator.delete_block() on STREAMINFO should have failed but didn't");
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!compare_chain_(chain, our_current_position, iterator.get_block()))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
2002-06-10 04:42:35 +00:00
|
|
|
}
|
2002-06-07 05:27:37 +00:00
|
|
|
our_current_position = 0;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SV\tmerge padding\n");
|
2002-06-10 04:42:35 +00:00
|
|
|
chain.merge_padding();
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-06-10 04:42:35 +00:00
|
|
|
if(!chain.write(/*use_padding=*/false, /*preserve_file_stats=*/false))
|
|
|
|
|
return die_c_("during chain.write(false, false)", chain.status());
|
2002-06-07 05:27:37 +00:00
|
|
|
if(!compare_chain_(chain, 0, 0))
|
|
|
|
|
return false;
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
2002-08-25 05:10:37 +00:00
|
|
|
printf("SV\tsort padding\n");
|
2002-06-10 04:42:35 +00:00
|
|
|
chain.sort_padding();
|
2002-06-07 05:27:37 +00:00
|
|
|
|
2002-06-10 04:42:35 +00:00
|
|
|
if(!chain.write(/*use_padding=*/false, /*preserve_file_stats=*/false))
|
|
|
|
|
return die_c_("during chain.write(false, false)", chain.status());
|
2002-06-07 05:27:37 +00:00
|
|
|
if(!compare_chain_(chain, 0, 0))
|
|
|
|
|
return false;
|
2002-06-08 04:53:42 +00:00
|
|
|
if(!test_file_(flacfile_, /*ignore_metadata=*/false))
|
2002-06-07 05:27:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if(!remove_file_(flacfile_))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool test_metadata_file_manipulation()
|
|
|
|
|
{
|
2002-06-08 04:53:42 +00:00
|
|
|
printf("\n+++ libFLAC++ unit test: metadata manipulation\n\n");
|
2002-06-07 05:27:37 +00:00
|
|
|
|
|
|
|
|
our_metadata_.num_blocks = 0;
|
|
|
|
|
|
|
|
|
|
if(!test_level_0_())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if(!test_level_1_())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if(!test_level_2_())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|