PageRenderTime 27ms CodeModel.GetById 12ms app.highlight 12ms RepoModel.GetById 2ms app.codeStats 0ms

/t/sdlx_sound.t

http://github.com/PerlGameDev/SDL
Unknown | 94 lines | 77 code | 17 blank | 0 comment | 0 complexity | b8342f549a9e82398f597dc5f09df497 MD5 | raw file
 1# basic testing of SDLx::Sound
 2
 3use strict;
 4use warnings;
 5
 6my $audiodriver;
 7
 8BEGIN {
 9	use Config;
10	if ( !$Config{'useithreads'} ) {
11		print("1..0 # Skip: Perl not compiled with 'useithreads'\n");
12		exit(0);
13	}
14
15	use Test::More;
16	use lib 't/lib';
17	use lib 'lib';
18	use SDL;
19	use SDL::TestTool;
20	use SDL::Config;
21	use SDLx::Sound;
22
23	$audiodriver = $ENV{SDL_AUDIODRIVER};
24	$ENV{SDL_AUDIODRIVER} = 'dummy' unless $ENV{SDL_RELEASE_TESTING};
25
26	if ( !SDL::TestTool->init(SDL_INIT_AUDIO) ) {
27		plan( skip_all => 'Failed to init sound' );
28	} elsif ( !SDL::Config->has('SDL_mixer') ) {
29		plan( skip_all => 'SDL_mixer support not compiled' );
30	}
31} 
32my $fase2 = 0;
33
34# load
35# NOTE: use ok is tested in t/00-load.t so we can bail out
36
37# methods
38can_ok(
39		'SDLx::Sound', qw/
40		new
41		load
42		unload
43		play
44		stop
45		loud
46		fade
47		/
48      );
49
50ok (my $snd = SDLx::Sound->new(), 'Can be instantiated');
51ok (my $snd2 = SDLx::Sound->new(), 'Can be instantiated again');
52
53isa_ok( $snd, 'SDLx::Sound', 'snd' );
54isa_ok( $snd2, 'SDLx::Sound', 'snd2' );
55
56# load and play a sound
57ok ($snd->play('test/data/sample.wav'), 'Can play a wav');
58
59SKIP:
60{
61	skip 'complex tests', 1 unless $fase2;
62# in a single act do the wole Sound
63	ok( my $snd2 = SDLx::Sound->new(
64				files => (
65					chanell_01 => "test/data/sample.wav",
66					chanell_02 => "test/data/tribe_i.wav"
67
68					),
69				loud  => (
70					channel_01 => 80,
71					channel_02 => 75
72					),
73				bangs => (
74					chanell_01 => 0,      # start
75					chanell_01 => 1256,   # miliseconds
76					chanell_02 => 2345
77					),
78				fade  => (
79					chanell_02 => [2345, 3456, -20]
80					)
81				)->play()
82	  );
83}
84
85#diag( "Testing SDLx::Sound $SDLx::Sound::VERSION, Perl $], $^X" );           
86
87
88if ($audiodriver) {
89	$ENV{SDL_AUDIODRIVER} = $audiodriver;
90} else {
91	delete $ENV{SDL_AUDIODRIVER};
92}
93
94done_testing();