cannam@85: /* cannam@85: ** Copyright (C) 2003-2011 Erik de Castro Lopo cannam@85: ** cannam@85: ** This program is free software; you can redistribute it and/or modify cannam@85: ** it under the terms of the GNU General Public License as published by cannam@85: ** the Free Software Foundation; either version 2 of the License, or cannam@85: ** (at your option) any later version. cannam@85: ** cannam@85: ** This program is distributed in the hope that it will be useful, cannam@85: ** but WITHOUT ANY WARRANTY; without even the implied warranty of cannam@85: ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the cannam@85: ** GNU General Public License for more details. cannam@85: ** cannam@85: ** You should have received a copy of the GNU General Public License cannam@85: ** along with this program; if not, write to the Free Software cannam@85: ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. cannam@85: */ cannam@85: cannam@85: #include "sfconfig.h" cannam@85: cannam@85: #include cannam@85: #include cannam@85: #include cannam@85: #include cannam@85: cannam@85: #if HAVE_UNISTD_H cannam@85: #include cannam@85: #endif cannam@85: cannam@85: #include cannam@85: cannam@85: #include "utils.h" cannam@85: cannam@85: #define BUFFER_LEN (1 << 10) cannam@85: #define LOG_BUFFER_SIZE 1024 cannam@85: cannam@85: static void string_start_test (const char *filename, int typemajor) ; cannam@85: static void string_start_end_test (const char *filename, int typemajor) ; cannam@85: static void string_multi_set_test (const char *filename, int typemajor) ; cannam@85: static void string_rdwr_test (const char *filename, int typemajor) ; cannam@85: static void string_short_rdwr_test (const char *filename, int typemajor) ; cannam@85: cannam@85: static void software_string_test (const char *filename) ; cannam@85: cannam@85: static int str_count (const char * haystack, const char * needle) ; cannam@85: cannam@85: int cannam@85: main (int argc, char *argv []) cannam@85: { int do_all = 0 ; cannam@85: int test_count = 0 ; cannam@85: cannam@85: if (argc != 2) cannam@85: { printf ("Usage : %s \n", argv [0]) ; cannam@85: printf (" Where is one of the following:\n") ; cannam@85: printf (" wav - test adding strings to WAV files\n") ; cannam@85: printf (" aiff - test adding strings to AIFF files\n") ; cannam@85: printf (" flac - test adding strings to FLAC files\n") ; cannam@85: printf (" ogg - test adding strings to OGG files\n") ; cannam@85: printf (" all - perform all tests\n") ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: do_all =! strcmp (argv [1], "all") ; cannam@85: cannam@85: if (do_all || ! strcmp (argv [1], "wav")) cannam@85: { string_start_end_test ("strings.wav", SF_FORMAT_WAV) ; cannam@85: string_multi_set_test ("multi.wav", SF_FORMAT_WAV) ; cannam@85: string_rdwr_test ("rdwr.wav", SF_FORMAT_WAV) ; cannam@85: string_short_rdwr_test ("short_rdwr.wav", SF_FORMAT_WAV) ; cannam@85: cannam@85: string_start_end_test ("strings.wavex", SF_FORMAT_WAVEX) ; cannam@85: string_multi_set_test ("multi.wavex", SF_FORMAT_WAVEX) ; cannam@85: string_rdwr_test ("rdwr.wavex", SF_FORMAT_WAVEX) ; cannam@85: string_short_rdwr_test ("short_rdwr.wavex", SF_FORMAT_WAVEX) ; cannam@85: cannam@85: string_start_end_test ("strings.rifx", SF_ENDIAN_BIG | SF_FORMAT_WAV) ; cannam@85: string_multi_set_test ("multi.rifx", SF_ENDIAN_BIG | SF_FORMAT_WAV) ; cannam@85: string_rdwr_test ("rdwr.rifx", SF_ENDIAN_BIG | SF_FORMAT_WAV) ; cannam@85: string_short_rdwr_test ("short_rdwr.rifx", SF_ENDIAN_BIG | SF_FORMAT_WAV) ; cannam@85: cannam@85: software_string_test ("software_string.wav") ; cannam@85: test_count++ ; cannam@85: } ; cannam@85: cannam@85: if (do_all || ! strcmp (argv [1], "aiff")) cannam@85: { string_start_end_test ("strings.aiff", SF_FORMAT_AIFF) ; cannam@85: /* cannam@85: string_multi_set_test ("multi.aiff", SF_FORMAT_AIFF) ; cannam@85: string_rdwr_test ("rdwr.aiff", SF_FORMAT_AIFF) ; cannam@85: string_short_rdwr_test ("short_rdwr.aiff", SF_FORMAT_AIFF) ; cannam@85: */ cannam@85: test_count++ ; cannam@85: } ; cannam@85: cannam@85: if (do_all || ! strcmp (argv [1], "flac")) cannam@85: { if (HAVE_EXTERNAL_LIBS) cannam@85: string_start_test ("strings.flac", SF_FORMAT_FLAC) ; cannam@85: else cannam@85: puts (" No FLAC tests because FLAC support was not compiled in.") ; cannam@85: test_count++ ; cannam@85: } ; cannam@85: cannam@85: if (do_all || ! strcmp (argv [1], "ogg")) cannam@85: { if (HAVE_EXTERNAL_LIBS) cannam@85: string_start_test ("vorbis.oga", SF_FORMAT_OGG) ; cannam@85: else cannam@85: puts (" No Ogg/Vorbis tests because Ogg/Vorbis support was not compiled in.") ; cannam@85: test_count++ ; cannam@85: } ; cannam@85: cannam@85: if (do_all || ! strcmp (argv [1], "rf64")) cannam@85: { puts ("\n\n **** String test not working yet for RF64 format. ****\n") ; cannam@85: /* cannam@85: string_start_end_test ("strings.rf64", SF_FORMAT_RF64) ; cannam@85: string_multi_set_test ("multi.rf64", SF_FORMAT_RF64) ; cannam@85: string_rdwr_test ("rdwr.rf64", SF_FORMAT_RF64) ; cannam@85: string_short_rdwr_test ("short_rdwr.rf64", SF_FORMAT_RF64) ; cannam@85: */ cannam@85: test_count++ ; cannam@85: } ; cannam@85: cannam@85: if (test_count == 0) cannam@85: { printf ("Mono : ************************************\n") ; cannam@85: printf ("Mono : * No '%s' test defined.\n", argv [1]) ; cannam@85: printf ("Mono : ************************************\n") ; cannam@85: return 1 ; cannam@85: } ; cannam@85: cannam@85: return 0 ; cannam@85: } /* main */ cannam@85: cannam@85: cannam@85: /*============================================================================================ cannam@85: ** Here are the test functions. cannam@85: */ cannam@85: cannam@85: static const char cannam@85: software [] = "software (libsndfile-X.Y.Z)", cannam@85: artist [] = "The Artist", cannam@85: copyright [] = "Copyright (c) 2001 Artist", cannam@85: comment [] = "Comment goes here!!!", cannam@85: date [] = "2001/01/27", cannam@85: album [] = "The Album", cannam@85: license [] = "The license", cannam@85: title [] = "This is the title", cannam@85: long_title [] = "This is a very long and very boring title for this file", cannam@85: long_artist [] = "The artist who kept on changing its name", cannam@85: genre [] = "The genre", cannam@85: trackno [] = "Track three" ; cannam@85: cannam@85: cannam@85: static short data_out [BUFFER_LEN] ; cannam@85: cannam@85: static void cannam@85: string_start_end_test (const char *filename, int typemajor) cannam@85: { const char *cptr ; cannam@85: SNDFILE *file ; cannam@85: SF_INFO sfinfo ; cannam@85: int errors = 0 ; cannam@85: cannam@85: typemajor = typemajor ; cannam@85: cannam@85: print_test_name ("string_start_end_test", filename) ; cannam@85: cannam@85: sfinfo.samplerate = 44100 ; cannam@85: sfinfo.channels = 1 ; cannam@85: sfinfo.frames = 0 ; cannam@85: sfinfo.format = typemajor | SF_FORMAT_PCM_16 ; cannam@85: cannam@85: file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; cannam@85: cannam@85: /* Write stuff at start of file. */ cannam@85: sf_set_string (file, SF_STR_TITLE, filename) ; cannam@85: sf_set_string (file, SF_STR_SOFTWARE, software) ; cannam@85: sf_set_string (file, SF_STR_ARTIST, artist) ; cannam@85: sf_set_string (file, SF_STR_GENRE, genre) ; cannam@85: sf_set_string (file, SF_STR_TRACKNUMBER, trackno) ; cannam@85: cannam@85: /* Write data to file. */ cannam@85: test_write_short_or_die (file, 0, data_out, BUFFER_LEN, __LINE__) ; cannam@85: test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ; cannam@85: cannam@85: /* Write more stuff at end of file. */ cannam@85: sf_set_string (file, SF_STR_COPYRIGHT, copyright) ; cannam@85: sf_set_string (file, SF_STR_COMMENT, comment) ; cannam@85: sf_set_string (file, SF_STR_DATE, date) ; cannam@85: sf_set_string (file, SF_STR_ALBUM, album) ; cannam@85: sf_set_string (file, SF_STR_LICENSE, license) ; cannam@85: cannam@85: sf_close (file) ; cannam@85: cannam@85: file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; cannam@85: cannam@85: check_log_buffer_or_die (file, __LINE__) ; cannam@85: cannam@85: if (sfinfo.frames != BUFFER_LEN) cannam@85: { printf ("***** Bad frame count %d (should be %d)\n\n", (int) sfinfo.frames, BUFFER_LEN) ; cannam@85: errors ++ ; cannam@85: } ; cannam@85: cannam@85: cptr = sf_get_string (file, SF_STR_TITLE) ; cannam@85: if (cptr == NULL || strcmp (filename, cptr) != 0) cannam@85: { if (errors++ == 0) cannam@85: puts ("\n") ; cannam@85: printf (" Bad filename : %s\n", cptr) ; cannam@85: } ; cannam@85: cannam@85: cptr = sf_get_string (file, SF_STR_COPYRIGHT) ; cannam@85: if (cptr == NULL || strcmp (copyright, cptr) != 0) cannam@85: { if (errors++ == 0) cannam@85: puts ("\n") ; cannam@85: printf (" Bad copyright : %s\n", cptr) ; cannam@85: } ; cannam@85: cannam@85: cptr = sf_get_string (file, SF_STR_SOFTWARE) ; cannam@85: if (cptr == NULL || strstr (cptr, software) != cptr) cannam@85: { if (errors++ == 0) cannam@85: puts ("\n") ; cannam@85: printf (" Bad software : %s\n", cptr) ; cannam@85: } ; cannam@85: cannam@85: if (str_count (cptr, "libsndfile") != 1) cannam@85: { if (errors++ == 0) cannam@85: puts ("\n") ; cannam@85: printf (" Bad software : %s\n", cptr) ; cannam@85: } ; cannam@85: cannam@85: cptr = sf_get_string (file, SF_STR_ARTIST) ; cannam@85: if (cptr == NULL || strcmp (artist, cptr) != 0) cannam@85: { if (errors++ == 0) cannam@85: puts ("\n") ; cannam@85: printf (" Bad artist : %s\n", cptr) ; cannam@85: } ; cannam@85: cannam@85: cptr = sf_get_string (file, SF_STR_COMMENT) ; cannam@85: if (cptr == NULL || strcmp (comment, cptr) != 0) cannam@85: { if (errors++ == 0) cannam@85: puts ("\n") ; cannam@85: printf (" Bad comment : %s\n", cptr) ; cannam@85: } ; cannam@85: cannam@85: if (typemajor != SF_FORMAT_AIFF) cannam@85: { cptr = sf_get_string (file, SF_STR_DATE) ; cannam@85: if (cptr == NULL || strcmp (date, cptr) != 0) cannam@85: { if (errors++ == 0) cannam@85: puts ("\n") ; cannam@85: printf (" Bad date : %s\n", cptr) ; cannam@85: } ; cannam@85: cannam@85: cptr = sf_get_string (file, SF_STR_GENRE) ; cannam@85: if (cptr == NULL || strcmp (genre, cptr) != 0) cannam@85: { if (errors++ == 0) cannam@85: puts ("\n") ; cannam@85: printf (" Bad genre : %s\n", cptr) ; cannam@85: } ; cannam@85: } ; cannam@85: cannam@85: switch (typemajor) cannam@85: { case SF_FORMAT_AIFF : cannam@85: case SF_FORMAT_WAV : cannam@85: case SF_FORMAT_WAVEX : cannam@85: case SF_ENDIAN_BIG | SF_FORMAT_WAV : cannam@85: break ; cannam@85: cannam@85: default : cannam@85: cptr = sf_get_string (file, SF_STR_ALBUM) ; cannam@85: if (cptr == NULL || strcmp (album, cptr) != 0) cannam@85: { if (errors++ == 0) cannam@85: puts ("\n") ; cannam@85: printf (" Bad album : %s\n", cptr) ; cannam@85: } ; cannam@85: cannam@85: cptr = sf_get_string (file, SF_STR_LICENSE) ; cannam@85: if (cptr == NULL || strcmp (license, cptr) != 0) cannam@85: { if (errors++ == 0) cannam@85: puts ("\n") ; cannam@85: printf (" Bad license : %s\n", cptr) ; cannam@85: } ; cannam@85: cannam@85: cptr = sf_get_string (file, SF_STR_TRACKNUMBER) ; cannam@85: if (cptr == NULL || strcmp (genre, cptr) != 0) cannam@85: { if (errors++ == 0) cannam@85: puts ("\n") ; cannam@85: printf (" Bad track no. : %s\n", cptr) ; cannam@85: } ; cannam@85: break ; cannam@85: } ; cannam@85: cannam@85: if (errors > 0) cannam@85: { printf ("\n*** Error count : %d ***\n\n", errors) ; cannam@85: dump_log_buffer (file) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: sf_close (file) ; cannam@85: unlink (filename) ; cannam@85: cannam@85: puts ("ok") ; cannam@85: } /* string_start_end_test */ cannam@85: cannam@85: static void cannam@85: string_start_test (const char *filename, int typemajor) cannam@85: { const char *cptr ; cannam@85: SNDFILE *file ; cannam@85: SF_INFO sfinfo ; cannam@85: int errors = 0 ; cannam@85: cannam@85: print_test_name ("string_start_test", filename) ; cannam@85: cannam@85: sfinfo.samplerate = 44100 ; cannam@85: sfinfo.channels = 1 ; cannam@85: sfinfo.frames = 0 ; cannam@85: cannam@85: switch (typemajor) cannam@85: { case SF_FORMAT_OGG : cannam@85: sfinfo.format = typemajor | SF_FORMAT_VORBIS ; cannam@85: break ; cannam@85: cannam@85: default : cannam@85: sfinfo.format = typemajor | SF_FORMAT_PCM_16 ; cannam@85: break ; cannam@85: } ; cannam@85: cannam@85: file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; cannam@85: cannam@85: /* Write stuff at start of file. */ cannam@85: sf_set_string (file, SF_STR_TITLE, filename) ; cannam@85: sf_set_string (file, SF_STR_SOFTWARE, software) ; cannam@85: sf_set_string (file, SF_STR_ARTIST, artist) ; cannam@85: sf_set_string (file, SF_STR_COPYRIGHT, copyright) ; cannam@85: sf_set_string (file, SF_STR_COMMENT, comment) ; cannam@85: sf_set_string (file, SF_STR_DATE, date) ; cannam@85: sf_set_string (file, SF_STR_ALBUM, album) ; cannam@85: sf_set_string (file, SF_STR_LICENSE, license) ; cannam@85: cannam@85: /* Write data to file. */ cannam@85: test_write_short_or_die (file, 0, data_out, BUFFER_LEN, __LINE__) ; cannam@85: cannam@85: sf_close (file) ; cannam@85: cannam@85: file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; cannam@85: cannam@85: check_log_buffer_or_die (file, __LINE__) ; cannam@85: cannam@85: if (sfinfo.frames != BUFFER_LEN) cannam@85: { printf ("***** Bad frame count %d (should be %d)\n\n", (int) sfinfo.frames, BUFFER_LEN) ; cannam@85: errors ++ ; cannam@85: } ; cannam@85: cannam@85: cptr = sf_get_string (file, SF_STR_TITLE) ; cannam@85: if (cptr == NULL || strcmp (filename, cptr) != 0) cannam@85: { if (errors++ == 0) cannam@85: puts ("\n") ; cannam@85: printf (" Bad filename : %s\n", cptr) ; cannam@85: } ; cannam@85: cannam@85: cptr = sf_get_string (file, SF_STR_COPYRIGHT) ; cannam@85: if (cptr == NULL || strcmp (copyright, cptr) != 0) cannam@85: { if (errors++ == 0) cannam@85: puts ("\n") ; cannam@85: printf (" Bad copyright : %s\n", cptr) ; cannam@85: } ; cannam@85: cannam@85: cptr = sf_get_string (file, SF_STR_SOFTWARE) ; cannam@85: if (cptr == NULL || strstr (cptr, software) != cptr) cannam@85: { if (errors++ == 0) cannam@85: puts ("\n") ; cannam@85: printf (" Bad software : %s\n", cptr) ; cannam@85: } ; cannam@85: cannam@85: if (str_count (cptr, "libsndfile") != 1) cannam@85: { if (errors++ == 0) cannam@85: puts ("\n") ; cannam@85: printf (" Bad software : %s\n", cptr) ; cannam@85: } ; cannam@85: cannam@85: cptr = sf_get_string (file, SF_STR_ARTIST) ; cannam@85: if (cptr == NULL || strcmp (artist, cptr) != 0) cannam@85: { if (errors++ == 0) cannam@85: puts ("\n") ; cannam@85: printf (" Bad artist : %s\n", cptr) ; cannam@85: } ; cannam@85: cannam@85: cptr = sf_get_string (file, SF_STR_COMMENT) ; cannam@85: if (cptr == NULL || strcmp (comment, cptr) != 0) cannam@85: { if (errors++ == 0) cannam@85: puts ("\n") ; cannam@85: printf (" Bad comment : %s\n", cptr) ; cannam@85: } ; cannam@85: cannam@85: if (typemajor != SF_FORMAT_AIFF) cannam@85: { cptr = sf_get_string (file, SF_STR_DATE) ; cannam@85: if (cptr == NULL || strcmp (date, cptr) != 0) cannam@85: { if (errors++ == 0) cannam@85: puts ("\n") ; cannam@85: printf (" Bad date : %s\n", cptr) ; cannam@85: } ; cannam@85: } ; cannam@85: cannam@85: if (typemajor != SF_FORMAT_WAV && typemajor != SF_FORMAT_AIFF) cannam@85: { cptr = sf_get_string (file, SF_STR_ALBUM) ; cannam@85: if (cptr == NULL || strcmp (album, cptr) != 0) cannam@85: { if (errors++ == 0) cannam@85: puts ("\n") ; cannam@85: printf (" Bad album : %s\n", cptr) ; cannam@85: } ; cannam@85: } ; cannam@85: cannam@85: if (typemajor != SF_FORMAT_WAV && typemajor != SF_FORMAT_AIFF) cannam@85: { cptr = sf_get_string (file, SF_STR_LICENSE) ; cannam@85: if (cptr == NULL || strcmp (license, cptr) != 0) cannam@85: { if (errors++ == 0) cannam@85: puts ("\n") ; cannam@85: printf (" Bad license : %s\n", cptr) ; cannam@85: } ; cannam@85: } ; cannam@85: cannam@85: if (errors > 0) cannam@85: { printf ("\n*** Error count : %d ***\n\n", errors) ; cannam@85: dump_log_buffer (file) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: sf_close (file) ; cannam@85: unlink (filename) ; cannam@85: cannam@85: puts ("ok") ; cannam@85: } /* string_start_test */ cannam@85: cannam@85: static void cannam@85: string_multi_set_test (const char *filename, int typemajor) cannam@85: { static const char cannam@85: new_software [] = "new software (libsndfile-X.Y.Z)", cannam@85: new_copyright [] = "Copyright (c) 2001 New Artist", cannam@85: new_artist [] = "The New Artist", cannam@85: new_title [] = "This is the new title" ; cannam@85: cannam@85: static char buffer [2048] ; cannam@85: SNDFILE *file ; cannam@85: SF_INFO sfinfo ; cannam@85: int count ; cannam@85: cannam@85: print_test_name (__func__, filename) ; cannam@85: cannam@85: sfinfo.format = typemajor | SF_FORMAT_PCM_16 ; cannam@85: sfinfo.samplerate = 44100 ; cannam@85: sfinfo.channels = 1 ; cannam@85: sfinfo.frames = 0 ; cannam@85: cannam@85: file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; cannam@85: cannam@85: /* Write stuff at start of file. */ cannam@85: sf_set_string (file, SF_STR_TITLE, title) ; cannam@85: sf_set_string (file, SF_STR_SOFTWARE, software) ; cannam@85: sf_set_string (file, SF_STR_ARTIST, artist) ; cannam@85: cannam@85: /* Write data to file. */ cannam@85: test_write_short_or_die (file, 0, data_out, BUFFER_LEN, __LINE__) ; cannam@85: cannam@85: /* Write it all again. */ cannam@85: cannam@85: sf_set_string (file, SF_STR_TITLE, new_title) ; cannam@85: sf_set_string (file, SF_STR_SOFTWARE, new_software) ; cannam@85: sf_set_string (file, SF_STR_ARTIST, new_artist) ; cannam@85: cannam@85: sf_set_string (file, SF_STR_COPYRIGHT, copyright) ; cannam@85: sf_set_string (file, SF_STR_COMMENT, comment) ; cannam@85: sf_set_string (file, SF_STR_DATE, date) ; cannam@85: sf_set_string (file, SF_STR_ALBUM, album) ; cannam@85: sf_set_string (file, SF_STR_LICENSE, license) ; cannam@85: sf_set_string (file, SF_STR_COPYRIGHT, new_copyright) ; cannam@85: sf_set_string (file, SF_STR_COMMENT, comment) ; cannam@85: sf_set_string (file, SF_STR_DATE, date) ; cannam@85: sf_set_string (file, SF_STR_ALBUM, album) ; cannam@85: sf_set_string (file, SF_STR_LICENSE, license) ; cannam@85: cannam@85: sf_close (file) ; cannam@85: cannam@85: file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; cannam@85: sf_command (file, SFC_GET_LOG_INFO, buffer, sizeof (buffer)) ; cannam@85: sf_close (file) ; cannam@85: cannam@85: count = str_count (buffer, new_title) ; cannam@85: exit_if_true (count < 1, "\n\nLine %d : Could not find new_title in :\n%s\n", __LINE__, buffer) ; cannam@85: exit_if_true (count > 1, "\n\nLine %d : new_title appears %d times in :\n\n%s\n", __LINE__, count, buffer) ; cannam@85: cannam@85: count = str_count (buffer, software) ; cannam@85: exit_if_true (count < 1, "\n\nLine %d : Could not find new_software in :\n%s\n", __LINE__, buffer) ; cannam@85: exit_if_true (count > 1, "\n\nLine %d : new_software appears %d times in :\n\n%s\n", __LINE__, count, buffer) ; cannam@85: cannam@85: count = str_count (buffer, new_artist) ; cannam@85: exit_if_true (count < 1, "\n\nLine %d : Could not find new_artist in :\n%s\n", __LINE__, buffer) ; cannam@85: exit_if_true (count > 1, "\n\nLine %d : new_artist appears %d times in :\n\n%s\n", __LINE__, count, buffer) ; cannam@85: cannam@85: count = str_count (buffer, new_copyright) ; cannam@85: exit_if_true (count < 1, "\n\nLine %d : Could not find new_copyright in :\n%s\n", __LINE__, buffer) ; cannam@85: exit_if_true (count > 1, "\n\nLine %d : new_copyright appears %d times in :\n\n%s\n", __LINE__, count, buffer) ; cannam@85: cannam@85: unlink (filename) ; cannam@85: cannam@85: puts ("ok") ; cannam@85: } /* string_multi_set_test */ cannam@85: cannam@85: static void cannam@85: string_rdwr_test (const char *filename, int typemajor) cannam@85: { SNDFILE *file ; cannam@85: SF_INFO sfinfo ; cannam@85: sf_count_t frames ; cannam@85: const char * str ; cannam@85: cannam@85: print_test_name (__func__, filename) ; cannam@85: create_short_sndfile (filename, typemajor | SF_FORMAT_PCM_16, 2) ; cannam@85: cannam@85: memset (&sfinfo, 0, sizeof (sfinfo)) ; cannam@85: file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, SF_FALSE, __LINE__) ; cannam@85: frames = sfinfo.frames ; cannam@85: sf_set_string (file, SF_STR_TITLE, title) ; cannam@85: sf_close (file) ; cannam@85: cannam@85: file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ; cannam@85: exit_if_true (frames != sfinfo.frames, "\n\nLine %d : Frame count %lld should be %lld.\n", __LINE__, sfinfo.frames, frames) ; cannam@85: str = sf_get_string (file, SF_STR_TITLE) ; cannam@85: exit_if_true (str == NULL, "\n\nLine %d : SF_STR_TITLE string is NULL.\n", __LINE__) ; cannam@85: exit_if_true (strcmp (str, title) != 0, "\n\nLine %d : SF_STR_TITLE doesn't match what was written.\n", __LINE__) ; cannam@85: sf_close (file) ; cannam@85: cannam@85: file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, SF_FALSE, __LINE__) ; cannam@85: frames = sfinfo.frames ; cannam@85: sf_set_string (file, SF_STR_TITLE, title) ; cannam@85: sf_close (file) ; cannam@85: cannam@85: file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, SF_FALSE, __LINE__) ; cannam@85: str = sf_get_string (file, SF_STR_TITLE) ; cannam@85: exit_if_true (str == NULL, "\n\nLine %d : SF_STR_TITLE string is NULL.\n", __LINE__) ; cannam@85: sf_set_string (file, SF_STR_ARTIST, artist) ; cannam@85: sf_close (file) ; cannam@85: cannam@85: file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ; cannam@85: cannam@85: str = sf_get_string (file, SF_STR_ARTIST) ; cannam@85: exit_if_true (str == NULL, "\n\nLine %d : SF_STR_ARTIST string is NULL.\n", __LINE__) ; cannam@85: exit_if_true (strcmp (str, artist) != 0, "\n\nLine %d : SF_STR_ARTIST doesn't match what was written.\n", __LINE__) ; cannam@85: cannam@85: str = sf_get_string (file, SF_STR_TITLE) ; cannam@85: exit_if_true (str == NULL, "\n\nLine %d : SF_STR_TITLE string is NULL.\n", __LINE__) ; cannam@85: exit_if_true (strcmp (str, title) != 0, "\n\nLine %d : SF_STR_TITLE doesn't match what was written.\n", __LINE__) ; cannam@85: cannam@85: exit_if_true (frames != sfinfo.frames, "\n\nLine %d : Frame count %lld should be %lld.\n", __LINE__, sfinfo.frames, frames) ; cannam@85: cannam@85: sf_close (file) ; cannam@85: unlink (filename) ; cannam@85: cannam@85: puts ("ok") ; cannam@85: } /* string_rdwr_test */ cannam@85: cannam@85: static void cannam@85: string_short_rdwr_test (const char *filename, int typemajor) cannam@85: { SNDFILE *file ; cannam@85: SF_INFO sfinfo ; cannam@85: sf_count_t frames = BUFFER_LEN ; cannam@85: const char * str ; cannam@85: cannam@85: print_test_name (__func__, filename) ; cannam@85: cannam@85: memset (&sfinfo, 0, sizeof (sfinfo)) ; cannam@85: sfinfo.format = typemajor | SF_FORMAT_PCM_16 ; cannam@85: sfinfo.samplerate = 44100 ; cannam@85: sfinfo.channels = 1 ; cannam@85: sfinfo.frames = 0 ; cannam@85: cannam@85: file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_FALSE, __LINE__) ; cannam@85: cannam@85: /* Write data to file. */ cannam@85: test_write_short_or_die (file, 0, data_out, BUFFER_LEN, __LINE__) ; cannam@85: cannam@85: sf_set_string (file, SF_STR_TITLE, long_title) ; cannam@85: sf_set_string (file, SF_STR_ARTIST, long_artist) ; cannam@85: sf_close (file) ; cannam@85: cannam@85: /* Open the file RDWR. */ cannam@85: file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, SF_FALSE, __LINE__) ; cannam@85: exit_if_true (frames != sfinfo.frames, "\n\nLine %d : Frame count %lld should be %lld.\n", __LINE__, sfinfo.frames, frames) ; cannam@85: str = sf_get_string (file, SF_STR_TITLE) ; cannam@85: exit_if_true (str == NULL, "\n\nLine %d : SF_STR_TITLE string is NULL.\n", __LINE__) ; cannam@85: exit_if_true (strcmp (str, long_title) != 0, "\n\nLine %d : SF_STR_TITLE doesn't match what was written.\n", __LINE__) ; cannam@85: str = sf_get_string (file, SF_STR_ARTIST) ; cannam@85: exit_if_true (str == NULL, "\n\nLine %d : SF_STR_TITLE string is NULL.\n", __LINE__) ; cannam@85: exit_if_true (strcmp (str, long_artist) != 0, "\n\nLine %d : SF_STR_ARTIST doesn't match what was written.\n", __LINE__) ; cannam@85: cannam@85: /* Change title and artist. */ cannam@85: sf_set_string (file, SF_STR_TITLE, title) ; cannam@85: sf_set_string (file, SF_STR_ARTIST, artist) ; cannam@85: cannam@85: sf_close (file) ; cannam@85: cannam@85: file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ; cannam@85: cannam@85: check_log_buffer_or_die (file, __LINE__) ; cannam@85: cannam@85: str = sf_get_string (file, SF_STR_TITLE) ; cannam@85: exit_if_true (str == NULL, "\n\nLine %d : SF_STR_TITLE string is NULL.\n", __LINE__) ; cannam@85: exit_if_true (strcmp (str, title) != 0, "\n\nLine %d : SF_STR_TITLE doesn't match what was written.\n", __LINE__) ; cannam@85: cannam@85: str = sf_get_string (file, SF_STR_ARTIST) ; cannam@85: exit_if_true (str == NULL, "\n\nLine %d : SF_STR_ARTIST string is NULL.\n", __LINE__) ; cannam@85: exit_if_true (strcmp (str, artist) != 0, "\n\nLine %d : SF_STR_ARTIST doesn't match what was written.\n", __LINE__) ; cannam@85: cannam@85: sf_close (file) ; cannam@85: unlink (filename) ; cannam@85: cannam@85: puts ("ok") ; cannam@85: } /* string_short_rdwr_test */ cannam@85: cannam@85: static int cannam@85: str_count (const char * haystack, const char * needle) cannam@85: { int count = 0 ; cannam@85: cannam@85: while ((haystack = strstr (haystack, needle)) != NULL) cannam@85: { count ++ ; cannam@85: haystack ++ ; cannam@85: } ; cannam@85: cannam@85: return count ; cannam@85: } /* str_count */ cannam@85: cannam@85: #define MIN(a,b) ((a) < (b) ? (a) : (b)) cannam@85: cannam@85: cannam@85: static void cannam@85: software_string_test (const char *filename) cannam@85: { size_t k ; cannam@85: cannam@85: print_test_name (__func__, filename) ; cannam@85: cannam@85: for (k = 0 ; k < 50 ; k++) cannam@85: { const char *result ; cannam@85: char sfname [64] ; cannam@85: SNDFILE *file ; cannam@85: SF_INFO info ; cannam@85: cannam@85: sf_info_setup (&info, SF_FORMAT_WAV | SF_FORMAT_PCM_16, 44100, 1) ; cannam@85: file = test_open_file_or_die (filename, SFM_WRITE, &info, SF_TRUE, __LINE__) ; cannam@85: cannam@85: snprintf (sfname, MIN (k, sizeof (sfname)), "%s", "abcdefghijklmnopqrestvwxyz0123456789abcdefghijklmnopqrestvwxyz") ; cannam@85: cannam@85: exit_if_true (sf_set_string (file, SF_STR_SOFTWARE, sfname), cannam@85: "\n\nLine %d : sf_set_string (f, SF_STR_SOFTWARE, '%s') failed : %s\n", __LINE__, sfname, sf_strerror (file)) ; cannam@85: cannam@85: sf_close (file) ; cannam@85: cannam@85: file = test_open_file_or_die (filename, SFM_READ, &info, SF_TRUE, __LINE__) ; cannam@85: result = sf_get_string (file, SF_STR_SOFTWARE) ; cannam@85: cannam@85: exit_if_true (result == NULL, "\n\nLine %d : sf_get_string (file, SF_STR_SOFTWARE) returned NULL.\n\n", __LINE__) ; cannam@85: cannam@85: exit_if_true (strstr (result, sfname) != result, cannam@85: "\n\nLine %d : String '%s''%s' -> '%s'\n\n", sfname, result) ; cannam@85: sf_close (file) ; cannam@85: } ; cannam@85: cannam@85: unlink (filename) ; cannam@85: puts ("ok") ; cannam@85: } /* new_test_test */