[project @ 5726]
[audio-mpd.git] / t / 24-info.t
blob917feab2f8a406e950186c0102c034f6d317c3c8
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 => 24;
33 my $mpd = Audio::MPD->new;
34 my $song;
37 # testing stats
38 $mpd->updatedb;
39 $mpd->add( 'title.ogg' );
40 $mpd->add( 'dir1/title-artist-album.ogg' );
41 $mpd->add( 'dir1/title-artist.ogg' );
42 my $stats = $mpd->stats;
43 is( $stats->{artists},      1, 'one artist in the database' );
44 is( $stats->{albums},       1, 'one album in the database' );
45 is( $stats->{songs},        4, '4 songs in the database' );
46 is( $stats->{playtime},     0, 'already played 0 seconds' );
47 is( $stats->{db_playtime},  8, '8 seconds worth of music in the db' );
48 isnt( $stats->{uptime}, undef, 'uptime is defined' );
49 isnt( $stats->{db_update},  0, 'database has been updated' );
53 # testing status.
54 $mpd->play;
55 $mpd->pause;
56 my $status = $mpd->status;
57 isa_ok( $status, 'Audio::MPD::Status', 'status return an Audio::MPD::Status object' );
61 # testing current song.
62 $song = $mpd->current;
63 isa_ok( $song, 'Audio::MPD::Item::Song', 'current return an Audio::MPD::Item::Song object' );
67 # testing playlist retrieval.
68 my $list = $mpd->playlist;
69 isa_ok( $list, 'ARRAY', 'playlist returns an array reference' );
70 isa_ok( $_, 'Audio::MPD::Item::Song', 'playlist returns Audio::MPD::Item::Song objects' )
71     for @$list;
72 is( $list->[0]->title, 'ok-title', 'first song reported first' );
76 # testing playlist changes retrieval.
77 my @list = $mpd->pl_changes(0);
78 isa_ok( $_, 'Audio::MPD::Item::Song', 'pl_changes() returns Audio::MPD::Item::Song objects' )
79     for @$list;
80 is( $list->[0]->title, 'ok-title', 'first song reported first' );
84 # testing song.
85 $song = $mpd->song(1);
86 isa_ok( $song, 'Audio::MPD::Item::Song', 'song() returns an Audio::MPD::Item::Song object' );
87 is( $song->file, 'dir1/title-artist-album.ogg', 'song() returns the wanted song' );
88 $song = $mpd->song; # default to current song
89 is( $song->file, 'title.ogg', 'song() defaults to current song' );
93 # testing songid.
94 $song = $mpd->songid(1);
95 isa_ok( $song, 'Audio::MPD::Item::Song', 'songid() returns an Audio::MPD::Item::Song object' );
96 is( $song->file, 'dir1/title-artist-album.ogg', 'songid() returns the wanted song' );
97 $song = $mpd->songid; # default to current song
98 is( $song->file, 'title.ogg', 'songid() defaults to current song' );
101 exit;