annotate src/libsndfile-1.0.27/tests/pipe_test.c @ 84:08ae793730bd

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