external_libs_test.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*
  2. ** Copyright (C) 2008-2017 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. #include "sfconfig.h"
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <string.h>
  22. #include <errno.h>
  23. #if HAVE_UNISTD_H
  24. #include <unistd.h>
  25. #else
  26. #include "sf_unistd.h"
  27. #endif
  28. #include <sndfile.h>
  29. #include "utils.h"
  30. static void major_format_test (void) ;
  31. static void subtype_format_test (void) ;
  32. static void simple_format_test (void) ;
  33. static void flac_subset_test (void) ;
  34. int
  35. main (void)
  36. {
  37. major_format_test () ;
  38. subtype_format_test () ;
  39. simple_format_test () ;
  40. if (HAVE_EXTERNAL_XIPH_LIBS)
  41. flac_subset_test () ;
  42. return 0 ;
  43. } /* main */
  44. static void
  45. major_format_test (void)
  46. { SF_FORMAT_INFO info ;
  47. int have_ogg = 0, have_flac = 0 ;
  48. int m, major_count ;
  49. print_test_name (__func__, NULL) ;
  50. sf_command (NULL, SFC_GET_FORMAT_MAJOR_COUNT, &major_count, sizeof (int)) ;
  51. for (m = 0 ; m < major_count ; m++)
  52. { info.format = m ;
  53. sf_command (NULL, SFC_GET_FORMAT_MAJOR, &info, sizeof (info)) ;
  54. have_flac = info.format == SF_FORMAT_FLAC ? 1 : have_flac ;
  55. have_ogg = info.format == SF_FORMAT_OGG ? 1 : have_ogg ;
  56. } ;
  57. if (HAVE_EXTERNAL_XIPH_LIBS)
  58. { exit_if_true (have_flac == 0, "\n\nLine %d : FLAC should be available.\n\n", __LINE__) ;
  59. exit_if_true (have_ogg == 0, "\n\nLine %d : Ogg/Vorbis should be available.\n\n", __LINE__) ;
  60. }
  61. else
  62. { exit_if_true (have_flac, "\n\nLine %d : FLAC should not be available.\n\n", __LINE__) ;
  63. exit_if_true (have_ogg, "\n\nLine %d : Ogg/Vorbis should not be available.\n\n", __LINE__) ;
  64. } ;
  65. puts ("ok") ;
  66. } /* major_format_test */
  67. static void
  68. subtype_format_test (void)
  69. { SF_FORMAT_INFO info ;
  70. int have_vorbis = 0 , have_opus = 0 ;
  71. int s, subtype_count ;
  72. print_test_name (__func__, NULL) ;
  73. sf_command (NULL, SFC_GET_FORMAT_SUBTYPE_COUNT, &subtype_count, sizeof (int)) ;
  74. for (s = 0 ; s < subtype_count ; s++)
  75. { info.format = s ;
  76. sf_command (NULL, SFC_GET_FORMAT_SUBTYPE, &info, sizeof (info)) ;
  77. have_vorbis = info.format == SF_FORMAT_VORBIS ? 1 : have_vorbis ;
  78. have_opus = info.format == SF_FORMAT_OPUS ? 1 : have_opus ;
  79. } ;
  80. if (HAVE_EXTERNAL_XIPH_LIBS)
  81. { exit_if_true (have_vorbis == 0, "\n\nLine %d : Ogg/Vorbis should be available.\n\n", __LINE__) ;
  82. exit_if_true (have_opus == 0, "\n\nLine %d : Ogg/Opus should be available.\n\n", __LINE__) ;
  83. }
  84. else
  85. { exit_if_true (have_vorbis, "\n\nLine %d : Ogg/Vorbis should not be available.\n\n", __LINE__) ;
  86. exit_if_true (have_opus, "\n\nLine %d : Ogg/Opus should not be available.\n\n", __LINE__) ;
  87. } ;
  88. puts ("ok") ;
  89. } /* subtype_format_test */
  90. static void
  91. simple_format_test (void)
  92. { SF_FORMAT_INFO info ;
  93. int have_flac = 0, have_ogg = 0, have_vorbis = 0, have_opus = 0 ;
  94. int s, simple_count ;
  95. print_test_name (__func__, NULL) ;
  96. sf_command (NULL, SFC_GET_SIMPLE_FORMAT_COUNT, &simple_count, sizeof (int)) ;
  97. for (s = 0 ; s < simple_count ; s++)
  98. { info.format = s ;
  99. sf_command (NULL, SFC_GET_SIMPLE_FORMAT, &info, sizeof (info)) ;
  100. switch (info.format & SF_FORMAT_TYPEMASK)
  101. { case SF_FORMAT_FLAC :
  102. have_flac = 1 ;
  103. break ;
  104. case SF_FORMAT_OGG :
  105. have_ogg = 1 ;
  106. break ;
  107. default :
  108. break ;
  109. } ;
  110. switch (info.format & SF_FORMAT_SUBMASK)
  111. { case SF_FORMAT_VORBIS :
  112. have_vorbis = 1 ;
  113. break ;
  114. case SF_FORMAT_OPUS :
  115. have_opus = 1 ;
  116. break ;
  117. default :
  118. break ;
  119. } ;
  120. } ;
  121. if (HAVE_EXTERNAL_XIPH_LIBS)
  122. { exit_if_true (have_flac == 0, "\n\nLine %d : FLAC should be available.\n\n", __LINE__) ;
  123. exit_if_true (have_ogg == 0, "\n\nLine %d : Ogg/Vorbis should be available.\n\n", __LINE__) ;
  124. exit_if_true (have_vorbis == 0, "\n\nLine %d : Ogg/Vorbis should be available.\n\n", __LINE__) ;
  125. exit_if_true (have_opus == 0, "\n\nLine %d : Ogg/Opus should be available.\n\n", __LINE__) ;
  126. }
  127. else
  128. { exit_if_true (have_flac, "\n\nLine %d : FLAC should not be available.\n\n", __LINE__) ;
  129. exit_if_true (have_ogg, "\n\nLine %d : Ogg/Vorbis should not be available.\n\n", __LINE__) ;
  130. exit_if_true (have_vorbis, "\n\nLine %d : Ogg/Vorbis should not be available.\n\n", __LINE__) ;
  131. exit_if_true (have_opus, "\n\nLine %d : Ogg/Opus should not be available.\n\n", __LINE__) ;
  132. } ;
  133. puts ("ok") ;
  134. } /* simple_format_test */
  135. static void
  136. flac_subset_test (void)
  137. { float whatever [256] ;
  138. SNDFILE *file ;
  139. SF_INFO sfinfo ;
  140. sf_count_t rc ;
  141. int samplerate ;
  142. const char *filename = "subset_test.flac" ;
  143. /* For some formats (like FLAC) the headers are written *just* before the
  144. ** first bit of audio data. This test makes sure errors in that process
  145. ** are caught.
  146. */
  147. print_test_name (__func__, NULL) ;
  148. for (samplerate = 65536 ; samplerate < 655350 ; samplerate *= 4)
  149. { sfinfo.samplerate = samplerate ;
  150. sfinfo.channels = 1 ;
  151. sfinfo.frames = 0 ;
  152. sfinfo.format = SF_FORMAT_FLAC | SF_FORMAT_PCM_16 ;
  153. file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
  154. rc = sf_write_float (file, whatever, ARRAY_LEN (whatever)) ;
  155. unlink (filename) ;
  156. exit_if_true (rc != 0, "\n\nLine %d : return code (%d) should be 0.\n\n", __LINE__, (int) rc) ;
  157. sf_close (file) ;
  158. } ;
  159. puts ("ok") ;
  160. } /* flac_subset_test */