cannam@85: /* cannam@85: ** Copyright (C) 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: cannam@85: #if HAVE_UNISTD_H cannam@85: #include cannam@85: #endif cannam@85: cannam@85: #include "sndfile.h" cannam@85: #include "utils.h" cannam@85: cannam@85: static void format_error_test (void) ; cannam@85: static void format_combo_test (void) ; cannam@85: cannam@85: int cannam@85: main (void) cannam@85: { cannam@85: format_error_test () ; cannam@85: format_combo_test () ; cannam@85: cannam@85: return 0 ; cannam@85: } /* main */ cannam@85: cannam@85: /*============================================================================== cannam@85: */ cannam@85: cannam@85: static void cannam@85: format_error_test (void) cannam@85: { const char *filename = "format-error.wav" ; cannam@85: SNDFILE *file ; cannam@85: SF_INFO info ; cannam@85: cannam@85: print_test_name (__func__, NULL) ; cannam@85: cannam@85: memset (&info, 0, sizeof (info)) ; cannam@85: info.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16 ; cannam@85: info.channels = 1 ; cannam@85: info.samplerate = 44100 ; cannam@85: cannam@85: info.format = SF_FORMAT_WAV ; cannam@85: file = sf_open (filename, SFM_WRITE, &info) ; cannam@85: exit_if_true (file != NULL, "\n\nLine %d : Format should not be valid.\n\n", __LINE__) ; cannam@85: exit_if_true ( cannam@85: strstr (sf_strerror (NULL), "minor format") == NULL, cannam@85: "\n\nLine %d : Error string should reference bad 'minor format'.\n\n", __LINE__ cannam@85: ) ; cannam@85: cannam@85: info.format = SF_FORMAT_PCM_16 ; cannam@85: file = sf_open (filename, SFM_WRITE, &info) ; cannam@85: exit_if_true (file != NULL, "\n\nLine %d : Format should not be valid.\n\n", __LINE__) ; cannam@85: exit_if_true ( cannam@85: strstr (sf_strerror (NULL), "major format") == NULL, cannam@85: "\n\nLine %d : Error string should reference bad 'major format'.\n\n", __LINE__ cannam@85: ) ; cannam@85: cannam@85: unlink (filename) ; cannam@85: puts ("ok") ; cannam@85: } /* format_error_test */ cannam@85: cannam@85: static void cannam@85: format_combo_test (void) cannam@85: { int container_max, codec_max, cont, codec ; cannam@85: cannam@85: print_test_name (__func__, NULL) ; cannam@85: cannam@85: sf_command (NULL, SFC_GET_FORMAT_MAJOR_COUNT, &container_max, sizeof (container_max)) ; cannam@85: sf_command (NULL, SFC_GET_FORMAT_SUBTYPE_COUNT, &codec_max, sizeof (codec_max)) ; cannam@85: cannam@85: for (cont = 0 ; cont < container_max + 10 ; cont ++) cannam@85: { SF_FORMAT_INFO major_fmt_info ; cannam@85: cannam@85: memset (&major_fmt_info, 0, sizeof (major_fmt_info)) ; cannam@85: major_fmt_info.format = cont ; cannam@85: (void) sf_command (NULL, SFC_GET_FORMAT_MAJOR, &major_fmt_info, sizeof (major_fmt_info)) ; cannam@85: cannam@85: for (codec = 0 ; codec < codec_max + 10 ; codec ++) cannam@85: { SF_FORMAT_INFO subtype_fmt_info ; cannam@85: SNDFILE * sndfile ; cannam@85: SF_INFO info ; cannam@85: char filename [128] ; cannam@85: int subtype_is_valid, check_is_valid ; cannam@85: cannam@85: memset (&subtype_fmt_info, 0, sizeof (subtype_fmt_info)) ; cannam@85: subtype_fmt_info.format = codec ; cannam@85: subtype_is_valid = sf_command (NULL, SFC_GET_FORMAT_SUBTYPE, &subtype_fmt_info, sizeof (subtype_fmt_info)) == 0 ; cannam@85: cannam@85: sf_info_setup (&info, major_fmt_info.format | subtype_fmt_info.format, 22050, 1) ; cannam@85: cannam@85: check_is_valid = sf_format_check (&info) ; cannam@85: cannam@85: exit_if_true ( cannam@85: NOT (subtype_is_valid) && check_is_valid, cannam@85: "\n\nLine %d : Subtype is not valid but checks ok.\n", cannam@85: __LINE__ cannam@85: ) ; cannam@85: cannam@85: snprintf (filename, sizeof (filename), "format-check.%s", major_fmt_info.extension) ; cannam@85: cannam@85: sndfile = sf_open (filename, SFM_WRITE, &info) ; cannam@85: cannam@85: sf_close (sndfile) ; cannam@85: unlink (filename) ; cannam@85: cannam@85: if (major_fmt_info.extension != NULL && strcmp (major_fmt_info.extension, "sd2") == 0) cannam@85: { snprintf (filename, sizeof (filename), "._format-check.%s", major_fmt_info.extension) ; cannam@85: unlink (filename) ; cannam@85: } ; cannam@85: cannam@85: exit_if_true ( cannam@85: sndfile && NOT (check_is_valid), cannam@85: "\n\nError : Format was not valid but file opened correctly.\n" cannam@85: " Container : %s\n" cannam@85: " Codec : %s\n\n", cannam@85: major_fmt_info.name, subtype_fmt_info.name cannam@85: ) ; cannam@85: cannam@85: exit_if_true ( cannam@85: NOT (sndfile) && check_is_valid, cannam@85: "\n\nError : Format was valid but file failed to open.\n" cannam@85: " Container : %s\n" cannam@85: " Codec : %s\n\n", cannam@85: major_fmt_info.name, subtype_fmt_info.name cannam@85: ) ; cannam@85: } ; cannam@85: } ; cannam@85: cannam@85: puts ("ok") ; cannam@85: } /* format_combo_test */ cannam@85: