annotate src/libsndfile-1.0.27/tests/stdio_test.c @ 83:ae30d91d2ffe

Replace these with versions built using an older toolset (so as to avoid ABI compatibilities when linking on Ubuntu 14.04 for packaging purposes)
author Chris Cannam
date Fri, 07 Feb 2020 11:51:13 +0000
parents 1df64224f5ac
children
rev   line source
Chris@40 1 /*
Chris@40 2 ** Copyright (C) 2001-2011 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 stdin and writing to
Chris@40 21 ** stdout.
Chris@40 22 */
Chris@40 23
Chris@40 24 #include "sfconfig.h"
Chris@40 25
Chris@40 26 #include <stdio.h>
Chris@40 27 #include <stdlib.h>
Chris@40 28 #include <string.h>
Chris@40 29
Chris@40 30 #if HAVE_UNISTD_H
Chris@40 31 #include <unistd.h>
Chris@40 32 #endif
Chris@40 33
Chris@40 34 #include <sys/types.h>
Chris@40 35 #include <sys/stat.h>
Chris@40 36
Chris@40 37 #if HAVE_SYS_WAIT_H
Chris@40 38 #include <sys/wait.h>
Chris@40 39 #endif
Chris@40 40
Chris@40 41 #include "utils.h"
Chris@40 42
Chris@40 43 /* EMX is OS/2. */
Chris@40 44 #if (OS_IS_WIN32) || defined (__EMX__)
Chris@40 45
Chris@40 46 int
Chris@40 47 main (void)
Chris@40 48 {
Chris@40 49 puts (" stdio_test : this test doesn't work on win32.") ;
Chris@40 50 return 0 ;
Chris@40 51 } /* main */
Chris@40 52
Chris@40 53 #else
Chris@40 54
Chris@40 55 #ifndef WIFEXITED
Chris@40 56 #define WIFEXITED(s) (((s) & 0xff) == 0)
Chris@40 57 #endif
Chris@40 58 #ifndef WEXITSTATUS
Chris@40 59 #define WEXITSTATUS(s) (((s) & 0xff00) >> 8)
Chris@40 60 #endif
Chris@40 61
Chris@40 62
Chris@40 63 static size_t file_length (const char *filename) ;
Chris@40 64 static int file_exists (const char *filename) ;
Chris@40 65 static void stdio_test (const char *filetype) ;
Chris@40 66
Chris@40 67 static const char *filetypes [] =
Chris@40 68 { "raw", "wav", "aiff", "au", "paf", "svx", "nist", "ircam",
Chris@40 69 "voc", "w64", "mat4", "mat5", "pvf",
Chris@40 70 NULL
Chris@40 71 } ;
Chris@40 72
Chris@40 73 int
Chris@40 74 main (void)
Chris@40 75 { int k ;
Chris@40 76
Chris@40 77 if (file_exists ("libsndfile.spec.in"))
Chris@40 78 exit_if_true (chdir ("tests") != 0, "\n Error : chdir ('tests') failed.\n") ;
Chris@40 79
Chris@40 80 for (k = 0 ; filetypes [k] ; k++)
Chris@40 81 stdio_test (filetypes [k]) ;
Chris@40 82
Chris@40 83 return 0 ;
Chris@40 84 } /* main */
Chris@40 85
Chris@40 86
Chris@40 87 static void
Chris@40 88 stdio_test (const char *filetype)
Chris@40 89 { static char buffer [256] ;
Chris@40 90
Chris@40 91 int file_size, retval ;
Chris@40 92
Chris@40 93 print_test_name ("stdio_test", filetype) ;
Chris@40 94
Chris@40 95 snprintf (buffer, sizeof (buffer), "./stdout_test %s > stdio.%s", filetype, filetype) ;
Chris@40 96 if ((retval = system (buffer)))
Chris@40 97 { retval = WIFEXITED (retval) ? WEXITSTATUS (retval) : 1 ;
Chris@40 98 printf ("%s : %s", buffer, (strerror (retval))) ;
Chris@40 99 exit (1) ;
Chris@40 100 } ;
Chris@40 101
Chris@40 102 snprintf (buffer, sizeof (buffer), "stdio.%s", filetype) ;
Chris@40 103 if ((file_size = file_length (buffer)) < PIPE_TEST_LEN)
Chris@40 104 { printf ("\n Error : test file '%s' too small (%d).\n\n", buffer, file_size) ;
Chris@40 105 exit (1) ;
Chris@40 106 } ;
Chris@40 107
Chris@40 108 snprintf (buffer, sizeof (buffer), "./stdin_test %s < stdio.%s", filetype, filetype) ;
Chris@40 109 if ((retval = system (buffer)))
Chris@40 110 { retval = WIFEXITED (retval) ? WEXITSTATUS (retval) : 1 ;
Chris@40 111 printf ("%s : %s", buffer, (strerror (retval))) ;
Chris@40 112 exit (1) ;
Chris@40 113 } ;
Chris@40 114
Chris@40 115 snprintf (buffer, sizeof (buffer), "rm stdio.%s", filetype) ;
Chris@40 116 if ((retval = system (buffer)))
Chris@40 117 { retval = WIFEXITED (retval) ? WEXITSTATUS (retval) : 1 ;
Chris@40 118 printf ("%s : %s", buffer, (strerror (retval))) ;
Chris@40 119 exit (1) ;
Chris@40 120 } ;
Chris@40 121
Chris@40 122 puts ("ok") ;
Chris@40 123
Chris@40 124 return ;
Chris@40 125 } /* stdio_test */
Chris@40 126
Chris@40 127
Chris@40 128
Chris@40 129
Chris@40 130 static size_t
Chris@40 131 file_length (const char *filename)
Chris@40 132 { struct stat buf ;
Chris@40 133
Chris@40 134 if (stat (filename, &buf))
Chris@40 135 { perror (filename) ;
Chris@40 136 exit (1) ;
Chris@40 137 } ;
Chris@40 138
Chris@40 139 return buf.st_size ;
Chris@40 140 } /* file_length */
Chris@40 141
Chris@40 142 static int
Chris@40 143 file_exists (const char *filename)
Chris@40 144 { struct stat buf ;
Chris@40 145
Chris@40 146 if (stat (filename, &buf))
Chris@40 147 return 0 ;
Chris@40 148
Chris@40 149 return 1 ;
Chris@40 150 } /* file_exists */
Chris@40 151
Chris@40 152 #endif
Chris@40 153