Chris@0
|
1 /*
|
Chris@0
|
2 ** Copyright (C) 2001-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
|
Chris@0
|
3 **
|
Chris@0
|
4 ** This program is free software; you can redistribute it and/or modify
|
Chris@0
|
5 ** it under the terms of the GNU General Public License as published by
|
Chris@0
|
6 ** the Free Software Foundation; either version 2 of the License, or
|
Chris@0
|
7 ** (at your option) any later version.
|
Chris@0
|
8 **
|
Chris@0
|
9 ** This program is distributed in the hope that it will be useful,
|
Chris@0
|
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Chris@0
|
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Chris@0
|
12 ** GNU General Public License for more details.
|
Chris@0
|
13 **
|
Chris@0
|
14 ** You should have received a copy of the GNU General Public License
|
Chris@0
|
15 ** along with this program; if not, write to the Free Software
|
Chris@0
|
16 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
Chris@0
|
17 */
|
Chris@0
|
18
|
Chris@0
|
19 /*==========================================================================
|
Chris@0
|
20 ** This is a test program which tests reading from and writing to pipes.
|
Chris@0
|
21 */
|
Chris@0
|
22
|
Chris@0
|
23 #include "sfconfig.h"
|
Chris@0
|
24
|
Chris@0
|
25 #include <stdio.h>
|
Chris@0
|
26 #include <stdlib.h>
|
Chris@0
|
27 #include <string.h>
|
Chris@0
|
28
|
Chris@0
|
29 #if (OS_IS_WIN32 || HAVE_PIPE == 0 || HAVE_WAITPID == 0)
|
Chris@0
|
30
|
Chris@0
|
31 int
|
Chris@0
|
32 main (void)
|
Chris@0
|
33 {
|
Chris@0
|
34 puts (" pipe_test : this test doesn't work on this OS.") ;
|
Chris@0
|
35 return 0 ;
|
Chris@0
|
36 } /* main */
|
Chris@0
|
37
|
Chris@0
|
38 #else
|
Chris@0
|
39
|
Chris@0
|
40 #if HAVE_UNISTD_H
|
Chris@0
|
41 #include <unistd.h>
|
Chris@0
|
42 #endif
|
Chris@0
|
43
|
Chris@0
|
44 #include <errno.h>
|
Chris@0
|
45 #include <sys/types.h>
|
Chris@0
|
46 #include <sys/stat.h>
|
Chris@0
|
47 #include <sys/wait.h>
|
Chris@0
|
48
|
Chris@0
|
49 #include <sndfile.h>
|
Chris@0
|
50
|
Chris@0
|
51 #include "utils.h"
|
Chris@0
|
52
|
Chris@0
|
53 typedef struct
|
Chris@0
|
54 { int format ;
|
Chris@0
|
55 const char *ext ;
|
Chris@0
|
56 } FILETYPE ;
|
Chris@0
|
57
|
Chris@0
|
58 static int file_exists (const char *filename) ;
|
Chris@0
|
59 static void useek_pipe_rw_test (int filetype, const char *ext) ;
|
Chris@0
|
60 static void pipe_read_test (int filetype, const char *ext) ;
|
Chris@0
|
61 static void pipe_write_test (const char *ext) ;
|
Chris@0
|
62 static void pipe_test_others (FILETYPE*, FILETYPE*) ;
|
Chris@0
|
63
|
Chris@0
|
64 static FILETYPE read_write_types [] =
|
Chris@0
|
65 { { SF_FORMAT_RAW , "raw" },
|
Chris@0
|
66 { SF_FORMAT_AU , "au" },
|
Chris@0
|
67 /* Lite remove start */
|
Chris@0
|
68 { SF_FORMAT_PAF , "paf" },
|
Chris@0
|
69 { SF_FORMAT_IRCAM , "ircam" },
|
Chris@0
|
70 { SF_FORMAT_PVF , "pvf" },
|
Chris@0
|
71 /* Lite remove end */
|
Chris@0
|
72 { 0 , NULL }
|
Chris@0
|
73 } ;
|
Chris@0
|
74
|
Chris@0
|
75 static FILETYPE read_only_types [] =
|
Chris@0
|
76 { { SF_FORMAT_RAW , "raw" },
|
Chris@0
|
77 { SF_FORMAT_AU , "au" },
|
Chris@0
|
78 { SF_FORMAT_AIFF , "aiff" },
|
Chris@0
|
79 { SF_FORMAT_WAV , "wav" },
|
Chris@0
|
80 { SF_FORMAT_W64 , "w64" },
|
Chris@0
|
81 /* Lite remove start */
|
Chris@0
|
82 { SF_FORMAT_PAF , "paf" },
|
Chris@0
|
83 { SF_FORMAT_NIST , "nist" },
|
Chris@0
|
84 { SF_FORMAT_IRCAM , "ircam" },
|
Chris@0
|
85 { SF_FORMAT_MAT4 , "mat4" },
|
Chris@0
|
86 { SF_FORMAT_MAT5 , "mat5" },
|
Chris@0
|
87 { SF_FORMAT_SVX , "svx" },
|
Chris@0
|
88 { SF_FORMAT_PVF , "pvf" },
|
Chris@0
|
89 /* Lite remove end */
|
Chris@0
|
90 { 0 , NULL }
|
Chris@0
|
91 } ;
|
Chris@0
|
92
|
Chris@0
|
93 int
|
Chris@0
|
94 main (void)
|
Chris@0
|
95 { int k ;
|
Chris@0
|
96
|
Chris@0
|
97 if (file_exists ("libsndfile.spec.in"))
|
Chris@0
|
98 exit_if_true (chdir ("tests") != 0, "\n Error : chdir ('tests') failed.\n") ;
|
Chris@0
|
99
|
Chris@0
|
100 for (k = 0 ; read_only_types [k].format ; k++)
|
Chris@0
|
101 pipe_read_test (read_only_types [k].format, read_only_types [k].ext) ;
|
Chris@0
|
102
|
Chris@0
|
103 for (k = 0 ; read_write_types [k].format ; k++)
|
Chris@0
|
104 pipe_write_test (read_write_types [k].ext) ;
|
Chris@0
|
105
|
Chris@0
|
106 for (k = 0 ; read_write_types [k].format ; k++)
|
Chris@0
|
107 useek_pipe_rw_test (read_write_types [k].format, read_write_types [k].ext) ;
|
Chris@0
|
108
|
Chris@0
|
109 if (0)
|
Chris@0
|
110 pipe_test_others (read_write_types, read_only_types) ;
|
Chris@0
|
111
|
Chris@0
|
112 return 0 ;
|
Chris@0
|
113 } /* main */
|
Chris@0
|
114
|
Chris@0
|
115 /*==============================================================================
|
Chris@0
|
116 */
|
Chris@0
|
117
|
Chris@0
|
118 static void
|
Chris@0
|
119 pipe_read_test (int filetype, const char *ext)
|
Chris@0
|
120 { static short data [PIPE_TEST_LEN] ;
|
Chris@0
|
121 static char buffer [256] ;
|
Chris@0
|
122 static char filename [256] ;
|
Chris@0
|
123
|
Chris@0
|
124 SNDFILE *outfile ;
|
Chris@0
|
125 SF_INFO sfinfo ;
|
Chris@0
|
126 int k, retval ;
|
Chris@0
|
127
|
Chris@0
|
128 snprintf (filename, sizeof (filename), "pipe_in.%s", ext) ;
|
Chris@0
|
129 print_test_name ("pipe_read_test", filename) ;
|
Chris@0
|
130
|
Chris@0
|
131 sfinfo.format = filetype | SF_FORMAT_PCM_16 ;
|
Chris@0
|
132 sfinfo.channels = 1 ;
|
Chris@0
|
133 sfinfo.samplerate = 44100 ;
|
Chris@0
|
134
|
Chris@0
|
135 for (k = 0 ; k < PIPE_TEST_LEN ; k++)
|
Chris@0
|
136 data [k] = PIPE_INDEX (k) ;
|
Chris@0
|
137
|
Chris@0
|
138 outfile = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
139 test_writef_short_or_die (outfile, 0, data, PIPE_TEST_LEN, __LINE__) ;
|
Chris@0
|
140 sf_close (outfile) ;
|
Chris@0
|
141
|
Chris@0
|
142 snprintf (buffer, sizeof (buffer), "cat %s | ./stdin_test %s ", filename, ext) ;
|
Chris@0
|
143 if ((retval = system (buffer)) != 0)
|
Chris@0
|
144 { retval = WEXITSTATUS (retval) ;
|
Chris@0
|
145 printf ("\n\n Line %d : pipe test returned error for file type \"%s\".\n\n", __LINE__, ext) ;
|
Chris@0
|
146 exit (retval) ;
|
Chris@0
|
147 } ;
|
Chris@0
|
148
|
Chris@0
|
149 unlink (filename) ;
|
Chris@0
|
150 puts ("ok") ;
|
Chris@0
|
151
|
Chris@0
|
152 return ;
|
Chris@0
|
153 } /* pipe_read_test */
|
Chris@0
|
154
|
Chris@0
|
155 static void
|
Chris@0
|
156 pipe_write_test (const char *ext)
|
Chris@0
|
157 { static char buffer [256] ;
|
Chris@0
|
158
|
Chris@0
|
159 int retval ;
|
Chris@0
|
160
|
Chris@0
|
161 print_test_name ("pipe_write_test", ext) ;
|
Chris@0
|
162
|
Chris@0
|
163 snprintf (buffer, sizeof (buffer), "./stdout_test %s | ./stdin_test %s ", ext, ext) ;
|
Chris@0
|
164 if ((retval = system (buffer)))
|
Chris@0
|
165 { retval = WEXITSTATUS (retval) ;
|
Chris@0
|
166 printf ("\n\n Line %d : pipe test returned error file type \"%s\".\n\n", __LINE__, ext) ;
|
Chris@0
|
167 exit (retval) ;
|
Chris@0
|
168 } ;
|
Chris@0
|
169
|
Chris@0
|
170 puts ("ok") ;
|
Chris@0
|
171
|
Chris@0
|
172 return ;
|
Chris@0
|
173 } /* pipe_write_test */
|
Chris@0
|
174
|
Chris@0
|
175 /*==============================================================================
|
Chris@0
|
176 */
|
Chris@0
|
177
|
Chris@0
|
178
|
Chris@0
|
179 static void
|
Chris@0
|
180 useek_pipe_rw_short (const char * ext, SF_INFO * psfinfo_write, SF_INFO * psfinfo_read)
|
Chris@0
|
181 { static short buffer [PIPE_TEST_LEN] ;
|
Chris@0
|
182 static short data [PIPE_TEST_LEN] ;
|
Chris@0
|
183 SNDFILE *outfile ;
|
Chris@0
|
184 SNDFILE *infile_piped ;
|
Chris@0
|
185
|
Chris@0
|
186 int k, status = 0 ;
|
Chris@0
|
187 int pipefd [2] ;
|
Chris@0
|
188 pid_t pida ;
|
Chris@0
|
189
|
Chris@0
|
190 for (k = 0 ; k < PIPE_TEST_LEN ; k++)
|
Chris@0
|
191 data [k] = PIPE_INDEX (k) ;
|
Chris@0
|
192
|
Chris@0
|
193 /*
|
Chris@0
|
194 ** Create the pipe.
|
Chris@0
|
195 */
|
Chris@0
|
196 exit_if_true (pipe (pipefd) != 0, "\n\n%s %d : pipe failed : %s\n", __func__, __LINE__, strerror (errno)) ;
|
Chris@0
|
197
|
Chris@0
|
198 /*
|
Chris@0
|
199 ** Attach the write end of the pipe to be written to.
|
Chris@0
|
200 */
|
Chris@0
|
201 if ((outfile = sf_open_fd (pipefd [1], SFM_WRITE, psfinfo_write, SF_TRUE)) == NULL)
|
Chris@0
|
202 { printf ("\n\n%s %d : unable to create unseekable pipe for write type \"%s\".\n", __func__, __LINE__, ext) ;
|
Chris@0
|
203 printf ("\t%s\n\n", sf_strerror (outfile)) ;
|
Chris@0
|
204 exit (1) ;
|
Chris@0
|
205 } ;
|
Chris@0
|
206
|
Chris@0
|
207 if (sf_error (outfile) != SF_ERR_NO_ERROR)
|
Chris@0
|
208 { printf ("\n\n%s %d : unable to open unseekable pipe for write type \"%s\".\n\n", __func__, __LINE__, ext) ;
|
Chris@0
|
209 exit (1) ;
|
Chris@0
|
210 } ;
|
Chris@0
|
211
|
Chris@0
|
212 /*
|
Chris@0
|
213 ** Attach the read end of the pipe to be read from.
|
Chris@0
|
214 */
|
Chris@0
|
215 if ((infile_piped = sf_open_fd (pipefd [0], SFM_READ, psfinfo_read, SF_TRUE)) == NULL)
|
Chris@0
|
216 { printf ("\n\n%s %d : unable to create unseekable pipe for read type. \"%s\".\n\n", __func__, __LINE__, ext) ;
|
Chris@0
|
217 exit (1) ;
|
Chris@0
|
218 } ;
|
Chris@0
|
219
|
Chris@0
|
220 if (sf_error (infile_piped) != SF_ERR_NO_ERROR)
|
Chris@0
|
221 { printf ("\n\n%s %d : unable to open unseekable pipe for read type \"%s\".\n\n", __func__, __LINE__, ext) ;
|
Chris@0
|
222 exit (1) ;
|
Chris@0
|
223 } ;
|
Chris@0
|
224
|
Chris@0
|
225 /* Fork a child process that will write directly into the pipe. */
|
Chris@0
|
226 if ((pida = fork ()) == 0) /* child process */
|
Chris@0
|
227 { test_writef_short_or_die (outfile, 0, data, PIPE_TEST_LEN, __LINE__) ;
|
Chris@0
|
228 exit (0) ;
|
Chris@0
|
229 } ;
|
Chris@0
|
230
|
Chris@0
|
231 /* In the parent process, read from the pipe and compare what is read
|
Chris@0
|
232 ** to what is written, if they match everything went as planned.
|
Chris@0
|
233 */
|
Chris@0
|
234 test_readf_short_or_die (infile_piped, 0, buffer, PIPE_TEST_LEN, __LINE__) ;
|
Chris@0
|
235 if (memcmp (buffer, data, sizeof (buffer)) != 0)
|
Chris@0
|
236 { printf ("\n\n%s %d : unseekable pipe test failed for file type \"%s\".\n\n", __func__, __LINE__, ext) ;
|
Chris@0
|
237 exit (1) ;
|
Chris@0
|
238 } ;
|
Chris@0
|
239
|
Chris@0
|
240 /* Wait for the child process to return. */
|
Chris@0
|
241 waitpid (pida, &status, 0) ;
|
Chris@0
|
242 status = WEXITSTATUS (status) ;
|
Chris@0
|
243 sf_close (outfile) ;
|
Chris@0
|
244 sf_close (infile_piped) ;
|
Chris@0
|
245
|
Chris@0
|
246 if (status != 0)
|
Chris@0
|
247 { printf ("\n\n%s %d : status of child process is %d for file type %s.\n\n", __func__, __LINE__, status, ext) ;
|
Chris@0
|
248 exit (1) ;
|
Chris@0
|
249 } ;
|
Chris@0
|
250
|
Chris@0
|
251 return ;
|
Chris@0
|
252 } /* useek_pipe_rw_short */
|
Chris@0
|
253
|
Chris@0
|
254
|
Chris@0
|
255 static void
|
Chris@0
|
256 useek_pipe_rw_float (const char * ext, SF_INFO * psfinfo_write, SF_INFO * psfinfo_read)
|
Chris@0
|
257 { static float buffer [PIPE_TEST_LEN] ;
|
Chris@0
|
258 static float data [PIPE_TEST_LEN] ;
|
Chris@0
|
259 SNDFILE *outfile ;
|
Chris@0
|
260 SNDFILE *infile_piped ;
|
Chris@0
|
261
|
Chris@0
|
262 int k, status = 0 ;
|
Chris@0
|
263 int pipefd [2] ;
|
Chris@0
|
264 pid_t pida ;
|
Chris@0
|
265
|
Chris@0
|
266 for (k = 0 ; k < PIPE_TEST_LEN ; k++)
|
Chris@0
|
267 data [k] = PIPE_INDEX (k) ;
|
Chris@0
|
268
|
Chris@0
|
269 /*
|
Chris@0
|
270 ** Create the pipe.
|
Chris@0
|
271 */
|
Chris@0
|
272 exit_if_true (pipe (pipefd) != 0, "\n\n%s %d : pipe failed : %s\n", __func__, __LINE__, strerror (errno)) ;
|
Chris@0
|
273
|
Chris@0
|
274 /*
|
Chris@0
|
275 ** Attach the write end of the pipe to be written to.
|
Chris@0
|
276 */
|
Chris@0
|
277 if ((outfile = sf_open_fd (pipefd [1], SFM_WRITE, psfinfo_write, SF_TRUE)) == NULL)
|
Chris@0
|
278 { printf ("\n\n%s %d : unable to create unseekable pipe for write type \"%s\".\n", __func__, __LINE__, ext) ;
|
Chris@0
|
279 printf ("\t%s\n\n", sf_strerror (outfile)) ;
|
Chris@0
|
280 exit (1) ;
|
Chris@0
|
281 } ;
|
Chris@0
|
282
|
Chris@0
|
283 if (sf_error (outfile) != SF_ERR_NO_ERROR)
|
Chris@0
|
284 { printf ("\n\n%s %d : unable to open unseekable pipe for write type \"%s\".\n\n", __func__, __LINE__, ext) ;
|
Chris@0
|
285 exit (1) ;
|
Chris@0
|
286 } ;
|
Chris@0
|
287
|
Chris@0
|
288 /*
|
Chris@0
|
289 ** Attach the read end of the pipe to be read from.
|
Chris@0
|
290 */
|
Chris@0
|
291 if ((infile_piped = sf_open_fd (pipefd [0], SFM_READ, psfinfo_read, SF_TRUE)) == NULL)
|
Chris@0
|
292 { printf ("\n\n%s %d : unable to create unseekable pipe for read type. \"%s\".\n\n", __func__, __LINE__, ext) ;
|
Chris@0
|
293 exit (1) ;
|
Chris@0
|
294 } ;
|
Chris@0
|
295
|
Chris@0
|
296 if (sf_error (infile_piped) != SF_ERR_NO_ERROR)
|
Chris@0
|
297 { printf ("\n\n%s %d : unable to open unseekable pipe for read type \"%s\".\n\n", __func__, __LINE__, ext) ;
|
Chris@0
|
298 exit (1) ;
|
Chris@0
|
299 } ;
|
Chris@0
|
300
|
Chris@0
|
301 /* Fork a child process that will write directly into the pipe. */
|
Chris@0
|
302 if ((pida = fork ()) == 0) /* child process */
|
Chris@0
|
303 { test_writef_float_or_die (outfile, 0, data, PIPE_TEST_LEN, __LINE__) ;
|
Chris@0
|
304 exit (0) ;
|
Chris@0
|
305 } ;
|
Chris@0
|
306
|
Chris@0
|
307 /* In the parent process, read from the pipe and compare what is read
|
Chris@0
|
308 ** to what is written, if they match everything went as planned.
|
Chris@0
|
309 */
|
Chris@0
|
310 test_readf_float_or_die (infile_piped, 0, buffer, PIPE_TEST_LEN, __LINE__) ;
|
Chris@0
|
311 if (memcmp (buffer, data, sizeof (buffer)) != 0)
|
Chris@0
|
312 { printf ("\n\n%s %d : unseekable pipe test failed for file type \"%s\".\n\n", __func__, __LINE__, ext) ;
|
Chris@0
|
313 exit (1) ;
|
Chris@0
|
314 } ;
|
Chris@0
|
315
|
Chris@0
|
316 /* Wait for the child process to return. */
|
Chris@0
|
317 waitpid (pida, &status, 0) ;
|
Chris@0
|
318 status = WEXITSTATUS (status) ;
|
Chris@0
|
319 sf_close (outfile) ;
|
Chris@0
|
320 sf_close (infile_piped) ;
|
Chris@0
|
321
|
Chris@0
|
322 if (status != 0)
|
Chris@0
|
323 { printf ("\n\n%s %d : status of child process is %d for file type %s.\n\n", __func__, __LINE__, status, ext) ;
|
Chris@0
|
324 exit (1) ;
|
Chris@0
|
325 } ;
|
Chris@0
|
326
|
Chris@0
|
327 return ;
|
Chris@0
|
328 } /* useek_pipe_rw_float */
|
Chris@0
|
329
|
Chris@0
|
330
|
Chris@0
|
331 static void
|
Chris@0
|
332 useek_pipe_rw_double (const char * ext, SF_INFO * psfinfo_write, SF_INFO * psfinfo_read)
|
Chris@0
|
333 { static double buffer [PIPE_TEST_LEN] ;
|
Chris@0
|
334 static double data [PIPE_TEST_LEN] ;
|
Chris@0
|
335 SNDFILE *outfile ;
|
Chris@0
|
336 SNDFILE *infile_piped ;
|
Chris@0
|
337
|
Chris@0
|
338 int k, status = 0 ;
|
Chris@0
|
339 int pipefd [2] ;
|
Chris@0
|
340 pid_t pida ;
|
Chris@0
|
341
|
Chris@0
|
342 for (k = 0 ; k < PIPE_TEST_LEN ; k++)
|
Chris@0
|
343 data [k] = PIPE_INDEX (k) ;
|
Chris@0
|
344
|
Chris@0
|
345 /*
|
Chris@0
|
346 ** Create the pipe.
|
Chris@0
|
347 */
|
Chris@0
|
348 exit_if_true (pipe (pipefd) != 0, "\n\n%s %d : pipe failed : %s\n", __func__, __LINE__, strerror (errno)) ;
|
Chris@0
|
349
|
Chris@0
|
350 /*
|
Chris@0
|
351 ** Attach the write end of the pipe to be written to.
|
Chris@0
|
352 */
|
Chris@0
|
353 if ((outfile = sf_open_fd (pipefd [1], SFM_WRITE, psfinfo_write, SF_TRUE)) == NULL)
|
Chris@0
|
354 { printf ("\n\n%s %d : unable to create unseekable pipe for write type \"%s\".\n", __func__, __LINE__, ext) ;
|
Chris@0
|
355 printf ("\t%s\n\n", sf_strerror (outfile)) ;
|
Chris@0
|
356 exit (1) ;
|
Chris@0
|
357 } ;
|
Chris@0
|
358
|
Chris@0
|
359 if (sf_error (outfile) != SF_ERR_NO_ERROR)
|
Chris@0
|
360 { printf ("\n\n%s %d : unable to open unseekable pipe for write type \"%s\".\n\n", __func__, __LINE__, ext) ;
|
Chris@0
|
361 exit (1) ;
|
Chris@0
|
362 } ;
|
Chris@0
|
363
|
Chris@0
|
364 /*
|
Chris@0
|
365 ** Attach the read end of the pipe to be read from.
|
Chris@0
|
366 */
|
Chris@0
|
367 if ((infile_piped = sf_open_fd (pipefd [0], SFM_READ, psfinfo_read, SF_TRUE)) == NULL)
|
Chris@0
|
368 { printf ("\n\n%s %d : unable to create unseekable pipe for read type. \"%s\".\n\n", __func__, __LINE__, ext) ;
|
Chris@0
|
369 exit (1) ;
|
Chris@0
|
370 } ;
|
Chris@0
|
371
|
Chris@0
|
372 if (sf_error (infile_piped) != SF_ERR_NO_ERROR)
|
Chris@0
|
373 { printf ("\n\n%s %d : unable to open unseekable pipe for read type \"%s\".\n\n", __func__, __LINE__, ext) ;
|
Chris@0
|
374 exit (1) ;
|
Chris@0
|
375 } ;
|
Chris@0
|
376
|
Chris@0
|
377 /* Fork a child process that will write directly into the pipe. */
|
Chris@0
|
378 if ((pida = fork ()) == 0) /* child process */
|
Chris@0
|
379 { test_writef_double_or_die (outfile, 0, data, PIPE_TEST_LEN, __LINE__) ;
|
Chris@0
|
380 exit (0) ;
|
Chris@0
|
381 } ;
|
Chris@0
|
382
|
Chris@0
|
383 /* In the parent process, read from the pipe and compare what is read
|
Chris@0
|
384 ** to what is written, if they match everything went as planned.
|
Chris@0
|
385 */
|
Chris@0
|
386 test_readf_double_or_die (infile_piped, 0, buffer, PIPE_TEST_LEN, __LINE__) ;
|
Chris@0
|
387 if (memcmp (buffer, data, sizeof (buffer)) != 0)
|
Chris@0
|
388 { printf ("\n\n%s %d : unseekable pipe test failed for file type \"%s\".\n\n", __func__, __LINE__, ext) ;
|
Chris@0
|
389 exit (1) ;
|
Chris@0
|
390 } ;
|
Chris@0
|
391
|
Chris@0
|
392 /* Wait for the child process to return. */
|
Chris@0
|
393 waitpid (pida, &status, 0) ;
|
Chris@0
|
394 status = WEXITSTATUS (status) ;
|
Chris@0
|
395 sf_close (outfile) ;
|
Chris@0
|
396 sf_close (infile_piped) ;
|
Chris@0
|
397
|
Chris@0
|
398 if (status != 0)
|
Chris@0
|
399 { printf ("\n\n%s %d : status of child process is %d for file type %s.\n\n", __func__, __LINE__, status, ext) ;
|
Chris@0
|
400 exit (1) ;
|
Chris@0
|
401 } ;
|
Chris@0
|
402
|
Chris@0
|
403 return ;
|
Chris@0
|
404 } /* useek_pipe_rw_double */
|
Chris@0
|
405
|
Chris@0
|
406
|
Chris@0
|
407
|
Chris@0
|
408
|
Chris@0
|
409 static void
|
Chris@0
|
410 useek_pipe_rw_test (int filetype, const char *ext)
|
Chris@0
|
411 { SF_INFO sfinfo_write ;
|
Chris@0
|
412 SF_INFO sfinfo_read ;
|
Chris@0
|
413
|
Chris@0
|
414 print_test_name ("useek_pipe_rw_test", ext) ;
|
Chris@0
|
415
|
Chris@0
|
416 /*
|
Chris@0
|
417 ** Setup the INFO structures for the filetype we will be
|
Chris@0
|
418 ** working with.
|
Chris@0
|
419 */
|
Chris@0
|
420 sfinfo_write.format = filetype | SF_FORMAT_PCM_16 ;
|
Chris@0
|
421 sfinfo_write.channels = 1 ;
|
Chris@0
|
422 sfinfo_write.samplerate = 44100 ;
|
Chris@0
|
423
|
Chris@0
|
424
|
Chris@0
|
425 sfinfo_read.format = 0 ;
|
Chris@0
|
426 if (filetype == SF_FORMAT_RAW)
|
Chris@0
|
427 { sfinfo_read.format = filetype | SF_FORMAT_PCM_16 ;
|
Chris@0
|
428 sfinfo_read.channels = 1 ;
|
Chris@0
|
429 sfinfo_read.samplerate = 44100 ;
|
Chris@0
|
430 } ;
|
Chris@0
|
431
|
Chris@0
|
432 useek_pipe_rw_short (ext, &sfinfo_write, &sfinfo_read) ;
|
Chris@0
|
433
|
Chris@0
|
434 sfinfo_read.format = sfinfo_write.format = filetype | SF_FORMAT_FLOAT ;
|
Chris@0
|
435 if (sf_format_check (&sfinfo_read) != 0)
|
Chris@0
|
436 useek_pipe_rw_float (ext, &sfinfo_write, &sfinfo_read) ;
|
Chris@0
|
437
|
Chris@0
|
438 sfinfo_read.format = sfinfo_write.format = filetype | SF_FORMAT_DOUBLE ;
|
Chris@0
|
439 if (sf_format_check (&sfinfo_read) != 0)
|
Chris@0
|
440 useek_pipe_rw_double (ext, &sfinfo_write, &sfinfo_read) ;
|
Chris@0
|
441
|
Chris@0
|
442 puts ("ok") ;
|
Chris@0
|
443 return ;
|
Chris@0
|
444 } /* useek_pipe_rw_test */
|
Chris@0
|
445
|
Chris@0
|
446
|
Chris@0
|
447
|
Chris@0
|
448 static void
|
Chris@0
|
449 pipe_test_others (FILETYPE* list1, FILETYPE* list2)
|
Chris@0
|
450 { SF_FORMAT_INFO info ;
|
Chris@0
|
451 int k, m, major_count, in_list ;
|
Chris@0
|
452
|
Chris@0
|
453 print_test_name ("pipe_test_others", "") ;
|
Chris@0
|
454
|
Chris@0
|
455 sf_command (NULL, SFC_GET_FORMAT_MAJOR_COUNT, &major_count, sizeof (int)) ;
|
Chris@0
|
456
|
Chris@0
|
457 for (k = 0 ; k < major_count ; k++)
|
Chris@0
|
458 { info.format = k ;
|
Chris@0
|
459
|
Chris@0
|
460 sf_command (NULL, SFC_GET_FORMAT_MAJOR, &info, sizeof (info)) ;
|
Chris@0
|
461
|
Chris@0
|
462 in_list = SF_FALSE ;
|
Chris@0
|
463 for (m = 0 ; list1 [m].format ; m++)
|
Chris@0
|
464 if (info.format == list1 [m].format)
|
Chris@0
|
465 in_list = SF_TRUE ;
|
Chris@0
|
466
|
Chris@0
|
467 for (m = 0 ; list2 [m].format ; m++)
|
Chris@0
|
468 if (info.format == list2 [m].format)
|
Chris@0
|
469 in_list = SF_TRUE ;
|
Chris@0
|
470
|
Chris@0
|
471 if (in_list)
|
Chris@0
|
472 continue ;
|
Chris@0
|
473
|
Chris@0
|
474 printf ("%s %x\n", info.name, info.format) ;
|
Chris@0
|
475
|
Chris@0
|
476 if (1)
|
Chris@0
|
477 { static short data [PIPE_TEST_LEN] ;
|
Chris@0
|
478 static char buffer [256] ;
|
Chris@0
|
479 static const char *filename = "pipe_in.dat" ;
|
Chris@0
|
480
|
Chris@0
|
481 SNDFILE *outfile ;
|
Chris@0
|
482 SF_INFO sfinfo ;
|
Chris@0
|
483 int retval ;
|
Chris@0
|
484
|
Chris@0
|
485 sfinfo.format = info.format | SF_FORMAT_PCM_16 ;
|
Chris@0
|
486 sfinfo.channels = 1 ;
|
Chris@0
|
487 sfinfo.samplerate = 44100 ;
|
Chris@0
|
488
|
Chris@0
|
489 outfile = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
490 test_writef_short_or_die (outfile, 0, data, PIPE_TEST_LEN, __LINE__) ;
|
Chris@0
|
491 sf_close (outfile) ;
|
Chris@0
|
492
|
Chris@0
|
493 snprintf (buffer, sizeof (buffer), "cat %s | ./stdin_test %s %d ", filename, info.extension, PIPE_TEST_LEN) ;
|
Chris@0
|
494 if ((retval = system (buffer)) == 0)
|
Chris@0
|
495 { retval = WEXITSTATUS (retval) ;
|
Chris@0
|
496 printf ("\n\n Line %d : pipe test should have returned error file type \"%s\" but didn't.\n\n", __LINE__, info.name) ;
|
Chris@0
|
497 exit (1) ;
|
Chris@0
|
498 } ;
|
Chris@0
|
499
|
Chris@0
|
500 unlink (filename) ;
|
Chris@0
|
501 } ;
|
Chris@0
|
502 } ;
|
Chris@0
|
503
|
Chris@0
|
504
|
Chris@0
|
505 puts ("ok") ;
|
Chris@0
|
506
|
Chris@0
|
507 return ;
|
Chris@0
|
508 } /* pipe_test_others */
|
Chris@0
|
509
|
Chris@0
|
510
|
Chris@0
|
511 /*==============================================================================
|
Chris@0
|
512 */
|
Chris@0
|
513
|
Chris@0
|
514 static int
|
Chris@0
|
515 file_exists (const char *filename)
|
Chris@0
|
516 { struct stat buf ;
|
Chris@0
|
517
|
Chris@0
|
518 if (stat (filename, &buf))
|
Chris@0
|
519 return 0 ;
|
Chris@0
|
520
|
Chris@0
|
521 return 1 ;
|
Chris@0
|
522 } /* file_exists */
|
Chris@0
|
523
|
Chris@0
|
524 #endif
|
Chris@0
|
525
|