1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
|
/*
** Copyright (C) 2001-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*==========================================================================
** This is a test program which tests reading from stdin and writing to
** stdout.
*/
#include "sfconfig.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <sys/types.h>
#include <sys/stat.h>
#if HAVE_SYS_WAIT_H
#include <sys/wait.h>
#endif
#include "utils.h"
/* EMX is OS/2. */
#if (OS_IS_WIN32) || defined (__EMX__)
int
main (void)
{
puts (" stdio_test : this test doesn't work on win32.") ;
return 0 ;
} /* main */
#else
#ifndef WIFEXITED
#define WIFEXITED(s) (((s) & 0xff) == 0)
#endif
#ifndef WEXITSTATUS
#define WEXITSTATUS(s) (((s) & 0xff00) >> 8)
#endif
static size_t file_length (const char *filename) ;
static int file_exists (const char *filename) ;
static void stdio_test (const char *filetype) ;
static const char *filetypes [] =
{ "raw", "wav", "aiff", "au", "paf", "svx", "nist", "ircam",
"voc", "w64", "mat4", "mat5", "pvf",
NULL
} ;
int
main (void)
{ int k ;
if (file_exists ("libsndfile.spec.in"))
exit_if_true (chdir ("tests") != 0, "\n Error : chdir ('tests') failed.\n") ;
for (k = 0 ; filetypes [k] ; k++)
stdio_test (filetypes [k]) ;
return 0 ;
} /* main */
static void
stdio_test (const char *filetype)
{ static char buffer [256] ;
int file_size, retval ;
print_test_name ("stdio_test", filetype) ;
snprintf (buffer, sizeof (buffer), "./stdout_test %s > stdio.%s", filetype, filetype) ;
if ((retval = system (buffer)))
{ retval = WIFEXITED (retval) ? WEXITSTATUS (retval) : 1 ;
printf ("%s : %s", buffer, (strerror (retval))) ;
exit (1) ;
} ;
snprintf (buffer, sizeof (buffer), "stdio.%s", filetype) ;
if ((file_size = file_length (buffer)) < PIPE_TEST_LEN)
{ printf ("\n Error : test file '%s' too small (%d).\n\n", buffer, file_size) ;
exit (1) ;
} ;
snprintf (buffer, sizeof (buffer), "./stdin_test %s < stdio.%s", filetype, filetype) ;
if ((retval = system (buffer)))
{ retval = WIFEXITED (retval) ? WEXITSTATUS (retval) : 1 ;
printf ("%s : %s", buffer, (strerror (retval))) ;
exit (1) ;
} ;
snprintf (buffer, sizeof (buffer), "rm stdio.%s", filetype) ;
if ((retval = system (buffer)))
{ retval = WIFEXITED (retval) ? WEXITSTATUS (retval) : 1 ;
printf ("%s : %s", buffer, (strerror (retval))) ;
exit (1) ;
} ;
puts ("ok") ;
return ;
} /* stdio_test */
static size_t
file_length (const char *filename)
{ struct stat buf ;
if (stat (filename, &buf))
{ perror (filename) ;
exit (1) ;
} ;
return buf.st_size ;
} /* file_length */
static int
file_exists (const char *filename)
{ struct stat buf ;
if (stat (filename, &buf))
return 0 ;
return 1 ;
} /* file_exists */
#endif
|