File: sdlx_music.t

package info (click to toggle)
libsdl-perl 2.548-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,972 kB
  • sloc: perl: 13,985; ansic: 583; makefile: 35
file content (145 lines) | stat: -rw-r--r-- 2,902 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/usr/bin/perl -w
use strict;
use warnings;
use SDL;
use SDL::Config;

my $audiodriver;

BEGIN {
    use Config;
    if ( !$Config{'useithreads'} ) {
        print("1..0 # Skip: Perl not compiled with 'useithreads'\n");
        exit(0);
    }
    require threads;
    require threads::shared;

    use Test::More;
    use lib 't/lib';
    use SDL::TestTool;

    $audiodriver = $ENV{SDL_AUDIODRIVER};
    $ENV{SDL_AUDIODRIVER} = 'dummy' unless $ENV{SDL_RELEASE_TESTING};

    if ( !SDL::TestTool->init(SDL_INIT_AUDIO) ) {
        plan( skip_all => 'Failed to init sound' );
    }
    elsif ( !SDL::Config->has('SDL_mixer') ) {
        plan( skip_all => 'SDL_mixer support not compiled' );
    }
}

use_ok( 'SDLx::Music', "Can load SDLx::Music" );

# Object Creation

can_ok( 'SDLx::Music', 'new' );

my $music = SDLx::Music->new();

#my $music2 = SDLx::Music->new();

isa_ok( $music, "SDLx::Music" );

#isa_ok( $music2, "SDLx::Music" );

# Music Data defination

can_ok( 'SDLx::Music', 'data' );

## Simple
ok( $music->data( silence => 'test/data/silence.wav' ) );

## Long
ok(
    $music->data(
        sample => {
            file    => 'test/data/sample.wav',
            loops   => 2,
            fade_in => 0.5,
            volume  => 72
        },
    )
);


## Check if stuff actually got loaded
my $silence = $music->data('silence');

isa_ok( $silence, "SDLx::Music::Data");
isa_ok( $music->data('sample'), "SDLx::Music::Data");

is_deeply( $silence, $music->{data}->{silence}, "Silence is retreived correctly");
is_deeply( $music->data('sample'), $music->{data}->{sample}, "Sample is retreived correctly");

# Chained changes

can_ok( 'SDLx::Music', 'playing');

$silence->volume(55)->loops(2)->file('test/data/silence.wav'); 

$music->play($silence);

my $played; 
while( $music->playing )
{
	$played = 1 unless $played;
}

is( $played, 1, "Music played and atleast one" ); 	

isa_ok( $music->{data}->{silence}->{_content}, "SDL::Mixer::MixMusic", "Didn't load data for play" );

can_ok(  'SDLx::Music', 'load' );

$music->load;

isa_ok( $music->{data}->{sample}->{_content}, "SDL::Mixer::MixMusic" );

$music->play( $music->data('sample') );

$played = 0;
while( $music->playing )
{
	$played = 1 unless $played;
}

is( $played, 1, "Music played and atleast one" ); 	

is( $silence->{volume}, 55);


# Clear the data 

can_ok ( 'SDLx::Music', 'clear' );

ok( $music->clear );

## Check if we are actually clear

is( $music->{data}, undef, "Is clear" );

# Check default call

can_ok ( 'SDLx::Music', 'default' );

isa_ok( $music->default, "SDLx::Music::Default" );

$music->default->ext('.wav');

isa_ok( SDLx::Music->default, "SDLx::Music::Default" );

SDLx::Music->default->ext('.ogg');

is( $music->default->ext, '.wav' );
is( SDLx::Music->default->ext, '.ogg');

if ($audiodriver) {
    $ENV{SDL_AUDIODRIVER} = $audiodriver;
}
else {
    delete $ENV{SDL_AUDIODRIVER};
}

done_testing();