PageRenderTime 51ms CodeModel.GetById 12ms app.highlight 35ms RepoModel.GetById 1ms app.codeStats 0ms

/t/mixer.t

http://github.com/PerlGameDev/SDL
Perl | 109 lines | 84 code | 19 blank | 6 comment | 7 complexity | 3b5790daa7f3f3d7d75bb6acfdf1164d 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#
 35
 36use SDL::Mixer;
 37use SDL::Version;
 38
 39my $v = SDL::Mixer::linked_version();
 40
 41isa_ok( $v, 'SDL::Version', '[linked_version]' );
 42printf( "got version: %d.%d.%d\n", $v->major, $v->minor, $v->patch );
 43
 44is( MIX_DEFAULT_CHANNELS, 2, 'MIX_DEFAULT_CHANNELS should be imported' );
 45is( MIX_DEFAULT_CHANNELS(), 2,
 46	'MIX_DEFAULT_CHANNELS() should also be available'
 47);
 48is( MIX_DEFAULT_FORMAT, 32784, 'MIX_DEFAULT_FORMAT should be imported' );
 49is( MIX_DEFAULT_FORMAT(), 32784,
 50	'MIX_DEFAULT_FORMAT() should also be available'
 51);
 52is( MIX_DEFAULT_FREQUENCY, 22050, 'MIX_DEFAULT_FREQUENCY should be imported' );
 53is( MIX_DEFAULT_FREQUENCY(), 22050,
 54	'MIX_DEFAULT_FREQUENCY() should also be available'
 55);
 56is( MIX_FADING_IN,    2,   'MIX_FADING_IN should be imported' );
 57is( MIX_FADING_IN(),  2,   'MIX_FADING_IN() should also be available' );
 58is( MIX_FADING_OUT,   1,   'MIX_FADING_OUT should be imported' );
 59is( MIX_FADING_OUT(), 1,   'MIX_FADING_OUT() should also be available' );
 60is( MIX_MAX_VOLUME,   128, 'MIX_MAX_VOLUME should be imported' );
 61is( MIX_MAX_VOLUME(), 128, 'MIX_MAX_VOLUME() should also be available' );
 62is( MIX_NO_FADING,    0,   'MIX_NO_FADING should be imported' );
 63is( MIX_NO_FADING(),  0,   'MIX_NO_FADING() should also be available' );
 64
 65SKIP:
 66{
 67	skip( 'Version 1.2.10 needed', 1 ) if $v < 1.2.10;
 68	my @flags = ( MIX_INIT_MP3, MIX_INIT_MOD, MIX_INIT_FLAC, MIX_INIT_OGG );
 69	my @names = qw/MP3 MOD FLAC OGG/;
 70	foreach ( 0 ... 3 ) {
 71		my $f = $flags[$_];
 72		my $n = $names[$_];
 73		( SDL::Mixer::init($f) != $f )
 74			? print "Tried to init $n" . SDL::get_error() . "\n"
 75			: print "You have $n support\n";
 76		pass 'Init ran';
 77	}
 78}
 79
 80is( SDL::Mixer::open_audio( 44100, SDL::Audio::AUDIO_S16SYS, 2, 4096 ),
 81	0, '[open_audio] ran'
 82);
 83
 84my $data = SDL::Mixer::query_spec();
 85
 86my ( $status, $freq, $format, $chan ) = @{$data};
 87
 88isnt( $status, 0, '[query_spec] ran' );
 89isnt( $freq,   0, '[query_spec] got frequency ' . $freq );
 90isnt( $format, 0, '[query_spec] got format ' );
 91isnt( $chan,   0, '[query_spec] got channels ' . $chan );
 92
 93SDL::Mixer::close_audio();
 94pass '[close_audio]  ran';
 95
 96SKIP:
 97{
 98	skip( 'Version 1.2.10 needed', 1 ) if $v < 1.2.10;
 99	SDL::Mixer::quit();
100	pass '[quit] ran';
101}
102
103if ($audiodriver) {
104	$ENV{SDL_AUDIODRIVER} = $audiodriver;
105} else {
106	delete $ENV{SDL_AUDIODRIVER};
107}
108
109done_testing();