Merge branch 'libsndfile'
[Faustine.git] / interpretor / lib / src / libsndfile-1.0.25 / tests / stdout_test.c
1 /*
2 ** Copyright (C) 2001-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 #include <math.h>
25
26 #if HAVE_UNISTD_H
27 #include <unistd.h>
28 #endif
29
30 #include <sndfile.h>
31
32 #include "utils.h"
33
34 static void stdout_test (int typemajor, int count) ;
35
36 int
37 main (int argc, char *argv [])
38 { int do_all, test_count = 0 ;
39
40 if (argc != 2)
41 { fprintf (stderr, "This program cannot be run by itself. It needs\n") ;
42 fprintf (stderr, "to be run from the stdio_test program.\n") ;
43 exit (1) ;
44 } ;
45
46 do_all =! strcmp (argv [1], "all") ;
47
48 if (do_all || ! strcmp (argv [1], "raw"))
49 { stdout_test (SF_FORMAT_RAW, PIPE_TEST_LEN) ;
50 test_count ++ ;
51 } ;
52
53 if (do_all || ! strcmp (argv [1], "wav"))
54 { stdout_test (SF_FORMAT_WAV, PIPE_TEST_LEN) ;
55 test_count ++ ;
56 } ;
57
58 if (do_all || ! strcmp (argv [1], "aiff"))
59 { stdout_test (SF_FORMAT_AIFF, PIPE_TEST_LEN) ;
60 test_count ++ ;
61 } ;
62
63 if (do_all || ! strcmp (argv [1], "au"))
64 { stdout_test (SF_FORMAT_AU, PIPE_TEST_LEN) ;
65 test_count ++ ;
66 } ;
67
68 if (do_all || ! strcmp (argv [1], "paf"))
69 { stdout_test (SF_FORMAT_PAF, PIPE_TEST_LEN) ;
70 test_count ++ ;
71 } ;
72
73 if (do_all || ! strcmp (argv [1], "svx"))
74 { stdout_test (SF_FORMAT_SVX, PIPE_TEST_LEN) ;
75 test_count ++ ;
76 } ;
77
78 if (do_all || ! strcmp (argv [1], "nist"))
79 { stdout_test (SF_FORMAT_NIST, PIPE_TEST_LEN) ;
80 test_count ++ ;
81 } ;
82
83 if (do_all || ! strcmp (argv [1], "ircam"))
84 { stdout_test (SF_FORMAT_IRCAM, PIPE_TEST_LEN) ;
85 test_count ++ ;
86 } ;
87
88 if (do_all || ! strcmp (argv [1], "voc"))
89 { stdout_test (SF_FORMAT_VOC, PIPE_TEST_LEN) ;
90 test_count ++ ;
91 } ;
92
93 if (do_all || ! strcmp (argv [1], "w64"))
94 { stdout_test (SF_FORMAT_W64, PIPE_TEST_LEN) ;
95 test_count ++ ;
96 } ;
97
98 if (do_all || ! strcmp (argv [1], "mat4"))
99 { stdout_test (SF_FORMAT_MAT4, PIPE_TEST_LEN) ;
100 test_count ++ ;
101 } ;
102
103 if (do_all || ! strcmp (argv [1], "mat5"))
104 { stdout_test (SF_FORMAT_MAT5, PIPE_TEST_LEN) ;
105 test_count ++ ;
106 } ;
107
108 if (do_all || ! strcmp (argv [1], "pvf"))
109 { stdout_test (SF_FORMAT_PVF, PIPE_TEST_LEN) ;
110 test_count ++ ;
111 } ;
112
113 if (test_count == 0)
114 { fprintf (stderr, "************************************\n") ;
115 fprintf (stderr, "* No '%s' test defined.\n", argv [1]) ;
116 fprintf (stderr, "************************************\n") ;
117 return 1 ;
118 } ;
119
120 return 0 ;
121 } /* main */
122
123 static void
124 stdout_test (int typemajor, int count)
125 { static short data [PIPE_TEST_LEN] ;
126
127 SNDFILE *file ;
128 SF_INFO sfinfo ;
129 int k, total, this_write ;
130
131 sfinfo.samplerate = 44100 ;
132 sfinfo.format = (typemajor | SF_FORMAT_PCM_16) ;
133 sfinfo.channels = 1 ;
134 sfinfo.frames = 0 ;
135
136 /* Create some random data. */
137 for (k = 0 ; k < PIPE_TEST_LEN ; k++)
138 data [k] = PIPE_INDEX (k) ;
139
140 if ((file = sf_open ("-", SFM_WRITE, &sfinfo)) == NULL)
141 { fprintf (stderr, "sf_open_write failed with error : ") ;
142 fprintf (stderr, "%s\n", sf_strerror (NULL)) ;
143 exit (1) ;
144 } ;
145
146 total = 0 ;
147
148 while (total < count)
149 { this_write = (count - total > 1024) ? 1024 : count - total ;
150 if ((k = sf_write_short (file, data + total, this_write)) != this_write)
151 { fprintf (stderr, "sf_write_short # %d failed with short write (%d -> %d)\n", count, this_write, k) ;
152 exit (1) ;
153 } ;
154 total += k ;
155 } ;
156
157 sf_close (file) ;
158
159 return ;
160 } /* stdout_test */
161