extended copyright info to 2009
[audio-mpd.git] / t / 26-playback.t
blob27e849c399d86a110c132c34f0b36ba93629e543
1 #!perl
3 # This file is part of Audio::MPD
4 # Copyright (c) 2007-2009 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.
11 use strict;
12 use warnings;
14 use Audio::MPD;
15 use Test::More;
17 # are we able to test module?
18 eval 'use Audio::MPD::Test';
19 plan skip_all => $@ if $@ =~ s/\n+Compilation failed.*//s;
21 plan tests => 19;
22 my $mpd = Audio::MPD->new;
26 # testing play / playid.
27 $mpd->playlist->clear;
28 $mpd->playlist->add( 'title.ogg' );
29 $mpd->playlist->add( 'dir1/title-artist-album.ogg' );
30 $mpd->playlist->add( 'dir1/title-artist.ogg' );
31 $mpd->playlist->add( 'dir2/album.ogg' );
33 $mpd->play;
34 is( $mpd->status->state, 'play', 'play() starts playback' );
35 $mpd->play(2);
36 is( $mpd->status->song,       2, 'play() can start playback at a given song' );
38 $mpd->play(0);
39 $mpd->pause;
40 sleep 1;
41 $mpd->playid;
42 is( $mpd->status->state, 'play', 'playid() starts playback' );
43 $mpd->playid(1);
44 is( $mpd->status->songid,     1, 'playid() can start playback at a given song' );
48 # testing pause.
49 $mpd->pause(1);
50 is( $mpd->status->state, 'pause', 'pause() forces playback pause' );
51 $mpd->pause(0);
52 is( $mpd->status->state, 'play', 'pause() can force playback resume' );
53 $mpd->pause;
54 is( $mpd->status->state, 'pause', 'pause() toggles to pause' );
55 $mpd->pause;
56 is( $mpd->status->state, 'play', 'pause() toggles to play' );
60 # testing stop.
61 $mpd->stop;
62 is( $mpd->status->state, 'stop', 'stop() forces full stop' );
66 # testing prev / next.
67 $mpd->play(1); $mpd->pause;
68 $mpd->next;
69 is( $mpd->status->song, 2, 'next() changes track to next one' );
70 $mpd->prev;
71 is( $mpd->status->song, 1, 'prev() changes track to previous one' );
75 # testing seek / seekid.
76 TODO: {
77     local $TODO = "detection method doesn't always work - depends on timing";
78     $mpd->pause(1);
79     $mpd->seek( 1, 2 );
80     is( $mpd->status->song,     2, 'seek() can change the current track' );
81     is( $mpd->status->time->sofar_secs, 1, 'seek() seeks in the song' );
82     $mpd->seek;
83     is( $mpd->status->time->sofar_secs, 0, 'seek() defaults to beginning of song' );
84     $mpd->seek(1);
85     is( $mpd->status->time->sofar_secs, 1, 'seek() defaults to current song ' );
88     $mpd->seekid( 1, 1 );
89     is( $mpd->status->songid,   1, 'seekid() can change the current track' );
90     is( $mpd->status->time->sofar_secs, 1, 'seekid() seeks in the song' );
91     $mpd->seekid;
92     is( $mpd->status->time->sofar_secs, 0, 'seekid() defaults to beginning of song' );
93     $mpd->seekid(1);
94     is( $mpd->status->time->sofar_secs, 1, 'seekid() defaults to current song' );
99 exit;