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