[project @ 7035]
[audio-mpd.git] / t / 21-new.t
blobe378b1e3349f4bf2c1834a3c24c02e4f0f8985cb
1 #!perl
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.
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 => 10;
22 my $mpd;
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.
35 my $port = 16600;
36 stop_test_mpd();
37 customize_test_mpd_configuration($port);
38 start_test_mpd();
42 # testing constructor params.
43 $mpd = Audio::MPD->new('127.0.0.1', $port, '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}, 'port default to $ENV{MPD_PASSWORD}' );
58 delete $ENV{MPD_HOST};
59 delete $ENV{MPD_PORT};
60 delete $ENV{MPD_PASSWORD};
62 exit;