2002-06-07 05:27:37 +00:00
/* test_libFLAC - Unit tester for libFLAC
2004-01-17 04:14:43 +00:00
* Copyright ( C ) 2002 , 2003 , 2004 Josh Coalson
2002-05-07 05:33:49 +00:00
*
* 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 .
*/
2002-05-17 06:28:09 +00:00
# include "file_utils.h"
2002-05-09 05:52:40 +00:00
# include "metadata_utils.h"
2002-05-07 06:08:40 +00:00
# include "FLAC/assert.h"
# include "FLAC/file_decoder.h"
2002-05-07 05:33:49 +00:00
# include "FLAC/metadata.h"
2002-11-07 05:07:30 +00:00
# include "share/grabbag.h"
2002-05-07 05:33:49 +00:00
# include <stdio.h>
# include <stdlib.h> /* for malloc() */
2004-07-14 00:50:52 +00:00
# if defined _MSC_VER || defined __MINGW32__
# include <sys/utime.h> /* for utime() */
# include <io.h> /* for chmod() */
# else
# include <sys/types.h> /* some flavors of BSD (like OS X) require this to get time_t */
# include <utime.h> /* for utime() */
# include <unistd.h> /* for chown(), unlink() */
# endif
# include <sys/stat.h> /* for stat(), maybe chmod() */
2002-05-11 05:41:42 +00:00
/******************************************************************************
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
a FLAC__FileDecoder over the dummy file after each operation , comparing
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-05-11 05:41:42 +00:00
will catch it while decoding .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-05-07 06:08:40 +00:00
typedef struct {
FLAC__bool error_occurred ;
} decoder_client_struct ;
2002-05-09 05:52:40 +00:00
typedef struct {
2002-06-08 04:53:42 +00:00
FLAC__StreamMetadata * blocks [ 64 ] ;
2002-05-09 05:52:40 +00:00
unsigned num_blocks ;
} our_metadata_struct ;
static const char * flacfile_ = " metadata.flac " ;
2002-05-11 05:41:42 +00:00
/* our copy of the metadata in flacfile_ */
2002-05-09 05:52:40 +00:00
static our_metadata_struct our_metadata_ ;
2002-05-11 05:41:42 +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-05-09 05:52:40 +00:00
static FLAC__bool die_ ( const char * msg )
{
printf ( " ERROR: %s \n " , msg ) ;
return false ;
}
2002-06-08 04:53:42 +00:00
static FLAC__bool die_c_ ( const char * msg , FLAC__Metadata_ChainStatus status )
2002-05-11 05:41:42 +00:00
{
printf ( " ERROR: %s \n " , msg ) ;
2002-06-08 04:53:42 +00:00
printf ( " status=%s \n " , FLAC__Metadata_ChainStatusString [ status ] ) ;
2002-05-11 05:41:42 +00:00
return false ;
}
2002-06-08 04:53:42 +00:00
static FLAC__bool die_ss_ ( const char * msg , FLAC__Metadata_SimpleIterator * iterator )
2002-05-07 05:33:49 +00:00
{
2002-05-07 06:08:40 +00:00
printf ( " ERROR: %s \n " , msg ) ;
2002-06-08 04:53:42 +00:00
printf ( " status=%s \n " , FLAC__Metadata_SimpleIteratorStatusString [ FLAC__metadata_simple_iterator_status ( iterator ) ] ) ;
2002-05-07 06:08:40 +00:00
return false ;
2002-05-07 05:33:49 +00:00
}
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-05-11 05:41:42 +00:00
/* functions for working with our metadata copy */
2002-06-08 04:53:42 +00:00
static FLAC__bool replace_in_our_metadata_ ( FLAC__StreamMetadata * block , unsigned position , FLAC__bool copy )
2002-05-09 05:52:40 +00:00
{
unsigned i ;
2002-06-08 04:53:42 +00:00
FLAC__StreamMetadata * obj = block ;
2002-05-09 05:52:40 +00:00
FLAC__ASSERT ( position < our_metadata_ . num_blocks ) ;
if ( copy ) {
2002-06-08 04:53:42 +00:00
if ( 0 = = ( obj = FLAC__metadata_object_clone ( block ) ) )
return die_ ( " during FLAC__metadata_object_clone() " ) ;
2002-05-09 05:52:40 +00:00
}
FLAC__metadata_object_delete ( our_metadata_ . blocks [ position ] ) ;
our_metadata_ . blocks [ position ] = obj ;
/* set the is_last flags */
for ( i = 0 ; i < our_metadata_ . num_blocks - 1 ; i + + )
our_metadata_ . blocks [ i ] - > is_last = false ;
our_metadata_ . blocks [ i ] - > is_last = true ;
return true ;
}
2002-06-08 04:53:42 +00:00
static FLAC__bool insert_to_our_metadata_ ( FLAC__StreamMetadata * block , unsigned position , FLAC__bool copy )
2002-05-09 05:52:40 +00:00
{
unsigned i ;
2002-06-08 04:53:42 +00:00
FLAC__StreamMetadata * obj = block ;
2002-05-09 05:52:40 +00:00
if ( copy ) {
2002-06-08 04:53:42 +00:00
if ( 0 = = ( obj = FLAC__metadata_object_clone ( block ) ) )
return die_ ( " during FLAC__metadata_object_clone() " ) ;
2002-05-09 05:52:40 +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 + + )
our_metadata_ . blocks [ i ] - > is_last = false ;
our_metadata_ . blocks [ i ] - > is_last = true ;
return true ;
}
static void delete_from_our_metadata_ ( unsigned position )
{
unsigned i ;
FLAC__ASSERT ( position < our_metadata_ . num_blocks ) ;
FLAC__metadata_object_delete ( our_metadata_ . blocks [ position ] ) ;
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 + + )
our_metadata_ . blocks [ i ] - > is_last = false ;
our_metadata_ . blocks [ i ] - > is_last = true ;
}
}
2004-07-14 00:50:52 +00:00
/*
2004-07-15 16:21:52 +00:00
* This wad of functions supports filename - and callback - based chain reading / writing .
2004-07-14 00:50:52 +00:00
* Everything up to set_file_stats_ ( ) is copied from libFLAC / metadata_iterators . c
*/
FLAC__bool open_tempfile_ ( const char * filename , FILE * * tempfile , char * * tempfilename )
{
static const char * tempfile_suffix = " .metadata_edit " ;
if ( 0 = = ( * tempfilename = ( char * ) malloc ( strlen ( filename ) + strlen ( tempfile_suffix ) + 1 ) ) )
return false ;
strcpy ( * tempfilename , filename ) ;
strcat ( * tempfilename , tempfile_suffix ) ;
2004-07-16 00:31:43 +00:00
if ( 0 = = ( * tempfile = fopen ( * tempfilename , " wb " ) ) )
2004-07-14 00:50:52 +00:00
return false ;
return true ;
}
void cleanup_tempfile_ ( FILE * * tempfile , char * * tempfilename )
{
if ( 0 ! = * tempfile ) {
( void ) fclose ( * tempfile ) ;
* tempfile = 0 ;
}
if ( 0 ! = * tempfilename ) {
( void ) unlink ( * tempfilename ) ;
free ( * tempfilename ) ;
* tempfilename = 0 ;
}
}
FLAC__bool transport_tempfile_ ( const char * filename , FILE * * tempfile , char * * tempfilename )
{
FLAC__ASSERT ( 0 ! = filename ) ;
FLAC__ASSERT ( 0 ! = tempfile ) ;
FLAC__ASSERT ( 0 ! = tempfilename ) ;
FLAC__ASSERT ( 0 ! = * tempfilename ) ;
if ( 0 ! = * tempfile ) {
( void ) fclose ( * tempfile ) ;
* tempfile = 0 ;
}
# if defined _MSC_VER || defined __MINGW32__
if ( unlink ( filename ) < 0 ) {
cleanup_tempfile_ ( tempfile , tempfilename ) ;
return false ;
}
# endif
if ( 0 ! = rename ( * tempfilename , filename ) ) {
cleanup_tempfile_ ( tempfile , tempfilename ) ;
return false ;
}
cleanup_tempfile_ ( tempfile , tempfilename ) ;
return true ;
}
FLAC__bool get_file_stats_ ( const char * filename , struct stat * stats )
{
FLAC__ASSERT ( 0 ! = filename ) ;
FLAC__ASSERT ( 0 ! = stats ) ;
return ( 0 = = stat ( filename , stats ) ) ;
}
void set_file_stats_ ( const char * filename , struct stat * stats )
{
struct utimbuf srctime ;
FLAC__ASSERT ( 0 ! = filename ) ;
FLAC__ASSERT ( 0 ! = stats ) ;
srctime . actime = stats - > st_atime ;
srctime . modtime = stats - > st_mtime ;
( void ) chmod ( filename , stats - > st_mode ) ;
( void ) utime ( filename , & srctime ) ;
# if !defined _MSC_VER && !defined __MINGW32__
( void ) chown ( filename , stats - > st_uid , - 1 ) ;
( void ) chown ( filename , - 1 , stats - > st_gid ) ;
# endif
}
# ifdef FLAC__VALGRIND_TESTING
static size_t chain_write_cb_ ( const void * ptr , size_t size , size_t nmemb , FLAC__IOHandle handle )
{
FILE * stream = ( FILE * ) handle ;
size_t ret = fwrite ( ptr , size , nmemb , stream ) ;
if ( ! ferror ( stream ) )
fflush ( stream ) ;
return ret ;
}
# endif
static int chain_seek_cb_ ( FLAC__IOHandle handle , FLAC__int64 offset , int whence )
{
long o = ( long ) offset ;
FLAC__ASSERT ( offset = = o ) ;
return fseek ( ( FILE * ) handle , o , whence ) ;
}
static FLAC__int64 chain_tell_cb_ ( FLAC__IOHandle handle )
{
return ftell ( ( FILE * ) handle ) ;
}
static int chain_eof_cb_ ( FLAC__IOHandle handle )
{
return feof ( ( FILE * ) handle ) ;
}
static FLAC__bool write_chain_ ( FLAC__Metadata_Chain * chain , FLAC__bool use_padding , FLAC__bool preserve_file_stats , FLAC__bool filename_based , const char * filename )
{
if ( filename_based )
return FLAC__metadata_chain_write ( chain , use_padding , preserve_file_stats ) ;
else {
FLAC__IOCallbacks callbacks ;
memset ( & callbacks , 0 , sizeof ( callbacks ) ) ;
callbacks . read = ( FLAC__IOCallback_Read ) fread ;
# ifdef FLAC__VALGRIND_TESTING
callbacks . write = chain_write_cb_ ;
# else
callbacks . write = ( FLAC__IOCallback_Write ) fwrite ;
# endif
callbacks . seek = chain_seek_cb_ ;
callbacks . eof = chain_eof_cb_ ;
if ( FLAC__metadata_chain_check_if_tempfile_needed ( chain , use_padding ) ) {
struct stat stats ;
FILE * file , * tempfile ;
char * tempfilename ;
if ( preserve_file_stats ) {
if ( ! get_file_stats_ ( filename , & stats ) )
return false ;
}
if ( 0 = = ( file = fopen ( filename , " rb " ) ) )
return false ; /*@@@ chain status still says OK though */
if ( ! open_tempfile_ ( filename , & tempfile , & tempfilename ) ) {
fclose ( file ) ;
cleanup_tempfile_ ( & tempfile , & tempfilename ) ;
return false ; /*@@@ chain status still says OK though */
}
2004-07-15 00:04:09 +00:00
if ( ! FLAC__metadata_chain_write_with_callbacks_and_tempfile ( chain , use_padding , ( FLAC__IOHandle ) file , callbacks , ( FLAC__IOHandle ) tempfile , callbacks ) ) {
fclose ( file ) ;
fclose ( tempfile ) ;
2004-07-14 00:50:52 +00:00
return false ;
2004-07-15 00:04:09 +00:00
}
fclose ( file ) ;
fclose ( tempfile ) ;
file = tempfile = 0 ;
2004-07-14 00:50:52 +00:00
if ( ! transport_tempfile_ ( filename , & tempfile , & tempfilename ) )
return false ;
if ( preserve_file_stats )
set_file_stats_ ( filename , & stats ) ;
}
else {
FILE * file = fopen ( filename , " r+b " ) ;
if ( 0 = = file )
return false ; /*@@@ chain status still says OK though */
if ( ! FLAC__metadata_chain_write_with_callbacks ( chain , use_padding , ( FLAC__IOHandle ) file , callbacks ) )
return false ;
2004-07-15 00:04:09 +00:00
fclose ( file ) ;
2004-07-14 00:50:52 +00:00
}
}
return true ;
}
2004-07-15 00:04:09 +00:00
static FLAC__bool read_chain_ ( FLAC__Metadata_Chain * chain , const char * filename , FLAC__bool filename_based )
2004-07-14 00:50:52 +00:00
{
if ( filename_based )
return FLAC__metadata_chain_read ( chain , flacfile_ ) ;
else {
FLAC__IOCallbacks callbacks ;
memset ( & callbacks , 0 , sizeof ( callbacks ) ) ;
callbacks . read = ( FLAC__IOCallback_Read ) fread ;
callbacks . seek = chain_seek_cb_ ;
callbacks . tell = chain_tell_cb_ ;
{
2004-07-15 00:04:09 +00:00
FLAC__bool ret ;
2004-07-14 00:50:52 +00:00
FILE * file = fopen ( filename , " rb " ) ;
if ( 0 = = file )
return false ; /*@@@ chain status still says OK though */
2004-07-15 00:04:09 +00:00
ret = FLAC__metadata_chain_read_with_callbacks ( chain , ( FLAC__IOHandle ) file , callbacks ) ;
fclose ( file ) ;
return ret ;
2004-07-14 00:50:52 +00:00
}
}
}
2002-06-08 04:53:42 +00:00
/* function for comparing our metadata to a FLAC__Metadata_Chain */
2002-05-11 05:41:42 +00:00
2002-06-08 04:53:42 +00:00
static FLAC__bool compare_chain_ ( FLAC__Metadata_Chain * chain , unsigned current_position , FLAC__StreamMetadata * current_block )
2002-05-11 05:41:42 +00:00
{
unsigned i ;
2002-06-08 04:53:42 +00:00
FLAC__Metadata_Iterator * iterator ;
FLAC__StreamMetadata * block ;
2002-05-11 05:41:42 +00:00
FLAC__bool next_ok = true ;
FLAC__ASSERT ( 0 ! = chain ) ;
printf ( " \t comparing chain... " ) ;
fflush ( stdout ) ;
if ( 0 = = ( iterator = FLAC__metadata_iterator_new ( ) ) )
return die_ ( " allocating memory for iterator " ) ;
FLAC__metadata_iterator_init ( iterator , chain ) ;
i = 0 ;
do {
printf ( " %u... " , i ) ;
fflush ( stdout ) ;
if ( 0 = = ( block = FLAC__metadata_iterator_get_block ( iterator ) ) ) {
FLAC__metadata_iterator_delete ( iterator ) ;
return die_ ( " getting block from iterator " ) ;
}
2003-01-10 05:45:48 +00:00
if ( ! mutils__compare_block ( our_metadata_ . blocks [ i ] , block ) ) {
2002-05-11 05:41:42 +00:00
FLAC__metadata_iterator_delete ( iterator ) ;
return die_ ( " metadata block mismatch " ) ;
}
i + + ;
next_ok = FLAC__metadata_iterator_next ( iterator ) ;
} while ( i < our_metadata_ . num_blocks & & next_ok ) ;
FLAC__metadata_iterator_delete ( iterator ) ;
if ( next_ok )
return die_ ( " chain has more blocks than expected " ) ;
if ( i < our_metadata_ . num_blocks )
return die_ ( " short block count in chain " ) ;
2002-05-14 06:04:47 +00:00
if ( 0 ! = current_block ) {
printf ( " CURRENT_POSITION... " ) ;
fflush ( stdout ) ;
2003-01-10 05:45:48 +00:00
if ( ! mutils__compare_block ( our_metadata_ . blocks [ current_position ] , current_block ) )
2002-05-14 06:04:47 +00:00
return die_ ( " metadata block mismatch " ) ;
}
2002-05-11 05:41:42 +00:00
printf ( " PASSED \n " ) ;
return true ;
}
/* decoder callbacks for checking the file */
2002-06-07 05:27:37 +00:00
static FLAC__StreamDecoderWriteStatus decoder_write_callback_ ( const FLAC__FileDecoder * decoder , const FLAC__Frame * frame , const FLAC__int32 * const buffer [ ] , void * client_data )
2002-05-07 05:33:49 +00:00
{
2002-05-11 05:41:42 +00:00
( void ) decoder , ( void ) buffer , ( void ) client_data ;
2002-05-07 06:08:40 +00:00
2002-05-10 06:43:17 +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-04 05:54:44 +00:00
return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE ;
2002-05-07 06:08:40 +00:00
}
2002-05-11 05:41:42 +00:00
/* this version pays no attention to the metadata */
2002-06-08 04:53:42 +00:00
static void decoder_metadata_callback_null_ ( const FLAC__FileDecoder * decoder , const FLAC__StreamMetadata * metadata , void * client_data )
2002-05-11 05:41:42 +00:00
{
( void ) decoder , ( void ) metadata , ( void ) client_data ;
printf ( " %d... " , mc_our_block_number_ ) ;
fflush ( stdout ) ;
mc_our_block_number_ + + ;
}
/* this version is used when we want to compare to our metadata copy */
2002-06-08 04:53:42 +00:00
static void decoder_metadata_callback_compare_ ( const FLAC__FileDecoder * decoder , const FLAC__StreamMetadata * metadata , void * client_data )
2002-05-11 05:41:42 +00:00
{
decoder_client_struct * dcd = ( decoder_client_struct * ) client_data ;
( void ) decoder ;
/* don't bother checking if we've already hit an error */
if ( dcd - > error_occurred )
return ;
printf ( " %d... " , mc_our_block_number_ ) ;
fflush ( stdout ) ;
if ( mc_our_block_number_ > = our_metadata_ . num_blocks ) {
( void ) die_ ( " got more metadata blocks than expected " ) ;
dcd - > error_occurred = true ;
}
else {
2003-01-10 05:45:48 +00:00
if ( ! mutils__compare_block ( our_metadata_ . blocks [ mc_our_block_number_ ] , metadata ) ) {
2002-05-11 05:41:42 +00:00
( void ) die_ ( " metadata block mismatch " ) ;
dcd - > error_occurred = true ;
}
}
mc_our_block_number_ + + ;
}
2002-06-08 04:53:42 +00:00
static void decoder_error_callback_ ( const FLAC__FileDecoder * decoder , FLAC__StreamDecoderErrorStatus status , void * client_data )
{
decoder_client_struct * dcd = ( decoder_client_struct * ) client_data ;
( void ) decoder ;
dcd - > error_occurred = true ;
printf ( " ERROR: got error callback, status = %s (%u) \n " , FLAC__StreamDecoderErrorStatusString [ status ] , ( unsigned ) status ) ;
}
2002-05-17 06:28:09 +00:00
static FLAC__bool generate_file_ ( )
2002-05-07 06:08:40 +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-05-09 05:52:40 +00:00
printf ( " generating FLAC file for test \n " ) ;
2002-05-11 05:41:42 +00:00
while ( our_metadata_ . num_blocks > 0 )
delete_from_our_metadata_ ( 0 ) ;
streaminfo . is_last = false ;
streaminfo . type = FLAC__METADATA_TYPE_STREAMINFO ;
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 ( 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 ;
2004-12-30 00:59:30 +00:00
vorbiscomment . data . vorbis_comment . vendor_string . entry = malloc_or_die_ ( vendor_string_length + 1 ) ;
memcpy ( vorbiscomment . data . vorbis_comment . vendor_string . entry , FLAC__VENDOR_STRING , vendor_string_length + 1 ) ;
2002-08-25 05:10:37 +00:00
vorbiscomment . data . vorbis_comment . num_comments = 0 ;
vorbiscomment . data . vorbis_comment . comments = 0 ;
}
2002-05-11 05:41:42 +00:00
padding . is_last = true ;
padding . type = FLAC__METADATA_TYPE_PADDING ;
padding . length = 1234 ;
2002-06-01 05:27:12 +00:00
metadata [ 0 ] = & padding ;
2002-08-25 05:10:37 +00:00
if (
! insert_to_our_metadata_ ( & streaminfo , 0 , /*copy=*/ true ) | |
! insert_to_our_metadata_ ( & vorbiscomment , 1 , /*copy=*/ true ) | |
! insert_to_our_metadata_ ( & padding , 2 , /*copy=*/ true )
)
2002-05-11 05:41:42 +00:00
return die_ ( " priming our metadata " ) ;
2002-06-04 05:54:44 +00:00
if ( ! file_utils__generate_flacfile ( flacfile_ , 0 , 512 * 1024 , & streaminfo , metadata , 1 ) )
2002-08-27 05:46:11 +00:00
return die_ ( " creating the encoded file " ) ;
2002-05-07 06:08:40 +00:00
2002-08-25 05:10:37 +00:00
free ( vorbiscomment . data . vorbis_comment . vendor_string . entry ) ;
2002-05-07 05:33:49 +00:00
return true ;
}
2004-07-14 00:50:52 +00:00
static FLAC__bool test_file_ ( const char * filename , FLAC__FileDecoderMetadataCallback metadata_callback )
2002-05-07 06:08:40 +00:00
{
FLAC__FileDecoder * decoder ;
decoder_client_struct decoder_client_data ;
FLAC__ASSERT ( 0 ! = filename ) ;
FLAC__ASSERT ( 0 ! = metadata_callback ) ;
2002-05-11 05:41:42 +00:00
mc_our_block_number_ = 0 ;
2002-05-07 06:08:40 +00:00
decoder_client_data . error_occurred = false ;
2002-05-10 06:43:17 +00:00
printf ( " \t testing '%s'... " , filename ) ;
fflush ( stdout ) ;
2002-05-09 05:52:40 +00:00
2002-05-07 06:08:40 +00:00
if ( 0 = = ( decoder = FLAC__file_decoder_new ( ) ) )
2002-06-08 04:53:42 +00:00
return die_ ( " couldn't allocate decoder instance " ) ;
2002-05-07 06:08:40 +00:00
FLAC__file_decoder_set_md5_checking ( decoder , true ) ;
FLAC__file_decoder_set_filename ( decoder , filename ) ;
FLAC__file_decoder_set_write_callback ( decoder , decoder_write_callback_ ) ;
FLAC__file_decoder_set_metadata_callback ( decoder , metadata_callback ) ;
FLAC__file_decoder_set_error_callback ( decoder , decoder_error_callback_ ) ;
FLAC__file_decoder_set_client_data ( decoder , & decoder_client_data ) ;
FLAC__file_decoder_set_metadata_respond_all ( decoder ) ;
if ( FLAC__file_decoder_init ( decoder ) ! = FLAC__FILE_DECODER_OK ) {
FLAC__file_decoder_finish ( decoder ) ;
FLAC__file_decoder_delete ( decoder ) ;
2002-05-09 05:52:40 +00:00
return die_ ( " initializing decoder \n " ) ;
2002-05-07 06:08:40 +00:00
}
2002-08-02 06:12:36 +00:00
if ( ! FLAC__file_decoder_process_until_end_of_file ( decoder ) ) {
2002-05-07 06:08:40 +00:00
FLAC__file_decoder_finish ( decoder ) ;
FLAC__file_decoder_delete ( decoder ) ;
2002-05-09 05:52:40 +00:00
return die_ ( " decoding file \n " ) ;
2002-05-07 06:08:40 +00:00
}
FLAC__file_decoder_finish ( decoder ) ;
FLAC__file_decoder_delete ( decoder ) ;
2002-05-10 06:43:17 +00:00
if ( decoder_client_data . error_occurred )
return false ;
2002-05-09 05:52:40 +00:00
2002-05-11 05:41:42 +00:00
if ( mc_our_block_number_ ! = our_metadata_ . num_blocks )
2002-05-10 06:43:17 +00:00
return die_ ( " short metadata block count " ) ;
printf ( " PASSED \n " ) ;
return true ;
2002-05-07 06:08:40 +00:00
}
2002-05-09 05:52:40 +00:00
static FLAC__bool change_stats_ ( const char * filename , FLAC__bool read_only )
{
2002-11-07 05:07:30 +00:00
if ( ! grabbag__file_change_stats ( filename , read_only ) )
return die_ ( " during grabbag__file_change_stats() " ) ;
2002-05-09 05:52:40 +00:00
return true ;
}
static FLAC__bool remove_file_ ( const char * filename )
{
2002-05-11 05:41:42 +00:00
while ( our_metadata_ . num_blocks > 0 )
delete_from_our_metadata_ ( 0 ) ;
2002-11-07 05:07:30 +00:00
if ( ! grabbag__file_remove_file ( filename ) )
2002-05-09 05:52:40 +00:00
return die_ ( " removing file " ) ;
return true ;
}
2002-05-17 06:28:09 +00:00
static FLAC__bool test_level_0_ ( )
2002-05-09 05:52:40 +00:00
{
2002-06-10 04:42:35 +00:00
FLAC__StreamMetadata streaminfo ;
2004-07-30 01:54:29 +00:00
FLAC__StreamMetadata * tags = 0 ;
2002-05-09 05:52:40 +00:00
printf ( " \n \n ++++++ testing level 0 interface \n " ) ;
2002-05-17 06:28:09 +00:00
if ( ! generate_file_ ( ) )
2002-05-09 05:52:40 +00:00
return false ;
2002-05-11 05:41:42 +00:00
if ( ! test_file_ ( flacfile_ , decoder_metadata_callback_null_ ) )
2002-05-09 05:52:40 +00:00
return false ;
2004-07-30 01:54:29 +00:00
printf ( " testing FLAC__metadata_get_streaminfo()... " ) ;
2002-05-09 05:52:40 +00:00
if ( ! FLAC__metadata_get_streaminfo ( flacfile_ , & streaminfo ) )
return die_ ( " during FLAC__metadata_get_streaminfo() " ) ;
/* check to see if some basic data matches (c.f. generate_file_()) */
2002-06-10 04:42:35 +00:00
if ( streaminfo . data . stream_info . channels ! = 1 )
return die_ ( " mismatch in streaminfo.data.stream_info.channels " ) ;
if ( streaminfo . data . stream_info . bits_per_sample ! = 8 )
return die_ ( " mismatch in streaminfo.data.stream_info.bits_per_sample " ) ;
if ( streaminfo . data . stream_info . sample_rate ! = 44100 )
return die_ ( " mismatch in streaminfo.data.stream_info.sample_rate " ) ;
if ( streaminfo . data . stream_info . min_blocksize ! = 576 )
return die_ ( " mismatch in streaminfo.data.stream_info.min_blocksize " ) ;
if ( streaminfo . data . stream_info . max_blocksize ! = 576 )
return die_ ( " mismatch in streaminfo.data.stream_info.max_blocksize " ) ;
2002-05-09 05:52:40 +00:00
2004-07-30 01:54:29 +00:00
printf ( " OK \n " ) ;
printf ( " testing FLAC__metadata_get_tags()... " ) ;
if ( ! FLAC__metadata_get_tags ( flacfile_ , & tags ) )
return die_ ( " during FLAC__metadata_get_tags() " ) ;
/* check to see if some basic data matches (c.f. generate_file_()) */
if ( tags - > data . vorbis_comment . num_comments ! = 0 )
return die_ ( " mismatch in tags->data.vorbis_comment.num_comments " ) ;
printf ( " OK \n " ) ;
FLAC__metadata_object_delete ( tags ) ;
2002-05-09 05:52:40 +00:00
if ( ! remove_file_ ( flacfile_ ) )
return false ;
return true ;
}
2002-05-17 06:28:09 +00:00
static FLAC__bool test_level_1_ ( )
2002-05-09 05:52:40 +00:00
{
2002-06-08 04:53:42 +00:00
FLAC__Metadata_SimpleIterator * iterator ;
FLAC__StreamMetadata * block , * app , * padding ;
2002-05-09 05:52:40 +00:00
FLAC__byte data [ 1000 ] ;
2002-05-11 05:41:42 +00:00
unsigned our_current_position = 0 ;
2002-05-09 05:52:40 +00:00
2002-12-28 07:06:38 +00:00
/* initialize 'data' to avoid Valgrind errors */
memset ( data , 0 , sizeof ( data ) ) ;
2002-05-09 05:52:40 +00:00
printf ( " \n \n ++++++ testing level 1 interface \n " ) ;
/************************************************************/
printf ( " simple iterator on read-only file \n " ) ;
2002-05-17 06:28:09 +00:00
if ( ! generate_file_ ( ) )
2002-05-09 05:52:40 +00:00
return false ;
if ( ! change_stats_ ( flacfile_ , /*read_only=*/ true ) )
return false ;
2002-05-11 05:41:42 +00:00
if ( ! test_file_ ( flacfile_ , decoder_metadata_callback_null_ ) )
2002-05-09 05:52:40 +00:00
return false ;
2002-06-08 04:53:42 +00:00
if ( 0 = = ( iterator = FLAC__metadata_simple_iterator_new ( ) ) )
2002-05-09 05:52:40 +00:00
return die_ ( " FLAC__metadata_simple_iterator_new() " ) ;
2002-08-30 05:41:31 +00:00
if ( ! FLAC__metadata_simple_iterator_init ( iterator , flacfile_ , /*read_only=*/ false , /*preserve_file_stats=*/ false ) )
2002-06-08 04:53:42 +00:00
return die_ ( " FLAC__metadata_simple_iterator_init() returned false " ) ;
2002-05-09 05:52:40 +00:00
2002-06-08 04:53:42 +00:00
printf ( " is writable = %u \n " , ( unsigned ) FLAC__metadata_simple_iterator_is_writable ( iterator ) ) ;
if ( FLAC__metadata_simple_iterator_is_writable ( iterator ) )
2002-06-13 06:59:53 +00:00
return die_ ( " iterator claims file is writable when tester thinks it should not be; are you running as root? \n " ) ;
2002-05-09 05:52:40 +00:00
printf ( " iterate forwards \n " ) ;
2002-06-08 04:53:42 +00:00
if ( FLAC__metadata_simple_iterator_get_block_type ( iterator ) ! = FLAC__METADATA_TYPE_STREAMINFO )
2002-05-09 05:52:40 +00:00
return die_ ( " expected STREAMINFO type from FLAC__metadata_simple_iterator_get_block_type() " ) ;
2002-06-08 04:53:42 +00:00
if ( 0 = = ( block = FLAC__metadata_simple_iterator_get_block ( iterator ) ) )
2002-05-09 05:52:40 +00:00
return die_ ( " getting block 0 " ) ;
if ( block - > type ! = FLAC__METADATA_TYPE_STREAMINFO )
return die_ ( " expected STREAMINFO type " ) ;
if ( block - > is_last )
return die_ ( " expected is_last to be false " ) ;
if ( block - > length ! = FLAC__STREAM_METADATA_STREAMINFO_LENGTH )
return die_ ( " bad STREAMINFO length " ) ;
/* check to see if some basic data matches (c.f. generate_file_()) */
if ( block - > data . stream_info . channels ! = 1 )
return die_ ( " mismatch in channels " ) ;
if ( block - > data . stream_info . bits_per_sample ! = 8 )
return die_ ( " mismatch in bits_per_sample " ) ;
if ( block - > data . stream_info . sample_rate ! = 44100 )
return die_ ( " mismatch in sample_rate " ) ;
if ( block - > data . stream_info . min_blocksize ! = 576 )
return die_ ( " mismatch in min_blocksize " ) ;
if ( block - > data . stream_info . max_blocksize ! = 576 )
return die_ ( " mismatch in max_blocksize " ) ;
2002-12-04 07:01:37 +00:00
FLAC__metadata_object_delete ( block ) ;
2002-05-09 05:52:40 +00:00
2002-06-08 04:53:42 +00:00
if ( ! FLAC__metadata_simple_iterator_next ( iterator ) )
2002-05-09 05:52:40 +00:00
return die_ ( " forward iterator ended early " ) ;
our_current_position + + ;
2002-08-25 05:10:37 +00:00
if ( ! FLAC__metadata_simple_iterator_next ( iterator ) )
return die_ ( " forward iterator ended early " ) ;
our_current_position + + ;
2002-06-08 04:53:42 +00:00
if ( FLAC__metadata_simple_iterator_get_block_type ( iterator ) ! = FLAC__METADATA_TYPE_PADDING )
2002-05-09 05:52:40 +00:00
return die_ ( " expected PADDING type from FLAC__metadata_simple_iterator_get_block_type() " ) ;
2002-06-08 04:53:42 +00:00
if ( 0 = = ( block = FLAC__metadata_simple_iterator_get_block ( iterator ) ) )
2002-08-25 05:10:37 +00:00
return die_ ( " getting block 2 " ) ;
2002-05-09 05:52:40 +00:00
if ( block - > type ! = FLAC__METADATA_TYPE_PADDING )
return die_ ( " expected PADDING type " ) ;
if ( ! block - > is_last )
return die_ ( " expected is_last to be true " ) ;
/* check to see if some basic data matches (c.f. generate_file_()) */
2002-05-11 05:41:42 +00:00
if ( block - > length ! = 1234 )
2002-06-08 04:53:42 +00:00
return die_ ( " bad PADDING length " ) ;
2002-12-04 07:01:37 +00:00
FLAC__metadata_object_delete ( block ) ;
2002-05-09 05:52:40 +00:00
2002-06-08 04:53:42 +00:00
if ( FLAC__metadata_simple_iterator_next ( iterator ) )
2002-05-09 05:52:40 +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 ( ! FLAC__metadata_simple_iterator_prev ( iterator ) )
return die_ ( " reverse iterator ended early " ) ;
2002-06-08 04:53:42 +00:00
if ( ! FLAC__metadata_simple_iterator_prev ( iterator ) )
2002-05-09 05:52:40 +00:00
return die_ ( " reverse iterator ended early " ) ;
2002-06-08 04:53:42 +00:00
if ( FLAC__metadata_simple_iterator_prev ( iterator ) )
2002-05-09 05:52:40 +00:00
return die_ ( " reverse iterator returned true but should have returned false " ) ;
printf ( " testing FLAC__metadata_simple_iterator_set_block() on read-only file... \n " ) ;
2002-06-08 04:53:42 +00:00
if ( ! FLAC__metadata_simple_iterator_set_block ( iterator , ( FLAC__StreamMetadata * ) 99 , false ) )
2003-01-15 03:16:26 +00:00
printf ( " OK: FLAC__metadata_simple_iterator_set_block() returned false like it should \n " ) ;
2002-05-09 05:52:40 +00:00
else
return die_ ( " FLAC__metadata_simple_iterator_set_block() returned true but shouldn ' t have " ) ;
2002-06-08 04:53:42 +00:00
FLAC__metadata_simple_iterator_delete ( iterator ) ;
2002-05-09 05:52:40 +00:00
/************************************************************/
printf ( " simple iterator on writable file \n " ) ;
if ( ! change_stats_ ( flacfile_ , /*read-only=*/ false ) )
return false ;
printf ( " creating APPLICATION block \n " ) ;
if ( 0 = = ( app = FLAC__metadata_object_new ( FLAC__METADATA_TYPE_APPLICATION ) ) )
return die_ ( " FLAC__metadata_object_new(FLAC__METADATA_TYPE_APPLICATION) " ) ;
2002-05-11 05:41:42 +00:00
memcpy ( app - > data . application . id , " duh " , ( FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8 ) ) ;
2002-05-09 05:52:40 +00:00
printf ( " creating PADDING block \n " ) ;
if ( 0 = = ( padding = FLAC__metadata_object_new ( FLAC__METADATA_TYPE_PADDING ) ) )
return die_ ( " FLAC__metadata_object_new(FLAC__METADATA_TYPE_PADDING) " ) ;
padding - > length = 20 ;
2002-06-08 04:53:42 +00:00
if ( 0 = = ( iterator = FLAC__metadata_simple_iterator_new ( ) ) )
2002-05-09 05:52:40 +00:00
return die_ ( " FLAC__metadata_simple_iterator_new() " ) ;
2002-08-30 05:41:31 +00:00
if ( ! FLAC__metadata_simple_iterator_init ( iterator , flacfile_ , /*read_only=*/ false , /*preserve_file_stats=*/ false ) )
2002-06-08 04:53:42 +00:00
return die_ ( " FLAC__metadata_simple_iterator_init() returned false " ) ;
2002-05-09 05:52:40 +00:00
our_current_position = 0 ;
2002-06-08 04:53:42 +00:00
printf ( " is writable = %u \n " , ( unsigned ) FLAC__metadata_simple_iterator_is_writable ( iterator ) ) ;
2002-05-09 05:52:40 +00:00
2002-08-25 05:10:37 +00:00
printf ( " [S]VP \t try to write over STREAMINFO block... \n " ) ;
2002-06-08 04:53:42 +00:00
if ( ! FLAC__metadata_simple_iterator_set_block ( iterator , app , false ) )
2002-05-25 02:14:26 +00:00
printf ( " \t FLAC__metadata_simple_iterator_set_block() returned false like it should \n " ) ;
2002-05-09 05:52:40 +00:00
else
return die_ ( " FLAC__metadata_simple_iterator_set_block() returned true but shouldn ' t have " ) ;
2002-08-25 05:10:37 +00:00
printf ( " [S]VP \t next \n " ) ;
2002-06-08 04:53:42 +00:00
if ( ! FLAC__metadata_simple_iterator_next ( iterator ) )
2002-05-10 06:43:17 +00:00
return die_ ( " iterator ended early \n " ) ;
our_current_position + + ;
2002-08-25 05:10:37 +00:00
printf ( " S[V]P \t next \n " ) ;
if ( ! FLAC__metadata_simple_iterator_next ( iterator ) )
return die_ ( " iterator ended early \n " ) ;
our_current_position + + ;
printf ( " SV[P] \t insert PADDING after, don't expand into padding \n " ) ;
2002-05-10 06:43:17 +00:00
padding - > length = 25 ;
2002-06-08 04:53:42 +00:00
if ( ! FLAC__metadata_simple_iterator_insert_block_after ( iterator , padding , false ) )
return die_ss_ ( " FLAC__metadata_simple_iterator_insert_block_after(iterator, padding, false) " , iterator) ;
2002-05-09 05:52:40 +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] \t prev \n " ) ;
2002-06-08 04:53:42 +00:00
if ( ! FLAC__metadata_simple_iterator_prev ( iterator ) )
2002-05-10 06:43:17 +00:00
return die_ ( " iterator ended early \n " ) ;
our_current_position - - ;
2002-08-25 05:10:37 +00:00
printf ( " SV[P]P \t prev \n " ) ;
2002-06-08 04:53:42 +00:00
if ( ! FLAC__metadata_simple_iterator_prev ( iterator ) )
2002-05-10 06:43:17 +00:00
return die_ ( " iterator ended early \n " ) ;
our_current_position - - ;
2002-08-25 05:10:37 +00:00
printf ( " S[V]PP \t insert PADDING after, don't expand into padding \n " ) ;
2002-05-10 06:43:17 +00:00
padding - > length = 30 ;
2002-06-08 04:53:42 +00:00
if ( ! FLAC__metadata_simple_iterator_insert_block_after ( iterator , padding , false ) )
return die_ss_ ( " FLAC__metadata_simple_iterator_insert_block_after(iterator, padding, false) " , iterator) ;
2002-05-10 06:43:17 +00:00
if ( ! insert_to_our_metadata_ ( padding , + + our_current_position , /*copy=*/ true ) )
2002-05-09 05:52:40 +00:00
return false ;
2002-05-11 05:41:42 +00:00
if ( ! test_file_ ( flacfile_ , decoder_metadata_callback_compare_ ) )
2002-05-10 06:43:17 +00:00
return false ;
2002-08-27 05:46:11 +00:00
2002-08-25 05:10:37 +00:00
printf ( " SV[P]PP \t prev \n " ) ;
if ( ! FLAC__metadata_simple_iterator_prev ( iterator ) )
return die_ ( " iterator ended early \n " ) ;
our_current_position - - ;
printf ( " S[V]PPP \t prev \n " ) ;
2002-06-08 04:53:42 +00:00
if ( ! FLAC__metadata_simple_iterator_prev ( iterator ) )
2002-05-09 05:52:40 +00:00
return die_ ( " iterator ended early \n " ) ;
our_current_position - - ;
2002-08-25 05:10:37 +00:00
printf ( " [S]VPPP \t delete (STREAMINFO block), must fail \n " ) ;
2002-06-08 04:53:42 +00:00
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) ;
2002-05-09 05:52:40 +00:00
2002-05-11 05:41:42 +00:00
if ( ! test_file_ ( flacfile_ , decoder_metadata_callback_compare_ ) )
2002-05-09 05:52:40 +00:00
return false ;
2002-08-25 05:10:37 +00:00
printf ( " [S]VPPP \t next \n " ) ;
2002-06-08 04:53:42 +00:00
if ( ! FLAC__metadata_simple_iterator_next ( iterator ) )
2002-05-10 06:43:17 +00:00
return die_ ( " iterator ended early \n " ) ;
our_current_position + + ;
2002-08-25 05:10:37 +00:00
printf ( " S[V]PPP \t next \n " ) ;
if ( ! FLAC__metadata_simple_iterator_next ( iterator ) )
return die_ ( " iterator ended early \n " ) ;
our_current_position + + ;
printf ( " SV[P]PP \t delete (middle block), replace with padding \n " ) ;
2002-06-08 04:53:42 +00:00
if ( ! FLAC__metadata_simple_iterator_delete_block ( iterator , true ) )
return die_ss_ ( " FLAC__metadata_simple_iterator_delete_block(iterator, true) " , iterator) ;
2002-05-10 06:43:17 +00:00
our_current_position - - ;
2002-08-25 05:10:37 +00:00
printf ( " S[V]PPP \t next \n " ) ;
2002-06-08 04:53:42 +00:00
if ( ! FLAC__metadata_simple_iterator_next ( iterator ) )
2002-05-09 05:52:40 +00:00
return die_ ( " iterator ended early \n " ) ;
our_current_position + + ;
2002-08-25 05:10:37 +00:00
printf ( " SV[P]PP \t delete (middle block), don't replace with padding \n " ) ;
2002-06-08 04:53:42 +00:00
if ( ! FLAC__metadata_simple_iterator_delete_block ( iterator , false ) )
return die_ss_ ( " FLAC__metadata_simple_iterator_delete_block(iterator, false) " , iterator) ;
2002-05-09 05:52:40 +00:00
delete_from_our_metadata_ ( our_current_position - - ) ;
2002-05-11 05:41:42 +00:00
if ( ! test_file_ ( flacfile_ , decoder_metadata_callback_compare_ ) )
2002-05-09 05:52:40 +00:00
return false ;
2002-08-25 05:10:37 +00:00
printf ( " S[V]PP \t next \n " ) ;
2002-06-08 04:53:42 +00:00
if ( ! FLAC__metadata_simple_iterator_next ( iterator ) )
2002-05-10 06:43:17 +00:00
return die_ ( " iterator ended early \n " ) ;
our_current_position + + ;
2002-08-25 05:10:37 +00:00
printf ( " SV[P]P \t next \n " ) ;
2002-06-08 04:53:42 +00:00
if ( ! FLAC__metadata_simple_iterator_next ( iterator ) )
2002-05-10 06:43:17 +00:00
return die_ ( " iterator ended early \n " ) ;
our_current_position + + ;
2002-08-25 05:10:37 +00:00
printf ( " SVP[P] \t delete (last block), replace with padding \n " ) ;
2002-06-08 04:53:42 +00:00
if ( ! FLAC__metadata_simple_iterator_delete_block ( iterator , true ) )
return die_ss_ ( " FLAC__metadata_simple_iterator_delete_block(iterator, false) " , iterator) ;
2002-05-10 06:43:17 +00:00
our_current_position - - ;
2002-05-11 05:41:42 +00:00
if ( ! test_file_ ( flacfile_ , decoder_metadata_callback_compare_ ) )
2002-05-10 06:43:17 +00:00
return false ;
2002-08-25 05:10:37 +00:00
printf ( " SV[P]P \t next \n " ) ;
2002-06-08 04:53:42 +00:00
if ( ! FLAC__metadata_simple_iterator_next ( iterator ) )
2002-05-09 05:52:40 +00:00
return die_ ( " iterator ended early \n " ) ;
our_current_position + + ;
2002-08-25 05:10:37 +00:00
printf ( " SVP[P] \t delete (last block), don't replace with padding \n " ) ;
2002-06-08 04:53:42 +00:00
if ( ! FLAC__metadata_simple_iterator_delete_block ( iterator , false ) )
return die_ss_ ( " FLAC__metadata_simple_iterator_delete_block(iterator, false) " , iterator) ;
2002-05-09 05:52:40 +00:00
delete_from_our_metadata_ ( our_current_position - - ) ;
2002-05-11 05:41:42 +00:00
if ( ! test_file_ ( flacfile_ , decoder_metadata_callback_compare_ ) )
2002-05-09 05:52:40 +00:00
return false ;
2002-08-25 05:10:37 +00:00
printf ( " SV[P] \t prev \n " ) ;
if ( ! FLAC__metadata_simple_iterator_prev ( iterator ) )
return die_ ( " iterator ended early \n " ) ;
our_current_position - - ;
printf ( " S[V]P \t prev \n " ) ;
2002-06-08 04:53:42 +00:00
if ( ! FLAC__metadata_simple_iterator_prev ( iterator ) )
2002-05-10 06:43:17 +00:00
return die_ ( " iterator ended early \n " ) ;
our_current_position - - ;
2002-08-25 05:10:37 +00:00
printf ( " [S]VP \t set STREAMINFO (change sample rate) \n " ) ;
2002-05-10 06:43:17 +00:00
FLAC__ASSERT ( our_current_position = = 0 ) ;
2002-06-08 04:53:42 +00:00
block = FLAC__metadata_simple_iterator_get_block ( iterator ) ;
2002-05-10 06:43:17 +00:00
block - > data . stream_info . sample_rate = 32000 ;
if ( ! replace_in_our_metadata_ ( block , our_current_position , /*copy=*/ true ) )
return die_ ( " copying object " ) ;
2002-06-08 04:53:42 +00:00
if ( ! FLAC__metadata_simple_iterator_set_block ( iterator , block , false ) )
return die_ss_ ( " FLAC__metadata_simple_iterator_set_block(iterator, block, false) " , iterator) ;
2002-05-10 06:43:17 +00:00
FLAC__metadata_object_delete ( block ) ;
2002-05-09 05:52:40 +00:00
2002-05-11 05:41:42 +00:00
if ( ! test_file_ ( flacfile_ , decoder_metadata_callback_compare_ ) )
2002-05-09 05:52:40 +00:00
return false ;
2002-08-25 05:10:37 +00:00
printf ( " [S]VP \t next \n " ) ;
if ( ! FLAC__metadata_simple_iterator_next ( iterator ) )
return die_ ( " iterator ended early \n " ) ;
our_current_position + + ;
printf ( " S[V]P \t insert APPLICATION after, expand into padding of exceeding size \n " ) ;
2002-05-09 05:52:40 +00:00
app - > data . application . id [ 0 ] = ' e ' ; /* twiddle the id so that our comparison doesn't miss transposition */
2002-06-08 04:53:42 +00:00
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) ;
2002-05-09 05:52:40 +00:00
if ( ! insert_to_our_metadata_ ( app , + + our_current_position , /*copy=*/ true ) )
return false ;
2002-05-11 05:41:42 +00:00
our_metadata_ . blocks [ our_current_position + 1 ] - > length - = ( FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8 ) + app - > length ;
2002-05-09 05:52:40 +00:00
2002-05-11 05:41:42 +00:00
if ( ! test_file_ ( flacfile_ , decoder_metadata_callback_compare_ ) )
2002-05-09 05:52:40 +00:00
return false ;
2002-08-25 05:10:37 +00:00
printf ( " SV[A]P \t next \n " ) ;
2002-06-08 04:53:42 +00:00
if ( ! FLAC__metadata_simple_iterator_next ( iterator ) )
2002-05-09 05:52:40 +00:00
return die_ ( " iterator ended early \n " ) ;
2002-05-10 06:43:17 +00:00
our_current_position + + ;
2002-05-09 05:52:40 +00:00
2002-08-25 05:10:37 +00:00
printf ( " SVA[P] \t set APPLICATION, expand into padding of exceeding size \n " ) ;
2002-05-09 05:52:40 +00:00
app - > data . application . id [ 0 ] = ' f ' ; /* twiddle the id */
2002-06-08 04:53:42 +00:00
if ( ! FLAC__metadata_simple_iterator_set_block ( iterator , app , true ) )
return die_ss_ ( " FLAC__metadata_simple_iterator_set_block(iterator, app, true) " , iterator) ;
2002-05-10 06:43:17 +00:00
if ( ! insert_to_our_metadata_ ( app , our_current_position , /*copy=*/ true ) )
2002-05-09 05:52:40 +00:00
return false ;
2002-05-11 05:41:42 +00:00
our_metadata_ . blocks [ our_current_position + 1 ] - > length - = ( FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8 ) + app - > length ;
2002-05-09 05:52:40 +00:00
2002-05-11 05:41:42 +00:00
if ( ! test_file_ ( flacfile_ , decoder_metadata_callback_compare_ ) )
2002-05-09 05:52:40 +00:00
return false ;
2002-08-25 05:10:37 +00:00
printf ( " SVA[A]P \t set APPLICATION (grow), don't expand into padding \n " ) ;
2002-05-10 06:43:17 +00:00
app - > data . application . id [ 0 ] = ' g ' ; /* twiddle the id */
if ( ! FLAC__metadata_object_application_set_data ( app , data , sizeof ( data ) , true ) )
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 ( ! FLAC__metadata_simple_iterator_set_block ( iterator , app , false ) )
return die_ss_ ( " FLAC__metadata_simple_iterator_set_block(iterator, app, false) " , iterator) ;
2002-05-10 06:43:17 +00:00
2002-05-11 05:41:42 +00:00
if ( ! test_file_ ( flacfile_ , decoder_metadata_callback_compare_ ) )
2002-05-10 06:43:17 +00:00
return false ;
2002-08-25 05:10:37 +00:00
printf ( " SVA[A]P \t set APPLICATION (shrink), don't fill in with padding \n " ) ;
2002-05-10 06:43:17 +00:00
app - > data . application . id [ 0 ] = ' h ' ; /* twiddle the id */
if ( ! FLAC__metadata_object_application_set_data ( app , data , 12 , true ) )
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 ( ! FLAC__metadata_simple_iterator_set_block ( iterator , app , false ) )
return die_ss_ ( " FLAC__metadata_simple_iterator_set_block(iterator, app, false) " , iterator) ;
2002-05-10 06:43:17 +00:00
2002-05-11 05:41:42 +00:00
if ( ! test_file_ ( flacfile_ , decoder_metadata_callback_compare_ ) )
2002-05-10 06:43:17 +00:00
return false ;
2002-08-25 05:10:37 +00:00
printf ( " SVA[A]P \t set APPLICATION (grow), expand into padding of exceeding size \n " ) ;
2002-05-10 06:43:17 +00:00
app - > data . application . id [ 0 ] = ' i ' ; /* twiddle the id */
if ( ! FLAC__metadata_object_application_set_data ( app , data , sizeof ( data ) , true ) )
return die_ ( " setting APPLICATION data " ) ;
if ( ! replace_in_our_metadata_ ( app , our_current_position , /*copy=*/ true ) )
return die_ ( " copying object " ) ;
our_metadata_ . blocks [ our_current_position + 1 ] - > length - = ( sizeof ( data ) - 12 ) ;
2002-06-08 04:53:42 +00:00
if ( ! FLAC__metadata_simple_iterator_set_block ( iterator , app , true ) )
return die_ss_ ( " FLAC__metadata_simple_iterator_set_block(iterator, app, true) " , iterator) ;
2002-05-10 06:43:17 +00:00
2002-05-11 05:41:42 +00:00
if ( ! test_file_ ( flacfile_ , decoder_metadata_callback_compare_ ) )
2002-05-10 06:43:17 +00:00
return false ;
2002-08-25 05:10:37 +00:00
printf ( " SVA[A]P \t set APPLICATION (shrink), fill in with padding \n " ) ;
2002-05-10 06:43:17 +00:00
app - > data . application . id [ 0 ] = ' j ' ; /* twiddle the id */
if ( ! FLAC__metadata_object_application_set_data ( app , data , 23 , true ) )
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-05-20 05:58:50 +00:00
our_metadata_ . blocks [ our_current_position + 1 ] - > length = sizeof ( data ) - 23 - FLAC__STREAM_METADATA_HEADER_LENGTH ;
2002-06-08 04:53:42 +00:00
if ( ! FLAC__metadata_simple_iterator_set_block ( iterator , app , true ) )
return die_ss_ ( " FLAC__metadata_simple_iterator_set_block(iterator, app, true) " , iterator) ;
2002-05-10 06:43:17 +00:00
2002-05-11 05:41:42 +00:00
if ( ! test_file_ ( flacfile_ , decoder_metadata_callback_compare_ ) )
2002-05-10 06:43:17 +00:00
return false ;
2002-08-25 05:10:37 +00:00
printf ( " SVA[A]PP \t next \n " ) ;
2002-06-08 04:53:42 +00:00
if ( ! FLAC__metadata_simple_iterator_next ( iterator ) )
2002-05-09 05:52:40 +00:00
return die_ ( " iterator ended early \n " ) ;
our_current_position + + ;
2002-08-25 05:10:37 +00:00
printf ( " SVAA[P]P \t next \n " ) ;
2002-06-08 04:53:42 +00:00
if ( ! FLAC__metadata_simple_iterator_next ( iterator ) )
2002-05-10 06:43:17 +00:00
return die_ ( " iterator ended early \n " ) ;
our_current_position + + ;
2002-08-25 05:10:37 +00:00
printf ( " SVAAP[P] \t set PADDING (shrink), don't fill in with padding \n " ) ;
2002-05-10 06:43:17 +00:00
padding - > length = 5 ;
if ( ! replace_in_our_metadata_ ( padding , our_current_position , /*copy=*/ true ) )
2002-05-09 05:52:40 +00:00
return die_ ( " copying object " ) ;
2002-06-08 04:53:42 +00:00
if ( ! FLAC__metadata_simple_iterator_set_block ( iterator , padding , false ) )
return die_ss_ ( " FLAC__metadata_simple_iterator_set_block(iterator, padding, false) " , iterator) ;
2002-05-10 06:43:17 +00:00
2002-05-11 05:41:42 +00:00
if ( ! test_file_ ( flacfile_ , decoder_metadata_callback_compare_ ) )
2002-05-10 06:43:17 +00:00
return false ;
2002-08-25 05:10:37 +00:00
printf ( " SVAAP[P] \t set APPLICATION (grow) \n " ) ;
2002-05-10 06:43:17 +00:00
app - > data . application . id [ 0 ] = ' k ' ; /* twiddle the id */
if ( ! replace_in_our_metadata_ ( app , our_current_position , /*copy=*/ true ) )
return die_ ( " copying object " ) ;
2002-06-08 04:53:42 +00:00
if ( ! FLAC__metadata_simple_iterator_set_block ( iterator , app , false ) )
return die_ss_ ( " FLAC__metadata_simple_iterator_set_block(iterator, app, false) " , iterator) ;
2002-05-09 05:52:40 +00:00
2002-05-11 05:41:42 +00:00
if ( ! test_file_ ( flacfile_ , decoder_metadata_callback_compare_ ) )
2002-05-09 05:52:40 +00:00
return false ;
2002-08-25 05:10:37 +00:00
printf ( " SVAAP[A] \t set PADDING (equal) \n " ) ;
2002-05-10 06:43:17 +00:00
padding - > length = 27 ;
if ( ! replace_in_our_metadata_ ( padding , our_current_position , /*copy=*/ true ) )
return die_ ( " copying object " ) ;
2002-06-08 04:53:42 +00:00
if ( ! FLAC__metadata_simple_iterator_set_block ( iterator , padding , false ) )
return die_ss_ ( " FLAC__metadata_simple_iterator_set_block(iterator, padding, false) " , iterator) ;
2002-05-10 06:43:17 +00:00
2002-05-11 05:41:42 +00:00
if ( ! test_file_ ( flacfile_ , decoder_metadata_callback_compare_ ) )
2002-05-10 06:43:17 +00:00
return false ;
2002-08-25 05:10:37 +00:00
printf ( " SVAAP[P] \t prev \n " ) ;
2002-06-08 04:53:42 +00:00
if ( ! FLAC__metadata_simple_iterator_prev ( iterator ) )
2002-05-09 05:52:40 +00:00
return die_ ( " iterator ended early \n " ) ;
our_current_position - - ;
2002-05-10 06:43:17 +00:00
2002-08-25 05:10:37 +00:00
printf ( " SVAA[P]P \t delete (middle block), don't replace with padding \n " ) ;
2002-06-08 04:53:42 +00:00
if ( ! FLAC__metadata_simple_iterator_delete_block ( iterator , false ) )
return die_ss_ ( " FLAC__metadata_simple_iterator_delete_block(iterator, false) " , iterator) ;
2002-05-10 06:43:17 +00:00
delete_from_our_metadata_ ( our_current_position - - ) ;
2002-05-11 05:41:42 +00:00
if ( ! test_file_ ( flacfile_ , decoder_metadata_callback_compare_ ) )
2002-05-10 06:43:17 +00:00
return false ;
2002-08-25 05:10:37 +00:00
printf ( " SVA[A]P \t delete (middle block), don't replace with padding \n " ) ;
2002-06-08 04:53:42 +00:00
if ( ! FLAC__metadata_simple_iterator_delete_block ( iterator , false ) )
return die_ss_ ( " FLAC__metadata_simple_iterator_delete_block(iterator, false) " , iterator) ;
2002-05-10 06:43:17 +00:00
delete_from_our_metadata_ ( our_current_position - - ) ;
2002-05-11 05:41:42 +00:00
if ( ! test_file_ ( flacfile_ , decoder_metadata_callback_compare_ ) )
2002-05-10 06:43:17 +00:00
return false ;
2002-08-25 05:10:37 +00:00
printf ( " SV[A]P \t next \n " ) ;
2002-06-08 04:53:42 +00:00
if ( ! FLAC__metadata_simple_iterator_next ( iterator ) )
2002-05-10 06:43:17 +00:00
return die_ ( " iterator ended early \n " ) ;
our_current_position + + ;
2002-08-25 05:10:37 +00:00
printf ( " SVA[P] \t insert PADDING after \n " ) ;
2002-05-10 06:43:17 +00:00
padding - > length = 5 ;
2002-06-08 04:53:42 +00:00
if ( ! FLAC__metadata_simple_iterator_insert_block_after ( iterator , padding , false ) )
return die_ss_ ( " FLAC__metadata_simple_iterator_insert_block_after(iterator, padding, false) " , iterator) ;
2002-05-10 06:43:17 +00:00
if ( ! insert_to_our_metadata_ ( padding , + + our_current_position , /*copy=*/ true ) )
return false ;
2002-05-11 05:41:42 +00:00
if ( ! test_file_ ( flacfile_ , decoder_metadata_callback_compare_ ) )
2002-05-10 06:43:17 +00:00
return false ;
2002-08-25 05:10:37 +00:00
printf ( " SVAP[P] \t prev \n " ) ;
2002-06-08 04:53:42 +00:00
if ( ! FLAC__metadata_simple_iterator_prev ( iterator ) )
2002-05-10 06:43:17 +00:00
return die_ ( " iterator ended early \n " ) ;
our_current_position - - ;
2002-08-25 05:10:37 +00:00
printf ( " SVA[P]P \t prev \n " ) ;
2002-06-08 04:53:42 +00:00
if ( ! FLAC__metadata_simple_iterator_prev ( iterator ) )
2002-05-10 06:43:17 +00:00
return die_ ( " iterator ended early \n " ) ;
our_current_position - - ;
2002-08-25 05:10:37 +00:00
printf ( " SV[A]PP \t set APPLICATION (grow), try to expand into padding which is too small \n " ) ;
2002-05-10 06:43:17 +00:00
if ( ! FLAC__metadata_object_application_set_data ( app , data , 32 , true ) )
2002-05-09 05:52:40 +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 ( ! FLAC__metadata_simple_iterator_set_block ( iterator , app , true ) )
return die_ss_ ( " FLAC__metadata_simple_iterator_set_block(iterator, app, true) " , iterator) ;
2002-05-09 05:52:40 +00:00
2002-05-11 05:41:42 +00:00
if ( ! test_file_ ( flacfile_ , decoder_metadata_callback_compare_ ) )
2002-05-09 05:52:40 +00:00
return false ;
2002-08-25 05:10:37 +00:00
printf ( " SV[A]PP \t set APPLICATION (grow), try to expand into padding which is 'close' but still too small \n " ) ;
2002-05-10 06:43:17 +00:00
if ( ! FLAC__metadata_object_application_set_data ( app , data , 60 , true ) )
2002-05-09 05:52:40 +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 ( ! FLAC__metadata_simple_iterator_set_block ( iterator , app , true ) )
return die_ss_ ( " FLAC__metadata_simple_iterator_set_block(iterator, app, true) " , iterator) ;
2002-05-09 05:52:40 +00:00
2002-05-11 05:41:42 +00:00
if ( ! test_file_ ( flacfile_ , decoder_metadata_callback_compare_ ) )
return false ;
2002-08-25 05:10:37 +00:00
printf ( " SV[A]PP \t set APPLICATION (grow), expand into padding which will leave 0-length pad \n " ) ;
2002-05-11 05:41:42 +00:00
if ( ! FLAC__metadata_object_application_set_data ( app , data , 87 , true ) )
return die_ ( " setting APPLICATION data " ) ;
if ( ! replace_in_our_metadata_ ( app , our_current_position , /*copy=*/ true ) )
return die_ ( " copying object " ) ;
our_metadata_ . blocks [ our_current_position + 1 ] - > length = 0 ;
2002-06-08 04:53:42 +00:00
if ( ! FLAC__metadata_simple_iterator_set_block ( iterator , app , true ) )
return die_ss_ ( " FLAC__metadata_simple_iterator_set_block(iterator, app, true) " , iterator) ;
2002-05-11 05:41:42 +00:00
if ( ! test_file_ ( flacfile_ , decoder_metadata_callback_compare_ ) )
2002-05-09 05:52:40 +00:00
return false ;
2002-08-25 05:10:37 +00:00
printf ( " SV[A]PP \t set APPLICATION (grow), expand into padding which is exactly consumed \n " ) ;
2002-05-10 06:43:17 +00:00
if ( ! FLAC__metadata_object_application_set_data ( app , data , 91 , true ) )
2002-05-09 05:52:40 +00:00
return die_ ( " setting APPLICATION data " ) ;
if ( ! replace_in_our_metadata_ ( app , our_current_position , /*copy=*/ true ) )
return die_ ( " copying object " ) ;
2002-05-10 06:43:17 +00:00
delete_from_our_metadata_ ( our_current_position + 1 ) ;
2002-06-08 04:53:42 +00:00
if ( ! FLAC__metadata_simple_iterator_set_block ( iterator , app , true ) )
return die_ss_ ( " FLAC__metadata_simple_iterator_set_block(iterator, app, true) " , iterator) ;
2002-05-10 06:43:17 +00:00
2002-05-11 05:41:42 +00:00
if ( ! test_file_ ( flacfile_ , decoder_metadata_callback_compare_ ) )
2002-05-10 06:43:17 +00:00
return false ;
2002-08-25 05:10:37 +00:00
printf ( " SV[A]P \t set APPLICATION (grow), expand into padding which is exactly consumed \n " ) ;
2002-05-10 06:43:17 +00:00
if ( ! FLAC__metadata_object_application_set_data ( app , data , 100 , true ) )
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 ) ;
our_metadata_ . blocks [ our_current_position ] - > is_last = true ;
2002-06-08 04:53:42 +00:00
if ( ! FLAC__metadata_simple_iterator_set_block ( iterator , app , true ) )
return die_ss_ ( " FLAC__metadata_simple_iterator_set_block(iterator, app, true) " , iterator) ;
2002-05-10 06:43:17 +00:00
2002-05-11 05:41:42 +00:00
if ( ! test_file_ ( flacfile_ , decoder_metadata_callback_compare_ ) )
2002-05-10 06:43:17 +00:00
return false ;
2002-08-25 05:10:37 +00:00
printf ( " SV[A] \t set PADDING (equal size) \n " ) ;
2002-05-10 06:43:17 +00:00
padding - > length = app - > length ;
if ( ! replace_in_our_metadata_ ( padding , our_current_position , /*copy=*/ true ) )
return die_ ( " copying object " ) ;
2002-06-08 04:53:42 +00:00
if ( ! FLAC__metadata_simple_iterator_set_block ( iterator , padding , true ) )
return die_ss_ ( " FLAC__metadata_simple_iterator_set_block(iterator, padding, true) " , iterator) ;
2002-05-10 06:43:17 +00:00
2002-05-11 05:41:42 +00:00
if ( ! test_file_ ( flacfile_ , decoder_metadata_callback_compare_ ) )
2002-05-10 06:43:17 +00:00
return false ;
2002-08-25 05:10:37 +00:00
printf ( " SV[P] \t insert PADDING after \n " ) ;
2002-06-08 04:53:42 +00:00
if ( ! FLAC__metadata_simple_iterator_insert_block_after ( iterator , padding , false ) )
return die_ss_ ( " FLAC__metadata_simple_iterator_insert_block_after(iterator, padding, false) " , iterator) ;
2002-05-10 06:43:17 +00:00
if ( ! insert_to_our_metadata_ ( padding , + + our_current_position , /*copy=*/ true ) )
return false ;
2002-05-11 05:41:42 +00:00
if ( ! test_file_ ( flacfile_ , decoder_metadata_callback_compare_ ) )
2002-05-10 06:43:17 +00:00
return false ;
2002-08-25 05:10:37 +00:00
printf ( " SVP[P] \t insert PADDING after \n " ) ;
2002-05-10 06:43:17 +00:00
padding - > length = 5 ;
2002-06-08 04:53:42 +00:00
if ( ! FLAC__metadata_simple_iterator_insert_block_after ( iterator , padding , false ) )
return die_ss_ ( " FLAC__metadata_simple_iterator_insert_block_after(iterator, padding, false) " , iterator) ;
2002-05-10 06:43:17 +00:00
if ( ! insert_to_our_metadata_ ( padding , + + our_current_position , /*copy=*/ true ) )
return false ;
2002-05-11 05:41:42 +00:00
if ( ! test_file_ ( flacfile_ , decoder_metadata_callback_compare_ ) )
2002-05-10 06:43:17 +00:00
return false ;
2002-08-25 05:10:37 +00:00
printf ( " SVPP[P] \t prev \n " ) ;
2002-06-08 04:53:42 +00:00
if ( ! FLAC__metadata_simple_iterator_prev ( iterator ) )
2002-05-10 06:43:17 +00:00
return die_ ( " iterator ended early \n " ) ;
our_current_position - - ;
2002-08-25 05:10:37 +00:00
printf ( " SVP[P]P \t prev \n " ) ;
2002-06-08 04:53:42 +00:00
if ( ! FLAC__metadata_simple_iterator_prev ( iterator ) )
2002-05-10 06:43:17 +00:00
return die_ ( " iterator ended early \n " ) ;
our_current_position - - ;
2002-08-25 05:10:37 +00:00
printf ( " SV[P]PP \t prev \n " ) ;
2002-06-08 04:53:42 +00:00
if ( ! FLAC__metadata_simple_iterator_prev ( iterator ) )
2002-05-10 06:43:17 +00:00
return die_ ( " iterator ended early \n " ) ;
our_current_position - - ;
2002-08-25 05:10:37 +00:00
printf ( " S[V]PPP \t insert APPLICATION after, try to expand into padding which is too small \n " ) ;
2002-05-10 06:43:17 +00:00
if ( ! FLAC__metadata_object_application_set_data ( app , data , 101 , true ) )
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 ( ! FLAC__metadata_simple_iterator_insert_block_after ( iterator , app , true ) )
return die_ss_ ( " FLAC__metadata_simple_iterator_insert_block_after(iterator, app, true) " , iterator) ;
2002-05-10 06:43:17 +00:00
2002-05-11 05:41:42 +00:00
if ( ! test_file_ ( flacfile_ , decoder_metadata_callback_compare_ ) )
2002-05-10 06:43:17 +00:00
return false ;
2002-08-25 05:10:37 +00:00
printf ( " SV[A]PPP \t delete (middle block), don't replace with padding \n " ) ;
2002-06-08 04:53:42 +00:00
if ( ! FLAC__metadata_simple_iterator_delete_block ( iterator , false ) )
return die_ss_ ( " FLAC__metadata_simple_iterator_delete_block(iterator, false) " , iterator) ;
2002-05-10 06:43:17 +00:00
delete_from_our_metadata_ ( our_current_position - - ) ;
2002-05-11 05:41:42 +00:00
if ( ! test_file_ ( flacfile_ , decoder_metadata_callback_compare_ ) )
2002-05-10 06:43:17 +00:00
return false ;
2002-08-25 05:10:37 +00:00
printf ( " S[V]PPP \t insert APPLICATION after, try to expand into padding which is 'close' but still too small \n " ) ;
2002-05-10 06:43:17 +00:00
if ( ! FLAC__metadata_object_application_set_data ( app , data , 97 , true ) )
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 ( ! FLAC__metadata_simple_iterator_insert_block_after ( iterator , app , true ) )
return die_ss_ ( " FLAC__metadata_simple_iterator_insert_block_after(iterator, app, true) " , iterator) ;
2002-05-10 06:43:17 +00:00
2002-05-11 05:41:42 +00:00
if ( ! test_file_ ( flacfile_ , decoder_metadata_callback_compare_ ) )
2002-05-10 06:43:17 +00:00
return false ;
2002-08-25 05:10:37 +00:00
printf ( " SV[A]PPP \t delete (middle block), don't replace with padding \n " ) ;
2002-06-08 04:53:42 +00:00
if ( ! FLAC__metadata_simple_iterator_delete_block ( iterator , false ) )
return die_ss_ ( " FLAC__metadata_simple_iterator_delete_block(iterator, false) " , iterator) ;
2002-05-10 06:43:17 +00:00
delete_from_our_metadata_ ( our_current_position - - ) ;
2002-05-11 05:41:42 +00:00
if ( ! test_file_ ( flacfile_ , decoder_metadata_callback_compare_ ) )
2002-05-10 06:43:17 +00:00
return false ;
2002-08-25 05:10:37 +00:00
printf ( " S[V]PPP \t insert APPLICATION after, expand into padding which is exactly consumed \n " ) ;
2002-05-10 06:43:17 +00:00
if ( ! FLAC__metadata_object_application_set_data ( app , data , 100 , true ) )
return die_ ( " setting APPLICATION data " ) ;
2002-05-11 05:41:42 +00:00
if ( ! insert_to_our_metadata_ ( app , + + our_current_position , /*copy=*/ true ) )
2002-05-10 06:43:17 +00:00
return die_ ( " copying object " ) ;
delete_from_our_metadata_ ( our_current_position + 1 ) ;
2002-06-08 04:53:42 +00:00
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) ;
2002-05-10 06:43:17 +00:00
2002-05-11 05:41:42 +00:00
if ( ! test_file_ ( flacfile_ , decoder_metadata_callback_compare_ ) )
2002-05-10 06:43:17 +00:00
return false ;
2002-08-25 05:10:37 +00:00
printf ( " SV[A]PP \t delete (middle block), don't replace with padding \n " ) ;
2002-06-08 04:53:42 +00:00
if ( ! FLAC__metadata_simple_iterator_delete_block ( iterator , false ) )
return die_ss_ ( " FLAC__metadata_simple_iterator_delete_block(iterator, false) " , iterator) ;
2002-05-10 06:43:17 +00:00
delete_from_our_metadata_ ( our_current_position - - ) ;
2002-05-11 05:41:42 +00:00
if ( ! test_file_ ( flacfile_ , decoder_metadata_callback_compare_ ) )
2002-05-10 06:43:17 +00:00
return false ;
2002-08-25 05:10:37 +00:00
printf ( " S[V]PP \t insert APPLICATION after, expand into padding which will leave 0-length pad \n " ) ;
2002-05-10 06:43:17 +00:00
if ( ! FLAC__metadata_object_application_set_data ( app , data , 96 , true ) )
return die_ ( " setting APPLICATION data " ) ;
2002-05-11 05:41:42 +00:00
if ( ! insert_to_our_metadata_ ( app , + + our_current_position , /*copy=*/ true ) )
2002-05-10 06:43:17 +00:00
return die_ ( " copying object " ) ;
our_metadata_ . blocks [ our_current_position + 1 ] - > length = 0 ;
2002-06-08 04:53:42 +00:00
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) ;
2002-05-10 06:43:17 +00:00
2002-05-11 05:41:42 +00:00
if ( ! test_file_ ( flacfile_ , decoder_metadata_callback_compare_ ) )
2002-05-10 06:43:17 +00:00
return false ;
2002-08-25 05:10:37 +00:00
printf ( " SV[A]PP \t delete (middle block), don't replace with padding \n " ) ;
2002-06-08 04:53:42 +00:00
if ( ! FLAC__metadata_simple_iterator_delete_block ( iterator , false ) )
return die_ss_ ( " FLAC__metadata_simple_iterator_delete_block(iterator, false) " , iterator) ;
2002-05-10 06:43:17 +00:00
delete_from_our_metadata_ ( our_current_position - - ) ;
2002-05-11 05:41:42 +00:00
if ( ! test_file_ ( flacfile_ , decoder_metadata_callback_compare_ ) )
2002-05-10 06:43:17 +00:00
return false ;
2002-08-25 05:10:37 +00:00
printf ( " S[V]PP \t next \n " ) ;
2002-06-08 04:53:42 +00:00
if ( ! FLAC__metadata_simple_iterator_next ( iterator ) )
2002-05-11 05:41:42 +00:00
return die_ ( " iterator ended early \n " ) ;
our_current_position + + ;
2002-08-25 05:10:37 +00:00
printf ( " SV[P]P \t delete (middle block), don't replace with padding \n " ) ;
2002-06-08 04:53:42 +00:00
if ( ! FLAC__metadata_simple_iterator_delete_block ( iterator , false ) )
return die_ss_ ( " FLAC__metadata_simple_iterator_delete_block(iterator, false) " , iterator) ;
2002-05-11 05:41:42 +00:00
delete_from_our_metadata_ ( our_current_position - - ) ;
if ( ! test_file_ ( flacfile_ , decoder_metadata_callback_compare_ ) )
return false ;
2002-08-25 05:10:37 +00:00
printf ( " S[V]P \t insert APPLICATION after, expand into padding which is exactly consumed \n " ) ;
2002-05-11 05:41:42 +00:00
if ( ! FLAC__metadata_object_application_set_data ( app , data , 1 , true ) )
2002-05-10 06:43:17 +00:00
return die_ ( " setting APPLICATION data " ) ;
2002-05-11 05:41:42 +00:00
if ( ! insert_to_our_metadata_ ( app , + + our_current_position , /*copy=*/ true ) )
2002-05-10 06:43:17 +00:00
return die_ ( " copying object " ) ;
delete_from_our_metadata_ ( our_current_position + 1 ) ;
2002-06-08 04:53:42 +00:00
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) ;
2002-05-09 05:52:40 +00:00
2002-05-11 05:41:42 +00:00
if ( ! test_file_ ( flacfile_ , decoder_metadata_callback_compare_ ) )
2002-05-09 05:52:40 +00:00
return false ;
2002-05-11 05:41:42 +00:00
printf ( " delete simple iterator \n " ) ;
2002-06-08 04:53:42 +00:00
FLAC__metadata_simple_iterator_delete ( iterator ) ;
2002-05-09 05:52:40 +00:00
FLAC__metadata_object_delete ( app ) ;
2002-05-10 06:43:17 +00:00
FLAC__metadata_object_delete ( padding ) ;
2002-05-09 05:52:40 +00:00
if ( ! remove_file_ ( flacfile_ ) )
return false ;
return true ;
}
2004-07-14 00:50:52 +00:00
static FLAC__bool test_level_2_ ( FLAC__bool filename_based )
2002-05-09 05:52:40 +00:00
{
2002-06-08 04:53:42 +00:00
FLAC__Metadata_Iterator * iterator ;
FLAC__Metadata_Chain * chain ;
FLAC__StreamMetadata * block , * app , * padding ;
2002-05-11 05:41:42 +00:00
FLAC__byte data [ 2000 ] ;
unsigned our_current_position ;
2002-12-28 07:06:38 +00:00
/* initialize 'data' to avoid Valgrind errors */
memset ( data , 0 , sizeof ( data ) ) ;
2004-07-14 00:50:52 +00:00
printf ( " \n \n ++++++ testing level 2 interface (%s-based) \n " , filename_based ? " filename " : " callback " ) ;
2002-05-09 05:52:40 +00:00
2002-05-11 05:41:42 +00:00
printf ( " generate read-only file \n " ) ;
2002-05-09 05:52:40 +00:00
2002-05-17 06:28:09 +00:00
if ( ! generate_file_ ( ) )
2002-05-11 05:41:42 +00:00
return false ;
2002-05-07 05:33:49 +00:00
2002-05-11 05:41:42 +00:00
if ( ! change_stats_ ( flacfile_ , /*read_only=*/ true ) )
return false ;
2002-05-09 05:52:40 +00:00
2002-05-11 05:41:42 +00:00
printf ( " create chain \n " ) ;
2002-05-09 05:52:40 +00:00
2002-05-11 05:41:42 +00:00
if ( 0 = = ( chain = FLAC__metadata_chain_new ( ) ) )
return die_ ( " allocating chain " ) ;
2002-05-09 05:52:40 +00:00
2002-05-11 05:41:42 +00:00
printf ( " read chain \n " ) ;
2002-05-09 05:52:40 +00:00
2004-07-15 00:04:09 +00:00
if ( ! read_chain_ ( chain , flacfile_ , filename_based ) )
2002-05-11 05:41:42 +00:00
return die_c_ ( " reading chain " , FLAC__metadata_chain_status ( chain ) ) ;
2002-05-09 05:52:40 +00:00
2002-08-25 05:10:37 +00:00
printf ( " [S]VP \t test initial metadata \n " ) ;
2002-05-09 05:52:40 +00:00
2002-05-14 06:04:47 +00:00
if ( ! compare_chain_ ( chain , 0 , 0 ) )
2002-05-11 05:41:42 +00:00
return false ;
if ( ! test_file_ ( flacfile_ , decoder_metadata_callback_compare_ ) )
return false ;
2002-05-09 05:52:40 +00:00
2002-05-11 05:41:42 +00:00
printf ( " switch file to read-write \n " ) ;
2002-05-09 05:52:40 +00:00
2002-05-11 05:41:42 +00:00
if ( ! change_stats_ ( flacfile_ , /*read-only=*/ false ) )
return false ;
2002-05-09 05:52:40 +00:00
2002-05-25 02:14:26 +00:00
printf ( " create iterator \n " ) ;
2002-05-11 05:41:42 +00:00
if ( 0 = = ( iterator = FLAC__metadata_iterator_new ( ) ) )
return die_ ( " allocating memory for iterator " ) ;
2002-05-09 05:52:40 +00:00
2002-05-11 05:41:42 +00:00
our_current_position = 0 ;
2002-05-09 05:52:40 +00:00
2002-05-11 05:41:42 +00:00
FLAC__metadata_iterator_init ( iterator , chain ) ;
2002-05-09 05:52:40 +00:00
2002-05-11 05:41:42 +00:00
if ( 0 = = ( block = FLAC__metadata_iterator_get_block ( iterator ) ) )
return die_ ( " getting block from iterator " ) ;
2002-05-09 05:52:40 +00:00
2002-05-11 05:41:42 +00:00
FLAC__ASSERT ( block - > type = = FLAC__METADATA_TYPE_STREAMINFO ) ;
2002-05-09 05:52:40 +00:00
2002-08-25 05:10:37 +00:00
printf ( " [S]VP \t modify STREAMINFO, write \n " ) ;
2002-05-25 02:14:26 +00:00
2002-05-11 05:41:42 +00:00
block - > data . stream_info . sample_rate = 32000 ;
if ( ! replace_in_our_metadata_ ( block , our_current_position , /*copy=*/ true ) )
return die_ ( " copying object " ) ;
2002-05-09 05:52:40 +00:00
2004-07-14 00:50:52 +00:00
if ( ! write_chain_ ( chain , /*use_padding=*/ false , /*preserve_file_stats=*/ true , filename_based , flacfile_ ) )
2002-05-11 05:41:42 +00:00
return die_c_ ( " during FLAC__metadata_chain_write(chain, false, true) " , FLAC__metadata_chain_status(chain)) ;
2002-05-14 06:04:47 +00:00
if ( ! compare_chain_ ( chain , our_current_position , FLAC__metadata_iterator_get_block ( iterator ) ) )
return false ;
2002-05-11 05:41:42 +00:00
if ( ! test_file_ ( flacfile_ , decoder_metadata_callback_compare_ ) )
return false ;
2002-05-09 05:52:40 +00:00
2002-08-25 05:10:37 +00:00
printf ( " [S]VP \t next \n " ) ;
if ( ! FLAC__metadata_iterator_next ( iterator ) )
return die_ ( " iterator ended early \n " ) ;
our_current_position + + ;
printf ( " S[V]P \t next \n " ) ;
2002-05-11 05:41:42 +00:00
if ( ! FLAC__metadata_iterator_next ( iterator ) )
return die_ ( " iterator ended early \n " ) ;
our_current_position + + ;
2002-05-09 05:52:40 +00:00
2002-08-25 05:10:37 +00:00
printf ( " SV[P] \t replace PADDING with identical-size APPLICATION \n " ) ;
2002-05-14 06:04:47 +00:00
if ( 0 = = ( block = FLAC__metadata_iterator_get_block ( iterator ) ) )
return die_ ( " getting block from iterator " ) ;
2002-05-11 05:41:42 +00:00
if ( 0 = = ( app = FLAC__metadata_object_new ( FLAC__METADATA_TYPE_APPLICATION ) ) )
return die_ ( " FLAC__metadata_object_new(FLAC__METADATA_TYPE_APPLICATION) " ) ;
memcpy ( app - > data . application . id , " duh " , ( FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8 ) ) ;
if ( ! FLAC__metadata_object_application_set_data ( app , data , block - > length - ( FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8 ) , true ) )
return die_ ( " setting APPLICATION data " ) ;
2002-05-14 06:16:02 +00:00
if ( ! replace_in_our_metadata_ ( app , our_current_position , /*copy=*/ true ) )
2002-05-11 05:41:42 +00:00
return die_ ( " copying object " ) ;
if ( ! FLAC__metadata_iterator_set_block ( iterator , app ) )
return die_c_ ( " FLAC__metadata_iterator_set_block(iterator, app) " , FLAC__metadata_chain_status(chain)) ;
2002-05-09 05:52:40 +00:00
2004-07-14 00:50:52 +00:00
if ( ! write_chain_ ( chain , /*use_padding=*/ false , /*preserve_file_stats=*/ false , filename_based , flacfile_ ) )
2002-05-25 02:14:26 +00:00
return die_c_ ( " during FLAC__metadata_chain_write(chain, false, false) " , FLAC__metadata_chain_status(chain)) ;
2002-05-14 06:04:47 +00:00
if ( ! compare_chain_ ( chain , our_current_position , FLAC__metadata_iterator_get_block ( iterator ) ) )
2002-05-11 05:41:42 +00:00
return false ;
2002-05-14 06:04:47 +00:00
if ( ! test_file_ ( flacfile_ , decoder_metadata_callback_compare_ ) )
return false ;
2002-08-25 05:10:37 +00:00
printf ( " SV[A] \t shrink APPLICATION, don't use padding \n " ) ;
2002-06-08 04:53:42 +00:00
if ( 0 = = ( app = FLAC__metadata_object_clone ( our_metadata_ . blocks [ our_current_position ] ) ) )
2002-05-14 06:04:47 +00:00
return die_ ( " copying object " ) ;
if ( ! FLAC__metadata_object_application_set_data ( app , data , 26 , true ) )
return die_ ( " setting APPLICATION data " ) ;
if ( ! replace_in_our_metadata_ ( app , our_current_position , /*copy=*/ true ) )
return die_ ( " copying object " ) ;
if ( ! FLAC__metadata_iterator_set_block ( iterator , app ) )
return die_c_ ( " FLAC__metadata_iterator_set_block(iterator, app) " , FLAC__metadata_chain_status(chain)) ;
2002-05-09 05:52:40 +00:00
2004-07-14 00:50:52 +00:00
if ( ! write_chain_ ( chain , /*use_padding=*/ false , /*preserve_file_stats=*/ false , filename_based , flacfile_ ) )
2002-05-25 02:14:26 +00:00
return die_c_ ( " during FLAC__metadata_chain_write(chain, false, false) " , FLAC__metadata_chain_status(chain)) ;
2002-05-14 06:04:47 +00:00
if ( ! compare_chain_ ( chain , our_current_position , FLAC__metadata_iterator_get_block ( iterator ) ) )
return false ;
if ( ! test_file_ ( flacfile_ , decoder_metadata_callback_compare_ ) )
return false ;
2002-05-09 05:52:40 +00:00
2002-08-25 05:10:37 +00:00
printf ( " SV[A] \t grow APPLICATION, don't use padding \n " ) ;
2002-06-08 04:53:42 +00:00
if ( 0 = = ( app = FLAC__metadata_object_clone ( our_metadata_ . blocks [ our_current_position ] ) ) )
2002-05-14 06:04:47 +00:00
return die_ ( " copying object " ) ;
if ( ! FLAC__metadata_object_application_set_data ( app , data , 28 , true ) )
return die_ ( " setting APPLICATION data " ) ;
if ( ! replace_in_our_metadata_ ( app , our_current_position , /*copy=*/ true ) )
return die_ ( " copying object " ) ;
if ( ! FLAC__metadata_iterator_set_block ( iterator , app ) )
return die_c_ ( " FLAC__metadata_iterator_set_block(iterator, app) " , FLAC__metadata_chain_status(chain)) ;
2004-07-14 00:50:52 +00:00
if ( ! write_chain_ ( chain , /*use_padding=*/ false , /*preserve_file_stats=*/ false , filename_based , flacfile_ ) )
2002-05-25 02:14:26 +00:00
return die_c_ ( " during FLAC__metadata_chain_write(chain, false, false) " , FLAC__metadata_chain_status(chain)) ;
2002-05-14 06:04:47 +00:00
if ( ! compare_chain_ ( chain , our_current_position , FLAC__metadata_iterator_get_block ( iterator ) ) )
return false ;
2002-05-11 05:41:42 +00:00
if ( ! test_file_ ( flacfile_ , decoder_metadata_callback_compare_ ) )
return false ;
2002-05-09 05:52:40 +00:00
2002-08-25 05:10:37 +00:00
printf ( " SV[A] \t grow APPLICATION, use padding, but last block is not padding \n " ) ;
2002-06-08 04:53:42 +00:00
if ( 0 = = ( app = FLAC__metadata_object_clone ( our_metadata_ . blocks [ our_current_position ] ) ) )
2002-05-14 06:04:47 +00:00
return die_ ( " copying object " ) ;
if ( ! FLAC__metadata_object_application_set_data ( app , data , 36 , true ) )
return die_ ( " setting APPLICATION data " ) ;
if ( ! replace_in_our_metadata_ ( app , our_current_position , /*copy=*/ true ) )
return die_ ( " copying object " ) ;
if ( ! FLAC__metadata_iterator_set_block ( iterator , app ) )
return die_c_ ( " FLAC__metadata_iterator_set_block(iterator, app) " , FLAC__metadata_chain_status(chain)) ;
2004-07-14 00:50:52 +00:00
if ( ! write_chain_ ( chain , /*use_padding=*/ false , /*preserve_file_stats=*/ false , filename_based , flacfile_ ) )
2002-05-25 02:14:26 +00:00
return die_c_ ( " during FLAC__metadata_chain_write(chain, false, false) " , FLAC__metadata_chain_status(chain)) ;
2002-05-14 06:04:47 +00:00
if ( ! compare_chain_ ( chain , our_current_position , FLAC__metadata_iterator_get_block ( iterator ) ) )
return false ;
if ( ! test_file_ ( flacfile_ , decoder_metadata_callback_compare_ ) )
return false ;
2002-08-25 05:10:37 +00:00
printf ( " SV[A] \t shrink APPLICATION, use padding, last block is not padding, but delta is too small for new PADDING block \n " ) ;
2002-06-08 04:53:42 +00:00
if ( 0 = = ( app = FLAC__metadata_object_clone ( our_metadata_ . blocks [ our_current_position ] ) ) )
2002-05-14 06:04:47 +00:00
return die_ ( " copying object " ) ;
if ( ! FLAC__metadata_object_application_set_data ( app , data , 33 , true ) )
return die_ ( " setting APPLICATION data " ) ;
if ( ! replace_in_our_metadata_ ( app , our_current_position , /*copy=*/ true ) )
return die_ ( " copying object " ) ;
if ( ! FLAC__metadata_iterator_set_block ( iterator , app ) )
return die_c_ ( " FLAC__metadata_iterator_set_block(iterator, app) " , FLAC__metadata_chain_status(chain)) ;
2004-07-14 00:50:52 +00:00
if ( ! write_chain_ ( chain , /*use_padding=*/ true , /*preserve_file_stats=*/ false , filename_based , flacfile_ ) )
2002-05-25 02:14:26 +00:00
return die_c_ ( " during FLAC__metadata_chain_write(chain, true, false) " , FLAC__metadata_chain_status(chain)) ;
2002-05-14 06:04:47 +00:00
if ( ! compare_chain_ ( chain , our_current_position , FLAC__metadata_iterator_get_block ( iterator ) ) )
return false ;
if ( ! test_file_ ( flacfile_ , decoder_metadata_callback_compare_ ) )
return false ;
2002-08-25 05:10:37 +00:00
printf ( " SV[A] \t shrink APPLICATION, use padding, last block is not padding, delta is enough for new PADDING block \n " ) ;
2002-05-14 06:04:47 +00:00
if ( 0 = = ( padding = FLAC__metadata_object_new ( FLAC__METADATA_TYPE_PADDING ) ) )
return die_ ( " creating PADDING block " ) ;
2002-06-08 04:53:42 +00:00
if ( 0 = = ( app = FLAC__metadata_object_clone ( our_metadata_ . blocks [ our_current_position ] ) ) )
2002-05-14 06:04:47 +00:00
return die_ ( " copying object " ) ;
if ( ! FLAC__metadata_object_application_set_data ( app , data , 29 , true ) )
return die_ ( " setting APPLICATION data " ) ;
if ( ! replace_in_our_metadata_ ( app , our_current_position , /*copy=*/ true ) )
return die_ ( " copying object " ) ;
padding - > length = 0 ;
if ( ! insert_to_our_metadata_ ( padding , our_current_position + 1 , /*copy=*/ false ) )
return die_ ( " internal error " ) ;
if ( ! FLAC__metadata_iterator_set_block ( iterator , app ) )
return die_c_ ( " FLAC__metadata_iterator_set_block(iterator, app) " , FLAC__metadata_chain_status(chain)) ;
2004-07-14 00:50:52 +00:00
if ( ! write_chain_ ( chain , /*use_padding=*/ true , /*preserve_file_stats=*/ false , filename_based , flacfile_ ) )
2002-05-25 02:14:26 +00:00
return die_c_ ( " during FLAC__metadata_chain_write(chain, true, false) " , FLAC__metadata_chain_status(chain)) ;
2002-05-14 06:04:47 +00:00
if ( ! compare_chain_ ( chain , our_current_position , FLAC__metadata_iterator_get_block ( iterator ) ) )
return false ;
if ( ! test_file_ ( flacfile_ , decoder_metadata_callback_compare_ ) )
return false ;
2002-08-25 05:10:37 +00:00
printf ( " SV[A]P \t shrink APPLICATION, use padding, last block is padding \n " ) ;
2002-06-08 04:53:42 +00:00
if ( 0 = = ( app = FLAC__metadata_object_clone ( our_metadata_ . blocks [ our_current_position ] ) ) )
2002-05-14 06:04:47 +00:00
return die_ ( " copying object " ) ;
if ( ! FLAC__metadata_object_application_set_data ( app , data , 16 , true ) )
return die_ ( " setting APPLICATION data " ) ;
if ( ! replace_in_our_metadata_ ( app , our_current_position , /*copy=*/ true ) )
return die_ ( " copying object " ) ;
our_metadata_ . blocks [ our_current_position + 1 ] - > length = 13 ;
if ( ! FLAC__metadata_iterator_set_block ( iterator , app ) )
return die_c_ ( " FLAC__metadata_iterator_set_block(iterator, app) " , FLAC__metadata_chain_status(chain)) ;
2004-07-14 00:50:52 +00:00
if ( ! write_chain_ ( chain , /*use_padding=*/ true , /*preserve_file_stats=*/ false , filename_based , flacfile_ ) )
2002-05-25 02:14:26 +00:00
return die_c_ ( " during FLAC__metadata_chain_write(chain, true, false) " , FLAC__metadata_chain_status(chain)) ;
2002-05-14 06:04:47 +00:00
if ( ! compare_chain_ ( chain , our_current_position , FLAC__metadata_iterator_get_block ( iterator ) ) )
return false ;
if ( ! test_file_ ( flacfile_ , decoder_metadata_callback_compare_ ) )
return false ;
2002-08-25 05:10:37 +00:00
printf ( " SV[A]P \t grow APPLICATION, use padding, last block is padding, but delta is too small \n " ) ;
2002-06-08 04:53:42 +00:00
if ( 0 = = ( app = FLAC__metadata_object_clone ( our_metadata_ . blocks [ our_current_position ] ) ) )
2002-05-14 06:04:47 +00:00
return die_ ( " copying object " ) ;
if ( ! FLAC__metadata_object_application_set_data ( app , data , 50 , true ) )
return die_ ( " setting APPLICATION data " ) ;
if ( ! replace_in_our_metadata_ ( app , our_current_position , /*copy=*/ true ) )
return die_ ( " copying object " ) ;
if ( ! FLAC__metadata_iterator_set_block ( iterator , app ) )
return die_c_ ( " FLAC__metadata_iterator_set_block(iterator, app) " , FLAC__metadata_chain_status(chain)) ;
2004-07-14 00:50:52 +00:00
if ( ! write_chain_ ( chain , /*use_padding=*/ true , /*preserve_file_stats=*/ false , filename_based , flacfile_ ) )
2002-05-25 02:14:26 +00:00
return die_c_ ( " during FLAC__metadata_chain_write(chain, true, false) " , FLAC__metadata_chain_status(chain)) ;
2002-05-14 06:04:47 +00:00
if ( ! compare_chain_ ( chain , our_current_position , FLAC__metadata_iterator_get_block ( iterator ) ) )
return false ;
if ( ! test_file_ ( flacfile_ , decoder_metadata_callback_compare_ ) )
return false ;
2002-08-25 05:10:37 +00:00
printf ( " SV[A]P \t grow APPLICATION, use padding, last block is padding of exceeding size \n " ) ;
2002-06-08 04:53:42 +00:00
if ( 0 = = ( app = FLAC__metadata_object_clone ( our_metadata_ . blocks [ our_current_position ] ) ) )
2002-05-14 06:04:47 +00:00
return die_ ( " copying object " ) ;
if ( ! FLAC__metadata_object_application_set_data ( app , data , 56 , true ) )
return die_ ( " setting APPLICATION data " ) ;
if ( ! replace_in_our_metadata_ ( app , our_current_position , /*copy=*/ true ) )
return die_ ( " copying object " ) ;
our_metadata_ . blocks [ our_current_position + 1 ] - > length - = ( 56 - 50 ) ;
if ( ! FLAC__metadata_iterator_set_block ( iterator , app ) )
return die_c_ ( " FLAC__metadata_iterator_set_block(iterator, app) " , FLAC__metadata_chain_status(chain)) ;
2004-07-14 00:50:52 +00:00
if ( ! write_chain_ ( chain , /*use_padding=*/ true , /*preserve_file_stats=*/ false , filename_based , flacfile_ ) )
2002-05-25 02:14:26 +00:00
return die_c_ ( " during FLAC__metadata_chain_write(chain, true, false) " , FLAC__metadata_chain_status(chain)) ;
2002-05-14 06:04:47 +00:00
if ( ! compare_chain_ ( chain , our_current_position , FLAC__metadata_iterator_get_block ( iterator ) ) )
return false ;
if ( ! test_file_ ( flacfile_ , decoder_metadata_callback_compare_ ) )
return false ;
2002-08-25 05:10:37 +00:00
printf ( " SV[A]P \t grow APPLICATION, use padding, last block is padding of exact size \n " ) ;
2002-06-08 04:53:42 +00:00
if ( 0 = = ( app = FLAC__metadata_object_clone ( our_metadata_ . blocks [ our_current_position ] ) ) )
2002-05-14 06:04:47 +00:00
return die_ ( " copying object " ) ;
if ( ! FLAC__metadata_object_application_set_data ( app , data , 67 , true ) )
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 ) ;
if ( ! FLAC__metadata_iterator_set_block ( iterator , app ) )
return die_c_ ( " FLAC__metadata_iterator_set_block(iterator, app) " , FLAC__metadata_chain_status(chain)) ;
2004-07-14 00:50:52 +00:00
if ( ! write_chain_ ( chain , /*use_padding=*/ true , /*preserve_file_stats=*/ false , filename_based , flacfile_ ) )
2002-05-25 02:14:26 +00:00
return die_c_ ( " during FLAC__metadata_chain_write(chain, true, false) " , FLAC__metadata_chain_status(chain)) ;
2002-05-14 06:04:47 +00:00
if ( ! compare_chain_ ( chain , our_current_position , FLAC__metadata_iterator_get_block ( iterator ) ) )
return false ;
if ( ! test_file_ ( flacfile_ , decoder_metadata_callback_compare_ ) )
return false ;
2002-08-25 05:10:37 +00:00
printf ( " SV[A] \t prev \n " ) ;
if ( ! FLAC__metadata_iterator_prev ( iterator ) )
return die_ ( " iterator ended early \n " ) ;
our_current_position - - ;
printf ( " S[V]A \t prev \n " ) ;
2002-05-14 06:04:47 +00:00
if ( ! FLAC__metadata_iterator_prev ( iterator ) )
return die_ ( " iterator ended early \n " ) ;
our_current_position - - ;
2002-08-25 05:10:37 +00:00
printf ( " [S]VA \t insert PADDING before STREAMINFO (should fail) \n " ) ;
2002-05-14 06:04:47 +00:00
if ( 0 = = ( padding = FLAC__metadata_object_new ( FLAC__METADATA_TYPE_PADDING ) ) )
return die_ ( " creating PADDING block " ) ;
padding - > length = 30 ;
if ( ! FLAC__metadata_iterator_insert_block_before ( iterator , padding ) )
printf ( " \t FLAC__metadata_iterator_insert_block_before() returned false like it should \n " ) ;
else
return die_ ( " FLAC__metadata_iterator_insert_block_before() should have returned false " ) ;
2002-08-25 05:10:37 +00:00
printf ( " [S]VP \t next \n " ) ;
if ( ! FLAC__metadata_iterator_next ( iterator ) )
return die_ ( " iterator ended early \n " ) ;
our_current_position + + ;
printf ( " S[V]A \t insert PADDING after \n " ) ;
2002-05-14 06:04:47 +00:00
if ( ! insert_to_our_metadata_ ( padding , + + our_current_position , /*copy=*/ true ) )
return die_ ( " copying metadata " ) ;
if ( ! FLAC__metadata_iterator_insert_block_after ( iterator , padding ) )
return die_ ( " FLAC__metadata_iterator_insert_block_after(iterator, padding) " ) ;
if ( ! compare_chain_ ( chain , our_current_position , FLAC__metadata_iterator_get_block ( iterator ) ) )
return false ;
2002-08-25 05:10:37 +00:00
printf ( " SV[P]A \t insert PADDING before \n " ) ;
2002-06-08 04:53:42 +00:00
if ( 0 = = ( padding = FLAC__metadata_object_clone ( our_metadata_ . blocks [ our_current_position ] ) ) )
2002-05-14 06:04:47 +00:00
return die_ ( " creating PADDING block " ) ;
padding - > length = 17 ;
if ( ! insert_to_our_metadata_ ( padding , our_current_position , /*copy=*/ true ) )
return die_ ( " copying metadata " ) ;
if ( ! FLAC__metadata_iterator_insert_block_before ( iterator , padding ) )
return die_ ( " FLAC__metadata_iterator_insert_block_before(iterator, padding) " ) ;
if ( ! compare_chain_ ( chain , our_current_position , FLAC__metadata_iterator_get_block ( iterator ) ) )
return false ;
2002-08-25 05:10:37 +00:00
printf ( " SV[P]PA \t insert PADDING before \n " ) ;
2002-06-08 04:53:42 +00:00
if ( 0 = = ( padding = FLAC__metadata_object_clone ( our_metadata_ . blocks [ our_current_position ] ) ) )
2002-05-14 06:04:47 +00:00
return die_ ( " creating PADDING block " ) ;
padding - > length = 0 ;
if ( ! insert_to_our_metadata_ ( padding , our_current_position , /*copy=*/ true ) )
return die_ ( " copying metadata " ) ;
if ( ! FLAC__metadata_iterator_insert_block_before ( iterator , padding ) )
return die_ ( " FLAC__metadata_iterator_insert_block_before(iterator, padding) " ) ;
if ( ! compare_chain_ ( chain , our_current_position , FLAC__metadata_iterator_get_block ( iterator ) ) )
return false ;
2002-08-25 05:10:37 +00:00
printf ( " SV[P]PPA \t next \n " ) ;
2002-05-14 06:04:47 +00:00
if ( ! FLAC__metadata_iterator_next ( iterator ) )
return die_ ( " iterator ended early \n " ) ;
our_current_position + + ;
2002-08-25 05:10:37 +00:00
printf ( " SVP[P]PA \t next \n " ) ;
2002-05-14 06:04:47 +00:00
if ( ! FLAC__metadata_iterator_next ( iterator ) )
return die_ ( " iterator ended early \n " ) ;
our_current_position + + ;
2002-08-25 05:10:37 +00:00
printf ( " SVPP[P]A \t next \n " ) ;
2002-05-14 06:04:47 +00:00
if ( ! FLAC__metadata_iterator_next ( iterator ) )
return die_ ( " iterator ended early \n " ) ;
our_current_position + + ;
2002-08-25 05:10:37 +00:00
printf ( " SVPPP[A] \t insert PADDING after \n " ) ;
if ( 0 = = ( padding = FLAC__metadata_object_clone ( our_metadata_ . blocks [ 2 ] ) ) )
2002-05-14 06:04:47 +00:00
return die_ ( " creating PADDING block " ) ;
padding - > length = 57 ;
if ( ! insert_to_our_metadata_ ( padding , + + our_current_position , /*copy=*/ true ) )
return die_ ( " copying metadata " ) ;
if ( ! FLAC__metadata_iterator_insert_block_after ( iterator , padding ) )
return die_ ( " FLAC__metadata_iterator_insert_block_after(iterator, padding) " ) ;
if ( ! compare_chain_ ( chain , our_current_position , FLAC__metadata_iterator_get_block ( iterator ) ) )
return false ;
2002-08-25 05:10:37 +00:00
printf ( " SVPPPA[P] \t insert PADDING before \n " ) ;
if ( 0 = = ( padding = FLAC__metadata_object_clone ( our_metadata_ . blocks [ 2 ] ) ) )
2002-05-14 06:04:47 +00:00
return die_ ( " creating PADDING block " ) ;
padding - > length = 99 ;
if ( ! insert_to_our_metadata_ ( padding , our_current_position , /*copy=*/ true ) )
return die_ ( " copying metadata " ) ;
if ( ! FLAC__metadata_iterator_insert_block_before ( iterator , padding ) )
return die_ ( " FLAC__metadata_iterator_insert_block_before(iterator, padding) " ) ;
if ( ! compare_chain_ ( chain , our_current_position , FLAC__metadata_iterator_get_block ( iterator ) ) )
return false ;
printf ( " delete iterator \n " ) ;
2002-05-11 05:41:42 +00:00
FLAC__metadata_iterator_delete ( iterator ) ;
2002-05-14 06:04:47 +00:00
our_current_position = 0 ;
2002-08-25 05:10:37 +00:00
printf ( " SVPPPAPP \t merge padding \n " ) ;
2002-05-14 06:04:47 +00:00
FLAC__metadata_chain_merge_padding ( chain ) ;
2002-08-25 05:10:37 +00:00
our_metadata_ . blocks [ 2 ] - > length + = ( FLAC__STREAM_METADATA_HEADER_LENGTH + our_metadata_ . blocks [ 3 ] - > length ) ;
our_metadata_ . blocks [ 2 ] - > length + = ( FLAC__STREAM_METADATA_HEADER_LENGTH + our_metadata_ . blocks [ 4 ] - > length ) ;
our_metadata_ . blocks [ 6 ] - > length + = ( FLAC__STREAM_METADATA_HEADER_LENGTH + our_metadata_ . blocks [ 7 ] - > length ) ;
delete_from_our_metadata_ ( 7 ) ;
delete_from_our_metadata_ ( 4 ) ;
2002-05-14 06:04:47 +00:00
delete_from_our_metadata_ ( 3 ) ;
2004-07-14 00:50:52 +00:00
if ( ! write_chain_ ( chain , /*use_padding=*/ true , /*preserve_file_stats=*/ false , filename_based , flacfile_ ) )
2002-05-25 02:14:26 +00:00
return die_c_ ( " during FLAC__metadata_chain_write(chain, true, false) " , FLAC__metadata_chain_status(chain)) ;
2002-05-14 06:04:47 +00:00
if ( ! compare_chain_ ( chain , 0 , 0 ) )
return false ;
if ( ! test_file_ ( flacfile_ , decoder_metadata_callback_compare_ ) )
return false ;
2002-08-25 05:10:37 +00:00
printf ( " SVPAP \t sort padding \n " ) ;
2002-05-14 06:04:47 +00:00
FLAC__metadata_chain_sort_padding ( chain ) ;
2002-08-25 05:10:37 +00:00
our_metadata_ . blocks [ 4 ] - > length + = ( FLAC__STREAM_METADATA_HEADER_LENGTH + our_metadata_ . blocks [ 2 ] - > length ) ;
delete_from_our_metadata_ ( 2 ) ;
2002-05-14 06:04:47 +00:00
2004-07-14 00:50:52 +00:00
if ( ! write_chain_ ( chain , /*use_padding=*/ true , /*preserve_file_stats=*/ false , filename_based , flacfile_ ) )
2002-05-25 02:14:26 +00:00
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_ ) )
return false ;
printf ( " create iterator \n " ) ;
if ( 0 = = ( iterator = FLAC__metadata_iterator_new ( ) ) )
return die_ ( " allocating memory for iterator " ) ;
our_current_position = 0 ;
FLAC__metadata_iterator_init ( iterator , chain ) ;
2002-08-25 05:10:37 +00:00
printf ( " [S]VAP \t next \n " ) ;
if ( ! FLAC__metadata_iterator_next ( iterator ) )
return die_ ( " iterator ended early \n " ) ;
our_current_position + + ;
printf ( " S[V]AP \t next \n " ) ;
2002-05-25 02:14:26 +00:00
if ( ! FLAC__metadata_iterator_next ( iterator ) )
return die_ ( " iterator ended early \n " ) ;
our_current_position + + ;
2002-08-25 05:10:37 +00:00
printf ( " SV[A]P \t delete middle block, replace with padding \n " ) ;
2002-05-25 02:14:26 +00:00
if ( 0 = = ( padding = FLAC__metadata_object_new ( FLAC__METADATA_TYPE_PADDING ) ) )
return die_ ( " creating PADDING block " ) ;
padding - > length = 71 ;
if ( ! replace_in_our_metadata_ ( padding , our_current_position - - , /*copy=*/ false ) )
return die_ ( " copying object " ) ;
if ( ! FLAC__metadata_iterator_delete_block ( iterator , /*replace_with_padding=*/ true ) )
return die_c_ ( " FLAC__metadata_iterator_delete_block(iterator, true) " , FLAC__metadata_chain_status(chain)) ;
if ( ! compare_chain_ ( chain , our_current_position , FLAC__metadata_iterator_get_block ( iterator ) ) )
return false ;
2002-08-25 05:10:37 +00:00
printf ( " S[V]PP \t next \n " ) ;
2002-05-25 02:14:26 +00:00
if ( ! FLAC__metadata_iterator_next ( iterator ) )
return die_ ( " iterator ended early \n " ) ;
our_current_position + + ;
2002-08-25 05:10:37 +00:00
printf ( " SV[P]P \t delete middle block, don't replace with padding \n " ) ;
2002-05-25 02:14:26 +00:00
delete_from_our_metadata_ ( our_current_position - - ) ;
if ( ! FLAC__metadata_iterator_delete_block ( iterator , /*replace_with_padding=*/ false ) )
return die_c_ ( " FLAC__metadata_iterator_delete_block(iterator, false) " , FLAC__metadata_chain_status(chain)) ;
if ( ! compare_chain_ ( chain , our_current_position , FLAC__metadata_iterator_get_block ( iterator ) ) )
return false ;
2002-08-25 05:10:37 +00:00
printf ( " S[V]P \t next \n " ) ;
2002-05-25 02:14:26 +00:00
if ( ! FLAC__metadata_iterator_next ( iterator ) )
return die_ ( " iterator ended early \n " ) ;
our_current_position + + ;
2002-08-25 05:10:37 +00:00
printf ( " SV[P] \t delete last block, replace with padding \n " ) ;
2002-05-25 02:14:26 +00:00
if ( 0 = = ( padding = FLAC__metadata_object_new ( FLAC__METADATA_TYPE_PADDING ) ) )
return die_ ( " creating PADDING block " ) ;
padding - > length = 219 ;
if ( ! replace_in_our_metadata_ ( padding , our_current_position - - , /*copy=*/ false ) )
return die_ ( " copying object " ) ;
if ( ! FLAC__metadata_iterator_delete_block ( iterator , /*replace_with_padding=*/ true ) )
return die_c_ ( " FLAC__metadata_iterator_delete_block(iterator, true) " , FLAC__metadata_chain_status(chain)) ;
if ( ! compare_chain_ ( chain , our_current_position , FLAC__metadata_iterator_get_block ( iterator ) ) )
return false ;
2002-08-25 05:10:37 +00:00
printf ( " S[V]P \t next \n " ) ;
2002-05-25 02:14:26 +00:00
if ( ! FLAC__metadata_iterator_next ( iterator ) )
return die_ ( " iterator ended early \n " ) ;
our_current_position + + ;
2002-08-25 05:10:37 +00:00
printf ( " SV[P] \t delete last block, don't replace with padding \n " ) ;
2002-05-25 02:14:26 +00:00
delete_from_our_metadata_ ( our_current_position - - ) ;
if ( ! FLAC__metadata_iterator_delete_block ( iterator , /*replace_with_padding=*/ false ) )
return die_c_ ( " FLAC__metadata_iterator_delete_block(iterator, false) " , FLAC__metadata_chain_status(chain)) ;
if ( ! compare_chain_ ( chain , our_current_position , FLAC__metadata_iterator_get_block ( iterator ) ) )
return false ;
2002-08-25 05:10:37 +00:00
printf ( " S[V] \t prev \n " ) ;
if ( ! FLAC__metadata_iterator_prev ( iterator ) )
return die_ ( " iterator ended early \n " ) ;
our_current_position - - ;
printf ( " [S]V \t delete STREAMINFO block, should fail \n " ) ;
2002-05-25 02:14:26 +00:00
if ( FLAC__metadata_iterator_delete_block ( iterator , /*replace_with_padding=*/ false ) )
return die_ ( " FLAC__metadata_iterator_delete_block() on STREAMINFO should have failed but didn ' t " ) ;
if ( ! compare_chain_ ( chain , our_current_position , FLAC__metadata_iterator_get_block ( iterator ) ) )
return false ;
printf ( " delete iterator \n " ) ;
FLAC__metadata_iterator_delete ( iterator ) ;
our_current_position = 0 ;
2002-08-25 05:10:37 +00:00
printf ( " SV \t merge padding \n " ) ;
2002-05-25 02:14:26 +00:00
FLAC__metadata_chain_merge_padding ( chain ) ;
2004-07-14 00:50:52 +00:00
if ( ! write_chain_ ( chain , /*use_padding=*/ false , /*preserve_file_stats=*/ false , filename_based , flacfile_ ) )
2002-05-25 02:14:26 +00:00
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_ ) )
return false ;
2002-08-25 05:10:37 +00:00
printf ( " SV \t sort padding \n " ) ;
2002-05-25 02:14:26 +00:00
FLAC__metadata_chain_sort_padding ( chain ) ;
2004-07-14 00:50:52 +00:00
if ( ! write_chain_ ( chain , /*use_padding=*/ false , /*preserve_file_stats=*/ false , filename_based , flacfile_ ) )
2002-05-25 02:14:26 +00:00
return die_c_ ( " during FLAC__metadata_chain_write(chain, false, false) " , FLAC__metadata_chain_status(chain)) ;
2002-05-14 06:04:47 +00:00
if ( ! compare_chain_ ( chain , 0 , 0 ) )
return false ;
if ( ! test_file_ ( flacfile_ , decoder_metadata_callback_compare_ ) )
return false ;
2002-05-09 05:52:40 +00:00
2002-05-11 05:41:42 +00:00
printf ( " delete chain \n " ) ;
2002-05-09 05:52:40 +00:00
2002-05-11 05:41:42 +00:00
FLAC__metadata_chain_delete ( chain ) ;
2002-05-09 05:52:40 +00:00
2002-05-11 05:41:42 +00:00
if ( ! remove_file_ ( flacfile_ ) )
return false ;
2002-05-09 05:52:40 +00:00
2002-05-11 05:41:42 +00:00
return true ;
}
2002-05-09 05:52:40 +00:00
2004-07-15 00:04:09 +00:00
static FLAC__bool test_level_2_misc_ ( )
{
FLAC__Metadata_Iterator * iterator ;
FLAC__Metadata_Chain * chain ;
FLAC__IOCallbacks callbacks ;
memset ( & callbacks , 0 , sizeof ( callbacks ) ) ;
callbacks . read = ( FLAC__IOCallback_Read ) fread ;
# ifdef FLAC__VALGRIND_TESTING
callbacks . write = chain_write_cb_ ;
# else
callbacks . write = ( FLAC__IOCallback_Write ) fwrite ;
# endif
callbacks . seek = chain_seek_cb_ ;
callbacks . tell = chain_tell_cb_ ;
callbacks . eof = chain_eof_cb_ ;
printf ( " \n \n ++++++ testing level 2 interface (mismatched read/write protections) \n " ) ;
printf ( " generate file \n " ) ;
if ( ! generate_file_ ( ) )
return false ;
printf ( " create chain \n " ) ;
if ( 0 = = ( chain = FLAC__metadata_chain_new ( ) ) )
return die_ ( " allocating chain " ) ;
printf ( " read chain (filename-based) \n " ) ;
if ( ! FLAC__metadata_chain_read ( chain , flacfile_ ) )
return die_c_ ( " reading chain " , FLAC__metadata_chain_status ( chain ) ) ;
printf ( " write chain with wrong method FLAC__metadata_chain_write_with_callbacks() \n " ) ;
{
if ( FLAC__metadata_chain_write_with_callbacks ( chain , /*use_padding=*/ false , 0 , callbacks ) )
return die_c_ ( " mismatched write should have failed " , FLAC__metadata_chain_status ( chain ) ) ;
if ( FLAC__metadata_chain_status ( chain ) ! = FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH )
return die_c_ ( " expected FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH " , FLAC__metadata_chain_status ( chain ) ) ;
printf ( " OK: FLAC__metadata_chain_write_with_callbacks() returned false,FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH like it should \n " ) ;
}
printf ( " read chain (filename-based) \n " ) ;
if ( ! FLAC__metadata_chain_read ( chain , flacfile_ ) )
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 " ) ;
{
if ( FLAC__metadata_chain_write_with_callbacks_and_tempfile ( chain , /*use_padding=*/ false , 0 , callbacks , 0 , callbacks ) )
return die_c_ ( " mismatched write should have failed " , FLAC__metadata_chain_status ( chain ) ) ;
if ( FLAC__metadata_chain_status ( chain ) ! = FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH )
return die_c_ ( " expected FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH " , FLAC__metadata_chain_status ( chain ) ) ;
printf ( " OK: FLAC__metadata_chain_write_with_callbacks_and_tempfile() returned false,FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH like it should \n " ) ;
}
printf ( " read chain (callback-based) \n " ) ;
{
FILE * file = fopen ( flacfile_ , " rb " ) ;
if ( 0 = = file )
return die_ ( " opening file " ) ;
if ( ! FLAC__metadata_chain_read_with_callbacks ( chain , ( FLAC__IOHandle ) file , callbacks ) ) {
fclose ( file ) ;
return die_c_ ( " reading chain " , FLAC__metadata_chain_status ( chain ) ) ;
}
fclose ( file ) ;
}
printf ( " write chain with wrong method FLAC__metadata_chain_write() \n " ) ;
{
if ( FLAC__metadata_chain_write ( chain , /*use_padding=*/ false , /*preserve_file_stats=*/ false ) )
return die_c_ ( " mismatched write should have failed " , FLAC__metadata_chain_status ( chain ) ) ;
if ( FLAC__metadata_chain_status ( chain ) ! = FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH )
return die_c_ ( " expected FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH " , FLAC__metadata_chain_status ( chain ) ) ;
printf ( " OK: FLAC__metadata_chain_write() returned false,FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH like it should \n " ) ;
}
printf ( " read chain (callback-based) \n " ) ;
{
FILE * file = fopen ( flacfile_ , " rb " ) ;
if ( 0 = = file )
return die_ ( " opening file " ) ;
if ( ! FLAC__metadata_chain_read_with_callbacks ( chain , ( FLAC__IOHandle ) file , callbacks ) ) {
fclose ( file ) ;
return die_c_ ( " reading chain " , FLAC__metadata_chain_status ( chain ) ) ;
}
fclose ( file ) ;
}
printf ( " testing FLAC__metadata_chain_check_if_tempfile_needed()... " ) ;
if ( ! FLAC__metadata_chain_check_if_tempfile_needed ( chain , /*use_padding=*/ false ) )
printf ( " OK: FLAC__metadata_chain_check_if_tempfile_needed() returned false like it should \n " ) ;
else
return die_ ( " FLAC__metadata_chain_check_if_tempfile_needed() returned true but shouldn ' t have " ) ;
printf ( " write chain with wrong method FLAC__metadata_chain_write_with_callbacks_and_tempfile() \n " ) ;
{
if ( FLAC__metadata_chain_write_with_callbacks_and_tempfile ( chain , /*use_padding=*/ false , 0 , callbacks , 0 , callbacks ) )
return die_c_ ( " mismatched write should have failed " , FLAC__metadata_chain_status ( chain ) ) ;
if ( FLAC__metadata_chain_status ( chain ) ! = FLAC__METADATA_CHAIN_STATUS_WRONG_WRITE_CALL )
return die_c_ ( " expected FLAC__METADATA_CHAIN_STATUS_WRONG_WRITE_CALL " , FLAC__metadata_chain_status ( chain ) ) ;
printf ( " OK: FLAC__metadata_chain_write_with_callbacks_and_tempfile() returned false,FLAC__METADATA_CHAIN_STATUS_WRONG_WRITE_CALL like it should \n " ) ;
}
printf ( " read chain (callback-based) \n " ) ;
{
FILE * file = fopen ( flacfile_ , " rb " ) ;
if ( 0 = = file )
return die_ ( " opening file " ) ;
if ( ! FLAC__metadata_chain_read_with_callbacks ( chain , ( FLAC__IOHandle ) file , callbacks ) ) {
fclose ( file ) ;
return die_c_ ( " reading chain " , FLAC__metadata_chain_status ( chain ) ) ;
}
fclose ( file ) ;
}
printf ( " create iterator \n " ) ;
if ( 0 = = ( iterator = FLAC__metadata_iterator_new ( ) ) )
return die_ ( " allocating memory for iterator " ) ;
FLAC__metadata_iterator_init ( iterator , chain ) ;
printf ( " [S]VP \t next \n " ) ;
if ( ! FLAC__metadata_iterator_next ( iterator ) )
return die_ ( " iterator ended early \n " ) ;
printf ( " S[V]P \t delete VORBIS_COMMENT, write \n " ) ;
if ( ! FLAC__metadata_iterator_delete_block ( iterator , /*replace_with_padding=*/ false ) )
return die_c_ ( " block delete failed \n " , FLAC__metadata_chain_status ( chain ) ) ;
printf ( " testing FLAC__metadata_chain_check_if_tempfile_needed()... " ) ;
if ( FLAC__metadata_chain_check_if_tempfile_needed ( chain , /*use_padding=*/ false ) )
printf ( " OK: FLAC__metadata_chain_check_if_tempfile_needed() returned true like it should \n " ) ;
else
return die_ ( " FLAC__metadata_chain_check_if_tempfile_needed() returned false but shouldn ' t have " ) ;
printf ( " write chain with wrong method FLAC__metadata_chain_write_with_callbacks() \n " ) ;
{
if ( FLAC__metadata_chain_write_with_callbacks ( chain , /*use_padding=*/ false , 0 , callbacks ) )
return die_c_ ( " mismatched write should have failed " , FLAC__metadata_chain_status ( chain ) ) ;
if ( FLAC__metadata_chain_status ( chain ) ! = FLAC__METADATA_CHAIN_STATUS_WRONG_WRITE_CALL )
return die_c_ ( " expected FLAC__METADATA_CHAIN_STATUS_WRONG_WRITE_CALL " , FLAC__metadata_chain_status ( chain ) ) ;
printf ( " OK: FLAC__metadata_chain_write_with_callbacks() returned false,FLAC__METADATA_CHAIN_STATUS_WRONG_WRITE_CALL like it should \n " ) ;
}
printf ( " delete iterator \n " ) ;
FLAC__metadata_iterator_delete ( iterator ) ;
printf ( " delete chain \n " ) ;
FLAC__metadata_chain_delete ( chain ) ;
if ( ! remove_file_ ( flacfile_ ) )
return false ;
return true ;
}
2002-06-07 05:27:37 +00:00
FLAC__bool test_metadata_file_manipulation ( )
2002-05-11 05:41:42 +00:00
{
2002-06-08 04:53:42 +00:00
printf ( " \n +++ libFLAC unit test: metadata manipulation \n \n " ) ;
2002-05-09 05:52:40 +00:00
2002-05-11 05:41:42 +00:00
our_metadata_ . num_blocks = 0 ;
2002-05-17 06:28:09 +00:00
if ( ! test_level_0_ ( ) )
2002-06-07 05:27:37 +00:00
return false ;
2002-05-11 05:41:42 +00:00
2002-05-17 06:28:09 +00:00
if ( ! test_level_1_ ( ) )
2002-06-07 05:27:37 +00:00
return false ;
2002-05-11 05:41:42 +00:00
2004-07-14 00:50:52 +00:00
if ( ! test_level_2_ ( /*filename_based=*/ true ) ) /* filename-based */
return false ;
if ( ! test_level_2_ ( /*filename_based=*/ false ) ) /* callback-based */
2002-06-07 05:27:37 +00:00
return false ;
2004-07-15 00:04:09 +00:00
if ( ! test_level_2_misc_ ( ) )
return false ;
2002-05-11 05:41:42 +00:00
2002-06-07 05:27:37 +00:00
return true ;
2002-05-11 05:41:42 +00:00
}