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