/t/mixer_samples.t

http://github.com/PerlGameDev/SDL · Perl · 117 lines · 90 code · 22 blank · 5 comment · 6 complexity · d4da1902f937282820cd6017c6952686 MD5 · raw file

  1. #!/usr/bin/perl -w
  2. use strict;
  3. use warnings;
  4. use SDL;
  5. use SDL::Config;
  6. my $audiodriver;
  7. BEGIN {
  8. use Config;
  9. if ( !$Config{'useithreads'} ) {
  10. print("1..0 # Skip: Perl not compiled with 'useithreads'\n");
  11. exit(0);
  12. }
  13. use Test::More;
  14. use lib 't/lib';
  15. use SDL::TestTool;
  16. $audiodriver = $ENV{SDL_AUDIODRIVER};
  17. $ENV{SDL_AUDIODRIVER} = 'dummy' unless $ENV{SDL_RELEASE_TESTING};
  18. if ( !SDL::TestTool->init(SDL_INIT_AUDIO) ) {
  19. plan( skip_all => 'Failed to init sound' );
  20. } elsif ( !SDL::Config->has('SDL_mixer') ) {
  21. plan( skip_all => 'SDL_mixer support not compiled' );
  22. }
  23. } #SDL_init(SDL_INIT_AUDIO) + Version bootstrap conflict prevention in windows
  24. #
  25. # To reproduce this bug do
  26. #
  27. # use SDL; use SDL::Version; SDL::init(SDL_INIT_AUDIO);
  28. use SDL::Mixer;
  29. use SDL::Mixer::MixChunk;
  30. use SDL::Mixer::Samples;
  31. use SDL::Mixer::Channels;
  32. use SDL::RWOps;
  33. use SDL::Version;
  34. my @done = qw/
  35. get_num_chunk_decoders
  36. get_chunk_decoder
  37. load_WAV
  38. volume_chunk
  39. load_WAV_RW
  40. /;
  41. my @left = qw/
  42. quick_load_WAV
  43. quick_load_RAW
  44. /;
  45. my $can_open = SDL::Mixer::open_audio( 44100, SDL::Audio::AUDIO_S16SYS, 2, 4096 );
  46. unless($can_open == 0)
  47. {
  48. plan( skip_all => 'Cannot open audio :'.SDL::get_error() );
  49. }my $version = SDL::Mixer::linked_version();
  50. printf(
  51. "got version: %d.%d.%d\n",
  52. $version->major, $version->minor, $version->patch
  53. );
  54. SKIP:
  55. {
  56. skip 'Need version 1.2.10', 2 if $version < 1.2.10;
  57. is( SDL::Mixer::Samples::get_num_chunk_decoders() >= 0,
  58. 1, '[get_num_chunk_decoders] passed'
  59. );
  60. my $stream = SDL::Mixer::Samples::get_chunk_decoder(0);
  61. is( defined $stream, 1, "[get_chunk_decoder] found decoder $stream" );
  62. }
  63. my $sample_chunk = SDL::Mixer::Samples::load_WAV('test/data/sample.wav');
  64. isa_ok( $sample_chunk, 'SDL::Mixer::MixChunk', '[load_WAV]' );
  65. is( SDL::Mixer::Samples::volume_chunk( $sample_chunk, 120 ),
  66. 128, '[volume_chunk] was at max 128 volume on start'
  67. );
  68. is( SDL::Mixer::Samples::volume_chunk( $sample_chunk, 10 ),
  69. 120, '[volume_chunk] is now at 120 volume'
  70. );
  71. my $file = SDL::RWOps->new_file( 'test/data/sample.wav', 'r' );
  72. isa_ok( $file, 'SDL::RWOps', '[new_file]' );
  73. isa_ok(
  74. SDL::Mixer::Samples::load_WAV_RW( $file, 0 ),
  75. 'SDL::Mixer::MixChunk', '[load_WAV_RW]'
  76. );
  77. my $why =
  78. '[Percentage Completion] '
  79. . int( 100 * ( $#done + 1 ) / ( $#done + $#left + 2 ) )
  80. . "\% implementation. "
  81. . ( $#done + 1 ) . " / "
  82. . ( $#done + $#left + 2 );
  83. TODO:
  84. {
  85. local $TODO = $why;
  86. fail "Not Implmented SDL::Mixer::*::$_" foreach (@left);
  87. }
  88. print "$why\n";
  89. pass 'Checking for segfaults';
  90. if ($audiodriver) {
  91. $ENV{SDL_AUDIODRIVER} = $audiodriver;
  92. } else {
  93. delete $ENV{SDL_AUDIODRIVER};
  94. }
  95. done_testing();