Update readme, install and license files.
[Faustine.git] / interpretor / lib / src / libsndfile-1.0.25 / tests / rdwr_test.c
1 /*
2 ** Copyright (C) 2010-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 #include <sys/stat.h>
26 #include <math.h>
27
28 #if HAVE_UNISTD_H
29 #include <unistd.h>
30 #endif
31
32 #if (HAVE_DECL_S_IRGRP == 0)
33 #include <sf_unistd.h>
34 #endif
35
36 #if (defined (WIN32) || defined (_WIN32))
37 #include <io.h>
38 #include <direct.h>
39 #endif
40
41 #include <sndfile.h>
42
43 #include "utils.h"
44
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) ;
50
51
52 int
53 main (void)
54 {
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") ;
60
61 return 0 ;
62 } /* main */
63
64
65 /*============================================================================================
66 ** Here are the test functions.
67 */
68
69 static void
70 rdwr_short_test (const char *filename)
71 { SNDFILE *file ;
72 SF_INFO sfinfo ;
73 sf_count_t frames ;
74 short buffer [160] ;
75
76 print_test_name ("rdwr_short_test", filename) ;
77
78 memset (buffer, 0, sizeof (buffer)) ;
79
80 /* Create sound file with no data. */
81 sfinfo.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16 ;
82 sfinfo.samplerate = 16000 ;
83 sfinfo.channels = 1 ;
84
85 unlink (filename) ;
86
87 frames = ARRAY_LEN (buffer) ;
88
89 /* Open again for read/write. */
90 file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, SF_TRUE, __LINE__) ;
91
92 test_write_short_or_die (file, 0, buffer, frames, __LINE__) ;
93
94 test_read_short_or_die (file, 0, buffer, frames, __LINE__) ;
95
96 sf_close (file) ;
97 unlink (filename) ;
98
99 puts ("ok") ;
100 return ;
101 } /* rdwr_short_test */
102
103 static void
104 rdwr_int_test (const char *filename)
105 { SNDFILE *file ;
106 SF_INFO sfinfo ;
107 sf_count_t frames ;
108 int buffer [160] ;
109
110 print_test_name ("rdwr_int_test", filename) ;
111
112 memset (buffer, 0, sizeof (buffer)) ;
113
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 ;
118
119 unlink (filename) ;
120
121 frames = ARRAY_LEN (buffer) ;
122
123 /* Open again for read/write. */
124 file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, SF_TRUE, __LINE__) ;
125
126 test_write_int_or_die (file, 0, buffer, frames, __LINE__) ;
127
128 test_read_int_or_die (file, 0, buffer, frames, __LINE__) ;
129
130 sf_close (file) ;
131 unlink (filename) ;
132
133 puts ("ok") ;
134 return ;
135 } /* rdwr_int_test */
136
137 static void
138 rdwr_float_test (const char *filename)
139 { SNDFILE *file ;
140 SF_INFO sfinfo ;
141 sf_count_t frames ;
142 float buffer [160] ;
143
144 print_test_name ("rdwr_float_test", filename) ;
145
146 memset (buffer, 0, sizeof (buffer)) ;
147
148 /* Create sound file with no data. */
149 sfinfo.format = SF_FORMAT_WAV | SF_FORMAT_FLOAT ;
150 sfinfo.samplerate = 16000 ;
151 sfinfo.channels = 1 ;
152
153 unlink (filename) ;
154
155 frames = ARRAY_LEN (buffer) ;
156
157 /* Open again for read/write. */
158 file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, SF_TRUE, __LINE__) ;
159
160 test_write_float_or_die (file, 0, buffer, frames, __LINE__) ;
161
162 test_read_float_or_die (file, 0, buffer, frames, __LINE__) ;
163
164 sf_close (file) ;
165 unlink (filename) ;
166
167 puts ("ok") ;
168 return ;
169 } /* rdwr_float_test */
170
171 static void
172 rdwr_double_test (const char *filename)
173 { SNDFILE *file ;
174 SF_INFO sfinfo ;
175 sf_count_t frames ;
176 double buffer [160] ;
177
178 print_test_name ("rdwr_double_test", filename) ;
179
180 memset (buffer, 0, sizeof (buffer)) ;
181
182 /* Create sound file with no data. */
183 sfinfo.format = SF_FORMAT_WAV | SF_FORMAT_DOUBLE ;
184 sfinfo.samplerate = 16000 ;
185 sfinfo.channels = 1 ;
186
187 unlink (filename) ;
188
189 frames = ARRAY_LEN (buffer) ;
190
191 /* Open again for read/write. */
192 file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, SF_TRUE, __LINE__) ;
193
194 test_write_double_or_die (file, 0, buffer, frames, __LINE__) ;
195
196 test_read_double_or_die (file, 0, buffer, frames, __LINE__) ;
197
198 sf_close (file) ;
199 unlink (filename) ;
200
201 puts ("ok") ;
202 return ;
203 } /* rdwr_double_test */
204
205 static void
206 rdwr_raw_test (const char *filename)
207 { SNDFILE *file ;
208 SF_INFO sfinfo ;
209 sf_count_t frames ;
210 unsigned char buffer [160] ;
211
212 print_test_name ("rdwr_raw_test", filename) ;
213
214 memset (buffer, 0, sizeof (buffer)) ;
215
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 ;
220
221 unlink (filename) ;
222
223 frames = ARRAY_LEN (buffer) ;
224
225 /* Open again for read/write. */
226 file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, SF_TRUE, __LINE__) ;
227
228 test_write_raw_or_die (file, 0, buffer, frames, __LINE__) ;
229
230 test_read_raw_or_die (file, 0, buffer, frames, __LINE__) ;
231
232 sf_close (file) ;
233 unlink (filename) ;
234
235 puts ("ok") ;
236 return ;
237 } /* rdwr_raw_test */
238
239
240