annotate src/libsndfile-1.0.27/tests/format_check_test.c @ 168:ceec0dd9ec9c

Replace these with versions built using an older toolset (so as to avoid ABI compatibilities when linking on Ubuntu 14.04 for packaging purposes)
author Chris Cannam <cannam@all-day-breakfast.com>
date Fri, 07 Feb 2020 11:51:13 +0000
parents cd6cdf86811e
children
rev   line source
cannam@125 1 /*
cannam@125 2 ** Copyright (C) 2011 Erik de Castro Lopo <erikd@mega-nerd.com>
cannam@125 3 **
cannam@125 4 ** This program is free software; you can redistribute it and/or modify
cannam@125 5 ** it under the terms of the GNU General Public License as published by
cannam@125 6 ** the Free Software Foundation; either version 2 of the License, or
cannam@125 7 ** (at your option) any later version.
cannam@125 8 **
cannam@125 9 ** This program is distributed in the hope that it will be useful,
cannam@125 10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
cannam@125 11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cannam@125 12 ** GNU General Public License for more details.
cannam@125 13 **
cannam@125 14 ** You should have received a copy of the GNU General Public License
cannam@125 15 ** along with this program; if not, write to the Free Software
cannam@125 16 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
cannam@125 17 */
cannam@125 18
cannam@125 19 #include "sfconfig.h"
cannam@125 20
cannam@125 21 #include <stdio.h>
cannam@125 22 #include <stdlib.h>
cannam@125 23 #include <string.h>
cannam@125 24
cannam@125 25 #if HAVE_UNISTD_H
cannam@125 26 #include <unistd.h>
cannam@125 27 #endif
cannam@125 28
cannam@125 29 #include "sndfile.h"
cannam@125 30 #include "utils.h"
cannam@125 31
cannam@125 32 static void format_error_test (void) ;
cannam@125 33 static void format_combo_test (void) ;
cannam@125 34
cannam@125 35 int
cannam@125 36 main (void)
cannam@125 37 {
cannam@125 38 format_error_test () ;
cannam@125 39 format_combo_test () ;
cannam@125 40
cannam@125 41 return 0 ;
cannam@125 42 } /* main */
cannam@125 43
cannam@125 44 /*==============================================================================
cannam@125 45 */
cannam@125 46
cannam@125 47 static void
cannam@125 48 format_error_test (void)
cannam@125 49 { const char *filename = "format-error.wav" ;
cannam@125 50 SNDFILE *file ;
cannam@125 51 SF_INFO info ;
cannam@125 52
cannam@125 53 print_test_name (__func__, NULL) ;
cannam@125 54
cannam@125 55 memset (&info, 0, sizeof (info)) ;
cannam@125 56 info.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16 ;
cannam@125 57 info.channels = 1 ;
cannam@125 58 info.samplerate = 44100 ;
cannam@125 59
cannam@125 60 info.format = SF_FORMAT_WAV ;
cannam@125 61 file = sf_open (filename, SFM_WRITE, &info) ;
cannam@125 62 exit_if_true (file != NULL, "\n\nLine %d : Format should not be valid.\n\n", __LINE__) ;
cannam@125 63 exit_if_true (
cannam@125 64 strstr (sf_strerror (NULL), "minor format") == NULL,
cannam@125 65 "\n\nLine %d : Error string should reference bad 'minor format'.\n\n", __LINE__
cannam@125 66 ) ;
cannam@125 67
cannam@125 68 info.format = SF_FORMAT_PCM_16 ;
cannam@125 69 file = sf_open (filename, SFM_WRITE, &info) ;
cannam@125 70 exit_if_true (file != NULL, "\n\nLine %d : Format should not be valid.\n\n", __LINE__) ;
cannam@125 71 exit_if_true (
cannam@125 72 strstr (sf_strerror (NULL), "major format") == NULL,
cannam@125 73 "\n\nLine %d : Error string should reference bad 'major format'.\n\n", __LINE__
cannam@125 74 ) ;
cannam@125 75
cannam@125 76 unlink (filename) ;
cannam@125 77 puts ("ok") ;
cannam@125 78 } /* format_error_test */
cannam@125 79
cannam@125 80 static void
cannam@125 81 format_combo_test (void)
cannam@125 82 { int container_max, codec_max, cont, codec ;
cannam@125 83
cannam@125 84 print_test_name (__func__, NULL) ;
cannam@125 85
cannam@125 86 sf_command (NULL, SFC_GET_FORMAT_MAJOR_COUNT, &container_max, sizeof (container_max)) ;
cannam@125 87 sf_command (NULL, SFC_GET_FORMAT_SUBTYPE_COUNT, &codec_max, sizeof (codec_max)) ;
cannam@125 88
cannam@125 89 for (cont = 0 ; cont < container_max + 10 ; cont ++)
cannam@125 90 { SF_FORMAT_INFO major_fmt_info ;
cannam@125 91
cannam@125 92 memset (&major_fmt_info, 0, sizeof (major_fmt_info)) ;
cannam@125 93 major_fmt_info.format = cont ;
cannam@125 94 (void) sf_command (NULL, SFC_GET_FORMAT_MAJOR, &major_fmt_info, sizeof (major_fmt_info)) ;
cannam@125 95
cannam@125 96 for (codec = 0 ; codec < codec_max + 10 ; codec ++)
cannam@125 97 { SF_FORMAT_INFO subtype_fmt_info ;
cannam@125 98 SNDFILE * sndfile ;
cannam@125 99 SF_INFO info ;
cannam@125 100 char filename [128] ;
cannam@125 101 int subtype_is_valid, check_is_valid ;
cannam@125 102
cannam@125 103 memset (&subtype_fmt_info, 0, sizeof (subtype_fmt_info)) ;
cannam@125 104 subtype_fmt_info.format = codec ;
cannam@125 105 subtype_is_valid = sf_command (NULL, SFC_GET_FORMAT_SUBTYPE, &subtype_fmt_info, sizeof (subtype_fmt_info)) == 0 ;
cannam@125 106
cannam@125 107 sf_info_setup (&info, major_fmt_info.format | subtype_fmt_info.format, 22050, 1) ;
cannam@125 108
cannam@125 109 check_is_valid = sf_format_check (&info) ;
cannam@125 110
cannam@125 111 exit_if_true (
cannam@125 112 NOT (subtype_is_valid) && check_is_valid,
cannam@125 113 "\n\nLine %d : Subtype is not valid but checks ok.\n",
cannam@125 114 __LINE__
cannam@125 115 ) ;
cannam@125 116
cannam@125 117 snprintf (filename, sizeof (filename), "format-check.%s", major_fmt_info.extension) ;
cannam@125 118
cannam@125 119 sndfile = sf_open (filename, SFM_WRITE, &info) ;
cannam@125 120
cannam@125 121 sf_close (sndfile) ;
cannam@125 122 unlink (filename) ;
cannam@125 123
cannam@125 124 if (major_fmt_info.extension != NULL && strcmp (major_fmt_info.extension, "sd2") == 0)
cannam@125 125 { snprintf (filename, sizeof (filename), "._format-check.%s", major_fmt_info.extension) ;
cannam@125 126 unlink (filename) ;
cannam@125 127 } ;
cannam@125 128
cannam@125 129 exit_if_true (
cannam@125 130 sndfile && NOT (check_is_valid),
cannam@125 131 "\n\nError : Format was not valid but file opened correctly.\n"
cannam@125 132 " Container : %s\n"
cannam@125 133 " Codec : %s\n\n",
cannam@125 134 major_fmt_info.name, subtype_fmt_info.name
cannam@125 135 ) ;
cannam@125 136
cannam@125 137 exit_if_true (
cannam@125 138 NOT (sndfile) && check_is_valid,
cannam@125 139 "\n\nError : Format was valid but file failed to open.\n"
cannam@125 140 " Container : %s\n"
cannam@125 141 " Codec : %s\n\n",
cannam@125 142 major_fmt_info.name, subtype_fmt_info.name
cannam@125 143 ) ;
cannam@125 144 } ;
cannam@125 145 } ;
cannam@125 146
cannam@125 147 puts ("ok") ;
cannam@125 148 } /* format_combo_test */
cannam@125 149