[project @ 5628]
[audio-mpd.git] / t / 20-connection.t
blobb46884c30e2747032ed834c1608c1f3647d5d56e
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 => 7;
34 my $mpd = Audio::MPD->new;
35 isa_ok($mpd, 'Audio::MPD');
39 # testing error during socket creation.
40 $mpd->_port( 16600 );
41 eval { $mpd->_send_command( "ping\n" ) };
42 like($@, qr/^Could not create socket/, 'error during socket creation');
43 $mpd->_port( 6600 );
46 # testing connection to a non-mpd server - here, we'll try to connect
47 # to a sendmail server.
48 my $sendmail_running = grep { /:25\s.*LISTEN/ } qx[ netstat -an ];
49 SKIP: {
50     skip 'need some sendmail server running', 1 unless $sendmail_running;
51     $mpd->_port( 25 );
52     eval { $mpd->ping };
53     like($@, qr/^Not a mpd server - welcome string was:/, 'wrong server');
55 $mpd->_port( 6600 );
59 # testing password sending.
60 $mpd->_password( 'wrong-password' );
61 eval { $mpd->ping };
62 like($@, qr/\{password\} incorrect password/, 'wrong password');
64 $mpd->_password('fulladmin');
65 eval { $mpd->ping };
66 is($@, '', 'correct password sent');
67 $mpd->_password('');
71 # testing command.
72 eval { $mpd->_send_command( "bad command\n" ); };
73 like($@, qr/unknown command "bad"/, 'unknown command');
75 my @output = $mpd->_send_command( "status\n" );
76 isnt(scalar @output, 0, 'commands return stuff');
79 exit;