PageRenderTime 41ms CodeModel.GetById 16ms app.highlight 21ms RepoModel.GetById 1ms app.codeStats 0ms

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