2007-05-14 09:55:24 +00:00
/*
2017-04-16 00:44:28 +00:00
* * Copyright ( C ) 2001 - 2017 Erik de Castro Lopo < erikd @ mega - nerd . com >
2007-05-14 09:55:24 +00:00
* *
2004-05-19 13:23:52 +00:00
* * This program is free software ; you can redistribute it and / or modify
2007-05-14 09:55:24 +00:00
* * it under the terms of the GNU General Public License as published by
2004-05-19 13:23:52 +00:00
* * the Free Software Foundation ; either version 2 of the License , or
2007-05-14 09:55:24 +00:00
* * ( at your option ) any later version .
* *
* * This program is distributed in the hope that it will be useful ,
2004-05-19 13:23:52 +00:00
* * but WITHOUT ANY WARRANTY ; without even the implied warranty of
2007-05-14 09:55:24 +00:00
* * 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
2004-05-19 13:23:52 +00:00
* * along with this program ; if not , write to the Free Software
2007-05-14 09:55:24 +00:00
* * Foundation , Inc . , 59 Temple Place - Suite 330 , Boston , MA 02111 - 1307 , USA .
*/
2005-09-03 06:12:30 +00:00
# include "sfconfig.h"
2007-05-14 09:55:24 +00:00
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
2006-11-19 01:22:45 +00:00
# include <errno.h>
2015-10-20 08:43:37 +00:00
# include <inttypes.h>
2007-05-14 09:55:24 +00:00
# include <sys/stat.h>
# include <math.h>
2005-09-03 06:12:30 +00:00
# if HAVE_UNISTD_H
2007-05-14 09:55:24 +00:00
# include <unistd.h>
# endif
2005-09-03 03:50:47 +00:00
# if (HAVE_DECL_S_IRGRP == 0)
2007-05-14 09:55:24 +00:00
# include <sf_unistd.h>
# endif
# if (defined (WIN32) || defined (_WIN32))
# include <io.h>
# include <direct.h>
# endif
# include <sndfile.h>
# include "utils.h"
2012-01-20 11:44:47 +00:00
# define BUFFER_LEN (1 << 10)
2007-05-14 09:55:24 +00:00
# define LOG_BUFFER_SIZE 1024
2008-07-29 23:32:26 +00:00
static void zero_data_test ( const char * filename , int format ) ;
static void filesystem_full_test ( int format ) ;
2007-05-14 09:55:24 +00:00
static void permission_test ( const char * filename , int typemajor ) ;
2008-07-03 10:29:42 +00:00
static void wavex_amb_test ( const char * filename ) ;
2015-10-20 08:43:37 +00:00
static void rf64_downgrade_test ( const char * filename ) ;
2017-04-16 00:44:28 +00:00
static void rf64_long_file_downgrade_test ( const char * filename ) ;
2007-05-14 09:55:24 +00:00
int
main ( int argc , char * argv [ ] )
{ int do_all = 0 ;
int test_count = 0 ;
if ( argc ! = 2 )
{ printf ( " Usage : %s <test> \n " , argv [ 0 ] ) ;
printf ( " Where <test> is one of the following: \n " ) ;
printf ( " wav - test WAV file peak chunk \n " ) ;
printf ( " aiff - test AIFF file PEAK chunk \n " ) ;
printf ( " all - perform all tests \n " ) ;
exit ( 1 ) ;
} ;
2012-01-21 03:24:38 +00:00
do_all = ! strcmp ( argv [ 1 ] , " all " ) ;
2007-05-14 09:55:24 +00:00
if ( do_all | | ! strcmp ( argv [ 1 ] , " wav " ) )
2008-07-29 23:32:26 +00:00
{ zero_data_test ( " zerolen.wav " , SF_FORMAT_WAV | SF_FORMAT_PCM_16 ) ;
filesystem_full_test ( SF_FORMAT_WAV | SF_FORMAT_PCM_16 ) ;
2007-05-14 09:55:24 +00:00
permission_test ( " readonly.wav " , SF_FORMAT_WAV ) ;
2008-07-03 10:29:42 +00:00
wavex_amb_test ( " ambisonic.wav " ) ;
2007-05-14 09:55:24 +00:00
test_count + + ;
} ;
if ( do_all | | ! strcmp ( argv [ 1 ] , " aiff " ) )
2008-07-29 23:32:26 +00:00
{ zero_data_test ( " zerolen.aiff " , SF_FORMAT_AIFF | SF_FORMAT_PCM_16 ) ;
filesystem_full_test ( SF_FORMAT_AIFF | SF_FORMAT_PCM_16 ) ;
2007-05-14 09:55:24 +00:00
permission_test ( " readonly.aiff " , SF_FORMAT_AIFF ) ;
test_count + + ;
} ;
if ( do_all | | ! strcmp ( argv [ 1 ] , " au " ) )
2008-07-29 23:32:26 +00:00
{ zero_data_test ( " zerolen.au " , SF_FORMAT_AU | SF_FORMAT_PCM_16 ) ;
filesystem_full_test ( SF_FORMAT_AU | SF_FORMAT_PCM_16 ) ;
2007-05-14 09:55:24 +00:00
permission_test ( " readonly.au " , SF_FORMAT_AU ) ;
test_count + + ;
} ;
2005-07-08 10:43:00 +00:00
if ( do_all | | ! strcmp ( argv [ 1 ] , " caf " ) )
2008-07-29 23:32:26 +00:00
{ zero_data_test ( " zerolen.caf " , SF_FORMAT_CAF | SF_FORMAT_PCM_16 ) ;
filesystem_full_test ( SF_FORMAT_CAF | SF_FORMAT_PCM_16 ) ;
2005-07-08 10:43:00 +00:00
permission_test ( " readonly.caf " , SF_FORMAT_CAF ) ;
test_count + + ;
} ;
2007-05-14 09:55:24 +00:00
if ( do_all | | ! strcmp ( argv [ 1 ] , " svx " ) )
2008-07-29 23:32:26 +00:00
{ zero_data_test ( " zerolen.svx " , SF_FORMAT_SVX | SF_FORMAT_PCM_16 ) ;
filesystem_full_test ( SF_FORMAT_SVX | SF_FORMAT_PCM_16 ) ;
2007-05-14 09:55:24 +00:00
permission_test ( " readonly.svx " , SF_FORMAT_SVX ) ;
test_count + + ;
} ;
if ( do_all | | ! strcmp ( argv [ 1 ] , " nist " ) )
2008-07-29 23:32:26 +00:00
{ zero_data_test ( " zerolen.nist " , SF_FORMAT_NIST | SF_FORMAT_PCM_16 ) ;
filesystem_full_test ( SF_FORMAT_NIST | SF_FORMAT_PCM_16 ) ;
2007-05-14 09:55:24 +00:00
permission_test ( " readonly.nist " , SF_FORMAT_NIST ) ;
test_count + + ;
} ;
if ( do_all | | ! strcmp ( argv [ 1 ] , " paf " ) )
2008-07-29 23:32:26 +00:00
{ zero_data_test ( " zerolen.paf " , SF_FORMAT_PAF | SF_FORMAT_PCM_16 ) ;
filesystem_full_test ( SF_FORMAT_PAF | SF_FORMAT_PCM_16 ) ;
2007-05-14 09:55:24 +00:00
permission_test ( " readonly.paf " , SF_FORMAT_PAF ) ;
test_count + + ;
} ;
if ( do_all | | ! strcmp ( argv [ 1 ] , " ircam " ) )
2008-07-29 23:32:26 +00:00
{ zero_data_test ( " zerolen.ircam " , SF_FORMAT_IRCAM | SF_FORMAT_PCM_16 ) ;
filesystem_full_test ( SF_FORMAT_IRCAM | SF_FORMAT_PCM_16 ) ;
2007-05-14 09:55:24 +00:00
permission_test ( " readonly.ircam " , SF_FORMAT_IRCAM ) ;
test_count + + ;
} ;
if ( do_all | | ! strcmp ( argv [ 1 ] , " voc " ) )
2008-07-29 23:32:26 +00:00
{ zero_data_test ( " zerolen.voc " , SF_FORMAT_VOC | SF_FORMAT_PCM_16 ) ;
filesystem_full_test ( SF_FORMAT_VOC | SF_FORMAT_PCM_16 ) ;
2007-05-14 09:55:24 +00:00
permission_test ( " readonly.voc " , SF_FORMAT_VOC ) ;
test_count + + ;
} ;
if ( do_all | | ! strcmp ( argv [ 1 ] , " w64 " ) )
2008-07-29 23:32:26 +00:00
{ zero_data_test ( " zerolen.w64 " , SF_FORMAT_W64 | SF_FORMAT_PCM_16 ) ;
filesystem_full_test ( SF_FORMAT_W64 | SF_FORMAT_PCM_16 ) ;
2007-05-14 09:55:24 +00:00
permission_test ( " readonly.w64 " , SF_FORMAT_W64 ) ;
test_count + + ;
} ;
2008-08-23 00:03:23 +00:00
if ( do_all | | ! strcmp ( argv [ 1 ] , " rf64 " ) )
2015-10-20 08:43:37 +00:00
{ zero_data_test ( " zerolen.rf64 " , SF_FORMAT_RF64 | SF_FORMAT_PCM_16 ) ;
filesystem_full_test ( SF_FORMAT_RF64 | SF_FORMAT_PCM_16 ) ;
permission_test ( " readonly.rf64 " , SF_FORMAT_RF64 ) ;
rf64_downgrade_test ( " downgrade.wav " ) ;
2017-04-16 00:44:28 +00:00
/* Disable this by default, because it needs to write 4 gigabytes of data. */
if ( SF_FALSE )
rf64_long_file_downgrade_test ( " no-downgrade.rf64 " ) ;
2008-08-23 00:03:23 +00:00
test_count + + ;
} ;
2007-05-14 09:55:24 +00:00
if ( do_all | | ! strcmp ( argv [ 1 ] , " mat4 " ) )
2008-07-29 23:32:26 +00:00
{ zero_data_test ( " zerolen.mat4 " , SF_FORMAT_MAT4 | SF_FORMAT_PCM_16 ) ;
filesystem_full_test ( SF_FORMAT_MAT4 | SF_FORMAT_PCM_16 ) ;
2007-05-14 09:55:24 +00:00
permission_test ( " readonly.mat4 " , SF_FORMAT_MAT4 ) ;
test_count + + ;
} ;
if ( do_all | | ! strcmp ( argv [ 1 ] , " mat5 " ) )
2008-07-29 23:32:26 +00:00
{ zero_data_test ( " zerolen.mat5 " , SF_FORMAT_MAT5 | SF_FORMAT_PCM_16 ) ;
filesystem_full_test ( SF_FORMAT_MAT5 | SF_FORMAT_PCM_16 ) ;
2007-05-14 09:55:24 +00:00
permission_test ( " readonly.mat5 " , SF_FORMAT_MAT5 ) ;
test_count + + ;
} ;
if ( do_all | | ! strcmp ( argv [ 1 ] , " pvf " ) )
2008-07-29 23:32:26 +00:00
{ zero_data_test ( " zerolen.pvf " , SF_FORMAT_PVF | SF_FORMAT_PCM_16 ) ;
filesystem_full_test ( SF_FORMAT_PVF | SF_FORMAT_PCM_16 ) ;
2007-05-14 09:55:24 +00:00
permission_test ( " readonly.pvf " , SF_FORMAT_PVF ) ;
test_count + + ;
} ;
if ( do_all | | ! strcmp ( argv [ 1 ] , " htk " ) )
2008-07-29 23:32:26 +00:00
{ zero_data_test ( " zerolen.htk " , SF_FORMAT_HTK | SF_FORMAT_PCM_16 ) ;
filesystem_full_test ( SF_FORMAT_HTK | SF_FORMAT_PCM_16 ) ;
2007-05-14 09:55:24 +00:00
permission_test ( " readonly.htk " , SF_FORMAT_HTK ) ;
test_count + + ;
} ;
2004-03-26 09:35:47 +00:00
if ( do_all | | ! strcmp ( argv [ 1 ] , " avr " ) )
2008-07-29 23:32:26 +00:00
{ zero_data_test ( " zerolen.avr " , SF_FORMAT_AVR | SF_FORMAT_PCM_16 ) ;
filesystem_full_test ( SF_FORMAT_AVR | SF_FORMAT_PCM_16 ) ;
2004-03-26 09:35:47 +00:00
permission_test ( " readonly.avr " , SF_FORMAT_AVR ) ;
test_count + + ;
} ;
2007-05-14 09:55:24 +00:00
if ( do_all | | ! strcmp ( argv [ 1 ] , " sds " ) )
2008-07-29 23:32:26 +00:00
{ zero_data_test ( " zerolen.sds " , SF_FORMAT_SDS | SF_FORMAT_PCM_16 ) ;
filesystem_full_test ( SF_FORMAT_SDS | SF_FORMAT_PCM_16 ) ;
2007-05-14 09:55:24 +00:00
permission_test ( " readonly.sds " , SF_FORMAT_SDS ) ;
test_count + + ;
} ;
2008-04-19 03:02:35 +00:00
if ( do_all | | ! strcmp ( argv [ 1 ] , " mpc2k " ) )
2008-07-29 23:32:26 +00:00
{ zero_data_test ( " zerolen.mpc " , SF_FORMAT_MPC2K | SF_FORMAT_PCM_16 ) ;
filesystem_full_test ( SF_FORMAT_MPC2K | SF_FORMAT_PCM_16 ) ;
2008-04-19 03:02:35 +00:00
permission_test ( " readonly.mpc " , SF_FORMAT_MPC2K ) ;
test_count + + ;
} ;
2008-07-29 23:32:26 +00:00
if ( do_all | | ! strcmp ( argv [ 1 ] , " ogg " ) )
{ zero_data_test ( " zerolen.oga " , SF_FORMAT_OGG | SF_FORMAT_VORBIS ) ;
/*-filesystem_full_test (SF_FORMAT_OGG | SF_FORMAT_VORBIS) ;-*/
permission_test ( " readonly.oga " , SF_FORMAT_OGG ) ;
test_count + + ;
} ;
2007-05-14 09:55:24 +00:00
if ( test_count = = 0 )
{ printf ( " Mono : ************************************ \n " ) ;
printf ( " Mono : * No '%s' test defined. \n " , argv [ 1 ] ) ;
printf ( " Mono : ************************************ \n " ) ;
return 1 ;
} ;
return 0 ;
} /* main */
/*============================================================================================
* * Here are the test functions .
*/
static void
2008-07-29 23:32:26 +00:00
zero_data_test ( const char * filename , int format )
2007-05-14 09:55:24 +00:00
{ SNDFILE * file ;
SF_INFO sfinfo ;
2008-07-30 22:40:49 +00:00
switch ( format & SF_FORMAT_TYPEMASK )
{ case SF_FORMAT_OGG :
2016-03-13 20:18:05 +00:00
if ( HAVE_EXTERNAL_XIPH_LIBS = = 0 )
2008-07-30 22:40:49 +00:00
return ;
break ;
default :
break ;
} ;
2007-05-14 09:55:24 +00:00
print_test_name ( " zero_data_test " , filename ) ;
2004-04-01 02:54:09 +00:00
sfinfo . samplerate = 44100 ;
2008-07-29 23:32:26 +00:00
sfinfo . format = format ;
2004-04-01 02:54:09 +00:00
sfinfo . channels = 1 ;
sfinfo . frames = 0 ;
2007-05-14 09:55:24 +00:00
2004-10-28 22:21:40 +00:00
file = test_open_file_or_die ( filename , SFM_WRITE , & sfinfo , SF_TRUE , __LINE__ ) ;
2007-05-14 09:55:24 +00:00
sf_close ( file ) ;
memset ( & sfinfo , 0 , sizeof ( sfinfo ) ) ;
2004-10-28 22:21:40 +00:00
file = test_open_file_or_die ( filename , SFM_READ , & sfinfo , SF_TRUE , __LINE__ ) ;
2007-05-14 09:55:24 +00:00
sf_close ( file ) ;
unlink ( filename ) ;
puts ( " ok " ) ;
} /* zero_data_test */
static void
2008-07-29 23:32:26 +00:00
filesystem_full_test ( int format )
2020-08-20 06:41:32 +00:00
{
2007-05-14 09:55:24 +00:00
# if (defined (WIN32) || defined (_WIN32))
2020-08-20 06:41:32 +00:00
( void ) format ;
2007-05-14 09:55:24 +00:00
/* Can't run this test on Win32 so return. */
return ;
2017-04-12 07:11:06 +00:00
# else
2020-08-20 06:41:32 +00:00
SNDFILE * file ;
SF_INFO sfinfo ;
struct stat buf ;
const char * filename = " /dev/full " , * errorstr ;
2007-05-14 09:55:24 +00:00
2006-11-19 01:22:45 +00:00
/* Make sure errno is zero before doing anything else. */
errno = 0 ;
2007-05-14 09:55:24 +00:00
print_test_name ( " filesystem_full_test " , filename ) ;
if ( stat ( filename , & buf ) ! = 0 )
{ puts ( " /dev/full missing " ) ;
return ;
} ;
if ( S_ISCHR ( buf . st_mode ) = = 0 & & S_ISBLK ( buf . st_mode ) = = 0 )
{ puts ( " /dev/full is not a device file " ) ;
return ;
} ;
2004-02-08 10:18:12 +00:00
sfinfo . samplerate = 44100 ;
2008-07-29 23:32:26 +00:00
sfinfo . format = format ;
2004-04-01 02:54:09 +00:00
sfinfo . channels = 1 ;
sfinfo . frames = 0 ;
2007-05-14 09:55:24 +00:00
if ( ( file = sf_open ( filename , SFM_WRITE , & sfinfo ) ) ! = NULL )
{ printf ( " \n \n Line %d : Error, file should not have openned. \n " , __LINE__ - 1 ) ;
exit ( 1 ) ;
} ;
errorstr = sf_strerror ( file ) ;
if ( strstr ( errorstr , " space " ) = = NULL | | strstr ( errorstr , " device " ) = = NULL )
{ printf ( " \n \n Line %d : Error bad error string : %s. \n " , __LINE__ - 1 , errorstr ) ;
exit ( 1 ) ;
} ;
puts ( " ok " ) ;
2017-04-12 07:11:06 +00:00
# endif
2007-05-14 09:55:24 +00:00
} /* filesystem_full_test */
static void
permission_test ( const char * filename , int typemajor )
2004-05-10 11:41:28 +00:00
{
# if (OS_IS_WIN32)
/* Avoid compiler warnings. */
2020-08-31 11:48:35 +00:00
( void ) filename ;
( void ) typemajor ;
2004-05-10 11:41:28 +00:00
/* Can't run this test on Win32 so return. */
return ;
# else
FILE * textfile ;
2007-05-14 09:55:24 +00:00
SNDFILE * file ;
SF_INFO sfinfo ;
const char * errorstr ;
2006-11-19 01:22:45 +00:00
/* Make sure errno is zero before doing anything else. */
errno = 0 ;
2007-05-14 09:55:24 +00:00
if ( getuid ( ) = = 0 )
{ /* If running as root bypass this test.
* * Root is allowed to open a readonly file for write .
*/
return ;
} ;
print_test_name ( " permission_test " , filename ) ;
2006-11-05 08:38:29 +00:00
if ( access ( filename , F_OK ) = = 0 )
{ chmod ( filename , S_IWUSR ) ;
unlink ( filename ) ;
} ;
2007-05-14 09:55:24 +00:00
if ( ( textfile = fopen ( filename , " w " ) ) = = NULL )
{ printf ( " \n \n Line %d : not able to open text file for write. \n " , __LINE__ ) ;
exit ( 1 ) ;
} ;
fprintf ( textfile , " This is a read only file. \n " ) ;
fclose ( textfile ) ;
if ( chmod ( filename , S_IRUSR | S_IRGRP ) )
{ printf ( " \n \n Line %d : chmod failed " , __LINE__ ) ;
fflush ( stdout ) ;
perror ( " " ) ;
exit ( 1 ) ;
} ;
2004-02-08 10:18:12 +00:00
sfinfo . samplerate = 44100 ;
2004-04-01 02:54:09 +00:00
sfinfo . format = ( typemajor | SF_FORMAT_PCM_16 ) ;
sfinfo . channels = 1 ;
sfinfo . frames = 0 ;
2007-05-14 09:55:24 +00:00
if ( ( file = sf_open ( filename , SFM_WRITE , & sfinfo ) ) ! = NULL )
{ printf ( " \n \n Line %d : Error, file should not have opened. \n " , __LINE__ - 1 ) ;
exit ( 1 ) ;
} ;
errorstr = sf_strerror ( file ) ;
if ( strstr ( errorstr , " ermission denied " ) = = NULL )
{ printf ( " \n \n Line %d : Error bad error string : %s. \n " , __LINE__ - 1 , errorstr ) ;
exit ( 1 ) ;
} ;
if ( chmod ( filename , S_IWUSR | S_IWGRP ) )
{ printf ( " \n \n Line %d : chmod failed " , __LINE__ ) ;
fflush ( stdout ) ;
perror ( " " ) ;
exit ( 1 ) ;
} ;
unlink ( filename ) ;
puts ( " ok " ) ;
2004-05-10 11:41:28 +00:00
# endif
2007-05-14 09:55:24 +00:00
} /* permission_test */
2008-07-03 10:29:42 +00:00
static void
wavex_amb_test ( const char * filename )
{ static short buffer [ 800 ] ;
SNDFILE * file ;
SF_INFO sfinfo ;
sf_count_t frames ;
print_test_name ( __func__ , filename ) ;
sfinfo . samplerate = 44100 ;
sfinfo . format = SF_FORMAT_WAVEX | SF_FORMAT_PCM_16 ;
sfinfo . channels = 4 ;
frames = ARRAY_LEN ( buffer ) / sfinfo . channels ;
file = test_open_file_or_die ( filename , SFM_WRITE , & sfinfo , SF_TRUE , __LINE__ ) ;
sf_command ( file , SFC_WAVEX_SET_AMBISONIC , NULL , SF_AMBISONIC_B_FORMAT ) ;
test_writef_short_or_die ( file , 0 , buffer , frames , __LINE__ ) ;
sf_close ( file ) ;
memset ( & sfinfo , 0 , sizeof ( sfinfo ) ) ;
file = test_open_file_or_die ( filename , SFM_READ , & sfinfo , SF_TRUE , __LINE__ ) ;
exit_if_true (
sf_command ( file , SFC_WAVEX_GET_AMBISONIC , NULL , 0 ) ! = SF_AMBISONIC_B_FORMAT ,
" \n \n Line %d : Error, this file should be in Ambisonic B format. \n " , __LINE__
) ;
sf_close ( file ) ;
unlink ( filename ) ;
puts ( " ok " ) ;
} /* wavex_amb_test */
2015-10-20 08:43:37 +00:00
static void
rf64_downgrade_test ( const char * filename )
{ static short output [ BUFFER_LEN ] ;
static short input [ BUFFER_LEN ] ;
SNDFILE * file ;
SF_INFO sfinfo ;
unsigned k ;
print_test_name ( __func__ , filename ) ;
sf_info_clear ( & sfinfo ) ;
sfinfo . samplerate = 44100 ;
sfinfo . frames = ARRAY_LEN ( output ) ;
sfinfo . channels = 1 ;
sfinfo . format = SF_FORMAT_RF64 | SF_FORMAT_PCM_16 ;
file = test_open_file_or_die ( filename , SFM_WRITE , & sfinfo , SF_TRUE , __LINE__ ) ;
exit_if_true ( sf_command ( file , SFC_RF64_AUTO_DOWNGRADE , NULL , SF_FALSE ) ! = SF_FALSE , " \n \n Line %d: sf_command failed. \n " , __LINE__ ) ;
exit_if_true ( sf_command ( file , SFC_RF64_AUTO_DOWNGRADE , NULL , SF_TRUE ) ! = SF_TRUE , " \n \n Line %d: sf_command failed. \n " , __LINE__ ) ;
test_write_short_or_die ( file , 0 , output , ARRAY_LEN ( output ) , __LINE__ ) ;
exit_if_true ( sf_command ( file , SFC_RF64_AUTO_DOWNGRADE , NULL , SF_FALSE ) ! = SF_TRUE , " \n \n Line %d: sf_command failed. \n " , __LINE__ ) ;
exit_if_true ( sf_command ( file , SFC_RF64_AUTO_DOWNGRADE , NULL , SF_TRUE ) ! = SF_TRUE , " \n \n Line %d: sf_command failed. \n " , __LINE__ ) ;
sf_close ( file ) ;
memset ( input , 0 , sizeof ( input ) ) ;
sf_info_clear ( & sfinfo ) ;
file = test_open_file_or_die ( filename , SFM_READ , & sfinfo , SF_TRUE , __LINE__ ) ;
exit_if_true ( sfinfo . format ! = ( SF_FORMAT_WAVEX | SF_FORMAT_PCM_16 ) , " \n \n Line %d: RF64 to WAV downgrade failed. \n " , __LINE__ ) ;
exit_if_true ( sfinfo . frames ! = ARRAY_LEN ( output ) , " \n \n Line %d: Incorrect number of frames in file (too short). (%d should be %d) \n " , __LINE__ , ( int ) sfinfo . frames , ( int ) ARRAY_LEN ( output ) ) ;
exit_if_true ( sfinfo . channels ! = 1 , " \n \n Line %d: Incorrect number of channels in file. \n " , __LINE__ ) ;
check_log_buffer_or_die ( file , __LINE__ ) ;
test_read_short_or_die ( file , 0 , input , ARRAY_LEN ( input ) , __LINE__ ) ;
sf_close ( file ) ;
for ( k = 0 ; k < ARRAY_LEN ( input ) ; k + + )
exit_if_true ( input [ k ] ! = output [ k ] ,
" \n \n Line: %d: Error on input %d, expected %d, got %d \n " , __LINE__ , k , output [ k ] , input [ k ] ) ;
puts ( " ok " ) ;
unlink ( filename ) ;
return ;
} /* rf64_downgrade_test */
2017-04-16 00:44:28 +00:00
static void
rf64_long_file_downgrade_test ( const char * filename )
{ static int output [ BUFFER_LEN ] ;
2017-04-18 10:07:03 +00:00
static int input [ 1 ] = { 0 } ;
2017-04-16 00:44:28 +00:00
SNDFILE * file ;
SF_INFO sfinfo ;
2017-04-18 10:07:03 +00:00
sf_count_t output_frames = 0 ;
2017-04-16 00:44:28 +00:00
print_test_name ( __func__ , filename ) ;
sf_info_clear ( & sfinfo ) ;
2017-04-18 10:07:03 +00:00
memset ( output , 0 , sizeof ( output ) ) ;
output [ 0 ] = 0x1020304 ;
2017-04-16 00:44:28 +00:00
sfinfo . samplerate = 44100 ;
sfinfo . frames = ARRAY_LEN ( output ) ;
sfinfo . channels = 1 ;
sfinfo . format = SF_FORMAT_RF64 | SF_FORMAT_PCM_32 ;
file = test_open_file_or_die ( filename , SFM_WRITE , & sfinfo , SF_TRUE , __LINE__ ) ;
exit_if_true ( sf_command ( file , SFC_RF64_AUTO_DOWNGRADE , NULL , SF_TRUE ) ! = SF_TRUE , " \n \n Line %d: sf_command failed. \n " , __LINE__ ) ;
while ( output_frames * sizeof ( output [ 0 ] ) < 0x100000000 )
{ test_write_int_or_die ( file , 0 , output , ARRAY_LEN ( output ) , __LINE__ ) ;
output_frames + = ARRAY_LEN ( output ) ;
} ;
sf_close ( file ) ;
sf_info_clear ( & sfinfo ) ;
file = test_open_file_or_die ( filename , SFM_READ , & sfinfo , SF_TRUE , __LINE__ ) ;
exit_if_true ( sfinfo . format ! = ( SF_FORMAT_RF64 | SF_FORMAT_PCM_32 ) , " \n \n Line %d: RF64 to WAV downgrade should have failed. \n " , __LINE__ ) ;
exit_if_true ( sfinfo . channels ! = 1 , " \n \n Line %d: Incorrect number of channels in file. \n " , __LINE__ ) ;
exit_if_true ( sfinfo . frames ! = output_frames , " \n \n Line %d: Incorrect number of frames in file (%d should be %d). \n " , __LINE__ , ( int ) sfinfo . frames , ( int ) output_frames ) ;
2017-04-18 10:07:03 +00:00
/* Check that the first sample read is the same as the first written. */
test_read_int_or_die ( file , 0 , input , ARRAY_LEN ( input ) , __LINE__ ) ;
exit_if_true ( input [ 0 ] ! = output [ 0 ] , " \n \n Line %d: Bad first sample (0x%08x). \n " , __LINE__ , input [ 0 ] ) ;
2017-04-16 00:44:28 +00:00
check_log_buffer_or_die ( file , __LINE__ ) ;
sf_close ( file ) ;
puts ( " ok " ) ;
unlink ( filename ) ;
return ;
} /* rf64_long_file_downgrade_test */