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.
15 use FindBin qw[ $Bin ];
18 # are we able to test module?
19 eval 'use Audio::MPD::Test';
20 plan skip_all => $@ if $@ =~ s/\n+Compilation failed.*//s;
24 my $mpd = Audio::MPD->new;
29 # testing collection accessor.
30 my $pl = $mpd->playlist;
31 isa_ok( $pl, 'Audio::MPD::Playlist',
32 'playlist return an Audio::MPD::Playlist object' );
36 # testing playlist retrieval.
39 'dir1/title-artist-album.ogg',
40 'dir1/title-artist.ogg' );
41 @items = $pl->as_items;
42 isa_ok( $_, 'Audio::MPD::Common::Item::Song',
43 'as_items() returns AMC::Item::Song objects' ) for @items;
44 is( $items[0]->title, 'ok-title', 'first song reported first' );
48 # testing playlist changes retrieval.
49 @items = $pl->items_changed_since(0);
50 isa_ok( $_, 'Audio::MPD::Common::Item::Song',
51 'items_changed_since() returns AMC::Item::Song objects' )
53 is( $items[0]->title, 'ok-title', 'first song reported first' );
57 # testing song insertion.
59 $nb = $mpd->status->playlistlength;
60 $pl->add( 'title.ogg' );
61 $pl->add( 'dir1/title-artist-album.ogg' );
62 $pl->add( 'dir1/title-artist.ogg' );
63 is( $mpd->status->playlistlength, $nb+3, 'add() songs' );
67 # testing song removal.
69 $pl->add( 'title.ogg' );
70 $pl->add( 'dir1/title-artist-album.ogg' );
71 $pl->add( 'dir1/title-artist.ogg' );
72 $mpd->play(0); # to set songid
74 $nb = $mpd->status->playlistlength;
75 $pl->delete( reverse 1..2 ); # reverse otherwise mpd will get it wrong
76 is( $mpd->status->playlistlength, $nb-2, 'delete() songs' );
78 $nb = $mpd->status->playlistlength;
79 $pl->deleteid( $mpd->status->songid );
80 is( $mpd->status->playlistlength, $nb-1, 'deleteid() songs' );
85 # testing playlist clearing
86 $pl->add( 'title.ogg' );
87 $pl->add( 'dir1/title-artist-album.ogg' );
88 $pl->add( 'dir1/title-artist.ogg' );
89 $nb = $mpd->status->playlistlength;
91 is( $mpd->status->playlistlength, 0, 'clear() leaves 0 songs' );
92 isnt( $mpd->status->playlistlength, $nb, 'clear() changes playlist length' );
97 $pl->add( 'title.ogg' );
98 $pl->add( 'dir1/title-artist-album.ogg' );
99 $pl->add( 'dir1/title-artist.ogg' );
100 $mpd->play(1); # to set song
103 is( $mpd->status->playlistlength, 1, 'crop() leaves only one song' );
109 $pl->add( 'title.ogg' );
110 $pl->add( 'dir1/title-artist-album.ogg' );
111 $pl->add( 'dir1/title-artist.ogg' );
112 my $vers = $mpd->status->playlist;
114 is( $mpd->status->playlist, $vers+1, 'shuffle() changes playlist version' );
120 $pl->add( 'title.ogg' );
121 $pl->add( 'dir1/title-artist-album.ogg' );
122 $pl->add( 'dir1/title-artist.ogg' );
124 is( ($pl->as_items)[2]->title, 'ok-title', 'swap() changes songs' );
130 $pl->add( 'title.ogg' );
131 $pl->add( 'dir1/title-artist-album.ogg' );
132 $pl->add( 'dir1/title-artist.ogg' );
133 @items = $pl->as_items;
134 $pl->swapid($items[0]->id,$items[2]->id);
135 is( ($pl->as_items)[2]->title, 'ok-title', 'swapid() changes songs' );
141 $pl->add( 'title.ogg' );
142 $pl->add( 'dir1/title-artist-album.ogg' );
143 $pl->add( 'dir1/title-artist.ogg' );
145 is( ($pl->as_items)[2]->title, 'ok-title', 'move() changes song' );
151 $pl->add( 'title.ogg' );
152 $pl->add( 'dir1/title-artist-album.ogg' );
153 $pl->add( 'dir1/title-artist.ogg' );
154 @items = $pl->as_items;
155 $pl->moveid($items[0]->id,2);
156 is( ($pl->as_items)[2]->title, 'ok-title', 'moveid() changes song' );
163 @items = $pl->as_items;
164 is( scalar @items, 1, 'load() adds songs' );
165 is( $items[0]->title, 'ok-title', 'load() adds the correct songs' );
171 $pl->save( 'test-jq' );
172 ok( -f "$Bin/mpd-test/playlists/test-jq.m3u", 'save() creates a playlist' );
177 $pl->rm( 'test-jq' );
178 ok( ! -f "$Bin/mpd-test/playlists/test-jq.m3u", 'rm() removes a playlist' );