[project @ 5580]
[audio-mpd.git] / t / 26-playback.t
blobfa30fbffc9b4e568ba903a535fc3fc8b877bac3b
1 #!perl
3 # This file is part of Audio::MPD.
4 # Copyright (c) 2007 Jerome Quelin <jquelin@cpan.org>
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or (at
9 # your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 use strict;
23 use warnings;
25 use Audio::MPD;
26 use Test::More;
28 # are we able to test module?
29 eval 'use Audio::MPD::Test';
30 plan skip_all => $@ if $@ =~ s/\n+Compilation failed.*//s;
32 plan tests => 19;
33 my $mpd = Audio::MPD->new;
37 # testing play / playid.
38 $mpd->clear;
39 $mpd->add( 'title.ogg' );
40 $mpd->add( 'dir1/title-artist-album.ogg' );
41 $mpd->add( 'dir1/title-artist.ogg' );
42 $mpd->add( 'dir2/album.ogg' );
44 $mpd->play;
45 is( $mpd->status->state, 'play', 'play starts playback' );
46 $mpd->play(2);
47 is( $mpd->status->song,       2, 'play can start playback at a given song' );
49 $mpd->pause;
50 $mpd->playid;
51 is( $mpd->status->state, 'play', 'playid starts playback' );
52 $mpd->playid(1);
53 is( $mpd->status->songid,     1, 'playid can start playback at a given song' );
57 # testing pause.
58 $mpd->pause(1);
59 is( $mpd->status->state, 'pause', 'pause forces playback pause' );
60 $mpd->pause(0);
61 is( $mpd->status->state, 'play', 'pause can force playback resume' );
62 $mpd->pause;
63 is( $mpd->status->state, 'pause', 'pause toggles to pause' );
64 $mpd->pause;
65 is( $mpd->status->state, 'play', 'pause toggles to play' );
69 # testing stop.
70 $mpd->stop;
71 is( $mpd->status->state, 'stop', 'stop forces full stop' );
75 # testing prev / next.
76 $mpd->play(1); $mpd->pause;
77 $mpd->next;
78 is( $mpd->status->song, 2, 'next changes track to next one' );
79 $mpd->prev;
80 is( $mpd->status->song, 1, 'prev changes track to previous one' );
84 # testing seek / seekid.
85 $mpd->pause(1);
86 $mpd->seek( 1, 2 );
87 is( $mpd->status->song,     2, 'seek can change the current track' );
88 is( $mpd->status->time, '1:2', 'seek seeks in the song' );
89 $mpd->seek;
90 is( $mpd->status->time, '0:2', 'seek defaults to beginning of song' );
91 $mpd->seek(1);
92 is( $mpd->status->time, '1:2', 'seek defaults to current song ' );
95 $mpd->seekid( 1, 1 );
96 is( $mpd->status->songid,   1, 'seekid can change the current track' );
97 is( $mpd->status->time, '1:2', 'seekid seeks in the song' );
98 $mpd->seekid;
99 is( $mpd->status->time, '0:2', 'seekid defaults to beginning of song' );
100 $mpd->seekid(1);
101 is( $mpd->status->time, '1:2', 'seekid defaults to current song' );
105 exit;