[project @ 6168]
[poe-component-client-mpd.git] / t / 40-collection.t
blob16f3b725f050ae26adb7f39b51ef994fb8d3dbb0
1 #!perl
3 # This file is part of POE::Component::Client::MPD.
4 # Copyright (c) 2007 Jerome Quelin, all rights reserved.
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 POE qw[ Component::Client::MPD::Message ];
26 use Readonly;
27 use Test::More;
30 our $nbtests = 2;
31 our @tests   = (
32     # [ 'event', [ $arg1, $arg2, ... ], $answer_back, \&check_results ]
33     [ 'coll.all_files', [], $SEND, \&check_all_files ],
37 # are we able to test module?
38 eval 'use POE::Component::Client::MPD::Test';
39 plan skip_all => $@ if $@ =~ s/\n+BEGIN failed--compilation aborted.*//s;
43 sub check_all_files {
44     my $list = $_[0]->data;
45     is( scalar @$list, 4, 'all_files return the pathes' );
46     like( $list->[0], qr/\.ogg$/, 'all_files return strings' );
50 __END__
52 my $mpd = POE::Component::Client::MPD->spawn;
53 my @list;
57 # testing collection accessor.
58 my $coll = $mpd->collection;
59 isa_ok( $coll, 'Audio::MPD::Collection',
60         'collection return an Audio::MPD::Collection object' );
64 # testing all_items.
65 @list = $coll->all_items;
66 is( scalar @list, 6, 'all_items return all 6 items' );
67 isa_ok( $_, 'Audio::MPD::Item', 'all_items return AMI objects' )
68     for @list;
69 @list = $coll->all_items( 'dir1' );
70 is( scalar @list, 3, 'all_items can be restricted to a subdir' );
71 is( $list[0]->directory, 'dir1', 'all_items return a subdir first' );
72 is( $list[1]->artist, 'dir1-artist', 'all_items can be restricted to a subdir' );
76 # testing all_items_simple.
77 @list = $coll->all_items_simple;
78 is( scalar @list, 6, 'all_items_simple return all 6 items' );
79 isa_ok( $_, 'Audio::MPD::Item', 'all_items_simple return AMI objects' )
80     for @list;
81 @list = $coll->all_items_simple( 'dir1' );
82 is( scalar @list, 3, 'all_items_simple can be restricted to a subdir' );
83 is( $list[0]->directory, 'dir1', 'all_items_simple return a subdir first' );
84 is( $list[1]->artist, undef, 'all_items_simple does not return full tags' );
88 # testing items_in_dir.
89 @list = $coll->items_in_dir;
90 is( scalar @list, 3, 'items_in_dir defaults to root' );
91 isa_ok( $_, 'Audio::MPD::Item', 'items_in_dir return AMI objects' ) for @list;
92 @list = $coll->items_in_dir( 'dir1' );
93 is( scalar @list, 2, 'items_in_dir can take a param' );
97 # testing all_songs.
98 @list = $coll->all_songs;
99 is( scalar @list, 4, 'all_songs return all 4 songs' );
100 isa_ok( $_, 'Audio::MPD::Item::Song', 'all_items return AMIS objects' ) for @list;
101 @list = $coll->all_songs( 'dir1' );
102 is( scalar @list, 2, 'all_songs can be restricted to a subdir' );
103 is( $list[0]->artist, 'dir1-artist', 'all_songs can be restricted to a subdir' );
107 # testing all_albums.
108 @list = $coll->all_albums;
109 is( scalar @list, 1, 'all_albums return the albums' );
110 is( $list[0], 'our album', 'all_albums return strings' );
114 # testing all_artists.
115 @list = $coll->all_artists;
116 is( scalar @list, 1, 'all_artists return the artists' );
117 is( $list[0], 'dir1-artist', 'all_artists return strings' );
121 # testing all_titles.
122 @list = $coll->all_titles;
123 is( scalar @list, 3, 'all_titles return the titles' );
124 like( $list[0], qr/-title$/, 'all_titles return strings' );
129 # testing song.
130 my $path = 'dir1/title-artist-album.ogg';
131 my $song = $coll->song($path);
132 isa_ok( $song, 'Audio::MPD::Item::Song', 'song return an AMI::Song object' );
133 is( $song->file, $path, 'song return the correct song' );
134 is( $song->title, 'foo-title', 'song return a full AMI::Song' );
138 # testing songs_with_filename_partial.
139 @list = $coll->songs_with_filename_partial('album');
140 isa_ok( $_, 'Audio::MPD::Item::Song', 'songs_with_filename_partial return AMI::Song objects' )
141     for @list;
142 like( $list[0]->file, qr/album/, 'songs_with_filename_partial return the correct song' );
146 # testing albums_by_artist.
147 @list = $coll->albums_by_artist( 'dir1-artist' );
148 is( scalar @list, 1, 'albums_by_artist return the album' );
149 is( $list[0], 'our album', 'albums_by_artist return plain strings' );
153 # testing songs_by_artist.
154 @list = $coll->songs_by_artist( 'dir1-artist' );
155 is( scalar @list, 2, 'songs_by_artist return all the songs found' );
156 isa_ok( $_, 'Audio::MPD::Item::Song', 'songs_by_artist return AMI::Songs' ) for @list;
157 is( $list[0]->artist, 'dir1-artist', 'songs_by_artist return correct objects' );
161 # testing songs_by_artist_partial.
162 @list = $coll->songs_by_artist_partial( 'artist' );
163 is( scalar @list, 2, 'songs_by_artist_partial return all the songs found' );
164 isa_ok( $_, 'Audio::MPD::Item::Song', 'songs_by_artist_partial return AMI::Songs' ) for @list;
165 like( $list[0]->artist, qr/artist/, 'songs_by_artist_partial return correct objects' );
169 # testing songs_from_album.
170 @list = $coll->songs_from_album( 'our album' );
171 is( scalar @list, 2, 'songs_from_album return all the songs found' );
172 isa_ok( $_, 'Audio::MPD::Item::Song', 'songs_from_album return AMI::Songs' ) for @list;
173 is( $list[0]->album, 'our album', 'songs_from_album_partial return correct objects' );
177 # testing songs_from_album_partial.
178 @list = $coll->songs_from_album_partial( 'album' );
179 is( scalar @list, 2, 'songs_from_album_partial return all the songs found' );
180 isa_ok( $_, 'Audio::MPD::Item::Song', 'songs_from_album_partial return AMI::Songs' ) for @list;
181 like( $list[0]->album, qr/album/, 'songs_from_album_partial return correct objects' );
185 # testing songs_with_title.
186 @list = $coll->songs_with_title( 'ok-title' );
187 is( scalar @list, 1, 'songs_with_title return all the songs found' );
188 isa_ok( $_, 'Audio::MPD::Item::Song', 'songs_with_title return AMI::Songs' ) for @list;
189 is( $list[0]->title, 'ok-title', 'songs_with_title return correct objects' );
193 # testing songs_with_title_partial.
194 @list = $coll->songs_with_title_partial( 'title' );
195 is( scalar @list, 3, 'songs_with_title_partial return all the songs found' );
196 isa_ok( $_, 'Audio::MPD::Item::Song', 'songs_with_title_partial return AMI::Songs' ) for @list;
197 like( $list[0]->title, qr/title/, 'songs_with_title_partial return correct objects' );
200 exit;