stdio_test.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. ** Copyright (C) 2001-2011 Erik de Castro Lopo <[email protected]>
  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. ** This is a test program which tests reading from stdin and writing to
  20. ** stdout.
  21. */
  22. #include "sfconfig.h"
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <string.h>
  26. #if HAVE_UNISTD_H
  27. #include <unistd.h>
  28. #else
  29. #include "sf_unistd.h"
  30. #endif
  31. #include <sys/types.h>
  32. #include <sys/stat.h>
  33. #if HAVE_SYS_WAIT_H
  34. #include <sys/wait.h>
  35. #endif
  36. #include "utils.h"
  37. /* EMX is OS/2. */
  38. #if (OS_IS_WIN32) || defined (__EMX__)
  39. int
  40. main (void)
  41. {
  42. puts (" stdio_test : this test doesn't work on win32.") ;
  43. return 0 ;
  44. } /* main */
  45. #else
  46. #ifndef WIFEXITED
  47. #define WIFEXITED(s) (((s) & 0xff) == 0)
  48. #endif
  49. #ifndef WEXITSTATUS
  50. #define WEXITSTATUS(s) (((s) & 0xff00) >> 8)
  51. #endif
  52. static size_t file_length (const char *filename) ;
  53. static void stdio_test (const char *filetype) ;
  54. static const char *filetypes [] =
  55. { "raw", "wav", "aiff", "au", "paf", "svx", "nist", "ircam",
  56. "voc", "w64", "mat4", "mat5", "pvf",
  57. NULL
  58. } ;
  59. int
  60. main (void)
  61. { int k ;
  62. for (k = 0 ; filetypes [k] ; k++)
  63. stdio_test (filetypes [k]) ;
  64. return 0 ;
  65. } /* main */
  66. static void
  67. stdio_test (const char *filetype)
  68. { static char buffer [256] ;
  69. int file_size, retval ;
  70. print_test_name ("stdio_test", filetype) ;
  71. snprintf (buffer, sizeof (buffer), "./tests/stdout_test %s > stdio.%s", filetype, filetype) ;
  72. if ((retval = system (buffer)))
  73. { retval = WIFEXITED (retval) ? WEXITSTATUS (retval) : 1 ;
  74. printf ("%s : %s", buffer, (strerror (retval))) ;
  75. exit (1) ;
  76. } ;
  77. snprintf (buffer, sizeof (buffer), "stdio.%s", filetype) ;
  78. if ((file_size = file_length (buffer)) < PIPE_TEST_LEN)
  79. { printf ("\n Error : test file '%s' too small (%d).\n\n", buffer, file_size) ;
  80. exit (1) ;
  81. } ;
  82. snprintf (buffer, sizeof (buffer), "./tests/stdin_test %s < stdio.%s", filetype, filetype) ;
  83. if ((retval = system (buffer)))
  84. { retval = WIFEXITED (retval) ? WEXITSTATUS (retval) : 1 ;
  85. printf ("%s : %s", buffer, (strerror (retval))) ;
  86. exit (1) ;
  87. } ;
  88. snprintf (buffer, sizeof (buffer), "rm stdio.%s", filetype) ;
  89. if ((retval = system (buffer)))
  90. { retval = WIFEXITED (retval) ? WEXITSTATUS (retval) : 1 ;
  91. printf ("%s : %s", buffer, (strerror (retval))) ;
  92. exit (1) ;
  93. } ;
  94. puts ("ok") ;
  95. return ;
  96. } /* stdio_test */
  97. static size_t
  98. file_length (const char *filename)
  99. { struct stat buf ;
  100. if (stat (filename, &buf))
  101. { perror (filename) ;
  102. exit (1) ;
  103. } ;
  104. return buf.st_size ;
  105. } /* file_length */
  106. #endif