2
0

rdwr_test.tpl 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. [+ AutoGen5 template c +]
  2. /*
  3. ** Copyright (C) 2010-2012 Erik de Castro Lopo <erikd@mega-nerd.com>
  4. **
  5. ** This program is free software ; you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation ; either version 2 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY ; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program ; if not, write to the Free Software
  17. ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. */
  19. #include "sfconfig.h"
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23. #include <sys/stat.h>
  24. #include <math.h>
  25. #if HAVE_UNISTD_H
  26. #include <unistd.h>
  27. #endif
  28. #if (HAVE_DECL_S_IRGRP == 0)
  29. #include <sf_unistd.h>
  30. #endif
  31. #if (defined (WIN32) || defined (_WIN32))
  32. #include <io.h>
  33. #include <direct.h>
  34. #endif
  35. #include <sndfile.h>
  36. #include "utils.h"
  37. [+ FOR data_type
  38. +]static void rdwr_[+ (get "name") +]_test (const char *filename) ;
  39. [+ ENDFOR data_type
  40. +]
  41. int
  42. main (void)
  43. {
  44. rdwr_short_test ("rdwr_short.wav") ;
  45. rdwr_int_test ("rdwr_int.wav") ;
  46. rdwr_float_test ("rdwr_float.wav") ;
  47. rdwr_double_test ("rdwr_double.wav") ;
  48. rdwr_raw_test ("rdwr_raw.wav") ;
  49. return 0 ;
  50. } /* main */
  51. /*============================================================================================
  52. ** Here are the test functions.
  53. */
  54. [+ FOR data_type
  55. +]static void
  56. rdwr_[+ (get "name") +]_test (const char *filename)
  57. { SNDFILE *file ;
  58. SF_INFO sfinfo ;
  59. sf_count_t frames ;
  60. [+ (get "type") +] buffer [160] ;
  61. print_test_name ("rdwr_[+ (get "name") +]_test", filename) ;
  62. memset (buffer, 0, sizeof (buffer)) ;
  63. /* Create sound file with no data. */
  64. sfinfo.format = SF_FORMAT_WAV | [+ (get "format") +] ;
  65. sfinfo.samplerate = 16000 ;
  66. sfinfo.channels = 1 ;
  67. unlink (filename) ;
  68. frames = ARRAY_LEN (buffer) ;
  69. /* Open again for read/write. */
  70. file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, SF_TRUE, __LINE__) ;
  71. test_write_[+ (get "name") +]_or_die (file, 0, buffer, frames, __LINE__) ;
  72. test_read_[+ (get "name") +]_or_die (file, 0, buffer, frames, __LINE__) ;
  73. sf_close (file) ;
  74. unlink (filename) ;
  75. puts ("ok") ;
  76. return ;
  77. } /* rdwr_[+ (get "name") +]_test */
  78. [+ ENDFOR data_type
  79. +]