2 ** Copyright (C) 2010-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 #if (HAVE_DECL_S_IRGRP == 0)
33 #include <sf_unistd.h>
36 #if (defined (WIN32) || defined (_WIN32))
45 static void rdwr_short_test (const char *filename
) ;
46 static void rdwr_int_test (const char *filename
) ;
47 static void rdwr_float_test (const char *filename
) ;
48 static void rdwr_double_test (const char *filename
) ;
49 static void rdwr_raw_test (const char *filename
) ;
55 rdwr_short_test ("rdwr_short.wav") ;
56 rdwr_int_test ("rdwr_int.wav") ;
57 rdwr_float_test ("rdwr_float.wav") ;
58 rdwr_double_test ("rdwr_double.wav") ;
59 rdwr_raw_test ("rdwr_raw.wav") ;
65 /*============================================================================================
66 ** Here are the test functions.
70 rdwr_short_test (const char *filename
)
76 print_test_name ("rdwr_short_test", filename
) ;
78 memset (buffer
, 0, sizeof (buffer
)) ;
80 /* Create sound file with no data. */
81 sfinfo
.format
= SF_FORMAT_WAV
| SF_FORMAT_PCM_16
;
82 sfinfo
.samplerate
= 16000 ;
87 frames
= ARRAY_LEN (buffer
) ;
89 /* Open again for read/write. */
90 file
= test_open_file_or_die (filename
, SFM_RDWR
, &sfinfo
, SF_TRUE
, __LINE__
) ;
92 test_write_short_or_die (file
, 0, buffer
, frames
, __LINE__
) ;
94 test_read_short_or_die (file
, 0, buffer
, frames
, __LINE__
) ;
101 } /* rdwr_short_test */
104 rdwr_int_test (const char *filename
)
110 print_test_name ("rdwr_int_test", filename
) ;
112 memset (buffer
, 0, sizeof (buffer
)) ;
114 /* Create sound file with no data. */
115 sfinfo
.format
= SF_FORMAT_WAV
| SF_FORMAT_PCM_32
;
116 sfinfo
.samplerate
= 16000 ;
117 sfinfo
.channels
= 1 ;
121 frames
= ARRAY_LEN (buffer
) ;
123 /* Open again for read/write. */
124 file
= test_open_file_or_die (filename
, SFM_RDWR
, &sfinfo
, SF_TRUE
, __LINE__
) ;
126 test_write_int_or_die (file
, 0, buffer
, frames
, __LINE__
) ;
128 test_read_int_or_die (file
, 0, buffer
, frames
, __LINE__
) ;
135 } /* rdwr_int_test */
138 rdwr_float_test (const char *filename
)
144 print_test_name ("rdwr_float_test", filename
) ;
146 memset (buffer
, 0, sizeof (buffer
)) ;
148 /* Create sound file with no data. */
149 sfinfo
.format
= SF_FORMAT_WAV
| SF_FORMAT_FLOAT
;
150 sfinfo
.samplerate
= 16000 ;
151 sfinfo
.channels
= 1 ;
155 frames
= ARRAY_LEN (buffer
) ;
157 /* Open again for read/write. */
158 file
= test_open_file_or_die (filename
, SFM_RDWR
, &sfinfo
, SF_TRUE
, __LINE__
) ;
160 test_write_float_or_die (file
, 0, buffer
, frames
, __LINE__
) ;
162 test_read_float_or_die (file
, 0, buffer
, frames
, __LINE__
) ;
169 } /* rdwr_float_test */
172 rdwr_double_test (const char *filename
)
176 double buffer
[160] ;
178 print_test_name ("rdwr_double_test", filename
) ;
180 memset (buffer
, 0, sizeof (buffer
)) ;
182 /* Create sound file with no data. */
183 sfinfo
.format
= SF_FORMAT_WAV
| SF_FORMAT_DOUBLE
;
184 sfinfo
.samplerate
= 16000 ;
185 sfinfo
.channels
= 1 ;
189 frames
= ARRAY_LEN (buffer
) ;
191 /* Open again for read/write. */
192 file
= test_open_file_or_die (filename
, SFM_RDWR
, &sfinfo
, SF_TRUE
, __LINE__
) ;
194 test_write_double_or_die (file
, 0, buffer
, frames
, __LINE__
) ;
196 test_read_double_or_die (file
, 0, buffer
, frames
, __LINE__
) ;
203 } /* rdwr_double_test */
206 rdwr_raw_test (const char *filename
)
210 unsigned char buffer
[160] ;
212 print_test_name ("rdwr_raw_test", filename
) ;
214 memset (buffer
, 0, sizeof (buffer
)) ;
216 /* Create sound file with no data. */
217 sfinfo
.format
= SF_FORMAT_WAV
| SF_FORMAT_PCM_U8
;
218 sfinfo
.samplerate
= 16000 ;
219 sfinfo
.channels
= 1 ;
223 frames
= ARRAY_LEN (buffer
) ;
225 /* Open again for read/write. */
226 file
= test_open_file_or_die (filename
, SFM_RDWR
, &sfinfo
, SF_TRUE
, __LINE__
) ;
228 test_write_raw_or_die (file
, 0, buffer
, frames
, __LINE__
) ;
230 test_read_raw_or_die (file
, 0, buffer
, frames
, __LINE__
) ;
237 } /* rdwr_raw_test */