2 ** Copyright (C) 2011 Erik de Castro Lopo <erikd@mega-nerd.com>
4 ** This program is free software; you can redistribute it and/or modify
5 ** it under the terms of the GNU General Public License as published by
6 ** the Free Software Foundation; either version 2 of the License, or
7 ** (at your option) any later version.
9 ** This program is distributed in the hope that it will be useful,
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ** GNU General Public License for more details.
14 ** You should have received a copy of the GNU General Public License
15 ** along with this program; if not, write to the Free Software
16 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32 static void format_error_test (void) ;
33 static void format_combo_test (void) ;
38 format_error_test () ;
39 format_combo_test () ;
44 /*==============================================================================
48 format_error_test (void)
49 { const char *filename
= "format-error.wav" ;
53 print_test_name (__func__
, NULL
) ;
55 memset (&info
, 0, sizeof (info
)) ;
56 info
.format
= SF_FORMAT_WAV
| SF_FORMAT_PCM_16
;
58 info
.samplerate
= 44100 ;
60 info
.format
= SF_FORMAT_WAV
;
61 file
= sf_open (filename
, SFM_WRITE
, &info
) ;
62 exit_if_true (file
!= NULL
, "\n\nLine %d : Format should not be valid.\n\n", __LINE__
) ;
64 strstr (sf_strerror (NULL
), "minor format") == NULL
,
65 "\n\nLine %d : Error string should reference bad 'minor format'.\n\n", __LINE__
68 info
.format
= SF_FORMAT_PCM_16
;
69 file
= sf_open (filename
, SFM_WRITE
, &info
) ;
70 exit_if_true (file
!= NULL
, "\n\nLine %d : Format should not be valid.\n\n", __LINE__
) ;
72 strstr (sf_strerror (NULL
), "major format") == NULL
,
73 "\n\nLine %d : Error string should reference bad 'major format'.\n\n", __LINE__
78 } /* format_error_test */
81 format_combo_test (void)
82 { int container_max
, codec_max
, cont
, codec
;
84 print_test_name (__func__
, NULL
) ;
86 sf_command (NULL
, SFC_GET_FORMAT_MAJOR_COUNT
, &container_max
, sizeof (container_max
)) ;
87 sf_command (NULL
, SFC_GET_FORMAT_SUBTYPE_COUNT
, &codec_max
, sizeof (codec_max
)) ;
89 for (cont
= 0 ; cont
< container_max
+ 10 ; cont
++)
90 { SF_FORMAT_INFO major_fmt_info
;
92 memset (&major_fmt_info
, 0, sizeof (major_fmt_info
)) ;
93 major_fmt_info
.format
= cont
;
94 (void) sf_command (NULL
, SFC_GET_FORMAT_MAJOR
, &major_fmt_info
, sizeof (major_fmt_info
)) ;
96 for (codec
= 0 ; codec
< codec_max
+ 10 ; codec
++)
97 { SF_FORMAT_INFO subtype_fmt_info
;
100 char filename
[128] ;
101 int subtype_is_valid
, check_is_valid
;
103 memset (&subtype_fmt_info
, 0, sizeof (subtype_fmt_info
)) ;
104 subtype_fmt_info
.format
= codec
;
105 subtype_is_valid
= sf_command (NULL
, SFC_GET_FORMAT_SUBTYPE
, &subtype_fmt_info
, sizeof (subtype_fmt_info
)) == 0 ;
107 sf_info_setup (&info
, major_fmt_info
.format
| subtype_fmt_info
.format
, 22050, 1) ;
109 check_is_valid
= sf_format_check (&info
) ;
112 NOT (subtype_is_valid
) && check_is_valid
,
113 "\n\nLine %d : Subtype is not valid but checks ok.\n",
117 snprintf (filename
, sizeof (filename
), "format-check.%s", major_fmt_info
.extension
) ;
119 sndfile
= sf_open (filename
, SFM_WRITE
, &info
) ;
124 if (major_fmt_info
.extension
!= NULL
&& strcmp (major_fmt_info
.extension
, "sd2") == 0)
125 { snprintf (filename
, sizeof (filename
), "._format-check.%s", major_fmt_info
.extension
) ;
130 sndfile
&& NOT (check_is_valid
),
131 "\n\nError : Format was not valid but file opened correctly.\n"
134 major_fmt_info
.name
, subtype_fmt_info
.name
138 NOT (sndfile
) && check_is_valid
,
139 "\n\nError : Format was valid but file failed to open.\n"
142 major_fmt_info
.name
, subtype_fmt_info
.name
148 } /* format_combo_test */