cannam@125: /* cannam@125: ** Copyright (C) 2011 Erik de Castro Lopo cannam@125: ** cannam@125: ** This program is free software; you can redistribute it and/or modify cannam@125: ** it under the terms of the GNU General Public License as published by cannam@125: ** the Free Software Foundation; either version 2 of the License, or cannam@125: ** (at your option) any later version. cannam@125: ** cannam@125: ** This program is distributed in the hope that it will be useful, cannam@125: ** but WITHOUT ANY WARRANTY; without even the implied warranty of cannam@125: ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the cannam@125: ** GNU General Public License for more details. cannam@125: ** cannam@125: ** You should have received a copy of the GNU General Public License cannam@125: ** along with this program; if not, write to the Free Software cannam@125: ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. cannam@125: */ cannam@125: cannam@125: #include "sfconfig.h" cannam@125: cannam@125: #include cannam@125: #include cannam@125: #include cannam@125: cannam@125: #if HAVE_UNISTD_H cannam@125: #include cannam@125: #endif cannam@125: cannam@125: #include "sndfile.h" cannam@125: #include "utils.h" cannam@125: cannam@125: static void format_error_test (void) ; cannam@125: static void format_combo_test (void) ; cannam@125: cannam@125: int cannam@125: main (void) cannam@125: { cannam@125: format_error_test () ; cannam@125: format_combo_test () ; cannam@125: cannam@125: return 0 ; cannam@125: } /* main */ cannam@125: cannam@125: /*============================================================================== cannam@125: */ cannam@125: cannam@125: static void cannam@125: format_error_test (void) cannam@125: { const char *filename = "format-error.wav" ; cannam@125: SNDFILE *file ; cannam@125: SF_INFO info ; cannam@125: cannam@125: print_test_name (__func__, NULL) ; cannam@125: cannam@125: memset (&info, 0, sizeof (info)) ; cannam@125: info.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16 ; cannam@125: info.channels = 1 ; cannam@125: info.samplerate = 44100 ; cannam@125: cannam@125: info.format = SF_FORMAT_WAV ; cannam@125: file = sf_open (filename, SFM_WRITE, &info) ; cannam@125: exit_if_true (file != NULL, "\n\nLine %d : Format should not be valid.\n\n", __LINE__) ; cannam@125: exit_if_true ( cannam@125: strstr (sf_strerror (NULL), "minor format") == NULL, cannam@125: "\n\nLine %d : Error string should reference bad 'minor format'.\n\n", __LINE__ cannam@125: ) ; cannam@125: cannam@125: info.format = SF_FORMAT_PCM_16 ; cannam@125: file = sf_open (filename, SFM_WRITE, &info) ; cannam@125: exit_if_true (file != NULL, "\n\nLine %d : Format should not be valid.\n\n", __LINE__) ; cannam@125: exit_if_true ( cannam@125: strstr (sf_strerror (NULL), "major format") == NULL, cannam@125: "\n\nLine %d : Error string should reference bad 'major format'.\n\n", __LINE__ cannam@125: ) ; cannam@125: cannam@125: unlink (filename) ; cannam@125: puts ("ok") ; cannam@125: } /* format_error_test */ cannam@125: cannam@125: static void cannam@125: format_combo_test (void) cannam@125: { int container_max, codec_max, cont, codec ; cannam@125: cannam@125: print_test_name (__func__, NULL) ; cannam@125: cannam@125: sf_command (NULL, SFC_GET_FORMAT_MAJOR_COUNT, &container_max, sizeof (container_max)) ; cannam@125: sf_command (NULL, SFC_GET_FORMAT_SUBTYPE_COUNT, &codec_max, sizeof (codec_max)) ; cannam@125: cannam@125: for (cont = 0 ; cont < container_max + 10 ; cont ++) cannam@125: { SF_FORMAT_INFO major_fmt_info ; cannam@125: cannam@125: memset (&major_fmt_info, 0, sizeof (major_fmt_info)) ; cannam@125: major_fmt_info.format = cont ; cannam@125: (void) sf_command (NULL, SFC_GET_FORMAT_MAJOR, &major_fmt_info, sizeof (major_fmt_info)) ; cannam@125: cannam@125: for (codec = 0 ; codec < codec_max + 10 ; codec ++) cannam@125: { SF_FORMAT_INFO subtype_fmt_info ; cannam@125: SNDFILE * sndfile ; cannam@125: SF_INFO info ; cannam@125: char filename [128] ; cannam@125: int subtype_is_valid, check_is_valid ; cannam@125: cannam@125: memset (&subtype_fmt_info, 0, sizeof (subtype_fmt_info)) ; cannam@125: subtype_fmt_info.format = codec ; cannam@125: subtype_is_valid = sf_command (NULL, SFC_GET_FORMAT_SUBTYPE, &subtype_fmt_info, sizeof (subtype_fmt_info)) == 0 ; cannam@125: cannam@125: sf_info_setup (&info, major_fmt_info.format | subtype_fmt_info.format, 22050, 1) ; cannam@125: cannam@125: check_is_valid = sf_format_check (&info) ; cannam@125: cannam@125: exit_if_true ( cannam@125: NOT (subtype_is_valid) && check_is_valid, cannam@125: "\n\nLine %d : Subtype is not valid but checks ok.\n", cannam@125: __LINE__ cannam@125: ) ; cannam@125: cannam@125: snprintf (filename, sizeof (filename), "format-check.%s", major_fmt_info.extension) ; cannam@125: cannam@125: sndfile = sf_open (filename, SFM_WRITE, &info) ; cannam@125: cannam@125: sf_close (sndfile) ; cannam@125: unlink (filename) ; cannam@125: cannam@125: if (major_fmt_info.extension != NULL && strcmp (major_fmt_info.extension, "sd2") == 0) cannam@125: { snprintf (filename, sizeof (filename), "._format-check.%s", major_fmt_info.extension) ; cannam@125: unlink (filename) ; cannam@125: } ; cannam@125: cannam@125: exit_if_true ( cannam@125: sndfile && NOT (check_is_valid), cannam@125: "\n\nError : Format was not valid but file opened correctly.\n" cannam@125: " Container : %s\n" cannam@125: " Codec : %s\n\n", cannam@125: major_fmt_info.name, subtype_fmt_info.name cannam@125: ) ; cannam@125: cannam@125: exit_if_true ( cannam@125: NOT (sndfile) && check_is_valid, cannam@125: "\n\nError : Format was valid but file failed to open.\n" cannam@125: " Container : %s\n" cannam@125: " Codec : %s\n\n", cannam@125: major_fmt_info.name, subtype_fmt_info.name cannam@125: ) ; cannam@125: } ; cannam@125: } ; cannam@125: cannam@125: puts ("ok") ; cannam@125: } /* format_combo_test */ cannam@125: