Update configure and Makefiles for the corrected name "interpreter".
[Faustine.git] / interpreter / lib / src / libsndfile-1.0.25 / tests / format_check_test.c
1 /*
2 ** Copyright (C) 2011 Erik de Castro Lopo <erikd@mega-nerd.com>
3 **
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.
8 **
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.
13 **
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.
17 */
18
19 #include "sfconfig.h"
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24
25 #if HAVE_UNISTD_H
26 #include <unistd.h>
27 #endif
28
29 #include "sndfile.h"
30 #include "utils.h"
31
32 static void format_error_test (void) ;
33 static void format_combo_test (void) ;
34
35 int
36 main (void)
37 {
38 format_error_test () ;
39 format_combo_test () ;
40
41 return 0 ;
42 } /* main */
43
44 /*==============================================================================
45 */
46
47 static void
48 format_error_test (void)
49 { const char *filename = "format-error.wav" ;
50 SNDFILE *file ;
51 SF_INFO info ;
52
53 print_test_name (__func__, NULL) ;
54
55 memset (&info, 0, sizeof (info)) ;
56 info.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16 ;
57 info.channels = 1 ;
58 info.samplerate = 44100 ;
59
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__) ;
63 exit_if_true (
64 strstr (sf_strerror (NULL), "minor format") == NULL,
65 "\n\nLine %d : Error string should reference bad 'minor format'.\n\n", __LINE__
66 ) ;
67
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__) ;
71 exit_if_true (
72 strstr (sf_strerror (NULL), "major format") == NULL,
73 "\n\nLine %d : Error string should reference bad 'major format'.\n\n", __LINE__
74 ) ;
75
76 unlink (filename) ;
77 puts ("ok") ;
78 } /* format_error_test */
79
80 static void
81 format_combo_test (void)
82 { int container_max, codec_max, cont, codec ;
83
84 print_test_name (__func__, NULL) ;
85
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)) ;
88
89 for (cont = 0 ; cont < container_max + 10 ; cont ++)
90 { SF_FORMAT_INFO major_fmt_info ;
91
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)) ;
95
96 for (codec = 0 ; codec < codec_max + 10 ; codec ++)
97 { SF_FORMAT_INFO subtype_fmt_info ;
98 SNDFILE * sndfile ;
99 SF_INFO info ;
100 char filename [128] ;
101 int subtype_is_valid, check_is_valid ;
102
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 ;
106
107 sf_info_setup (&info, major_fmt_info.format | subtype_fmt_info.format, 22050, 1) ;
108
109 check_is_valid = sf_format_check (&info) ;
110
111 exit_if_true (
112 NOT (subtype_is_valid) && check_is_valid,
113 "\n\nLine %d : Subtype is not valid but checks ok.\n",
114 __LINE__
115 ) ;
116
117 snprintf (filename, sizeof (filename), "format-check.%s", major_fmt_info.extension) ;
118
119 sndfile = sf_open (filename, SFM_WRITE, &info) ;
120
121 sf_close (sndfile) ;
122 unlink (filename) ;
123
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) ;
126 unlink (filename) ;
127 } ;
128
129 exit_if_true (
130 sndfile && NOT (check_is_valid),
131 "\n\nError : Format was not valid but file opened correctly.\n"
132 " Container : %s\n"
133 " Codec : %s\n\n",
134 major_fmt_info.name, subtype_fmt_info.name
135 ) ;
136
137 exit_if_true (
138 NOT (sndfile) && check_is_valid,
139 "\n\nError : Format was valid but file failed to open.\n"
140 " Container : %s\n"
141 " Codec : %s\n\n",
142 major_fmt_info.name, subtype_fmt_info.name
143 ) ;
144 } ;
145 } ;
146
147 puts ("ok") ;
148 } /* format_combo_test */
149