3 # This file is part of POE::Component::Client::MPD.
4 # Copyright (c) 2007 Jerome Quelin, all rights reserved.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the same terms as Perl itself.
14 use POE qw[ Component::Client::MPD::Message ];
21 title.ogg dir1/title-artist-album.ogg
22 dir1/title-artist.ogg dir2/album.ogg
25 # [ 'event', [ $arg1, $arg2, ... ], $answer_back, \&check_results ]
27 [ 'pl.clear', [], $DISCARD, undef ],
28 [ 'pl.add', \@songs, $DISCARD, undef ],
31 [ 'play', [], $DISCARD, undef ],
32 [ 'status', [], $SEND, \&check_play1 ],
33 [ 'play', [2], $DISCARD, undef ],
34 [ 'status', [], $SEND, \&check_play2 ],
37 [ 'play', [0], $DISCARD, undef ],
38 [ 'pause', [], $DISCARD, undef ],
39 [ 'playid', [], $DISCARD, undef ],
40 [ 'status', [], $SEND, \&check_playid1 ],
41 [ 'playid', [1], $DISCARD, undef ],
42 [ 'status', [], $SEND, \&check_playid2 ],
45 [ 'pause', [1], $DISCARD, undef ],
46 [ 'status', [], $SEND, \&check_pause1 ],
47 [ 'pause', [0], $DISCARD, undef ],
48 [ 'status', [], $SEND, \&check_pause2 ],
49 [ 'pause', [], $DISCARD, undef ],
50 [ 'status', [], $SEND, \&check_pause3 ],
51 [ 'pause', [], $DISCARD, undef ],
52 [ 'status', [], $SEND, \&check_pause4 ],
55 [ 'stop', [], $DISCARD, undef ],
56 [ 'status', [], $SEND, \&check_stop ],
59 [ 'play', [1], $DISCARD, undef ],
60 [ 'pause', [], $DISCARD, undef ],
61 [ 'next', [], $DISCARD, undef ],
62 [ 'status', [], $SEND, \&check_prev ],
63 [ 'prev', [], $DISCARD, undef ],
64 [ 'status', [], $SEND, \&check_next ],
67 [ 'seek', [1,2], $DISCARD, undef ],
68 [ 'pause', [1], $DISCARD, undef ],
69 [ 'status', [], $SEND, \&check_seek1 ],
70 [ 'seek', [], $DISCARD, undef ],
71 [ 'pause', [1], $SLEEP1, undef ],
72 [ 'status', [], $SEND, \&check_seek2 ],
73 [ 'seek', [1], $DISCARD, undef ],
74 [ 'pause', [1], $SLEEP1, undef ],
75 [ 'status', [], $SEND, \&check_seek3 ],
78 [ 'seekid', [1,1], $DISCARD, undef ],
79 [ 'status', [], $SEND, \&check_seekid1 ],
80 [ 'seekid', [], $DISCARD, undef ],
81 [ 'pause', [1], $SLEEP1, undef ],
82 [ 'status', [], $SEND, \&check_seekid2 ],
83 [ 'seekid', [1], $DISCARD, undef ],
84 [ 'pause', [1], $SLEEP1, undef ],
85 [ 'status', [], $SEND, \&check_seekid3 ],
89 # are we able to test module?
90 eval 'use POE::Component::Client::MPD::Test';
91 plan skip_all => $@ if $@ =~ s/\n+BEGIN failed--compilation aborted.*//s;
94 sub check_play1 { is( $_[0]->data->state, 'play', 'play() starts playback' ); }
95 sub check_play2 { is( $_[0]->data->song, 2, 'play() can start playback at a given song' ); }
96 sub check_playid1 { is( $_[0]->data->state, 'play', 'playid() starts playback' ); }
97 sub check_playid2 { is( $_[0]->data->songid, 1, 'playid() can start playback at a given song' ); }
98 sub check_pause1 { is( $_[0]->data->state, 'pause', 'pause() forces playback pause' ); }
99 sub check_pause2 { is( $_[0]->data->state, 'play', 'pause() forces playback resume' ); }
100 sub check_pause3 { is( $_[0]->data->state, 'pause', 'pause() toggles to pause' ); }
101 sub check_pause4 { is( $_[0]->data->state, 'play', 'pause() toggles to play' ); }
102 sub check_stop { is( $_[0]->data->state, 'stop', 'stop() forces full stop' ); }
103 sub check_prev { is( $_[0]->data->song, 2, 'next() changes track to next one' ); }
104 sub check_next { is( $_[0]->data->song, 1, 'prev() changes track to previous one' ); }
106 my $status = $_[0]->data;
107 is( $status->song, 2, 'seek() can change the current track' );
108 is( $status->time->sofar_secs, 1, 'seek() seeks in the song' );
110 sub check_seek2 { is( $_[0]->data->time->sofar_secs, 0, 'seek() defaults to beginning of song' ); }
111 sub check_seek3 { is( $_[0]->data->time->sofar_secs, 1, 'seek() defaults to current song ' ); }
113 my $status = $_[0]->data;
114 is( $status->songid, 1, 'seekid() can change the current track' );
115 is( $status->time->sofar_secs, 1, 'seekid() seeks in the song' );
117 sub check_seekid2 { is( $_[0]->data->time->sofar_secs, 0, 'seekid() defaults to beginning of song' ); }
118 sub check_seekid3 { is( $_[0]->data->time->sofar_secs, 1, 'seekid() defaults to current song' ); }