libsndfile-ocaml source files.
[Faustine.git] / interpretor / lib / src / libsndfile-1.0.25 / tests / rdwr_test.tpl
1 [+ AutoGen5 template c +]
2 /*
3 ** Copyright (C) 2010-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
4 **
5 ** This program is free software ; you can redistribute it and/or modify
6 ** it under the terms of the GNU General Public License as published by
7 ** the Free Software Foundation ; either version 2 of the License, or
8 ** (at your option) any later version.
9 **
10 ** This program is distributed in the hope that it will be useful,
11 ** but WITHOUT ANY WARRANTY ; without even the implied warranty of
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ** GNU General Public License for more details.
14 **
15 ** You should have received a copy of the GNU General Public License
16 ** along with this program ; if not, write to the Free Software
17 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19
20 #include "sfconfig.h"
21
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25
26 #include <sys/stat.h>
27 #include <math.h>
28
29 #if HAVE_UNISTD_H
30 #include <unistd.h>
31 #endif
32
33 #if (HAVE_DECL_S_IRGRP == 0)
34 #include <sf_unistd.h>
35 #endif
36
37 #if (defined (WIN32) || defined (_WIN32))
38 #include <io.h>
39 #include <direct.h>
40 #endif
41
42 #include <sndfile.h>
43
44 #include "utils.h"
45
46 [+ FOR data_type
47 +]static void rdwr_[+ (get "name") +]_test (const char *filename) ;
48 [+ ENDFOR data_type
49 +]
50
51 int
52 main (void)
53 {
54 rdwr_short_test ("rdwr_short.wav") ;
55 rdwr_int_test ("rdwr_int.wav") ;
56 rdwr_float_test ("rdwr_float.wav") ;
57 rdwr_double_test ("rdwr_double.wav") ;
58 rdwr_raw_test ("rdwr_raw.wav") ;
59
60 return 0 ;
61 } /* main */
62
63
64 /*============================================================================================
65 ** Here are the test functions.
66 */
67
68 [+ FOR data_type
69 +]static void
70 rdwr_[+ (get "name") +]_test (const char *filename)
71 { SNDFILE *file ;
72 SF_INFO sfinfo ;
73 sf_count_t frames ;
74 [+ (get "type") +] buffer [160] ;
75
76 print_test_name ("rdwr_[+ (get "name") +]_test", filename) ;
77
78 memset (buffer, 0, sizeof (buffer)) ;
79
80 /* Create sound file with no data. */
81 sfinfo.format = SF_FORMAT_WAV | [+ (get "format") +] ;
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_[+ (get "name") +]_or_die (file, 0, buffer, frames, __LINE__) ;
93
94 test_read_[+ (get "name") +]_or_die (file, 0, buffer, frames, __LINE__) ;
95
96 sf_close (file) ;
97 unlink (filename) ;
98
99 puts ("ok") ;
100 return ;
101 } /* rdwr_[+ (get "name") +]_test */
102
103 [+ ENDFOR data_type
104 +]
105