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.
17 # are we able to test module?
18 eval 'use Audio::MPD::Test';
19 plan skip_all => $@ if $@ =~ s/\n+Compilation failed.*//s;
25 # testing constructor defaults.
26 $mpd = Audio::MPD->new;
27 is( $mpd->_host, 'localhost', 'host defaults to localhost' );
28 is( $mpd->_port, 6600, 'port defaults to 6600' );
29 is( $mpd->_password, '', 'password default to empty string' );
30 isa_ok( $mpd, 'Audio::MPD', 'object creation' );
34 # changing fake mpd config to test constructor.
37 customize_test_mpd_configuration($port);
42 # testing constructor params.
43 $mpd = Audio::MPD->new( host=>'127.0.0.1', port=>$port, password=>'foobar' );
44 is( $mpd->_host, '127.0.0.1', 'host set to param' );
45 is( $mpd->_port, $port, 'port set to param' );
46 is( $mpd->_password, 'foobar', 'password set to param' );
49 # testing constructor environment defaults...
50 $ENV{MPD_HOST} = '127.0.0.1';
51 $ENV{MPD_PORT} = $port;
52 $ENV{MPD_PASSWORD} = 'foobar';
53 $mpd = Audio::MPD->new;
54 is( $mpd->_host, $ENV{MPD_HOST}, 'host default to $ENV{MPD_HOST}' );
55 is( $mpd->_port, $ENV{MPD_PORT}, 'port default to $ENV{MPD_PORT}' );
56 is( $mpd->_password, $ENV{MPD_PASSWORD}, 'password default to $ENV{MPD_PASSWORD}' );
58 delete $ENV{MPD_HOST};
59 delete $ENV{MPD_PASSWORD};
60 $ENV{MPD_HOST} = 'foobar@127.0.0.1';
61 is( $mpd->_host, '127.0.0.1', 'host detected when $ENV{MPD_HOST} is passwd@host' );
62 is( $mpd->_password, 'foobar', 'password detected when $ENV{MPD_HOST} is passwd@host' );
64 $mpd = Audio::MPD->new;
66 delete $ENV{MPD_HOST};
67 delete $ENV{MPD_PORT};
71 # testing connection type
72 $mpd = Audio::MPD->new( port=>16600,conntype=>$REUSE );
76 isa_ok( $mpd->_socket, 'IO::Socket', 'socket is created and retained' );