annotate src/libsndfile-1.0.25/tests/pipe_test.c @ 85:545efbb81310

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