• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #else
33 #include "sf_unistd.h"
34 #endif
35 
36 #include <sys/types.h>
37 #include <sys/stat.h>
38 
39 #if HAVE_SYS_WAIT_H
40 #include <sys/wait.h>
41 #endif
42 
43 #include "utils.h"
44 
45 /* EMX is OS/2. */
46 #if (OS_IS_WIN32) || defined (__EMX__)
47 
48 int
main(void)49 main (void)
50 {
51 	puts ("    stdio_test : this test doesn't work on win32.") ;
52 	return 0 ;
53 } /* main */
54 
55 #else
56 
57 #ifndef WIFEXITED
58 #define WIFEXITED(s) (((s) & 0xff) == 0)
59 #endif
60 #ifndef WEXITSTATUS
61 #define WEXITSTATUS(s) (((s) & 0xff00) >> 8)
62 #endif
63 
64 
65 static size_t	file_length (const char *filename) ;
66 static void		stdio_test (const char *filetype) ;
67 
68 static const char *filetypes [] =
69 {	"raw", "wav", "aiff", "au", "paf", "svx", "nist", "ircam",
70 	"voc", "w64", "mat4", "mat5", "pvf",
71 	NULL
72 } ;
73 
74 int
main(void)75 main (void)
76 {	int k ;
77 
78 	for (k = 0 ; filetypes [k] ; k++)
79 		stdio_test (filetypes [k]) ;
80 
81 	return 0 ;
82 } /* main */
83 
84 
85 static void
stdio_test(const char * filetype)86 stdio_test (const char *filetype)
87 {	static char buffer [256] ;
88 
89 	int file_size, retval ;
90 
91 	print_test_name ("stdio_test", filetype) ;
92 
93 	snprintf (buffer, sizeof (buffer), "./tests/stdout_test %s > stdio.%s", filetype, filetype) ;
94 	if ((retval = system (buffer)))
95 	{	retval = WIFEXITED (retval) ? WEXITSTATUS (retval) : 1 ;
96 		printf ("%s : %s", buffer, (strerror (retval))) ;
97 		exit (1) ;
98 		} ;
99 
100 	snprintf (buffer, sizeof (buffer), "stdio.%s", filetype) ;
101 	if ((file_size = file_length (buffer)) < PIPE_TEST_LEN)
102 	{	printf ("\n    Error : test file '%s' too small (%d).\n\n", buffer, file_size) ;
103 		exit (1) ;
104 		} ;
105 
106 	snprintf (buffer, sizeof (buffer), "./tests/stdin_test %s < stdio.%s", filetype, filetype) ;
107 	if ((retval = system (buffer)))
108 	{	retval = WIFEXITED (retval) ? WEXITSTATUS (retval) : 1 ;
109 		printf ("%s : %s", buffer, (strerror (retval))) ;
110 		exit (1) ;
111 		} ;
112 
113 	snprintf (buffer, sizeof (buffer), "rm stdio.%s", filetype) ;
114 	if ((retval = system (buffer)))
115 	{	retval = WIFEXITED (retval) ? WEXITSTATUS (retval) : 1 ;
116 		printf ("%s : %s", buffer, (strerror (retval))) ;
117 		exit (1) ;
118 		} ;
119 
120 	puts ("ok") ;
121 
122 	return ;
123 } /* stdio_test */
124 
125 
126 
127 
128 static size_t
file_length(const char * filename)129 file_length (const char *filename)
130 {	struct stat buf ;
131 
132 	if (stat (filename, &buf))
133 	{	perror (filename) ;
134 		exit (1) ;
135 		} ;
136 
137 	return buf.st_size ;
138 } /* file_length */
139 
140 #endif
141 
142