File: 41-cmds-output.t

package info (click to toggle)
libpoe-component-client-mpd-perl 1.121670-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 320 kB
  • sloc: perl: 2,070; makefile: 2
file content (97 lines) | stat: -rw-r--r-- 2,788 bytes parent folder | download | duplicates (6)
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
#!perl
#
# This file is part of POE-Component-Client-MPD
#
# This software is copyright (c) 2007 by Jerome Quelin.
#
# This is free software; you can redistribute it and/or modify it under
# the same terms as the Perl 5 programming language system itself.
#

use 5.010;
use strict;
use warnings;

use POE;
use POE::Component::Client::MPD;
use POE::Component::Client::MPD::Test;
use Test::More;

# are we able to test module?
eval 'use Test::Corpus::Audio::MPD';
plan skip_all=>$@ if $@ =~ s/\n+BEGIN failed--compilation aborted.*//s;
plan tests => 20;

# launch fake mpd
POE::Component::Client::MPD->spawn;

# launch the tests
my @songs   = qw{ title.ogg dir1/title-artist-album.ogg dir1/title-artist.ogg };
POE::Component::Client::MPD::Test->new( { tests => [
    # [ 'event', [ $arg1, $arg2, ... ], $sleep, \&check_results ]

    # volume
    [ 'volume', [10], 0,  \&check_success                  ],  # init to sthg we know
    [ 'volume', [4],  0,  \&check_success                  ],
    [ 'status', [],   0,  \&check_volume_absolute          ],

    [ 'volume', ['+5'], 1, \&check_success                 ],
    [ 'status', [],     0, \&check_volume_relative_pos     ],

    [ 'volume', ['-4'], 1, \&check_success                 ],
    [ 'status', [],     0, \&check_volume_relative_neg     ],

    # output_disable.
    [ 'pl.add',         \@songs, 0, \&check_success        ],
    [ 'play',           [],      0, \&check_success        ],
    [ 'output_disable', [0],     1, \&check_success        ],
    [ 'status',         [],      0, \&check_output_disable ],

    # enable_output.
    [ 'output_enable',  [0],     1, \&check_success        ],
    [ 'play',           [],      0, \&check_success        ],
    [ 'pause',          [],      0, \&check_success        ],
    [ 'status',         [],      0, \&check_output_enable  ],
] } );
POE::Kernel->run;
exit;

#--

sub check_success {
    my ($msg) = @_;
    is($msg->status, 1, "command '" . $msg->request . "' returned an ok status");
}

sub check_volume_absolute {
    my ($msg, $status) = @_;
    check_success($msg);
    is($status->volume, 4, 'setting volume');
}

sub check_volume_relative_pos {
    my ($msg, $status) = @_;
    check_success($msg);
    is($status->volume, 9, 'increasing volume');
}

sub check_volume_relative_neg {
    my ($msg, $status) = @_;
    check_success($msg);
    is($status->volume, 5, 'decreasing volume');
}

sub check_output_disable {
    my ($msg, $status) = @_;
    check_success($msg);
    SKIP: {
        skip "detection method doesn't always work - depends on timing", 1;
        like($status->error, qr/^problems/, 'disabling output' );
    }
}

sub check_output_enable {
    my ($msg, $status) = @_;
    check_success($msg);
    is($status->error, undef, 'enabling output' );
}