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
28 # are we able to test module?
29 eval 'use Audio::MPD::Test';
30 plan skip_all => $@ if $@ =~ s/\n+Compilation failed.*//s;
33 my $mpd = Audio::MPD->new;
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' )
61 is( $items[0]->title, 'ok-title', 'first song reported first' );
65 # testing song insertion.
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.
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
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;
99 is( $mpd->status->playlistlength, 0, 'clear() leaves 0 songs' );
100 isnt( $mpd->status->playlistlength, $nb, 'clear() changes playlist length' );
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
111 is( $mpd->status->playlistlength, 1, 'crop() leaves only one song' );
117 $pl->add( 'title.ogg' );
118 $pl->add( 'dir1/title-artist-album.ogg' );
119 $pl->add( 'dir1/title-artist.ogg' );
120 my $vers = $mpd->status->playlist;
122 is( $mpd->status->playlist, $vers+1, 'shuffle() changes playlist version' );
128 $pl->add( 'title.ogg' );
129 $pl->add( 'dir1/title-artist-album.ogg' );
130 $pl->add( 'dir1/title-artist.ogg' );
132 is( ($pl->as_items)[2]->title, 'ok-title', 'swap() changes songs' );
138 $pl->add( 'title.ogg' );
139 $pl->add( 'dir1/title-artist-album.ogg' );
140 $pl->add( 'dir1/title-artist.ogg' );
141 @items = $pl->as_items;
142 $pl->swapid($items[0]->id,$items[2]->id);
143 is( ($pl->as_items)[2]->title, 'ok-title', 'swapid() changes songs' );