3 # This file is part of Audio::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 same terms as Perl itself.
17 # are we able to test module?
18 eval 'use Audio::MPD::Test';
19 plan skip_all => $@ if $@ =~ s/\n+Compilation failed.*//s;
23 my $mpd = Audio::MPD->new;
24 isa_ok($mpd, 'Audio::MPD');
28 # testing error during socket creation.
30 eval { $mpd->_send_command( "ping\n" ) };
31 like($@, qr/^Could not create socket/, 'error during socket creation');
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 ];
39 skip 'need some sendmail server running', 1 unless $sendmail_running;
42 like($@, qr/^Not a mpd server - welcome string was:/, 'wrong server');
48 # testing password sending.
49 $mpd->_password( 'wrong-password' );
51 like($@, qr/\{password\} incorrect password/, 'wrong password');
53 $mpd->_password('fulladmin');
55 is($@, '', 'correct password sent');
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::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.