Sync file with libnet-1.0901-tobe
[p5sagit/p5-mst-13.2.git] / lib / Net / t / config.t
1 #!./perl -w
2
3 BEGIN {
4     if ($ENV{PERL_CORE}) {
5         chdir 't' if -d 't';
6         @INC = '../lib';
7     }
8 }
9
10 (my $libnet_t = __FILE__) =~ s/config.t/libnet_t.pl/;
11 require $libnet_t;
12
13 print "1..10\n";
14
15 use Net::Config;
16 ok( exists $INC{'Net/Config.pm'}, 'Net::Config should have been used' );
17 ok( keys %NetConfig, '%NetConfig should be imported' );
18
19 undef $NetConfig{'ftp_firewall'};
20 is( Net::Config->requires_firewall(), 0, 
21         'requires_firewall() should return 0 without ftp_firewall defined' );
22
23 $NetConfig{'ftp_firewall'} = 1;
24 is( Net::Config->requires_firewall(''), -1,
25         '... should return -1 without a valid hostname' );
26
27 delete $NetConfig{'local_netmask'};
28 is( Net::Config->requires_firewall('127.0.0.1'), 0,
29         '... should return 0 without local_netmask defined' );
30
31 $NetConfig{'local_netmask'} = '127.0.0.1/24';
32 is( Net::Config->requires_firewall('127.0.0.1'), 0,
33         '... should return false if host is within netmask' );
34 is( Net::Config->requires_firewall('192.168.10.0'), 1,
35         '... should return true if host is outside netmask' );
36
37 # now try more netmasks
38 $NetConfig{'local_netmask'} = [ '127.0.0.1/24', '10.0.0.0/8' ];
39 is( Net::Config->requires_firewall('10.10.255.254'), 0,
40         '... should find success with mutiple local netmasks' );
41 is( Net::Config->requires_firewall('192.168.10.0'), 1,
42         '... should handle failure with multiple local netmasks' );
43
44 is( \&Net::Config::is_external, \&Net::Config::requires_firewall,
45         'is_external() should be an alias for requires_firewall()' );