Add test for flac regression update-header-before-write

Explicitly writing the header with SFC_UPDATE_HEADER_NOW before
the first sf_write() was making sf_write() calls fail. This is a
test to verify that the fix works.

Signed-off-by: Erik de Castro Lopo <erikd@mega-nerd.com>
This commit is contained in:
Henner Zeller 2017-08-07 20:49:10 -07:00 committed by Erik de Castro Lopo
parent a81308ee40
commit f96e5a2047
2 changed files with 39 additions and 3 deletions

View File

@ -48,6 +48,7 @@
#define LOG_BUFFER_SIZE 1024
static void update_header_test (const char *filename, int typemajor) ;
static void update_header_before_write_test (const char *filename, int typemajor) ;
[+ FOR data_type
+]static void update_seek_[+ (get "name") +]_test (const char *filename, int filetype) ;
@ -226,6 +227,14 @@ main (int argc, char *argv [])
test_count++ ;
} ;
if (do_all || ! strcmp (argv [1], "flac"))
{ if (HAVE_EXTERNAL_XIPH_LIBS)
update_header_before_write_test ("header.flac", SF_FORMAT_FLAC) ;
else
puts (" No FLAC tests because FLAC support was not compiled in.") ;
test_count++ ;
} ;
if (test_count == 0)
{ printf ("Mono : ************************************\n") ;
printf ("Mono : * No '%s' test defined.\n", argv [1]) ;
@ -323,6 +332,35 @@ update_header_test (const char *filename, int typemajor)
puts ("ok") ;
} /* update_header_test */
static void
update_header_before_write_test (const char *filename, int typemajor)
{
SNDFILE *outfile ;
SF_INFO sfinfo ;
int k ;
print_test_name ("update_header_before_write", filename);
memset (&sfinfo, 0, sizeof (sfinfo)) ;
sfinfo.samplerate = 44100 ;
sfinfo.format = (typemajor | SF_FORMAT_PCM_16) ;
sfinfo.channels = 1 ;
outfile = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
/* FLAC can only write the header once; if the first call to sf_write() will
** also attempt to write the header, it fails. FLAC-specific regression
*/
sf_command (outfile, SFC_UPDATE_HEADER_NOW, NULL, 0) ;
for (k = 0 ; k < BUFFER_LEN ; k++)
data_out [k] = k + 1 ;
test_write_int_or_die (outfile, 0, data_out, BUFFER_LEN, __LINE__) ;
unlink (filename) ;
puts ("ok") ;
} /* update_header_before_write_test */
/*==============================================================================
*/
@ -542,4 +580,3 @@ extra_header_test (const char *filename, int filetype)
return ;
#endif
} /* extra_header_test */

View File

@ -346,6 +346,7 @@ echo "----------------------------------------------------------------------"
./write_read_test@EXEEXT@ flac
./compression_size_test@EXEEXT@ flac
./string_test@EXEEXT@ flac
./header_test@EXEEXT@ flac
echo "----------------------------------------------------------------------"
echo " $sfversion passed tests on FLAC files."
echo "----------------------------------------------------------------------"
@ -367,5 +368,3 @@ echo "----------------------------------------------------------------------"
echo "----------------------------------------------------------------------"
echo " $sfversion passed stdio/pipe/vio tests."
echo "----------------------------------------------------------------------"