[project @ 5748]
[audio-mpd.git] / t / 27-playlist.t
blobce9e282f90413630ffceb6c39894fd5633fd7357
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 => 6;
33 my $mpd = Audio::MPD->new;
34 my $nb;
37 # testing song insertion.
38 $mpd->clear;
39 $nb = $mpd->status->playlistlength;
40 $mpd->add( 'title.ogg' );
41 $mpd->add( 'dir1/title-artist-album.ogg' );
42 $mpd->add( 'dir1/title-artist.ogg' );
43 is( $mpd->status->playlistlength, $nb+3, 'adding songs' );
47 # testing song removal.
48 $mpd->clear;
49 $mpd->add( 'title.ogg' );
50 $mpd->add( 'dir1/title-artist-album.ogg' );
51 $mpd->add( 'dir1/title-artist.ogg' );
52 $mpd->play(0); # to set songid
53 $mpd->stop;
54 $nb = $mpd->status->playlistlength;
55 $mpd->delete( reverse 1..2 ); # reverse otherwise mpd will get it wrong
56 is( $mpd->status->playlistlength, $nb-2, 'delete songs' );
58 $nb = $mpd->status->playlistlength;
59 $mpd->deleteid( $mpd->status->songid );
60 is( $mpd->status->playlistlength, $nb-1, 'deleteid songs' );
65 # testing playlist clearing
66 $mpd->add( 'title.ogg' );
67 $mpd->add( 'dir1/title-artist-album.ogg' );
68 $mpd->add( 'dir1/title-artist.ogg' );
69 $nb = $mpd->status->playlistlength;
70 $mpd->clear;
71 is(   $mpd->status->playlistlength, 0,   'clearing playlist leaves 0 songs' );
72 isnt( $mpd->status->playlistlength, $nb, 'clearing songs changes playlist length' );
76 # testing cropping.
77 $mpd->add( 'title.ogg' );
78 $mpd->add( 'dir1/title-artist-album.ogg' );
79 $mpd->add( 'dir1/title-artist.ogg' );
80 $mpd->play(1); # to set song
81 $mpd->stop;
82 $mpd->crop;
83 is( $mpd->status->playlistlength, 1, 'cropping leaves only one song' );
84 # FIXME is( $mpd->status->get_current
87 exit;