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