extended copyright info to 2009
[audio-mpd.git] / t / 20-connection.t
blob564f61f817e0894607dc086d17d82455ee51df55
1 #!perl
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.
11 use strict;
12 use warnings;
14 use Audio::MPD;
15 use Test::More;
17 # are we able to test module?
18 eval 'use Audio::MPD::Test';
19 plan skip_all => $@ if $@ =~ s/\n+Compilation failed.*//s;
21 plan tests => 18;
23 my $mpd = Audio::MPD->new;
24 isa_ok($mpd, 'Audio::MPD');
28 # testing error during socket creation.
29 $mpd->_port( 16600 );
30 eval { $mpd->_send_command( "ping\n" ) };
31 like($@, qr/^Could not create socket/, 'error during socket creation');
32 $mpd->_port( 6600 );
35 # testing connection to a non-mpd server - here, we'll try to connect
36 # to a sendmail server.
37 my $sendmail_running = grep { /:25\s.*LISTEN/ } qx[ netstat -an ];
38 SKIP: {
39     skip 'need some sendmail server running', 1 unless $sendmail_running;
40     $mpd->_port( 25 );
41     eval { $mpd->ping };
42     like($@, qr/^Not a mpd server - welcome string was:/, 'wrong server');
44 $mpd->_port( 6600 );
48 # testing password sending.
49 $mpd->_password( 'wrong-password' );
50 eval { $mpd->ping };
51 like($@, qr/\{password\} incorrect password/, 'wrong password');
53 $mpd->_password('fulladmin');
54 eval { $mpd->ping };
55 is($@, '', 'correct password sent');
56 $mpd->_password('');
60 # testing command.
61 eval { $mpd->_send_command( "bad command\n" ); };
62 like($@, qr/unknown command "bad"/, 'unknown command');
64 my @output = $mpd->_send_command( "status\n" );
65 isnt(scalar @output, 0, 'commands return stuff');
69 # testing _cooked_command_as_items
70 my @items = $mpd->_cooked_command_as_items( "lsinfo\n" );
71 isa_ok( $_, 'Audio::MPD::Common::Item', '_cooked_command_as_items return items' ) for @items;
75 # testing _cooked_command_strip_first_field
76 my @list = $mpd->_cooked_command_strip_first_field( "stats\n" );
77 unlike( $_, qr/\D/, '_cooked_command_strip_first_field return only 2nd field' ) for @list;
78 # stats return numerical data as second field.
80 exit;