[project @ 5840]
[audio-mpd.git] / t / 40-playlist.t
blob5b0ef1971d61cda7ce3d088ba2e9e406ac8bbb29
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 => 17;
33 my $mpd = Audio::MPD->new;
34 my ($nb, @items);
38 # testing collection accessor.
39 my $pl = $mpd->playlist;
40 isa_ok( $pl, 'Audio::MPD::Playlist',
41         'playlist return an Audio::MPD::Playlist object' );
45 # testing playlist retrieval.
46 $pl->add( 'title.ogg' );
47 $pl->add( 'dir1/title-artist-album.ogg' );
48 $pl->add( 'dir1/title-artist.ogg' );
49 @items = $pl->as_items;
50 isa_ok( $_, 'Audio::MPD::Item::Song',
51         'as_items() returns Audio::MPD::Item::Song objects' ) for @items;
52 is( $items[0]->title, 'ok-title', 'first song reported first' );
56 # testing playlist changes retrieval.
57 @items = $pl->items_changed_since(0);
58 isa_ok( $_, 'Audio::MPD::Item::Song',
59         'items_changed_since() returns Audio::MPD::Item::Song objects' )
60     for @items;
61 is( $items[0]->title, 'ok-title', 'first song reported first' );
65 # testing song insertion.
66 $pl->clear;
67 $nb = $mpd->status->playlistlength;
68 $pl->add( 'title.ogg' );
69 $pl->add( 'dir1/title-artist-album.ogg' );
70 $pl->add( 'dir1/title-artist.ogg' );
71 is( $mpd->status->playlistlength, $nb+3, 'add() songs' );
75 # testing song removal.
76 $pl->clear;
77 $pl->add( 'title.ogg' );
78 $pl->add( 'dir1/title-artist-album.ogg' );
79 $pl->add( 'dir1/title-artist.ogg' );
80 $mpd->play(0); # to set songid
81 $mpd->stop;
82 $nb = $mpd->status->playlistlength;
83 $pl->delete( reverse 1..2 ); # reverse otherwise mpd will get it wrong
84 is( $mpd->status->playlistlength, $nb-2, 'delete() songs' );
86 $nb = $mpd->status->playlistlength;
87 $pl->deleteid( $mpd->status->songid );
88 is( $mpd->status->playlistlength, $nb-1, 'deleteid() songs' );
93 # testing playlist clearing
94 $pl->add( 'title.ogg' );
95 $pl->add( 'dir1/title-artist-album.ogg' );
96 $pl->add( 'dir1/title-artist.ogg' );
97 $nb = $mpd->status->playlistlength;
98 $pl->clear;
99 is(   $mpd->status->playlistlength, 0,   'clear() leaves 0 songs' );
100 isnt( $mpd->status->playlistlength, $nb, 'clear() changes playlist length' );
104 # testing cropping.
105 $pl->add( 'title.ogg' );
106 $pl->add( 'dir1/title-artist-album.ogg' );
107 $pl->add( 'dir1/title-artist.ogg' );
108 $mpd->play(1); # to set song
109 $mpd->stop;
110 $pl->crop;
111 is( $mpd->status->playlistlength, 1, 'crop() leaves only one song' );
115 # testing swap.
116 $pl->clear;
117 $pl->add( 'title.ogg' );
118 $pl->add( 'dir1/title-artist-album.ogg' );
119 $pl->add( 'dir1/title-artist.ogg' );
120 $pl->swap(0,2);
121 is( ($pl->as_items)[2]->title, 'ok-title', 'swap() changes' );
125 # testing swapid.
126 $pl->clear;
127 $pl->add( 'title.ogg' );
128 $pl->add( 'dir1/title-artist-album.ogg' );
129 $pl->add( 'dir1/title-artist.ogg' );
130 @items = $pl->as_items;
131 $pl->swapid($items[0]->id,$items[2]->id);
132 is( ($pl->as_items)[2]->title, 'ok-title', 'swapid() changes' );
137 exit;