[project @ 6089]
[poe-component-client-mpd.git] / t / 42-cmds-info.t
blob0d43ea58d15f112917cb0036d5f5a2da3c64c3f1
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 = 10;
31 my @songs = qw[ title.ogg dir1/title-artist-album.ogg dir1/title-artist.ogg ];
32 our @tests   = (
33     # [ 'event', [ $arg1, $arg2, ... ], $answer_back, \&check_results ]
35 #     [ 'updatedb', [],      $DISCARD, \&check_stats  ],
36     [ 'pl.add',   \@songs, $DISCARD, \&check_stats  ],
37     [ 'stats',    [],      $SEND,    \&check_stats  ],
39     [ 'play',     [],      $DISCARD, undef          ],
40     [ 'pause',    [],      $DISCARD, undef          ],
41     [ 'status',   [],      $SEND,    \&check_status ],
43     [ 'current',  [],      $SEND,    \&check_current ],
48 # are we able to test module?
49 eval 'use POE::Component::Client::MPD::Test';
50 plan skip_all => $@ if $@ =~ s/\n+BEGIN failed--compilation aborted.*//s;
53 sub check_stats {
54     my $stats = $_[0]->data;
55     isa_ok( $stats, 'POE::Component::Client::MPD::Stats',
56             'stats() returns a pococm::stats object' );
57     is( $stats->artists,      1, 'one artist in the database' );
58     is( $stats->albums,       1, 'one album in the database' );
59     is( $stats->songs,        4, '4 songs in the database' );
60     is( $stats->playtime,     0, 'already played 0 seconds' );
61     is( $stats->db_playtime,  8, '8 seconds worth of music in the db' );
62     isnt( $stats->uptime, undef, 'uptime is defined' );
63     isnt( $stats->db_update,  0, 'database has been updated' );
66 sub check_status {
67     my $status = $_[0]->data;
68     isa_ok( $status, 'POE::Component::Client::MPD::Status',
69             'status return a pococm::status object' );
72 sub check_current {
73     my $song = $_[0]->data;
74     isa_ok( $song, 'POE::Component::Client::MPD::Item::Song',
75             'current return a POCOCM::Item::Song object' );
78 __END__
83 # testing song.
84 $song = $mpd->song(1);
85 isa_ok( $song, 'Audio::MPD::Item::Song', 'song() returns an Audio::MPD::Item::Song object' );
86 is( $song->file, 'dir1/title-artist-album.ogg', 'song() returns the wanted song' );
87 $song = $mpd->song; # default to current song
88 is( $song->file, 'title.ogg', 'song() defaults to current song' );
92 # testing songid.
93 $song = $mpd->songid(1);
94 isa_ok( $song, 'Audio::MPD::Item::Song', 'songid() returns an Audio::MPD::Item::Song object' );
95 is( $song->file, 'dir1/title-artist-album.ogg', 'songid() returns the wanted song' );
96 $song = $mpd->songid; # default to current song
97 is( $song->file, 'title.ogg', 'songid() defaults to current song' );
100 exit;