annotate src/libsndfile-1.0.27/tests/pipe_test.c @ 127:7867fa7e1b6b

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