예제 #1
0
static void
error_value_test (void)
{	static unsigned char aiff_data [0x1b0] =
	{	'F' , 'O' , 'R' , 'M' ,
		0x00, 0x00, 0x01, 0xA8, /* FORM length */

		'A' , 'I' , 'F' , 'C' ,
	} ;

	const char *filename = "error.aiff" ;
	SNDFILE *file ;
	SF_INFO sfinfo ;
	int error_num ;

	print_test_name ("error_value_test", filename) ;

	dump_data_to_file (filename, aiff_data, sizeof (aiff_data)) ;

	file = sf_open (filename, SFM_READ, &sfinfo) ;
	if (file != NULL)
	{	printf ("\n\nLine %d : Should not have been able to open this file.\n\n", __LINE__) ;
		exit (1) ;
	} ;

	if ((error_num = sf_error (NULL)) <= 1 || error_num > 300)
	{	printf ("\n\nLine %d : Should not have had an error number of %d.\n\n", __LINE__, error_num) ;
		exit (1) ;
	} ;

	remove (filename) ;
	puts ("ok") ;
	return ;
} /* error_value_test */
예제 #2
0
int
main (void)
{	const char *filename = "rw.aifc" ;

	print_test_name ("aiff_rw_test", filename) ;

	dump_data_to_file (filename, aifc_data, sizeof (aifc_data)) ;

	rw_test (filename) ;

	unlink (filename) ;

	puts ("ok") ;
	return 0 ;
} /* main */
예제 #3
0
static void
vio_test (const char *fname, int format)
{	static VIO_DATA vio_data ;
	static short data [256] ;

	SF_VIRTUAL_IO vio ;
	SNDFILE * file ;
	SF_INFO sfinfo ;

	print_test_name ("virtual i/o test", fname) ;

	/* Set up pointers to the locally defined functions. */
	vio.get_filelen = vfget_filelen ;
	vio.seek = vfseek ;
	vio.read = vfread ;
	vio.write = vfwrite ;
	vio.tell = vftell ;

	/* Set virtual file offset and length to zero. */
	vio_data.offset = 0 ;
	vio_data.length = 0 ;

	memset (&sfinfo, 0, sizeof (sfinfo)) ;
	sfinfo.format = format ;
	sfinfo.channels = 2 ;
	sfinfo.samplerate = 44100 ;

	if ((file = sf_open_virtual (&vio, SFM_WRITE, &sfinfo, &vio_data)) == NULL)
	{	printf ("\n\nLine %d : sf_open_write failed with error : ", __LINE__) ;
		fflush (stdout) ;
		puts (sf_strerror (NULL)) ;
		exit (1) ;
		} ;

	if (vfget_filelen (&vio_data) < 0)
	{	printf ("\n\nLine %d : vfget_filelen returned negative length.\n\n", __LINE__) ;
		exit (1) ;
		} ;

	gen_short_data (data, ARRAY_LEN (data), 0) ;
	sf_write_short (file, data, ARRAY_LEN (data)) ;

	gen_short_data (data, ARRAY_LEN (data), 1) ;
	sf_write_short (file, data, ARRAY_LEN (data)) ;

	gen_short_data (data, ARRAY_LEN (data), 2) ;
	sf_write_short (file, data, ARRAY_LEN (data)) ;

	sf_close (file) ;

	/* Now test read. */
	memset (&sfinfo, 0, sizeof (sfinfo)) ;

	vio_data.offset = 0 ;

	if ((file = sf_open_virtual (&vio, SFM_READ, &sfinfo, &vio_data)) == NULL)
	{	printf ("\n\nLine %d : sf_open_write failed with error : ", __LINE__) ;
		fflush (stdout) ;
		puts (sf_strerror (NULL)) ;

		dump_data_to_file (fname, vio_data.data, vio_data.length) ;
		exit (1) ;
		} ;


	sf_read_short (file, data, ARRAY_LEN (data)) ;
	check_short_data (data, ARRAY_LEN (data), 0, __LINE__) ;

	sf_read_short (file, data, ARRAY_LEN (data)) ;
	check_short_data (data, ARRAY_LEN (data), 1, __LINE__) ;

	sf_read_short (file, data, ARRAY_LEN (data)) ;
	check_short_data (data, ARRAY_LEN (data), 2, __LINE__) ;

	sf_close (file) ;

	puts ("ok") ;
} /* vio_test */