stdio_test.c 3.5 KB

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