From 0e46fbf73c569d4c92206e714e8b9c7d92256b5d Mon Sep 17 00:00:00 2001 From: Erik de Castro Lopo Date: Wed, 19 May 2004 13:23:52 +0000 Subject: [PATCH] Fix UPDATE_HEADER_AUTO corner case bug. --- ChangeLog | 15 +++ src/sndfile.c | 48 +++---- tests/Makefile.am | 34 ++++- tests/header_test.tpl | 297 ++++++++++-------------------------------- tests/misc_test.c | 159 +++------------------- 5 files changed, 155 insertions(+), 398 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5197a126..cde908ae 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2004-05-19 Erik de Castro Lopo + + * src/sndfile.c + Fix another weird corner case bug found by Martin Rumori. Thanks. + + * tests/header_test.(tpl|def) + Two new files to test for the absence of the above bug and include tests + moved from tests/misc_test.c. + + * tests/Makefile.am + Hook new tests into build/test system. + + * tests/misc_test.c + Remove update_header_test() which has been moved to the new files above. + 2004-05-16 Erik de Castro Lopo * src/aiff.c diff --git a/src/sndfile.c b/src/sndfile.c index eeb7d303..700c37c6 100644 --- a/src/sndfile.c +++ b/src/sndfile.c @@ -1589,14 +1589,14 @@ sf_write_short (SNDFILE *sndfile, short *ptr, sf_count_t len) psf->write_current += count / psf->sf.channels ; - if (psf->write_current > psf->sf.frames) - psf->sf.frames = psf->write_current ; - psf->last_op = SFM_WRITE ; if (psf->auto_header) psf->write_header (psf, SF_TRUE) ; + if (psf->write_current > psf->sf.frames) + psf->sf.frames = psf->write_current ; + return count ; } /* sf_write_short */ @@ -1629,14 +1629,14 @@ sf_writef_short (SNDFILE *sndfile, short *ptr, sf_count_t frames) psf->write_current += count / psf->sf.channels ; - if (psf->write_current > psf->sf.frames) - psf->sf.frames = psf->write_current ; - psf->last_op = SFM_WRITE ; if (psf->auto_header) psf->write_header (psf, SF_TRUE) ; + if (psf->write_current > psf->sf.frames) + psf->sf.frames = psf->write_current ; + return count / psf->sf.channels ; } /* sf_writef_short */ @@ -1677,14 +1677,14 @@ sf_write_int (SNDFILE *sndfile, int *ptr, sf_count_t len) psf->write_current += count / psf->sf.channels ; - if (psf->write_current > psf->sf.frames) - psf->sf.frames = psf->write_current ; - psf->last_op = SFM_WRITE ; if (psf->auto_header) psf->write_header (psf, SF_TRUE) ; + if (psf->write_current > psf->sf.frames) + psf->sf.frames = psf->write_current ; + return count ; } /* sf_write_int */ @@ -1717,14 +1717,14 @@ sf_writef_int (SNDFILE *sndfile, int *ptr, sf_count_t frames) psf->write_current += count / psf->sf.channels ; - if (psf->write_current > psf->sf.frames) - psf->sf.frames = psf->write_current ; - psf->last_op = SFM_WRITE ; if (psf->auto_header) psf->write_header (psf, SF_TRUE) ; + if (psf->write_current > psf->sf.frames) + psf->sf.frames = psf->write_current ; + return count / psf->sf.channels ; } /* sf_writef_int */ @@ -1765,14 +1765,14 @@ sf_write_float (SNDFILE *sndfile, float *ptr, sf_count_t len) psf->write_current += count / psf->sf.channels ; - if (psf->write_current > psf->sf.frames) - psf->sf.frames = psf->write_current ; - psf->last_op = SFM_WRITE ; if (psf->auto_header) psf->write_header (psf, SF_TRUE) ; + if (psf->write_current > psf->sf.frames) + psf->sf.frames = psf->write_current ; + return count ; } /* sf_write_float */ @@ -1805,14 +1805,14 @@ sf_writef_float (SNDFILE *sndfile, float *ptr, sf_count_t frames) psf->write_current += count / psf->sf.channels ; - if (psf->write_current > psf->sf.frames) - psf->sf.frames = psf->write_current ; - psf->last_op = SFM_WRITE ; if (psf->auto_header) psf->write_header (psf, SF_TRUE) ; + if (psf->write_current > psf->sf.frames) + psf->sf.frames = psf->write_current ; + return count / psf->sf.channels ; } /* sf_writef_float */ @@ -1853,14 +1853,14 @@ sf_write_double (SNDFILE *sndfile, double *ptr, sf_count_t len) psf->write_current += count / psf->sf.channels ; - if (psf->write_current > psf->sf.frames) - psf->sf.frames = psf->write_current ; - psf->last_op = SFM_WRITE ; if (psf->auto_header) psf->write_header (psf, SF_TRUE) ; + if (psf->write_current > psf->sf.frames) + psf->sf.frames = psf->write_current ; + return count ; } /* sf_write_double */ @@ -1893,14 +1893,14 @@ sf_writef_double (SNDFILE *sndfile, double *ptr, sf_count_t frames) psf->write_current += count / psf->sf.channels ; - if (psf->write_current > psf->sf.frames) - psf->sf.frames = psf->write_current ; - psf->last_op = SFM_WRITE ; if (psf->auto_header) psf->write_header (psf, SF_TRUE) ; + if (psf->write_current > psf->sf.frames) + psf->sf.frames = psf->write_current ; + return count / psf->sf.channels ; } /* sf_writef_double */ diff --git a/tests/Makefile.am b/tests/Makefile.am index 42cd7821..0ce47c59 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -3,8 +3,8 @@ noinst_PROGRAMS = sfversion floating_point_test write_read_test \ lossy_comp_test error_test ulaw_test alaw_test dwvw_test \ peak_chunk_test command_test stdin_test stdout_test stdio_test \ - pcm_test headerless_test pipe_test benchmark misc_test raw_test \ - string_test open_fail_test multi_file_test dither_test \ + pcm_test headerless_test pipe_test benchmark header_test misc_test \ + raw_test string_test open_fail_test multi_file_test dither_test \ scale_clip_test win32_test fix_this aiff_rw_test SNDFILEDIR = ../src @@ -13,6 +13,7 @@ noinst_HEADERS = dft_cmp.h utils.h autogen_sources = write_read_test.tpl write_read_test.def \ pcm_test.tpl pcm_test.def \ + header_test.tpl header_test.def \ utils.tpl utils.def \ command_test.tpl command_test.def \ scale_clip_test.tpl scale_clip_test.def \ @@ -71,6 +72,9 @@ pipe_test_LDADD = $(SNDFILEDIR)/libsndfile.la benchmark_SOURCES = benchmark.c benchmark_LDADD = $(SNDFILEDIR)/libsndfile.la +header_test_SOURCES = header_test.c utils.c +header_test_LDADD = $(SNDFILEDIR)/libsndfile.la + misc_test_SOURCES = misc_test.c utils.c misc_test_LDADD = $(SNDFILEDIR)/libsndfile.la @@ -114,6 +118,9 @@ write_read_test.c: write_read_test.def write_read_test.tpl pcm_test.c: pcm_test.def pcm_test.tpl autogen --writable --source-time pcm_test.def +header_test.c: header_test.def header_test.tpl + autogen --writable --source-time header_test.def + utils.c: utils.def utils.tpl autogen --writable --source-time utils.def @@ -155,7 +162,7 @@ generic-tests : error_test$(EXEEXT) ulaw_test$(EXEEXT) alaw_test$(EXEEXT) comman @echo " `./sfversion$(EXEEXT)` passed common tests." @echo "----------------------------------------------------------------------" -wav-tests: write_read_test$(EXEEXT) lossy_comp_test$(EXEEXT) peak_chunk_test$(EXEEXT) misc_test$(EXEEXT) multi_file_test$(EXEEXT) +wav-tests: write_read_test$(EXEEXT) lossy_comp_test$(EXEEXT) peak_chunk_test$(EXEEXT) header_test$(EXEEXT) misc_test$(EXEEXT) multi_file_test$(EXEEXT) ./write_read_test$(EXEEXT) wav ./lossy_comp_test$(EXEEXT) wav_ima ./lossy_comp_test$(EXEEXT) wav_msadpcm @@ -163,6 +170,7 @@ wav-tests: write_read_test$(EXEEXT) lossy_comp_test$(EXEEXT) peak_chunk_test$(EX ./lossy_comp_test$(EXEEXT) wav_alaw ./lossy_comp_test$(EXEEXT) wav_gsm610 ./peak_chunk_test$(EXEEXT) wav + ./header_test$(EXEEXT) wav ./misc_test$(EXEEXT) wav ./string_test$(EXEEXT) wav ./multi_file_test$(EXEEXT) wav @@ -171,7 +179,7 @@ wav-tests: write_read_test$(EXEEXT) lossy_comp_test$(EXEEXT) peak_chunk_test$(EX @echo " `./sfversion$(EXEEXT)` passed tests on WAV files." @echo "----------------------------------------------------------------------" -aiff-tests: write_read_test$(EXEEXT) lossy_comp_test$(EXEEXT) peak_chunk_test$(EXEEXT) misc_test$(EXEEXT) aiff_rw_test$(EXEEXT) +aiff-tests: write_read_test$(EXEEXT) lossy_comp_test$(EXEEXT) peak_chunk_test$(EXEEXT) header_test$(EXEEXT) misc_test$(EXEEXT) aiff_rw_test$(EXEEXT) ./write_read_test$(EXEEXT) aiff ./lossy_comp_test$(EXEEXT) aiff_ulaw ./lossy_comp_test$(EXEEXT) aiff_alaw @@ -180,6 +188,7 @@ aiff-tests: write_read_test$(EXEEXT) lossy_comp_test$(EXEEXT) peak_chunk_test$(E @echo "./lossy_comp_test$(EXEEXT) aiff_ima" @echo "==========================" ./peak_chunk_test$(EXEEXT) aiff + ./header_test$(EXEEXT) aiff ./misc_test$(EXEEXT) aiff ./string_test$(EXEEXT) aiff ./multi_file_test$(EXEEXT) aiff @@ -188,12 +197,13 @@ aiff-tests: write_read_test$(EXEEXT) lossy_comp_test$(EXEEXT) peak_chunk_test$(E @echo " `./sfversion$(EXEEXT)` passed tests on AIFF files." @echo "----------------------------------------------------------------------" -au-tests: write_read_test$(EXEEXT) lossy_comp_test$(EXEEXT) misc_test$(EXEEXT) +au-tests: write_read_test$(EXEEXT) lossy_comp_test$(EXEEXT) header_test$(EXEEXT) misc_test$(EXEEXT) ./write_read_test$(EXEEXT) au ./lossy_comp_test$(EXEEXT) au_ulaw ./lossy_comp_test$(EXEEXT) au_alaw ./lossy_comp_test$(EXEEXT) au_g721 ./lossy_comp_test$(EXEEXT) au_g723 + ./header_test$(EXEEXT) au ./misc_test$(EXEEXT) au ./multi_file_test$(EXEEXT) wav @echo "----------------------------------------------------------------------" @@ -217,6 +227,7 @@ w64-tests: write_read_test$(EXEEXT) lossy_comp_test$(EXEEXT) misc_test$(EXEEXT) ./lossy_comp_test$(EXEEXT) w64_ulaw ./lossy_comp_test$(EXEEXT) w64_alaw ./lossy_comp_test$(EXEEXT) w64_gsm610 + ./header_test$(EXEEXT) w64 ./misc_test$(EXEEXT) w64 @echo "----------------------------------------------------------------------" @echo " `./sfversion$(EXEEXT)` passed tests on W64 files." @@ -225,6 +236,7 @@ w64-tests: write_read_test$(EXEEXT) lossy_comp_test$(EXEEXT) misc_test$(EXEEXT) # Lite remove start paf-tests: write_read_test$(EXEEXT) misc_test$(EXEEXT) ./write_read_test$(EXEEXT) paf + ./header_test$(EXEEXT) paf ./misc_test$(EXEEXT) paf @echo "----------------------------------------------------------------------" @echo " `./sfversion$(EXEEXT)` passed tests on PAF files." @@ -232,6 +244,7 @@ paf-tests: write_read_test$(EXEEXT) misc_test$(EXEEXT) svx-tests: write_read_test$(EXEEXT) misc_test$(EXEEXT) ./write_read_test$(EXEEXT) svx + ./header_test$(EXEEXT) svx ./misc_test$(EXEEXT) svx @echo "----------------------------------------------------------------------" @echo " `./sfversion$(EXEEXT)` passed tests on SVX files." @@ -241,6 +254,7 @@ nist-tests: write_read_test$(EXEEXT) lossy_comp_test$(EXEEXT) misc_test$(EXEEXT) ./write_read_test$(EXEEXT) nist ./lossy_comp_test$(EXEEXT) nist_ulaw ./lossy_comp_test$(EXEEXT) nist_alaw + ./header_test$(EXEEXT) nist ./misc_test$(EXEEXT) nist @echo "----------------------------------------------------------------------" @echo " `./sfversion$(EXEEXT)` passed tests on NIST files." @@ -250,6 +264,7 @@ ircam-tests: write_read_test$(EXEEXT) lossy_comp_test$(EXEEXT) misc_test$(EXEEXT ./write_read_test$(EXEEXT) ircam ./lossy_comp_test$(EXEEXT) ircam_ulaw ./lossy_comp_test$(EXEEXT) ircam_alaw + ./header_test$(EXEEXT) ircam ./misc_test$(EXEEXT) ircam @echo "----------------------------------------------------------------------" @echo " `./sfversion$(EXEEXT)` passed tests on IRCAM files." @@ -259,6 +274,7 @@ voc-tests: write_read_test$(EXEEXT) lossy_comp_test$(EXEEXT) misc_test$(EXEEXT) ./write_read_test$(EXEEXT) voc ./lossy_comp_test$(EXEEXT) voc_ulaw ./lossy_comp_test$(EXEEXT) voc_alaw + ./header_test$(EXEEXT) voc ./misc_test$(EXEEXT) voc @echo "----------------------------------------------------------------------" @echo " `./sfversion$(EXEEXT)` passed tests on VOC files." @@ -266,6 +282,7 @@ voc-tests: write_read_test$(EXEEXT) lossy_comp_test$(EXEEXT) misc_test$(EXEEXT) mat4-tests: write_read_test$(EXEEXT) misc_test$(EXEEXT) ./write_read_test$(EXEEXT) mat4 + ./header_test$(EXEEXT) mat4 ./misc_test$(EXEEXT) mat4 @echo "----------------------------------------------------------------------" @echo " `./sfversion$(EXEEXT)` passed tests on MAT4 files." @@ -273,6 +290,7 @@ mat4-tests: write_read_test$(EXEEXT) misc_test$(EXEEXT) mat5-tests: write_read_test$(EXEEXT) misc_test$(EXEEXT) ./write_read_test$(EXEEXT) mat5 + ./header_test$(EXEEXT) mat5 ./misc_test$(EXEEXT) mat5 @echo "----------------------------------------------------------------------" @echo " `./sfversion$(EXEEXT)` passed tests on MAT5 files." @@ -280,6 +298,7 @@ mat5-tests: write_read_test$(EXEEXT) misc_test$(EXEEXT) pvf-tests: write_read_test$(EXEEXT) misc_test$(EXEEXT) ./write_read_test$(EXEEXT) pvf + ./header_test$(EXEEXT) pvf ./misc_test$(EXEEXT) pvf @echo "----------------------------------------------------------------------" @echo " `./sfversion$(EXEEXT)` passed tests on PVF files." @@ -293,6 +312,7 @@ xi-tests: lossy_comp_test$(EXEEXT) htk-tests: write_read_test$(EXEEXT) misc_test$(EXEEXT) ./write_read_test$(EXEEXT) htk + ./header_test$(EXEEXT) htk ./misc_test$(EXEEXT) htk @echo "----------------------------------------------------------------------" @echo " `./sfversion$(EXEEXT)` passed tests on HTK files." @@ -300,6 +320,7 @@ htk-tests: write_read_test$(EXEEXT) misc_test$(EXEEXT) avr-tests: write_read_test$(EXEEXT) misc_test$(EXEEXT) ./write_read_test$(EXEEXT) avr + ./header_test$(EXEEXT) avr ./misc_test$(EXEEXT) avr @echo "----------------------------------------------------------------------" @echo " `./sfversion$(EXEEXT)` passed tests on AVR files." @@ -307,6 +328,7 @@ avr-tests: write_read_test$(EXEEXT) misc_test$(EXEEXT) sds-tests: write_read_test$(EXEEXT) misc_test$(EXEEXT) ./write_read_test$(EXEEXT) sds + ./header_test$(EXEEXT) sds ./misc_test$(EXEEXT) sds @echo "----------------------------------------------------------------------" @echo " `./sfversion$(EXEEXT)` passed tests on SDS files." @@ -321,8 +343,6 @@ stdio-tests: stdio_test$(EXEEXT) stdin_test$(EXEEXT) stdout_test$(EXEEXT) pipe_t @echo " `./sfversion$(EXEEXT)` passed stdio and pipe tests." @echo "----------------------------------------------------------------------" - - ## Do not edit or modify anything in this comment block. ## The arch-tag line is a file identity tag for the GNU Arch ## revision control system. diff --git a/tests/header_test.tpl b/tests/header_test.tpl index 38f7a374..7a3483cd 100644 --- a/tests/header_test.tpl +++ b/tests/header_test.tpl @@ -1,6 +1,6 @@ [+ AutoGen5 template c +] /* -** Copyright (C) 2001-2005 Erik de Castro Lopo +** Copyright (C) 2001-2004 Erik de Castro Lopo ** ** 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 @@ -17,7 +17,7 @@ ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include "sfconfig.h" +#include "config.h" #include #include @@ -26,7 +26,7 @@ #include #include -#if HAVE_UNISTD_H +#ifdef HAVE_UNISTD_H #include #endif @@ -53,8 +53,6 @@ static void update_header_test (const char *filename, int typemajor) ; [+ ENDFOR data_type +] -static void extra_header_test (const char *filename, int filetype) ; - /* Force the start of this buffer to be double aligned. Sparc-solaris will ** choke if its not. */ @@ -83,7 +81,6 @@ main (int argc, char *argv []) update_seek_int_test ("header_int.wav", SF_FORMAT_WAV) ; update_seek_float_test ("header_float.wav", SF_FORMAT_WAV) ; update_seek_double_test ("header_double.wav", SF_FORMAT_WAV) ; - extra_header_test ("extra.wav", SF_FORMAT_WAV) ; test_count++ ; } ; @@ -93,108 +90,71 @@ main (int argc, char *argv []) update_seek_int_test ("header_int.aiff", SF_FORMAT_AIFF) ; update_seek_float_test ("header_float.aiff", SF_FORMAT_AIFF) ; update_seek_double_test ("header_double.aiff", SF_FORMAT_AIFF) ; - extra_header_test ("extra.aiff", SF_FORMAT_AIFF) ; test_count++ ; } ; if (do_all || ! strcmp (argv [1], "au")) { update_header_test ("header.au", SF_FORMAT_AU) ; - update_seek_short_test ("header_short.au", SF_FORMAT_AU) ; - update_seek_int_test ("header_int.au", SF_FORMAT_AU) ; - update_seek_float_test ("header_float.au", SF_FORMAT_AU) ; - update_seek_double_test ("header_double.au", SF_FORMAT_AU) ; - test_count++ ; - } ; - - if (do_all || ! strcmp (argv [1], "caf")) - { update_header_test ("header.caf", SF_FORMAT_CAF) ; - update_seek_short_test ("header_short.caf", SF_FORMAT_CAF) ; - update_seek_int_test ("header_int.caf", SF_FORMAT_CAF) ; - update_seek_float_test ("header_float.caf", SF_FORMAT_CAF) ; - update_seek_double_test ("header_double.caf", SF_FORMAT_CAF) ; - /* extra_header_test ("extra.caf", SF_FORMAT_CAF) ; */ - test_count++ ; - } ; - - if (do_all || ! strcmp (argv [1], "nist")) - { update_header_test ("header.nist", SF_FORMAT_NIST) ; - update_seek_short_test ("header_short.nist", SF_FORMAT_NIST) ; - update_seek_int_test ("header_int.nist", SF_FORMAT_NIST) ; - test_count++ ; - } ; - - if (do_all || ! strcmp (argv [1], "paf")) - { update_header_test ("header.paf", SF_FORMAT_PAF) ; - update_seek_short_test ("header_short.paf", SF_FORMAT_PAF) ; - test_count++ ; - } ; - - if (do_all || ! strcmp (argv [1], "ircam")) - { update_header_test ("header.ircam", SF_FORMAT_IRCAM) ; - update_seek_short_test ("header_short.ircam", SF_FORMAT_IRCAM) ; - test_count++ ; - } ; - - if (do_all || ! strcmp (argv [1], "w64")) - { update_header_test ("header.w64", SF_FORMAT_W64) ; - update_seek_short_test ("header_short.w64", SF_FORMAT_W64) ; - update_seek_int_test ("header_int.w64", SF_FORMAT_W64) ; - update_seek_float_test ("header_float.w64", SF_FORMAT_W64) ; - update_seek_double_test ("header_double.w64", SF_FORMAT_W64) ; - test_count++ ; - } ; - - if (do_all || ! strcmp (argv [1], "mat4")) - { update_header_test ("header.mat4", SF_FORMAT_MAT4) ; - update_seek_short_test ("header_short.mat4", SF_FORMAT_MAT4) ; - update_seek_int_test ("header_int.mat4", SF_FORMAT_MAT4) ; - update_seek_float_test ("header_float.mat4", SF_FORMAT_MAT4) ; - update_seek_double_test ("header_double.mat4", SF_FORMAT_MAT4) ; - test_count++ ; - } ; - - if (do_all || ! strcmp (argv [1], "mat5")) - { update_header_test ("header.mat5", SF_FORMAT_MAT5) ; - update_seek_short_test ("header_short.mat5", SF_FORMAT_MAT5) ; - update_seek_int_test ("header_int.mat5", SF_FORMAT_MAT5) ; - update_seek_float_test ("header_float.mat5", SF_FORMAT_MAT5) ; - update_seek_double_test ("header_double.mat5", SF_FORMAT_MAT5) ; - test_count++ ; - } ; - - if (do_all || ! strcmp (argv [1], "pvf")) - { update_header_test ("header.pvf", SF_FORMAT_PVF) ; - update_seek_short_test ("header_short.pvf", SF_FORMAT_PVF) ; - test_count++ ; - } ; - - if (do_all || ! strcmp (argv [1], "avr")) - { update_header_test ("header.avr", SF_FORMAT_AVR) ; - update_seek_short_test ("header_short.avr", SF_FORMAT_AVR) ; - test_count++ ; - } ; - - if (do_all || ! strcmp (argv [1], "htk")) - { update_header_test ("header.htk", SF_FORMAT_HTK) ; - update_seek_short_test ("header_short.htk", SF_FORMAT_HTK) ; test_count++ ; } ; if (do_all || ! strcmp (argv [1], "svx")) { update_header_test ("header.svx", SF_FORMAT_SVX) ; - update_seek_short_test ("header_short.svx", SF_FORMAT_SVX) ; + test_count++ ; + } ; + + if (do_all || ! strcmp (argv [1], "nist")) + { update_header_test ("header.nist", SF_FORMAT_NIST) ; + test_count++ ; + } ; + + if (do_all || ! strcmp (argv [1], "paf")) + { update_header_test ("header.paf", SF_FORMAT_PAF) ; + test_count++ ; + } ; + + if (do_all || ! strcmp (argv [1], "ircam")) + { update_header_test ("header.ircam", SF_FORMAT_IRCAM) ; test_count++ ; } ; if (do_all || ! strcmp (argv [1], "voc")) { update_header_test ("header.voc", SF_FORMAT_VOC) ; - /*-update_seek_short_test ("header_short.voc", SF_FORMAT_VOC) ;-*/ + test_count++ ; + } ; + + if (do_all || ! strcmp (argv [1], "w64")) + { update_header_test ("header.w64", SF_FORMAT_W64) ; + test_count++ ; + } ; + + if (do_all || ! strcmp (argv [1], "mat4")) + { update_header_test ("header.mat4", SF_FORMAT_MAT4) ; + test_count++ ; + } ; + + if (do_all || ! strcmp (argv [1], "mat5")) + { update_header_test ("header.mat5", SF_FORMAT_MAT5) ; + test_count++ ; + } ; + + if (do_all || ! strcmp (argv [1], "pvf")) + { update_header_test ("header.pvf", SF_FORMAT_PVF) ; + test_count++ ; + } ; + + if (do_all || ! strcmp (argv [1], "htk")) + { update_header_test ("header.htk", SF_FORMAT_HTK) ; + test_count++ ; + } ; + + if (do_all || ! strcmp (argv [1], "avr")) + { update_header_test ("header.avr", SF_FORMAT_AVR) ; test_count++ ; } ; if (do_all || ! strcmp (argv [1], "sds")) { update_header_test ("header.sds", SF_FORMAT_SDS) ; - /*-update_seek_short_test ("header_short.sds", SF_FORMAT_SDS) ;-*/ test_count++ ; } ; @@ -226,7 +186,7 @@ update_header_sub (const char *filename, int typemajor, int write_mode) frames = BUFFER_LEN / sfinfo.channels ; - outfile = test_open_file_or_die (filename, write_mode, &sfinfo, SF_TRUE, __LINE__) ; + outfile = test_open_file_or_die (filename, write_mode, &sfinfo, __LINE__) ; for (k = 0 ; k < BUFFER_LEN ; k++) data_out [k] = k + 1 ; @@ -234,7 +194,7 @@ update_header_sub (const char *filename, int typemajor, int write_mode) if (typemajor != SF_FORMAT_HTK) { /* The HTK header is not correct when the file is first written. */ - infile = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; + infile = test_open_file_or_die (filename, SFM_READ, &sfinfo, __LINE__) ; sf_close (infile) ; } ; @@ -244,8 +204,8 @@ update_header_sub (const char *filename, int typemajor, int write_mode) ** Open file and check log buffer for an error. If header update failed ** the the log buffer will contain errors. */ - infile = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; - check_log_buffer_or_die (infile, __LINE__) ; + infile = test_open_file_or_die (filename, SFM_READ, &sfinfo, __LINE__) ; + check_log_buffer_or_die (infile) ; if (sfinfo.frames < BUFFER_LEN || sfinfo.frames > BUFFER_LEN + 50) { printf ("\n\nLine %d : Incorrect sample count (%ld should be %d)\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), BUFFER_LEN) ; @@ -269,8 +229,8 @@ update_header_sub (const char *filename, int typemajor, int write_mode) test_write_int_or_die (outfile, 0, data_out, BUFFER_LEN, __LINE__) ; /* Open file again and make sure no errors in log buffer. */ - infile = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; - check_log_buffer_or_die (infile, __LINE__) ; + infile = test_open_file_or_die (filename, SFM_READ, &sfinfo, __LINE__) ; + check_log_buffer_or_die (infile) ; if (sfinfo.frames < 2 * BUFFER_LEN || sfinfo.frames > 2 * BUFFER_LEN + 50) { printf ("\n\nLine %d : Incorrect sample count (%ld should be %d)\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), 2 * BUFFER_LEN) ; @@ -290,7 +250,7 @@ update_header_test (const char *filename, int typemajor) { print_test_name ("update_header_test", filename) ; -#if 0 /*-(OS_IS_WIN32 == 0)-*/ +#if (defined (WIN32) || defined (_WIN32)) if (typemajor == SF_FORMAT_PAF) { /* ** I think this is a bug in the win32 file I/O code in src/file_io.c. @@ -313,39 +273,35 @@ update_header_test (const char *filename, int typemajor) */ [+ FOR data_type -+]static void -update_seek_[+ (get "name") +]_test (const char *filename, int filetype) -{ SNDFILE *outfile, *infile ; ++]static void update_seek_[+ (get "name") +]_test (const char *filename, int filetype) +{ SNDFILE *file ; SF_INFO sfinfo ; sf_count_t frames ; - [+ (get "name") +] buffer [8] ; + [+ (get "name") +] buffer [16] ; int k ; print_test_name ("update_seek_[+ (get "name") +]_test", filename) ; memset (buffer, 0, sizeof (buffer)) ; - /* Create sound outfile with no data. */ + /* Create sound file with no data. */ sfinfo.format = filetype | [+ (get "format") +] ; sfinfo.samplerate = 48000 ; sfinfo.channels = 2 ; - if (sf_format_check (&sfinfo) == SF_FALSE) - sfinfo.channels = 1 ; - - outfile = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; - sf_close (outfile) ; + file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, __LINE__) ; + sf_close (file) ; /* Open again for read/write. */ - outfile = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, SF_TRUE, __LINE__) ; + file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, __LINE__) ; /* ** In auto header update mode, seeking to the end of the file with ** SEEK_SET will fail from the 2nd seek on. seeking to 0, SEEK_END ** will seek to 0 anyway */ - if (sf_command (outfile, SFC_SET_UPDATE_HEADER_AUTO, NULL, SF_TRUE) == 0) - { printf ("\n\nError : sf_command (SFC_SET_UPDATE_HEADER_AUTO) return error : %s\n\n", sf_strerror (outfile)) ; + if (sf_command (file, SFC_SET_UPDATE_HEADER_AUTO, NULL, SF_TRUE) == 0) + { printf ("\n\nError : sf_command (SFC_SET_UPDATE_HEADER_AUTO) return error : %s\n\n", sf_strerror (file)) ; exit (1) ; } ; @@ -353,27 +309,16 @@ update_seek_[+ (get "name") +]_test (const char *filename, int filetype) frames = ARRAY_LEN (buffer) / sfinfo.channels ; for (k = 0 ; k < 6 ; k++) - { test_seek_or_die (outfile, k * frames, SEEK_SET, k * frames, sfinfo.channels, __LINE__) ; - test_seek_or_die (outfile, 0, SEEK_END, k * frames, sfinfo.channels, __LINE__) ; - - /* Open file again and make sure no errors in log buffer. */ - infile = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; - check_log_buffer_or_die (infile, __LINE__) ; - sf_close (infile) ; - - if (sfinfo.frames != k * frames) - { printf ("\n\nLine %d : Incorrect sample count (%ld should be %ld)\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), SF_COUNT_TO_LONG (k + frames)) ; - dump_log_buffer (infile) ; - exit (1) ; - } ; + { test_seek_or_die (file, k * frames, SEEK_SET, k * frames, sfinfo.channels, __LINE__) ; + test_seek_or_die (file, 0, SEEK_END, k * frames, sfinfo.channels, __LINE__) ; if ((k & 1) == 0) - test_write_[+ (get "name") +]_or_die (outfile, k, buffer, sfinfo.channels * frames, __LINE__) ; + test_write_[+ (get "name") +]_or_die (file, k, buffer, sfinfo.channels * frames, __LINE__) ; else - test_writef_[+ (get "name") +]_or_die (outfile, k, buffer, frames, __LINE__) ; + test_writef_[+ (get "name") +]_or_die (file, k, buffer, frames, __LINE__) ; } ; - sf_close (outfile) ; + sf_close (file) ; unlink (filename) ; puts ("ok") ; @@ -383,110 +328,6 @@ update_seek_[+ (get "name") +]_test (const char *filename, int filetype) +] - - - -static void -extra_header_test (const char *filename, int filetype) -{ SNDFILE *outfile, *infile ; - SF_INFO sfinfo ; - sf_count_t frames ; - short buffer [8] ; - int k = 0 ; - - print_test_name ("extra_header_test", filename) ; - - sfinfo.samplerate = 44100 ; - sfinfo.format = (filetype | SF_FORMAT_PCM_16) ; - sfinfo.channels = 1 ; - - memset (buffer, 0xA0, sizeof (buffer)) ; - - /* Now write some frames. */ - frames = ARRAY_LEN (buffer) / sfinfo.channels ; - - /* Test the file with extra header data. */ - outfile = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, [+ (tpl-file-line "%2$d") +]) ; - sf_set_string (outfile, SF_STR_TITLE, filename) ; - test_writef_short_or_die (outfile, k, buffer, frames, [+ (tpl-file-line "%2$d") +]) ; - sf_set_string (outfile, SF_STR_COPYRIGHT, "(c) 1980 Erik") ; - sf_close (outfile) ; - -#if 1 - /* - ** Erik de Castro Lopo May 23 2004. - ** - ** This file has extra string data in the header and therefore cannot - ** currently be opened in SFM_RDWR mode. This is fixable, but its in - ** a part of the code I don't want to fiddle with until the Ogg/Vorbis - ** integration is done. - */ - - if ((infile = sf_open (filename, SFM_RDWR, &sfinfo)) != NULL) - { printf ("\n\nError : should not be able to open this file in SFM_RDWR.\n\n") ; - exit (1) ; - } ; - - unlink (filename) ; - puts ("ok") ; - return ; -#else - - hexdump_file (filename, 0, 100000) ; - - /* Open again for read/write. */ - outfile = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, [+ (tpl-file-line "%2$d") +]) ; - - /* - ** In auto header update mode, seeking to the end of the file with - ** SEEK_SET will fail from the 2nd seek on. seeking to 0, SEEK_END - ** will seek to 0 anyway - */ - if (sf_command (outfile, SFC_SET_UPDATE_HEADER_AUTO, NULL, SF_TRUE) == 0) - { printf ("\n\nError : sf_command (SFC_SET_UPDATE_HEADER_AUTO) return error : %s\n\n", sf_strerror (outfile)) ; - exit (1) ; - } ; - - /* Now write some frames. */ - frames = ARRAY_LEN (buffer) / sfinfo.channels ; - - for (k = 1 ; k < 6 ; k++) - { - printf ("\n*** pass %d\n", k) ; - memset (buffer, 0xA0 + k, sizeof (buffer)) ; - - - test_seek_or_die (outfile, k * frames, SEEK_SET, k * frames, sfinfo.channels, [+ (tpl-file-line "%2$d") +]) ; - test_seek_or_die (outfile, 0, SEEK_END, k * frames, sfinfo.channels, [+ (tpl-file-line "%2$d") +]) ; - - /* Open file again and make sure no errors in log buffer. */ - if (0) - { infile = test_open_file_or_die (filename, SFM_READ, &sfinfo, [+ (tpl-file-line "%2$d") +]) ; - check_log_buffer_or_die (infile, [+ (tpl-file-line "%2$d") +]) ; - sf_close (infile) ; - } ; - - if (sfinfo.frames != k * frames) - { printf ("\n\nLine %d : Incorrect sample count (%ld should be %ld)\n", [+ (tpl-file-line "%2$d") +], SF_COUNT_TO_LONG (sfinfo.frames), SF_COUNT_TO_LONG (k + frames)) ; - dump_log_buffer (infile) ; - exit (1) ; - } ; - - if ((k & 1) == 0) - test_write_short_or_die (outfile, k, buffer, sfinfo.channels * frames, [+ (tpl-file-line "%2$d") +]) ; - else - test_writef_short_or_die (outfile, k, buffer, frames, [+ (tpl-file-line "%2$d") +]) ; - hexdump_file (filename, 0, 100000) ; - } ; - - sf_close (outfile) ; - unlink (filename) ; - - puts ("ok") ; - return ; -#endif -} /* extra_header_test */ - [+ COMMENT Do not edit or modify anything in this comment block. diff --git a/tests/misc_test.c b/tests/misc_test.c index ae4299df..827c10c1 100644 --- a/tests/misc_test.c +++ b/tests/misc_test.c @@ -1,18 +1,18 @@ /* ** Copyright (C) 2001-2004 Erik de Castro Lopo ** -** This program is free software; you can redistribute it and/or modify +** 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 +** 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 +** 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 +** along with this program ; if not, write to the Free Software ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ @@ -45,17 +45,10 @@ #define BUFFER_LEN (1<<10) #define LOG_BUFFER_SIZE 1024 -static void update_header_test (const char *filename, int typemajor) ; static void zero_data_test (const char *filename, int typemajor) ; static void filesystem_full_test (int typemajor) ; static void permission_test (const char *filename, int typemajor) ; -/* Force the start of this buffer to be double aligned. Sparc-solaris will -** choke if its not. -*/ -static int data_out [BUFFER_LEN] ; -static int data_in [BUFFER_LEN] ; - int main (int argc, char *argv []) { int do_all = 0 ; @@ -73,120 +66,105 @@ main (int argc, char *argv []) do_all=!strcmp (argv [1], "all") ; if (do_all || ! strcmp (argv [1], "wav")) - { update_header_test ("header.wav", SF_FORMAT_WAV) ; - zero_data_test ("zerolen.wav", SF_FORMAT_WAV) ; + { zero_data_test ("zerolen.wav", SF_FORMAT_WAV) ; filesystem_full_test (SF_FORMAT_WAV) ; permission_test ("readonly.wav", SF_FORMAT_WAV) ; test_count++ ; } ; if (do_all || ! strcmp (argv [1], "aiff")) - { update_header_test ("header.aiff", SF_FORMAT_AIFF) ; - zero_data_test ("zerolen.aiff", SF_FORMAT_AIFF) ; + { zero_data_test ("zerolen.aiff", SF_FORMAT_AIFF) ; filesystem_full_test (SF_FORMAT_AIFF) ; permission_test ("readonly.aiff", SF_FORMAT_AIFF) ; test_count++ ; } ; if (do_all || ! strcmp (argv [1], "au")) - { update_header_test ("header.au", SF_FORMAT_AU) ; - zero_data_test ("zerolen.au", SF_FORMAT_AU) ; + { zero_data_test ("zerolen.au", SF_FORMAT_AU) ; filesystem_full_test (SF_FORMAT_AU) ; permission_test ("readonly.au", SF_FORMAT_AU) ; test_count++ ; } ; if (do_all || ! strcmp (argv [1], "svx")) - { update_header_test ("header.svx", SF_FORMAT_SVX) ; - zero_data_test ("zerolen.svx", SF_FORMAT_SVX) ; + { zero_data_test ("zerolen.svx", SF_FORMAT_SVX) ; filesystem_full_test (SF_FORMAT_SVX) ; permission_test ("readonly.svx", SF_FORMAT_SVX) ; test_count++ ; } ; if (do_all || ! strcmp (argv [1], "nist")) - { update_header_test ("header.nist", SF_FORMAT_NIST) ; - zero_data_test ("zerolen.nist", SF_FORMAT_NIST) ; + { zero_data_test ("zerolen.nist", SF_FORMAT_NIST) ; filesystem_full_test (SF_FORMAT_NIST) ; permission_test ("readonly.nist", SF_FORMAT_NIST) ; test_count++ ; } ; if (do_all || ! strcmp (argv [1], "paf")) - { update_header_test ("header.paf", SF_FORMAT_PAF) ; - zero_data_test ("zerolen.paf", SF_FORMAT_PAF) ; + { zero_data_test ("zerolen.paf", SF_FORMAT_PAF) ; filesystem_full_test (SF_FORMAT_PAF) ; permission_test ("readonly.paf", SF_FORMAT_PAF) ; test_count++ ; } ; if (do_all || ! strcmp (argv [1], "ircam")) - { update_header_test ("header.ircam", SF_FORMAT_IRCAM) ; - zero_data_test ("zerolen.ircam", SF_FORMAT_IRCAM) ; + { zero_data_test ("zerolen.ircam", SF_FORMAT_IRCAM) ; filesystem_full_test (SF_FORMAT_IRCAM) ; permission_test ("readonly.ircam", SF_FORMAT_IRCAM) ; test_count++ ; } ; if (do_all || ! strcmp (argv [1], "voc")) - { update_header_test ("header.voc", SF_FORMAT_VOC) ; - zero_data_test ("zerolen.voc", SF_FORMAT_VOC) ; + { zero_data_test ("zerolen.voc", SF_FORMAT_VOC) ; filesystem_full_test (SF_FORMAT_VOC) ; permission_test ("readonly.voc", SF_FORMAT_VOC) ; test_count++ ; } ; if (do_all || ! strcmp (argv [1], "w64")) - { update_header_test ("header.w64", SF_FORMAT_W64) ; - zero_data_test ("zerolen.w64", SF_FORMAT_W64) ; + { zero_data_test ("zerolen.w64", SF_FORMAT_W64) ; filesystem_full_test (SF_FORMAT_W64) ; permission_test ("readonly.w64", SF_FORMAT_W64) ; test_count++ ; } ; if (do_all || ! strcmp (argv [1], "mat4")) - { update_header_test ("header.mat4", SF_FORMAT_MAT4) ; - zero_data_test ("zerolen.mat4", SF_FORMAT_MAT4) ; + { zero_data_test ("zerolen.mat4", SF_FORMAT_MAT4) ; filesystem_full_test (SF_FORMAT_MAT4) ; permission_test ("readonly.mat4", SF_FORMAT_MAT4) ; test_count++ ; } ; if (do_all || ! strcmp (argv [1], "mat5")) - { update_header_test ("header.mat5", SF_FORMAT_MAT5) ; - zero_data_test ("zerolen.mat5", SF_FORMAT_MAT5) ; + { zero_data_test ("zerolen.mat5", SF_FORMAT_MAT5) ; filesystem_full_test (SF_FORMAT_MAT5) ; permission_test ("readonly.mat5", SF_FORMAT_MAT5) ; test_count++ ; } ; if (do_all || ! strcmp (argv [1], "pvf")) - { update_header_test ("header.pvf", SF_FORMAT_PVF) ; - zero_data_test ("zerolen.pvf", SF_FORMAT_PVF) ; + { zero_data_test ("zerolen.pvf", SF_FORMAT_PVF) ; filesystem_full_test (SF_FORMAT_PVF) ; permission_test ("readonly.pvf", SF_FORMAT_PVF) ; test_count++ ; } ; if (do_all || ! strcmp (argv [1], "htk")) - { update_header_test ("header.htk", SF_FORMAT_HTK) ; - zero_data_test ("zerolen.htk", SF_FORMAT_HTK) ; + { zero_data_test ("zerolen.htk", SF_FORMAT_HTK) ; filesystem_full_test (SF_FORMAT_HTK) ; permission_test ("readonly.htk", SF_FORMAT_HTK) ; test_count++ ; } ; if (do_all || ! strcmp (argv [1], "avr")) - { update_header_test ("header.avr", SF_FORMAT_AVR) ; - zero_data_test ("zerolen.avr", SF_FORMAT_AVR) ; + { zero_data_test ("zerolen.avr", SF_FORMAT_AVR) ; filesystem_full_test (SF_FORMAT_AVR) ; permission_test ("readonly.avr", SF_FORMAT_AVR) ; test_count++ ; } ; if (do_all || ! strcmp (argv [1], "sds")) - { update_header_test ("header.sds", SF_FORMAT_SDS) ; - zero_data_test ("zerolen.sds", SF_FORMAT_SDS) ; + { zero_data_test ("zerolen.sds", SF_FORMAT_SDS) ; filesystem_full_test (SF_FORMAT_SDS) ; permission_test ("readonly.sds", SF_FORMAT_SDS) ; test_count++ ; @@ -207,102 +185,6 @@ main (int argc, char *argv []) ** Here are the test functions. */ -static void -update_header_sub (const char *filename, int typemajor, int write_mode) -{ SNDFILE *outfile, *infile ; - SF_INFO sfinfo ; - int k, frames ; - - sfinfo.samplerate = 44100 ; - sfinfo.format = (typemajor | SF_FORMAT_PCM_16) ; - sfinfo.channels = 1 ; - sfinfo.frames = 0 ; - - frames = BUFFER_LEN / sfinfo.channels ; - - outfile = test_open_file_or_die (filename, write_mode, &sfinfo, __LINE__) ; - - for (k = 0 ; k < BUFFER_LEN ; k++) - data_out [k] = k + 1 ; - test_write_int_or_die (outfile, 0, data_out, BUFFER_LEN, __LINE__) ; - - if (typemajor != SF_FORMAT_HTK) - { /* The HTK header is not correct when the file is first written. */ - infile = test_open_file_or_die (filename, SFM_READ, &sfinfo, __LINE__) ; - sf_close (infile) ; - } ; - - sf_command (outfile, SFC_UPDATE_HEADER_NOW, NULL, 0) ; - - /* - ** Open file and check log buffer for an error. If header update failed - ** the the log buffer will contain errors. - */ - infile = test_open_file_or_die (filename, SFM_READ, &sfinfo, __LINE__) ; - check_log_buffer_or_die (infile) ; - - if (sfinfo.frames < BUFFER_LEN || sfinfo.frames > BUFFER_LEN + 50) - { printf ("\n\nLine %d : Incorrect sample count (%ld should be %d)\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), BUFFER_LEN) ; - dump_log_buffer (infile) ; - exit (1) ; - } ; - - test_read_int_or_die (infile, 0, data_in, BUFFER_LEN, __LINE__) ; - for (k = 0 ; k < BUFFER_LEN ; k++) - if (data_out [k] != k + 1) - printf ("Error : line %d\n", __LINE__) ; - - sf_close (infile) ; - - /* Set auto update on. */ - sf_command (outfile, SFC_SET_UPDATE_HEADER_AUTO, NULL, SF_TRUE) ; - - /* Write more data_out. */ - for (k = 0 ; k < BUFFER_LEN ; k++) - data_out [k] = k + 2 ; - test_write_int_or_die (outfile, 0, data_out, BUFFER_LEN, __LINE__) ; - - /* Open file again and make sure no errors in log buffer. */ - infile = test_open_file_or_die (filename, SFM_READ, &sfinfo, __LINE__) ; - check_log_buffer_or_die (infile) ; - - if (sfinfo.frames < 2 * BUFFER_LEN || sfinfo.frames > 2 * BUFFER_LEN + 50) - { printf ("\n\nLine %d : Incorrect sample count (%ld should be %d)\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), 2 * BUFFER_LEN) ; - dump_log_buffer (infile) ; - exit (1) ; - } ; - - sf_close (infile) ; - - sf_close (outfile) ; - - unlink (filename) ; -} /* update_header_sub */ - -static void -update_header_test (const char *filename, int typemajor) -{ - print_test_name ("update_header_test", filename) ; - -#if (defined (WIN32) || defined (_WIN32)) - if (typemajor == SF_FORMAT_PAF) - { /* - ** I think this is a bug in the win32 file I/O code in src/file_io.c. - ** I didn't write that code and I don't have the time to debug and - ** fix it. Patches will gladly be accepted. Erik - */ - puts ("doesn't work on win32") ; - return ; - } ; -#endif - - update_header_sub (filename, typemajor, SFM_WRITE) ; - update_header_sub (filename, typemajor, SFM_RDWR) ; - - unlink (filename) ; - puts ("ok") ; -} /* update_header_test */ - static void zero_data_test (const char *filename, int typemajor) { SNDFILE *file ; @@ -455,10 +337,9 @@ permission_test (const char *filename, int typemajor) #endif } /* permission_test */ - /* ** Do not edit or modify anything in this comment block. -** The arch-tag line is a file identity tag for the GNU Arch +** The arch-tag line is a file identity tag for the GNU Arch ** revision control system. ** ** arch-tag: efc6c227-8881-4a1d-8680-0d1255975267